Permalink
Browse files

Merge branch 'next' of git://github.com/rtyler/cheetah into next

  • Loading branch information...
2 parents e658b4b + da52de5 commit e4705b12f2d53202a9a7ef4b8e5cc084f11c83fd @abbeyj abbeyj committed Aug 25, 2009
View
@@ -33,24 +33,30 @@
import os
import os.path
+import sys
from distutils.core import Extension
-## we only assume the presence of a c compiler on Posix systems, NT people will
-# have to enable this manually.
-if os.name == 'posix':
- ext_modules=[Extension("Cheetah._namemapper", [os.path.join("cheetah" ,"_namemapper.c")]
- )
- ]
-else:
- ext_modules=[]
-
+ext_modules=[
+ Extension("Cheetah._namemapper",
+ [os.path.join('cheetah', 'c', '_namemapper.c')]),
+ Extension("Cheetah._verifytype",
+ [os.path.join('cheetah', 'c', '_verifytype.c')]),
+ Extension("Cheetah._filters",
+ [os.path.join('cheetah', 'c', '_filters.c')]),
+ Extension('Cheetah._template',
+ [os.path.join('cheetah', 'c', '_template.c')]),
+ ]
## Data Files and Scripts
scripts = ['bin/cheetah-compile',
'bin/cheetah',
]
-data_files = ['recursive: cheetah *.tmpl *.txt LICENSE README TODO CHANGES',
- ]
+
+if sys.platform == "win32":
+ scripts.append('bin/cheetah.bat')
+
+data_files = ['recursive: src *.tmpl *.txt LICENSE README TODO CHANGES',]
+
if not os.getenv('CHEETAH_INSTALL_WITHOUT_SETUPTOOLS'):
try:
from setuptools import setup
View
@@ -0,0 +1 @@
+cheetah.bat -crlf
View
@@ -0,0 +1 @@
+@"%~dp0..\python" "%~dpn0" %*
View
@@ -22,30 +22,26 @@ def __init__(self, template=None):
"""
self.template = template
- def filter(self, val,
- #encoding='utf8',
- encoding=None,
- str=str,
- **kw):
- """Pass Unicode strings through unmolested, unless an encoding is specified.
- """
+ def filter(self, val, encoding=None, str=str, **kw):
+ '''
+ Pass Unicode strings through unmolested, unless an encoding is specified.
+ '''
+ if val is None:
+ return u''
if isinstance(val, unicode):
if encoding:
- filtered = val.encode(encoding)
+ return val.encode(encoding)
else:
- filtered = val
- elif val is None:
- filtered = ''
+ return val
else:
try:
- filtered = str(val)
+ return str(val)
except UnicodeEncodeError:
- filtered = unicode(val)
- return filtered
+ return unicode(val)
+ return u''
RawOrEncodedUnicode = Filter
-
class EncodeUnicode(Filter):
def filter(self, val,
encoding='utf8',
@@ -231,6 +227,7 @@ def test():
print "Unicode:", `EncodeUnicode().filter(u'aoeu12345\u1234')`
-if __name__ == "__main__": test()
+if __name__ == "__main__":
+ test()
# vim: shiftwidth=4 tabstop=4 expandtab
View
@@ -25,11 +25,6 @@
from types import StringTypes
except ImportError:
StringTypes = (types.StringType,types.UnicodeType)
-try:
- from types import BooleanType
- boolTypeAvailable = True
-except ImportError:
- boolTypeAvailable = False
try:
from threading import Lock
@@ -56,7 +51,14 @@ def release(self):
from Cheetah import ErrorCatchers # for placeholder tags
from Cheetah import Filters # the output filters
from Cheetah.convertTmplPathToModuleName import convertTmplPathToModuleName
-from Cheetah.Utils import VerifyType # Used in Template.__init__
+
+try:
+ from Cheetah._verifytype import *
+except ImportError:
+ from Cheetah.Utils import VerifyType
+ verifyType = VerifyType.VerifyType
+ verifyTypeClass = VerifyType.VerifyTypeClass
+
from Cheetah.Utils.Misc import checkKeywords # Used in Template.__init__
from Cheetah.Utils.Indenter import Indenter # Used in Template.__init__ and for
# placeholders
@@ -117,11 +119,14 @@ def _genUniqueModuleName(baseModuleName):
# This is only relavent to templates used as CGI scripts.
_formUsedByWebInput = None
-# used in Template.compile()
-def valOrDefault(val, default):
- if val is not Unspecified:
- return val
- return default
+try:
+ from Cheetah._template import valOrDefault
+except ImportError:
+ # used in Template.compile()
+ def valOrDefault(val, default):
+ if val is not Unspecified:
+ return val
+ return default
def updateLinecache(filename, src):
import linecache
@@ -592,74 +597,70 @@ def __str__(self): return self.respond()
##################################################
## normalize and validate args
try:
- vt = VerifyType.VerifyType
- vtc = VerifyType.VerifyTypeClass
+ vt = verifyType
+ vtc = verifyTypeClass
N = types.NoneType; S = types.StringType; U = types.UnicodeType
D = types.DictType; F = types.FileType
C = types.ClassType; M = types.ModuleType
- I = types.IntType
+ I = types.IntType; B = types.BooleanType
- if boolTypeAvailable:
- B = types.BooleanType
-
- vt(source, 'source', [N,S,U], 'string or None')
- vt(file, 'file',[N,S,U,F], 'string, file-like object, or None')
+ IB = (I, B)
+ NS = (N, S)
+
+ vt(source, 'source', (N,S,U), 'string or None')
+ vt(file, 'file',(N,S,U,F), 'string, file-like object, or None')
baseclass = valOrDefault(baseclass, klass._CHEETAH_defaultBaseclassForTemplates)
if isinstance(baseclass, Template):
baseclass = baseclass.__class__
- vt(baseclass, 'baseclass', [N,S,C,type], 'string, class or None')
+ vt(baseclass, 'baseclass', (N,S,C,type), 'string, class or None')
cacheCompilationResults = valOrDefault(
cacheCompilationResults, klass._CHEETAH_cacheCompilationResults)
- if boolTypeAvailable:
- vt(cacheCompilationResults, 'cacheCompilationResults', [I,B], 'boolean')
+ vt(cacheCompilationResults, 'cacheCompilationResults', IB, 'boolean')
useCache = valOrDefault(useCache, klass._CHEETAH_useCompilationCache)
- if boolTypeAvailable:
- vt(cacheCompilationResults, 'cacheCompilationResults', [I,B], 'boolean')
+ vt(useCache, 'useCache', IB, 'boolean')
compilerSettings = valOrDefault(
compilerSettings, klass._getCompilerSettings(source, file) or {})
- vt(compilerSettings, 'compilerSettings', [D], 'dictionary')
+ vt(compilerSettings, 'compilerSettings', (D,), 'dictionary')
compilerClass = valOrDefault(compilerClass, klass._getCompilerClass(source, file))
preprocessors = valOrDefault(preprocessors, klass._CHEETAH_preprocessors)
keepRefToGeneratedCode = valOrDefault(
keepRefToGeneratedCode, klass._CHEETAH_keepRefToGeneratedCode)
- if boolTypeAvailable:
- vt(cacheCompilationResults, 'cacheCompilationResults', [I,B], 'boolean')
-
- vt(moduleName, 'moduleName', [N,S], 'string or None')
+ vt(keepRefToGeneratedCode, 'keepRefToGeneratedCode', IB, 'boolean')
+
+ vt(moduleName, 'moduleName', NS, 'string or None')
__orig_file__ = None
if not moduleName:
if file and type(file) in StringTypes:
moduleName = convertTmplPathToModuleName(file)
__orig_file__ = file
else:
moduleName = klass._CHEETAH_defaultModuleNameForTemplates
-
+
className = valOrDefault(
className, klass._CHEETAH_defaultClassNameForTemplates)
- vt(className, 'className', [N,S], 'string or None')
+ vt(className, 'className', NS, 'string or None')
className = className or moduleName
mainMethodName = valOrDefault(
mainMethodName, klass._CHEETAH_defaultMainMethodNameForTemplates)
- vt(mainMethodName, 'mainMethodName', [N,S], 'string or None')
+ vt(mainMethodName, 'mainMethodName', NS, 'string or None')
moduleGlobals = valOrDefault(
moduleGlobals, klass._CHEETAH_defaultModuleGlobalsForTemplates)
cacheModuleFilesForTracebacks = valOrDefault(
cacheModuleFilesForTracebacks, klass._CHEETAH_cacheModuleFilesForTracebacks)
- if boolTypeAvailable:
- vt(cacheModuleFilesForTracebacks, 'cacheModuleFilesForTracebacks', [I,B], 'boolean')
-
+ vt(cacheModuleFilesForTracebacks, 'cacheModuleFilesForTracebacks', IB, 'boolean')
+
cacheDirForModuleFiles = valOrDefault(
cacheDirForModuleFiles, klass._CHEETAH_cacheDirForModuleFiles)
- vt(cacheDirForModuleFiles, 'cacheDirForModuleFiles', [N,S], 'string or None')
+ vt(cacheDirForModuleFiles, 'cacheDirForModuleFiles', NS, 'string or None')
except TypeError, reason:
raise TypeError(reason)
@@ -1144,26 +1145,24 @@ def __init__(self, source=None,
D = types.DictType; F = types.FileType
C = types.ClassType; M = types.ModuleType
N = types.NoneType
- vt = VerifyType.VerifyType
- vtc = VerifyType.VerifyTypeClass
+ vt = verifyType
+ vtc = verifyTypeClass
try:
- vt(source, 'source', [N,S,U], 'string or None')
- vt(file, 'file', [N,S,U,F], 'string, file open for reading, or None')
- vtc(filter, 'filter', [S,C,type], 'string or class',
+ vt(source, 'source', (N,S,U), 'string or None')
+ vt(file, 'file', (N,S,U,F), 'string, file open for reading, or None')
+ vtc(filter, 'filter', (S,C,type), 'string or class',
Filters.Filter,
'(if class, must be subclass of Cheetah.Filters.Filter)')
- vt(filtersLib, 'filtersLib', [S,M], 'string or module',
+ vt(filtersLib, 'filtersLib', (S,M), 'string or module',
'(if module, must contain subclasses of Cheetah.Filters.Filter)')
- vtc(errorCatcher, 'errorCatcher', [N,S,C,type], 'string, class or 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:
- vt(compilerSettings, 'compilerSettings', [D], 'dictionary')
+ vt(compilerSettings, 'compilerSettings', (D,), 'dictionary')
- except TypeError, reason:
- # Re-raise the exception here so that the traceback will end in
- # this function rather than in some utility function.
- raise TypeError(reason)
+ except TypeError:
+ raise
if source is not None and file is not None:
raise TypeError("you must supply either a source string or the" +
@@ -1463,7 +1462,7 @@ def _initCheetahInstance(self,
# @@TR: consider allowing simple callables as the filter argument
self._CHEETAH__filtersLib = filtersLib
self._CHEETAH__filters = {}
- if type(filter) in StringTypes:
+ if isinstance(filter, basestring):
filterName = filter
klass = getattr(self._CHEETAH__filtersLib, filterName)
else:
@@ -1474,7 +1473,7 @@ def _initCheetahInstance(self,
self._CHEETAH__errorCatchers = {}
if errorCatcher:
- if type(errorCatcher) in StringTypes:
+ if isinstance(errorCatcher, basestring):
errorCatcherClass = getattr(ErrorCatchers, errorCatcher)
elif type(errorCatcher) == ClassType:
errorCatcherClass = errorCatcher
View
@@ -41,7 +41,3 @@
results = runner.run(unittest.TestSuite(suites))
-
-
-
-
View
@@ -1,5 +1,5 @@
-# $Id: Indenter.py,v 1.7 2006/01/08 01:09:30 tavis_rudd Exp $
-"""Indentation maker.
+"""
+Indentation maker.
@@TR: this code is unsupported and largely undocumented ...
This version is based directly on code by Robert Kuzelj
@@ -8,26 +8,15 @@
$self._CHEETAH__indenter.indent() to prevent '_indenter' being looked up on the
searchList and another one being found. The directive syntax will
soon be changed somewhat.
-
-Meta-Data
-================================================================================
-Author: Mike Orr <iron@mso.oz.net>
-License: This software is released for unlimited distribution under the
- terms of the MIT license. See the LICENSE file.
-Version: $Revision: 1.7 $
-Start Date: 2001/11/07
-Last Revision Date: $Date: 2006/01/08 01:09:30 $
"""
-__author__ = "Mike Orr <iron@mso.oz.net>"
-__revision__ = "$Revision: 1.7 $"[11:-2]
import re
import sys
def indentize(source):
return IndentProcessor().process(source)
-class IndentProcessor:
+class IndentProcessor(object):
"""Preprocess #indent tags."""
LINE_SEP = '\n'
ARGS = "args"
@@ -88,15 +77,16 @@ def process(self, _txt):
return self.LINE_SEP.join(result)
-class Indenter:
- """A class that keeps track of the current indentation level.
+class Indenter(object):
+ """
+ A class that keeps track of the current indentation level.
.indent() returns the appropriate amount of indentation.
"""
- def __init__(self):
- self.On = 1
- self.Level = 0
- self.Chars = " "*4
- self.LevelStack = []
+ On = 1
+ Level = 0
+ Chars = ' '
+ LevelStack = []
+
def on(self):
self.On = 1
def off(self):
@@ -129,6 +119,5 @@ def setChar(self, _chars):
def indent(self, _default=0):
if self.On:
return self.Chars * self.Level
- else:
- return " " * _default
+ return " " * _default
@@ -51,6 +51,7 @@ def VerifyType(arg, argname, legalTypes, ltd, errmsgExtra=''):
if type(arg) not in legalTypes:
m = _errmsg(argname, ltd, errmsgExtra)
raise TypeError(m)
+ return True
def VerifyTypeClass(arg, argname, legalTypes, ltd, klass, errmsgExtra=''):
@@ -71,6 +72,7 @@ def VerifyTypeClass(arg, argname, legalTypes, ltd, klass, errmsgExtra=''):
# Must test for "is class type" to avoid TypeError from issubclass().
m = _errmsg(argname, ltd, errmsgExtra)
raise TypeError(m)
+ return True
# @@MO: Commented until we determine whether it's useful.
#def VerifyClass(arg, argname, klass, ltd):
Oops, something went wrong.

0 comments on commit e4705b1

Please sign in to comment.