Permalink
Browse files

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

  • Loading branch information...
2 parents 2fc2c59 + 1c42c23 commit 45f570f03abfbe929a14a7c23e2aa2a39ce152c5 R. Tyler Ballance committed Apr 17, 2009
Showing with 6,285 additions and 1,475 deletions.
  1. +3 −0 .gitignore
  2. +1 −15 BUGS
  3. +14 −3 CHANGES
  4. +3 −2 SetupConfig.py
  5. +6 −14 TODO
  6. +339 −0 contrib/editors/kde-cheetah.xml
  7. +0 −4 docs/devel_guide_src/.cvsignore
  8. +0 −1 docs/users_guide_2_src/.cvsignore
  9. +0 −4 docs/users_guide_src/.cvsignore
  10. +0 −2 src/.cvsignore
  11. +24 −59 src/CheetahWrapper.py
  12. +19 −6 src/Compiler.py
  13. +40 −0 src/DummyTransaction.py
  14. +97 −31 src/Filters.py
  15. +6 −1 src/ImportManager.py
  16. +25 −0 src/Parser.py
  17. +23 −17 src/Template.py
  18. +0 −3 src/Templates/.cvsignore
  19. +0 −2 src/Tests/.cvsignore
  20. +1 −1 src/Tests/CheetahWrapper.py
  21. +0 −55 src/Tests/FileRefresh.py
  22. +65 −0 src/Tests/Filters.py
  23. +55 −11 src/Tests/Regressions.py
  24. +1 −1 src/Tests/Template.py
  25. +21 −44 src/Tests/Test.py
  26. +73 −0 src/Tests/Unicode.py
  27. +3 −2 src/Tests/unittest_local_copy.py
  28. +28 −25 src/Tests/xmlrunner.py
  29. +0 −2 src/Tools/.cvsignore
  30. +21 −15 src/Tools/RecursiveNull.py
  31. +0 −2 src/Utils/.cvsignore
  32. +0 −2 src/Utils/optik/.cvsignore
  33. +0 −32 src/Utils/optik/__init__.py
  34. +0 −52 src/Utils/optik/errors.py
  35. +0 −354 src/Utils/optik/option.py
  36. +0 −667 src/Utils/optik/option_parser.py
  37. +304 −0 src/Utils/statprof.py
  38. +2 −2 src/Version.py
  39. +45 −44 src/_namemapper.c
  40. 0 src/contrib/__init__.py
  41. +30 −0 src/contrib/markdown/LICENSE
  42. +603 −0 src/contrib/markdown/__init__.py
  43. +95 −0 src/contrib/markdown/blockparser.py
  44. +460 −0 src/contrib/markdown/blockprocessors.py
  45. +96 −0 src/contrib/markdown/commandline.py
  46. +33 −0 src/contrib/markdown/etree_loader.py
  47. 0 src/contrib/markdown/extensions/__init__.py
  48. +95 −0 src/contrib/markdown/extensions/abbr.py
  49. +224 −0 src/contrib/markdown/extensions/codehilite.py
  50. +104 −0 src/contrib/markdown/extensions/def_list.py
  51. +49 −0 src/contrib/markdown/extensions/extra.py
  52. +117 −0 src/contrib/markdown/extensions/fenced_code.py
  53. +293 −0 src/contrib/markdown/extensions/footnotes.py
  54. +195 −0 src/contrib/markdown/extensions/headerid.py
  55. +62 −0 src/contrib/markdown/extensions/html_tidy.py
  56. +119 −0 src/contrib/markdown/extensions/imagelinks.py
  57. +468 −0 src/contrib/markdown/extensions/legacy.py
  58. +90 −0 src/contrib/markdown/extensions/meta.py
  59. +114 −0 src/contrib/markdown/extensions/rss.py
  60. +97 −0 src/contrib/markdown/extensions/tables.py
  61. +140 −0 src/contrib/markdown/extensions/toc.py
  62. +155 −0 src/contrib/markdown/extensions/wikilinks.py
  63. +274 −0 src/contrib/markdown/html4.py
  64. +371 −0 src/contrib/markdown/inlinepatterns.py
  65. +162 −0 src/contrib/markdown/odict.py
  66. +77 −0 src/contrib/markdown/postprocessors.py
  67. +214 −0 src/contrib/markdown/preprocessors.py
  68. +329 −0 src/contrib/markdown/treeprocessors.py
View
@@ -1,3 +1,6 @@
*.pyc
*.swp
*.so
+www/*.html
+build
+*.py.bak
View
16 BUGS
@@ -1,16 +1,2 @@
-Known Bugs in Cheetah
---------------------------
- - See the file CHANGES for a list of bugs that have been resolved.
- - Developers: if a bug was significant and affected a released version of
- Cheetah, be sure to note its fix in the CHANGES file!
---------------------------
-
-Dict method bug
----------------
-Do not use placeholder names identical to Python dict methods, or Cheetah will
-return the wrong value. The most notorious names are $update, $keys, $values,
-$items. A complete list is at http://docs.python.org/lib/typesmapping.html.
-Note that future versions of Python may add dict methods. This bug is
-difficult to fix given Cheetah's NameMapper, so it will remain around for a
-long time. (MO 2006/02/11)
+Please see http://bugs.communitycheetah.org
View
17 CHANGES
@@ -1,6 +1,17 @@
-Please initial your changes (there's a key at bottom) and add a date for each
-release
-================================================================================
+
+2.1.1 (April 16, 2009)
+ - Support __eq__() and __ne__() the way you might expect in src/Tools/RecursiveNull (patch suggested by Peter Warasin <peter@endian.com>)
+ - Applied patch to avoid hitting the filesystem to get the file modification time everytime a #include directive is processed (Jean-Baptiste Quenot <jbq@caraldi.com>)
+ - Applied patch to fix some annoying cases when Cheetah writes to stderr instead of propagating the exception (Jean-Baptiste Quenot <jbq@caraldi.com>)
+ - Added KDE editor support
+ - Applied patch to correct importHook behavior on Python 2.6 (reported/patched by Toshio Ernie Kuratomi <a.badger@gmail.com>)
+ - Correct unicode issue when calling/embedding unicode templates inside of other templtes (testcase Tests.Unicode.JPQ_UTF8_Test3. reported by Jean-Baptiste Quenot <jbq@caraldi.com>)
+ - Added --shbang option (e.g. "cheetah compile --shbang '#!/usr/bin/python2.6' ")
+ - Removed dependency on optik OptionParser in favor of builtin Python optparse module
+ - Introduction of the #transform directive for whole-document filtering
+ - Introduction of Cheetah.contrib.markdown and Cheetah.Filters.Markdown for outputting a markdown processed template (meant for #transform)
+ - Cheetah.Filters.CodeHighlighter, pygments-based code highlighting filter for use with #transform
+ - Addition of "useLegacyImportMode" compiler setting (defaulted to True) to allow for older (read: broken) import behavior
2.1.0.1 (March 27, 2009)
- Fix inline import issue introduced in v2.1.0
View
@@ -1,5 +1,5 @@
#-------Main Package Settings-----------#
-name = "Cheetah Community Edition"
+name = 'Cheetah'
from src.Version import Version as version
maintainer = "R. Tyler Ballance"
author = "Tavis Rudd"
@@ -11,7 +11,8 @@
'Cheetah.Tests',
'Cheetah.Tools',
'Cheetah.Utils',
- 'Cheetah.Utils.optik',
+ 'Cheetah.contrib',
+ 'Cheetah.contrib.markdown',
]
classifiers = [line.strip() for line in '''\
#Development Status :: 4 - Beta
View
20 TODO
@@ -1,16 +1,9 @@
-Cheetah TODO list
------------------
-* If you are working on a task please put your initials at the end of the
- description
-* When a task is completed please remember to note it in the CHANGES file
-* Unresolved bugs are listed in the BUGS file. Resolved bugs are be listed
- in the CHANGES file if the bug is considered significant enough and it
- affected a released version of Cheetah.
-
-Required for Cheetah 2.0
-========================
-- Replace Optik with Python's optparse. Optik license has been removed from
- Users' Guide.
+NOTE: Please see http://bugs.communitycheetah.org
+ for future feature requests/bugs/TODO
+
+
+===============================================================================
+===============================================================================
Desired for Cheetah 2.0
=======================
@@ -38,7 +31,6 @@ TODO Items (many are just ideas. This is not an official roadmap!)
leak from one fill to the next.
- CheetahWrapper stuff: (MO)
- * "cheetah compile --shbang '#!/usr/bin/python2.2'"
* "cheetah preview [options] [FILES]" print template-specific portion of main
method(s) to stdout, with line numbers based on the .py template module.
Make a Template method to do the same thing, a la .generatedModuleCode().

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,4 +0,0 @@
-.cvsignore
-*.aux
-*.l2h
-devel_guide
@@ -1 +0,0 @@
-*.html
@@ -1,4 +0,0 @@
-.cvsignore
-*.aux
-*.l2h
-users_guide
View
@@ -1,2 +0,0 @@
-.cvsignore
-*.pyc
View
@@ -18,11 +18,11 @@
import getopt, glob, os, pprint, re, shutil, sys
import cPickle as pickle
+from optparse import OptionParser
from Cheetah.Version import Version
from Cheetah.Template import Template, DEFAULT_COMPILER_SETTINGS
from Cheetah.Utils.Misc import mkdirsWithPyInitFiles
-from Cheetah.Utils.optik import OptionParser
optionDashesRE = re.compile( R"^-{1,2}" )
moduleNameRE = re.compile( R"^[a-zA-Z_][a-zA-Z_0-9]*$" )
@@ -53,18 +53,6 @@ def __repr__(self):
return "<Bundle %r>" % self.__dict__
-class MyOptionParser(OptionParser):
- standard_option_list = [] # We use commands for Optik's standard options.
-
- def error(self, msg):
- """Print our usage+error page."""
- usage(HELP_PAGE2, msg)
-
- def print_usage(self, file=None):
- """Our usage+error page already has this."""
- pass
-
-
##################################################
## USAGE FUNCTION & MESSAGES
@@ -108,36 +96,10 @@ def usage(usageMessage, errorMessage="", out=sys.stderr):
Run "cheetah options" for the list of valid options.
"""
-HELP_PAGE2 = """\
-OPTIONS FOR "compile" AND "fill":
----------------------------------
- --idir DIR, --odir DIR : input/output directories (default: current dir)
- --iext EXT, --oext EXT : input/output filename extensions
- (default for compile: tmpl/py, fill: tmpl/html)
- -R : recurse subdirectories looking for input files
- --debug : print lots of diagnostic output to standard error
- --env : put the environment in the searchList
- --flat : no destination subdirectories
- --nobackup : don't make backups
- --pickle FILE : unpickle FILE and put that object in the searchList
- --stdout, -p : output to standard output (pipe)
- --settings : a string representing the compiler settings to use
- e.g. --settings='useNameMapper=False,useFilters=False'
- This string is eval'd in Python so it should contain
- valid Python syntax.
- --templateAPIClass : a string representing a subclass of
- Cheetah.Template:Template to use for compilation
-
- --parallel : compile or fill templates in parallel, e.g.
- --parallel 4
-
-Run "cheetah help" for the main help screen.
-"""
-
##################################################
## CheetahWrapper CLASS
-class CheetahWrapper:
+class CheetahWrapper(object):
MAKE_BACKUPS = True
BACKUP_SUFFIX = ".bak"
_templateClass = None
@@ -150,6 +112,7 @@ def __init__(self):
self.pathArgs = None
self.sourceFiles = []
self.searchList = []
+ self.parser = None
##################################################
## MAIN ROUTINE
@@ -192,24 +155,25 @@ def parseOpts(self, args):
C, D, W = self.chatter, self.debug, self.warn
self.isCompile = isCompile = self.command[0] == 'c'
defaultOext = isCompile and ".py" or ".html"
- parser = MyOptionParser()
- pao = parser.add_option
- pao("--idir", action="store", dest="idir", default="")
- pao("--odir", action="store", dest="odir", default="")
- pao("--iext", action="store", dest="iext", default=".tmpl")
- pao("--oext", action="store", dest="oext", default=defaultOext)
- pao("-R", action="store_true", dest="recurse", default=False)
- pao("--stdout", "-p", action="store_true", dest="stdout", default=False)
- pao("--debug", action="store_true", dest="debug", default=False)
- pao("--env", action="store_true", dest="env", default=False)
- pao("--pickle", action="store", dest="pickle", default="")
- pao("--flat", action="store_true", dest="flat", default=False)
- pao("--nobackup", action="store_true", dest="nobackup", default=False)
- pao("--settings", action="store", dest="compilerSettingsString", default=None)
- pao("--templateAPIClass", action="store", dest="templateClassName", default=None)
- pao("--parallel", action="store", type="int", dest="parallel", default=1)
-
- self.opts, self.pathArgs = opts, files = parser.parse_args(args)
+ self.parser = OptionParser()
+ pao = self.parser.add_option
+ pao("--idir", action="store", dest="idir", default='', help='Input directory (defaults to current directory)')
+ pao("--odir", action="store", dest="odir", default="", help='Output directory (defaults to current directory)')
+ pao("--iext", action="store", dest="iext", default=".tmpl", help='File input extension (defaults: compile: .tmpl, fill: .tmpl)')
+ pao("--oext", action="store", dest="oext", default=defaultOext, help='File output extension (defaults: compile: .py, fill: .html)')
+ pao("-R", action="store_true", dest="recurse", default=False, help='Recurse through subdirectories looking for input files')
+ pao("--stdout", "-p", action="store_true", dest="stdout", default=False, help='Verbosely print informational messages to stdout')
+ pao("--debug", action="store_true", dest="debug", default=False, help='Print diagnostic/debug information to stderr')
+ pao("--env", action="store_true", dest="env", default=False, help='Pass the environment into the search list')
+ pao("--pickle", action="store", dest="pickle", default="", help='Unpickle FILE and pass it through in the search list')
+ pao("--flat", action="store_true", dest="flat", default=False, help='Do not build destination subdirectories')
+ pao("--nobackup", action="store_true", dest="nobackup", default=False, help='Do not make backup files when generating new ones')
+ pao("--settings", action="store", dest="compilerSettingsString", default=None, help='String of compiler settings to pass through, e.g. --settings="useNameMapper=False,useFilters=False"')
+ pao("--templateAPIClass", action="store", dest="templateClassName", default=None, help='Name of a subclass of Cheetah.Template.Template to use for compilation, e.g. MyTemplateClass')
+ pao("--parallel", action="store", type="int", dest="parallel", default=1, help='Compile/fill templates in parallel, e.g. --parallel=4')
+ pao('--shbang', dest='shbang', default='#!/usr/bin/env python', help='Specify the shbang to place at the top of compiled templates, e.g. --shbang="#!/usr/bin/python2.6"')
+
+ self.opts, self.pathArgs = opts, files = self.parser.parse_args(args)
D("""\
cheetah compile %s
Options are
@@ -252,7 +216,7 @@ def help(self):
usage(HELP_PAGE1, "", sys.stdout)
def options(self):
- usage(HELP_PAGE2, "", sys.stdout)
+ return self.parser.print_help()
def test(self):
# @@MO: Ugly kludge.
@@ -604,6 +568,7 @@ def _compileOrFillBundle(self, b):
pysrc = TemplateClass.compile(file=src, returnAClass=False,
moduleName=basename,
className=basename,
+ commandlineopts=self.opts,
compilerSettings=compilerSettings)
output = pysrc
else:
View
@@ -63,6 +63,7 @@ class Error(Exception): pass
'alwaysFilterNone':True, # filter out None, before the filter is called
'useFilters':True, # use str instead if =False
'includeRawExprInFilterArgs':True,
+ 'useLegacyImportMode' : True,
#'lookForTransactionAttr':False,
'autoAssignDummyTransactionToSelf':False,
@@ -973,9 +974,16 @@ def setErrorCatcher(self, errorCatcherName):
def nextFilterRegionID(self):
return self.nextCacheID()
+
+ def setTransform(self, transformer, isKlass):
+ self.addChunk('trans = TransformerTransaction()')
+ self.addChunk('trans._response = trans.response()')
+ self.addChunk('trans._response._filter = %s' % transformer)
+ self.addChunk('write = trans._response.write')
def setFilter(self, theFilter, isKlass):
- class FilterDetails: pass
+ class FilterDetails:
+ pass
filterDetails = FilterDetails()
filterDetails.ID = ID = self.nextFilterRegionID()
filterDetails.theFilter = theFilter
@@ -1566,8 +1574,8 @@ def __init__(self, source=None, file=None,
self._fileDirName, self._fileBaseName = os.path.split(self._filePath)
self._fileBaseNameRoot, self._fileBaseNameExt = os.path.splitext(self._fileBaseName)
- if not isinstance(source, (str,unicode)):
- source = str(source)
+ if not isinstance(source, basestring):
+ source = unicode(source)
# by converting to string here we allow objects such as other Templates
# to be passed in
@@ -1638,7 +1646,7 @@ def _setupCompilerState(self):
"from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion",
"from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple",
"from Cheetah.Template import Template",
- "from Cheetah.DummyTransaction import DummyTransaction",
+ "from Cheetah.DummyTransaction import *",
"from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList",
"from Cheetah.CacheRegion import CacheRegion",
"import Cheetah.Filters as Filters",
@@ -1712,9 +1720,10 @@ def importedVarNames(self):
return self._importedVarNames
def addImportedVarNames(self, varNames, raw_statement=None):
+ settings = self.settings()
if not varNames:
return
- if self._methodBodyChunks and raw_statement:
+ if self._methodBodyChunks and raw_statement and not settings.get('useLegacyImportMode'):
self.addChunk(raw_statement)
else:
self._importedVarNames.extend(varNames)
@@ -1836,7 +1845,11 @@ def addSpecialVar(self, basename, contents, includeUnderscores=True):
self._specialVars[name] = contents.strip()
def addImportStatement(self, impStatement):
- self._importStatements.append(impStatement)
+ settings = self.settings()
+ if not self._methodBodyChunks or settings.get('useLegacyImportMode'):
+ # In the case where we are importing inline in the middle of a source block
+ # we don't want to inadvertantly import the module at the top of the file either
+ self._importStatements.append(impStatement)
#@@TR 2005-01-01: there's almost certainly a cleaner way to do this!
importVarNames = impStatement[impStatement.find('import') + len('import'):].split(',')
View
@@ -15,6 +15,8 @@
__author__ = "Tavis Rudd <tavis@damnsimple.com>"
__revision__ = "$Revision: 1.13 $"[11:-2]
+import types
+
def flush():
pass
@@ -56,3 +58,41 @@ def __init__(self, DummyResponse=DummyResponse):
def response(resp=DummyResponse()):
return resp
self.response = response
+
+class TransformerResponse(object):
+ def __init__(self, *args, **kwargs):
+ self._output = []
+ self._filter = None
+
+ def write(self, value):
+ self._output.append(value)
+
+ def flush(self):
+ pass
+
+ def writeln(self, line):
+ self.write(line)
+ self.write('\n')
+
+ def writelines(self, *lines):
+ [self.writeln(line) for line in lines]
+
+ def getvalue(self, **kwargs):
+ output = kwargs.get('outputChunks') or self._output
+ rc = ''.join(output)
+ if self._filter:
+ _filter = self._filter
+ if isinstance(_filter, types.TypeType):
+ _filter = _filter()
+ return _filter.filter(rc)
+ return rc
+
+
+class TransformerTransaction(object):
+ def __init__(self, *args, **kwargs):
+ self._response = None
+ def response(self):
+ if self._response:
+ return self._response
+ return TransformerResponse()
+
Oops, something went wrong.

0 comments on commit 45f570f

Please sign in to comment.