Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #10 from bukzor/master

None and empty-string are legitimate values to return from a function
  • Loading branch information...
commit f468c96602196b189c3dd99fd29773774fe83cd4 2 parents 0697042 + ddc1904
@Roguelazer Roguelazer authored
Showing with 16 additions and 11 deletions.
  1. +8 −6 cheetah/Compiler.py
  2. +6 −3 cheetah/Template.py
  3. +2 −2 cheetah/Version.py
View
14 cheetah/Compiler.py
@@ -416,9 +416,9 @@ def addFilteredChunk(self, chunk, filterArgs=None, rawExpr=None, lineCol=None):
self.addChunk("_v = %s"%chunk)
if self.setting('useFilters'):
- self.addChunk("if _v is not None: write(_filter(_v%s))"%filterArgs)
+ self.addChunk("if _v is not NO_CONTENT: write(_filter(_v%s))"%filterArgs)
else:
- self.addChunk("if _v is not None: write(str(_v))")
+ self.addChunk("if _v is not NO_CONTENT: write(str(_v))")
else:
if self.setting('useFilters'):
self.addChunk("write(_filter(%s%s))"%(chunk, filterArgs))
@@ -1102,9 +1102,9 @@ def _addAutoCleanupCode(self):
def addStop(self, expr=None):
if self.setting('autoAssignDummyTransactionToSelf'):
- empty = None
+ no_content = 'NO_CONTENT'
else:
- empty = ''
+ no_content = "''"
self.addChunk('if _dummyTrans:')
self.indent()
@@ -1113,7 +1113,7 @@ def addStop(self, expr=None):
self.dedent()
self.addChunk('else:')
self.indent()
- self.addChunk('return %r' % empty)
+ self.addChunk('return %s' % no_content)
self.dedent()
def addMethArg(self, name, defVal=None):
@@ -1664,7 +1664,7 @@ def _setupCompilerState(self):
"import types",
"from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion",
"from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple",
- "from Cheetah.Template import Template",
+ "from Cheetah.Template import Template, NO_CONTENT",
"from Cheetah.DummyTransaction import *",
"from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList",
"from Cheetah.CacheRegion import CacheRegion",
@@ -2042,3 +2042,5 @@ def moduleFooter(self):
## Make Compiler an alias for ModuleCompiler
Compiler = ModuleCompiler
+
+# vim: shiftwidth=4 tabstop=4 expandtab
View
9 cheetah/Template.py
@@ -103,6 +103,10 @@ def hashDict(d):
################################################################################
## MODULE GLOBALS AND CONSTANTS
+# Singleton object, representing no data to be written.
+# None or empty-string can be filtered into useful data, unlike NO_CONTENT.
+NO_CONTENT = object()
+
def _genUniqueModuleName(baseModuleName):
"""The calling code is responsible for concurrency locking.
"""
@@ -1409,9 +1413,8 @@ def capture(self, function, *args, **kwargs):
retval = function(*args, **kwargs)
buffer = self.transaction.response().getvalue()
- if retval is None:
- # Template functions using transactions always return an empty
- # string
+ if retval is NO_CONTENT:
+ # Template functions using transactions always return no content.
return buffer
else:
# ...but this one didn't, which means either the function is a
View
4 cheetah/Version.py
@@ -1,5 +1,5 @@
-Version = '2.4.5'
-VersionTuple = (2, 4, 5, 'development', 0)
+Version = '2.4.6'
+VersionTuple = (2, 4, 6, 'development', 0)
MinCompatibleVersion = '2.0rc6'
MinCompatibleVersionTuple = (2, 0, 0, 'candidate', 6)
Please sign in to comment.
Something went wrong with that request. Please try again.