summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@slide.com>2009-06-27 22:47:05 -0700
committerR. Tyler Ballance <tyler@slide.com>2009-06-27 22:47:05 -0700
commita97aa33e964cefa6659e5bdf32b7182ad611390a (patch)
treefb30d34e9e252306c99baf24d56ae72fab95f056
parent0e6ad42e44f0a1c1d4401ca22a7ea0d2f9b3e8a1 (diff)
downloadpython-cheetah-a97aa33e964cefa6659e5bdf32b7182ad611390a.tar.gz
Revert "Prune the unnecessary use of the Unspecified class"
This reverts commit 61526548f802a7e1683e8fc9e3bbb400c531df98. Conflicts: src/Template.py
-rw-r--r--src/Parser.py24
-rw-r--r--src/Template.py41
-rw-r--r--src/Tests/SyntaxAndOutput.py7
3 files changed, 40 insertions, 32 deletions
diff --git a/src/Parser.py b/src/Parser.py
index f80bd08..3e6e7fe 100644
--- a/src/Parser.py
+++ b/src/Parser.py
@@ -31,6 +31,7 @@ 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
@@ -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 @@ class _LowLevelParser(SourceReader):
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 @@ class _LowLevelParser(SourceReader):
"""
# @@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 @@ class _LowLevelParser(SourceReader):
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 @@ class _LowLevelParser(SourceReader):
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 @@ class _LowLevelParser(SourceReader):
pyToken.
"""
- if useNameMapper is not None:
+ if useNameMapper is not Unspecified:
useNameMapper_orig = self.setting('useNameMapper')
self.setSetting('useNameMapper', useNameMapper)
@@ -1147,7 +1151,7 @@ class _LowLevelParser(SourceReader):
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 @@ class _LowLevelParser(SourceReader):
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.
diff --git a/src/Template.py b/src/Template.py
index 42e3599..2fd9c50 100644
--- a/src/Template.py
+++ b/src/Template.py
@@ -72,6 +72,8 @@ 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):
@@ -125,10 +127,9 @@ _formUsedByWebInput = None
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 @@ class Template(Servlet):
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 @@ class Template(Servlet):
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 @@ 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 None:
+ if compilerSettings is not Unspecified:
vt(compilerSettings, 'compilerSettings', (D,), 'dictionary')
except TypeError:
@@ -1332,7 +1333,7 @@ class Template(Servlet):
## 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 @@ class Template(Servlet):
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 @@ class Template(Servlet):
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 @@ class Template(Servlet):
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
diff --git a/src/Tests/SyntaxAndOutput.py b/src/Tests/SyntaxAndOutput.py
index af48a98..78e0cc5 100644
--- a/src/Tests/SyntaxAndOutput.py
+++ b/src/Tests/SyntaxAndOutput.py
@@ -33,6 +33,9 @@ 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)
@@ -141,9 +144,9 @@ Template output mismatch:
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)