Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Import __builtin__ in generated template code in a compatible way wit…

…h 2 and 3
  • Loading branch information...
commit 020059f74d1fe5b4d2147718dda001e1c1ec6323 1 parent dd56eea
@rtyler authored
Showing with 17 additions and 4 deletions.
  1. +5 −2 cheetah/Compiler.py
  2. +12 −2 cheetah/Tests/NameMapper.py
View
7 cheetah/Compiler.py
@@ -266,7 +266,7 @@ def genNameMapperVar(self, nameChunks):
+ repr(defaultUseAC and useAC) + ')'
+ remainder)
else:
- pythonCode = ('VFSL([locals()]+SL+[globals(), __builtin__],'
+ pythonCode = ('VFSL([locals()]+SL+[globals(), builtin],'
'"'+ name + '",'
+ repr(defaultUseAC and useAC) + ')'
+ remainder)
@@ -1615,7 +1615,10 @@ def _setupCompilerState(self):
"import sys",
"import os",
"import os.path",
- "import __builtin__",
+ 'try:',
+ ' import builtins as builtin',
+ 'except ImportError:',
+ ' import __builtin__ as builtin',
"from os.path import getmtime, exists",
"import time",
"import types",
View
14 cheetah/Tests/NameMapper.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-
import sys
import types
import os
@@ -11,7 +10,7 @@
valueForName, valueFromSearchList, valueFromFrame, valueFromFrameOrSearchList
-class DummyClass:
+class DummyClass(object):
classVar1 = 123
def __init__(self):
@@ -518,6 +517,17 @@ class VFFSL_4(VFFSL):
del VFF, VFFSL, VFFSL_2, VFFSL_3, VFFSL_4
+class MapBuiltins(unittest.TestCase):
+ def test_int(self):
+ from Cheetah.Template import Template
+ t = Template('''
+ #def intify(val)
+ #return $int(val)
+ #end def''', compilerSettings={'useStackFrames' : False})
+ self.assertEquals(5, t.intify('5'))
+
+
+
##################################################
## if run from the command line ##
Please sign in to comment.
Something went wrong with that request. Please try again.