summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@slide.com>2009-06-27 19:29:02 -0700
committerR. Tyler Ballance <tyler@slide.com>2009-06-27 19:29:02 -0700
commit61526548f802a7e1683e8fc9e3bbb400c531df98 (patch)
tree79434a68bb194f06b9487caeaa534b3b9bf37139 /src
parentcec1d6bafc43764430b19f3a69b570f63c74f642 (diff)
downloadpython-cheetah-61526548f802a7e1683e8fc9e3bbb400c531df98.tar.gz
Prune the unnecessary use of the Unspecified class
Diffstat (limited to 'src')
-rw-r--r--src/Parser.py24
-rw-r--r--src/Template.py40
-rw-r--r--src/Tests/SyntaxAndOutput.py7
3 files changed, 31 insertions, 40 deletions
diff --git a/src/Parser.py b/src/Parser.py
index 3e6e7fe..f80bd08 100644
--- a/src/Parser.py
+++ b/src/Parser.py
@@ -31,7 +31,6 @@ import traceback
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,7 +880,7 @@ class _LowLevelParser(SourceReader):
def getCallArgString(self,
enclosures=[], # list of tuples (char, pos), where char is ({ or [
- useNameMapper=Unspecified):
+ useNameMapper=None):
""" Get a method/function call argument string.
@@ -889,13 +888,10 @@ class _LowLevelParser(SourceReader):
"""
# @@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 @@ class _LowLevelParser(SourceReader):
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,7 +1049,7 @@ class _LowLevelParser(SourceReader):
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
@@ -1061,7 +1057,7 @@ class _LowLevelParser(SourceReader):
pyToken.
"""
- if useNameMapper is not Unspecified:
+ if useNameMapper is not None:
useNameMapper_orig = self.setting('useNameMapper')
self.setSetting('useNameMapper', useNameMapper)
@@ -1151,7 +1147,7 @@ class _LowLevelParser(SourceReader):
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
@@ -1159,7 +1155,7 @@ class _LowLevelParser(SourceReader):
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.
diff --git a/src/Template.py b/src/Template.py
index 5ed959f..232451b 100644
--- a/src/Template.py
+++ b/src/Template.py
@@ -72,8 +72,6 @@ from Cheetah.CacheStore import MemoryCacheStore, MemcachedCacheStore
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 @@ _formUsedByWebInput = None
# 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 @@ class Template(Servlet):
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 @@ class Template(Servlet):
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 @@ class Template(Servlet):
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 @@ class Template(Servlet):
## 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 @@ class Template(Servlet):
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,7 +1499,7 @@ class Template(Servlet):
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.
@@ -1509,7 +1507,7 @@ class Template(Servlet):
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
diff --git a/src/Tests/SyntaxAndOutput.py b/src/Tests/SyntaxAndOutput.py
index 78e0cc5..af48a98 100644
--- a/src/Tests/SyntaxAndOutput.py
+++ b/src/Tests/SyntaxAndOutput.py
@@ -33,9 +33,6 @@ from Cheetah.Parser import ParseError
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 @@ Template output mismatch:
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)