Permalink
Browse files

Prune the unnecessary use of the Unspecified class

  • Loading branch information...
1 parent cec1d6b commit 61526548f802a7e1683e8fc9e3bbb400c531df98 R. Tyler Ballance committed Jun 28, 2009
Showing with 31 additions and 40 deletions.
  1. +10 −14 src/Parser.py
  2. +19 −21 src/Template.py
  3. +2 −5 src/Tests/SyntaxAndOutput.py
View
@@ -31,7 +31,6 @@
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
@@ -368,8 +367,8 @@ class _LowLevelParser(SourceReader):
def setSettingsManager(self, settingsManager):
self._settingsManager = settingsManager
- def setting(self, key, default=Unspecified):
- if default is Unspecified:
+ def setting(self, key, default=None):
+ if default is None:
return self._settingsManager.setting(key)
else:
return self._settingsManager.setting(key, default=default)
@@ -881,21 +880,18 @@ def getCheetahVarNameChunks(self):
def getCallArgString(self,
enclosures=[], # list of tuples (char, pos), where char is ({ or [
- useNameMapper=Unspecified):
+ useNameMapper=None):
""" Get a method/function call argument string.
This method understands *arg, and **kw
"""
# @@TR: this settings mangling should be removed
- if useNameMapper is not Unspecified:
+ if useNameMapper is not None:
useNameMapper_orig = self.setting('useNameMapper')
self.setSetting('useNameMapper', useNameMapper)
-
- if enclosures:
- pass
- else:
+ if not enclosures:
if not self.peek() == '(':
raise ParseError(self, msg="Expected '('")
startPos = self.pos()
@@ -957,7 +953,7 @@ def getCallArgString(self,
token = self.transformToken(token, beforeTokenPos)
addBit(token)
- if useNameMapper is not Unspecified:
+ if useNameMapper is not None:
self.setSetting('useNameMapper', useNameMapper_orig) # @@TR: see comment above
return ''.join(argStringBits)
@@ -1053,15 +1049,15 @@ def getExpressionParts(self,
enclosed=False,
enclosures=None, # list of tuples (char, pos), where char is ({ or [
pyTokensToBreakAt=None, # only works if not enclosed
- useNameMapper=Unspecified,
+ useNameMapper=None,
):
""" Get a Cheetah expression that includes $CheetahVars and break at
directive end tokens, the end of an enclosure, or at a specified
pyToken.
"""
- if useNameMapper is not Unspecified:
+ if useNameMapper is not None:
useNameMapper_orig = self.setting('useNameMapper')
self.setSetting('useNameMapper', useNameMapper)
@@ -1151,15 +1147,15 @@ def getExpressionParts(self,
if not self.atEnd() and self.peek() == '(':
exprBits.append(self.getCallArgString())
##
- if useNameMapper is not Unspecified:
+ if useNameMapper is not None:
self.setSetting('useNameMapper', useNameMapper_orig) # @@TR: see comment above
return exprBits
def getExpression(self,
enclosed=False,
enclosures=None, # list of tuples (char, pos), where # char is ({ or [
pyTokensToBreakAt=None,
- useNameMapper=Unspecified,
+ useNameMapper=None,
):
"""Returns the output of self.getExpressionParts() as a concatenated
string rather than as a list.
View
@@ -72,8 +72,6 @@ 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):
@@ -126,7 +124,7 @@ def _genUniqueModuleName(baseModuleName):
# used in Template.compile()
def valOrDefault(val, default):
- if val is not Unspecified:
+ if val is not None:
return val
return default
@@ -341,20 +339,20 @@ def _getCompilerSettings(klass, source=None, file=None):
def compile(klass, source=None, file=None,
returnAClass=True,
- compilerSettings=Unspecified,
- compilerClass=Unspecified,
+ compilerSettings=None,
+ compilerClass=None,
moduleName=None,
- className=Unspecified,
- mainMethodName=Unspecified,
- baseclass=Unspecified,
- moduleGlobals=Unspecified,
- cacheCompilationResults=Unspecified,
- useCache=Unspecified,
- preprocessors=Unspecified,
- cacheModuleFilesForTracebacks=Unspecified,
- cacheDirForModuleFiles=Unspecified,
+ className=None,
+ mainMethodName=None,
+ baseclass=None,
+ moduleGlobals=None,
+ cacheCompilationResults=None,
+ useCache=None,
+ preprocessors=None,
+ cacheModuleFilesForTracebacks=None,
+ cacheDirForModuleFiles=None,
commandlineopts=None,
- keepRefToGeneratedCode=Unspecified,
+ keepRefToGeneratedCode=None,
):
"""
@@ -1031,7 +1029,7 @@ def __init__(self, source=None,
filtersLib=Filters,
errorCatcher=None,
- compilerSettings=Unspecified, # control the behaviour of the compiler
+ compilerSettings=None, # control the behaviour of the compiler
_globalSetVars=None, # used internally for #include'd templates
_preBuiltSearchList=None # used internally for #include'd templates
):
@@ -1164,7 +1162,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 Unspecified:
+ if compilerSettings is not None:
vt(compilerSettings, 'compilerSettings', [D], 'dictionary')
except TypeError:
@@ -1330,7 +1328,7 @@ def shutdown(self):
## utility functions ##
- def getVar(self, varName, default=Unspecified, autoCall=True):
+ def getVar(self, varName, default=None, 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.
@@ -1339,7 +1337,7 @@ def getVar(self, varName, default=Unspecified, autoCall=True):
try:
return valueFromSearchList(self.searchList(), varName.replace('$',''), autoCall)
except NotFound:
- if default is not Unspecified:
+ if default is not None:
return default
else:
raise
@@ -1501,15 +1499,15 @@ def _initCheetahInstance(self,
if self._CHEETAH_cacheStore is not None:
self._CHEETAH__cacheStore = self._CHEETAH_cacheStore
- def _compile(self, source=None, file=None, compilerSettings=Unspecified,
+ def _compile(self, source=None, file=None, compilerSettings=None,
moduleName=None, mainMethodName=None):
"""Compile the template. This method is automatically called by
Template.__init__ it is provided with 'file' or 'source' args.
USERS SHOULD *NEVER* CALL THIS METHOD THEMSELVES. Use Template.compile
instead.
"""
- if compilerSettings is Unspecified:
+ if compilerSettings is None:
compilerSettings = self._getCompilerSettings(source, file) or {}
mainMethodName = mainMethodName or self._CHEETAH_defaultMainMethodName
self._fileMtime = None
@@ -33,9 +33,6 @@
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)
@@ -144,9 +141,9 @@ def searchList(self):
def verify(self, input, expectedOutput,
inputEncoding=None,
outputEncoding=None,
- convertEOLs=Unspecified):
+ convertEOLs=None):
if self._EOLreplacement:
- if convertEOLs is Unspecified:
+ if convertEOLs is None:
convertEOLs = self.convertEOLs
if convertEOLs:
input = input.replace('\n', self._EOLreplacement)

0 comments on commit 6152654

Please sign in to comment.