Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Prune the unnecessary use of the Unspecified class"

This reverts commit 6152654.

Conflicts:

	src/Template.py

Signed-off-by: James Abbatiello <abbeyj@gmail.com>
  • Loading branch information...
commit 40f1cc21921aa8d11692bb5309f01d87883428bf 1 parent b2e128b
R. Tyler Ballance authored abbeyj committed
Showing with 40 additions and 32 deletions.
  1. +14 −10 src/Parser.py
  2. +21 −20 src/Template.py
  3. +5 −2 src/Tests/SyntaxAndOutput.py
View
24 src/Parser.py
@@ -31,6 +31,7 @@
from Cheetah.SourceReader import SourceReader
from Cheetah import Filters
from Cheetah import ErrorCatchers
+from Cheetah.Unspecified import Unspecified
from Cheetah.Macros.I18n import I18n
# re tools
@@ -367,8 +368,8 @@ class _LowLevelParser(SourceReader):
def setSettingsManager(self, settingsManager):
self._settingsManager = settingsManager
- def setting(self, key, default=None):
- if default is None:
+ def setting(self, key, default=Unspecified):
+ if default is Unspecified:
return self._settingsManager.setting(key)
else:
return self._settingsManager.setting(key, default=default)
@@ -880,7 +881,7 @@ def getCheetahVarNameChunks(self):
def getCallArgString(self,
enclosures=[], # list of tuples (char, pos), where char is ({ or [
- useNameMapper=None):
+ useNameMapper=Unspecified):
""" Get a method/function call argument string.
@@ -888,10 +889,13 @@ def getCallArgString(self,
"""
# @@TR: this settings mangling should be removed
- if useNameMapper is not None:
+ if useNameMapper is not Unspecified:
useNameMapper_orig = self.setting('useNameMapper')
self.setSetting('useNameMapper', useNameMapper)
- if not enclosures:
+
+ if enclosures:
+ pass
+ else:
if not self.peek() == '(':
raise ParseError(self, msg="Expected '('")
startPos = self.pos()
@@ -953,7 +957,7 @@ def getCallArgString(self,
token = self.transformToken(token, beforeTokenPos)
addBit(token)
- if useNameMapper is not None:
+ if useNameMapper is not Unspecified:
self.setSetting('useNameMapper', useNameMapper_orig) # @@TR: see comment above
return ''.join(argStringBits)
@@ -1049,7 +1053,7 @@ def getExpressionParts(self,
enclosed=False,
enclosures=None, # list of tuples (char, pos), where char is ({ or [
pyTokensToBreakAt=None, # only works if not enclosed
- useNameMapper=None,
+ useNameMapper=Unspecified,
):
""" Get a Cheetah expression that includes $CheetahVars and break at
@@ -1057,7 +1061,7 @@ def getExpressionParts(self,
pyToken.
"""
- if useNameMapper is not None:
+ if useNameMapper is not Unspecified:
useNameMapper_orig = self.setting('useNameMapper')
self.setSetting('useNameMapper', useNameMapper)
@@ -1147,7 +1151,7 @@ def getExpressionParts(self,
if not self.atEnd() and self.peek() == '(':
exprBits.append(self.getCallArgString())
##
- if useNameMapper is not None:
+ if useNameMapper is not Unspecified:
self.setSetting('useNameMapper', useNameMapper_orig) # @@TR: see comment above
return exprBits
@@ -1155,7 +1159,7 @@ def getExpression(self,
enclosed=False,
enclosures=None, # list of tuples (char, pos), where # char is ({ or [
pyTokensToBreakAt=None,
- useNameMapper=None,
+ useNameMapper=Unspecified,
):
"""Returns the output of self.getExpressionParts() as a concatenated
string rather than as a list.
View
41 src/Template.py
@@ -72,6 +72,8 @@ def release(self):
from Cheetah.CacheRegion import CacheRegion
from Cheetah.Utils.WebInputMixin import _Converter, _lookup, NonNumericInputError
+from Cheetah.Unspecified import Unspecified
+
# Decide whether to use the file modification time in file's cache key
__checkFileMtime = True
def checkFileMtime(value):
@@ -125,10 +127,9 @@ def _genUniqueModuleName(baseModuleName):
try:
from Cheetah._template import valOrDefault
except ImportError:
- raise
# used in Template.compile()
def valOrDefault(val, default):
- if val is not None:
+ if val is not Unspecified:
return val
return default
@@ -343,20 +344,20 @@ def _getCompilerSettings(klass, source=None, file=None):
def compile(klass, source=None, file=None,
returnAClass=True,
- compilerSettings=None,
- compilerClass=None,
+ compilerSettings=Unspecified,
+ compilerClass=Unspecified,
moduleName=None,
- className=None,
- mainMethodName=None,
- baseclass=None,
- moduleGlobals=None,
- cacheCompilationResults=None,
- useCache=None,
- preprocessors=None,
- cacheModuleFilesForTracebacks=None,
- cacheDirForModuleFiles=None,
+ className=Unspecified,
+ mainMethodName=Unspecified,
+ baseclass=Unspecified,
+ moduleGlobals=Unspecified,
+ cacheCompilationResults=Unspecified,
+ useCache=Unspecified,
+ preprocessors=Unspecified,
+ cacheModuleFilesForTracebacks=Unspecified,
+ cacheDirForModuleFiles=Unspecified,
commandlineopts=None,
- keepRefToGeneratedCode=None,
+ keepRefToGeneratedCode=Unspecified,
):
"""
@@ -1033,7 +1034,7 @@ def __init__(self, source=None,
filtersLib=Filters,
errorCatcher=None,
- compilerSettings=None, # control the behaviour of the compiler
+ compilerSettings=Unspecified, # control the behaviour of the compiler
_globalSetVars=None, # used internally for #include'd templates
_preBuiltSearchList=None # used internally for #include'd templates
):
@@ -1166,7 +1167,7 @@ def __init__(self, source=None,
vtc(errorCatcher, 'errorCatcher', (N,S,C,type), 'string, class or None',
ErrorCatchers.ErrorCatcher,
'(if class, must be subclass of Cheetah.ErrorCatchers.ErrorCatcher)')
- if compilerSettings is not None:
+ if compilerSettings is not Unspecified:
vt(compilerSettings, 'compilerSettings', (D,), 'dictionary')
except TypeError:
@@ -1332,7 +1333,7 @@ def shutdown(self):
## utility functions ##
- def getVar(self, varName, default=None, autoCall=True):
+ def getVar(self, varName, default=Unspecified, autoCall=True):
"""Get a variable from the searchList. If the variable can't be found
in the searchList, it returns the default value if one was given, or
raises NameMapper.NotFound.
@@ -1341,7 +1342,7 @@ def getVar(self, varName, default=None, autoCall=True):
try:
return valueFromSearchList(self.searchList(), varName.replace('$',''), autoCall)
except NotFound:
- if default is not None:
+ if default is not Unspecified:
return default
else:
raise
@@ -1503,7 +1504,7 @@ def _initCheetahInstance(self,
if self._CHEETAH_cacheStore is not None:
self._CHEETAH__cacheStore = self._CHEETAH_cacheStore
- def _compile(self, source=None, file=None, compilerSettings=None,
+ def _compile(self, source=None, file=None, compilerSettings=Unspecified,
moduleName=None, mainMethodName=None):
"""Compile the template. This method is automatically called by
Template.__init__ it is provided with 'file' or 'source' args.
@@ -1511,7 +1512,7 @@ def _compile(self, source=None, file=None, compilerSettings=None,
USERS SHOULD *NEVER* CALL THIS METHOD THEMSELVES. Use Template.compile
instead.
"""
- if compilerSettings is None:
+ if compilerSettings is Unspecified:
compilerSettings = self._getCompilerSettings(source, file) or {}
mainMethodName = mainMethodName or self._CHEETAH_defaultMainMethodName
self._fileMtime = None
View
7 src/Tests/SyntaxAndOutput.py
@@ -33,6 +33,9 @@
from Cheetah.Compiler import Compiler, DEFAULT_COMPILER_SETTINGS
import unittest_local_copy as unittest
+class Unspecified(object):
+ pass
+
majorVer, minorVer = sys.version_info[0], sys.version_info[1]
versionTuple = (majorVer, minorVer)
@@ -141,9 +144,9 @@ def searchList(self):
def verify(self, input, expectedOutput,
inputEncoding=None,
outputEncoding=None,
- convertEOLs=None):
+ convertEOLs=Unspecified):
if self._EOLreplacement:
- if convertEOLs is None:
+ if convertEOLs is Unspecified:
convertEOLs = self.convertEOLs
if convertEOLs:
input = input.replace('\n', self._EOLreplacement)
Please sign in to comment.
Something went wrong with that request. Please try again.