From 32ff74d688d0679d6271afd41f7c9677c0976fa7 Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Tue, 2 Jan 2007 07:18:21 +0000
Subject: [PATCH] - fix so that "cache_timeout" parameter is propigated

---
 CHANGES             |  1 +
 lib/mako/codegen.py | 13 ++++++++++---
 test/cache.py       | 21 +++++++++++++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES
index b26f575..5eee6da 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,7 @@ handling for the given expression.
 usage is like:  ${data | encoding('utf-8', errors='strict')}
 - removed textmate tmbundle from contrib and into separate SVN location; windows users
 cant handle those files, setuptools not very good at "pruning" certain directories
+- fix so that "cache_timeout" parameter is propigated
 
 0.1.0
 
diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py
index a0bc70a..0496614 100644
--- a/lib/mako/codegen.py
+++ b/lib/mako/codegen.py
@@ -344,15 +344,22 @@ class _GenerateRenderMethod(object):
         self.printer.writeline("__%s = %s" % (name, name))
         cachekey = node_or_pagetag.parsed_attributes.get('cache_key', repr(name))
         cacheargs = {}
-        for arg in (('cache_type', 'type'), ('cache_dir', 'data_dir')):
+        print node_or_pagetag
+        for arg in (('cache_type', 'type'), ('cache_dir', 'data_dir'), ('cache_timeout', 'timeout')):
             val = node_or_pagetag.parsed_attributes.get(arg[0], None)
             if val is not None:
-                cacheargs[arg[1]] = val
+                if arg[1] == 'timeout':
+                    cacheargs[arg[1]] = int(eval(val))
+                else:
+                    cacheargs[arg[1]] = val
             else:
                 if self.compiler.pagetag is not None:
                     val = self.compiler.pagetag.parsed_attributes.get(arg[0], None)
                     if val is not None:
-                        cacheargs[arg[1]] = val
+                        if arg[1] == 'timeout':
+                            cacheargs[arg[1]] == int(eval(val))
+                        else:
+                            cacheargs[arg[1]] = val
             
         self.printer.writeline("def %s(context, *args, **kwargs):" % name)
 
diff --git a/test/cache.py b/test/cache.py
index 345f6fe..de53743 100644
--- a/test/cache.py
+++ b/test/cache.py
@@ -144,6 +144,27 @@ class CacheTest(unittest.TestCase):
         ]
         assert m.kwargs == {'data_dir':'./test_htdocs', 'type':'dbm'}
 
+    def test_args_complete(self):
+        t = Template("""
+        <%def name="foo()" cached="True" cache_timeout="30" cache_dir="./test_htdocs" cache_type="file" cache_key='somekey'>
+            this is foo
+        </%def>
+
+        ${foo()}
+""")
+        m = self._install_mock_cache(t)
+        t.render()
+        assert m.kwargs == {'data_dir':'./test_htdocs', 'type':'file', 'timeout':30}
+        
+        
+        t2 = Template("""
+        <%page cached="True" cache_timeout="30" cache_dir="./test_htdocs" cache_type="file" cache_key='somekey'/>
+        hi
+        """)
+        m = self._install_mock_cache(t2)
+        t2.render()
+        assert m.kwargs == {'data_dir':'./test_htdocs', 'type':'file', 'timeout':30}
+
     def test_fileargs_lookup(self):
         l = lookup.TemplateLookup(cache_dir='./test_htdocs', cache_type='file')
         l.put_string("test","""
-- 
GitLab