[Checkins] SVN: five.pt/trunk/ Update to Chameleon 2.0. This commit marks a stable development version.

Malthe Borch mborch at gmail.com
Mon Feb 21 10:12:08 EST 2011


Log message for revision 120503:
  Update to Chameleon 2.0. This commit marks a stable development version.

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/README.txt
  U   five.pt/trunk/bootstrap.py
  U   five.pt/trunk/buildout.cfg
  U   five.pt/trunk/setup.py
  U   five.pt/trunk/src/five/pt/__init__.py
  U   five.pt/trunk/src/five/pt/configure.zcml
  U   five.pt/trunk/src/five/pt/expressions.py
  U   five.pt/trunk/src/five/pt/pagetemplate.py
  U   five.pt/trunk/src/five/pt/patches.py
  U   five.pt/trunk/src/five/pt/tests/secure.pt
  U   five.pt/trunk/src/five/pt/tests/simple.pt
  A   five.pt/trunk/src/five/pt/tests/test_basetemplatefile.py
  A   five.pt/trunk/src/five/pt/tests/test_patches.py
  U   five.pt/trunk/src/five/pt/tests/test_viewpagetemplatefile.py
  U   five.pt/trunk/versions.cfg

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/CHANGES.txt	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,8 +1,17 @@
 Changelog
 =========
 
-In next release...
+In next release ...
 
+- Update to Chameleon 2.0.
+
+  This release includes many changes and is a complete rewrite of the
+  1.x series.
+
+  Note that Python 2.7+ is now required.
+
+  [malthe]
+
 - Python-expressions are now subject to access-control security.
   [malthe]
 
@@ -12,7 +21,6 @@
 - Apply patches at import time instead of product initialisation.
   [wichert]
 
-
 1.3.2 - 2010-09-29
 ~~~~~~~~~~~~~~~~~~
 
@@ -31,7 +39,8 @@
 ~~~~~~~~~~~~~~~~
 
 - Added support for ``PageTemplate`` and
-  ``ZopePageTemplate``. [malthe]
+  ``ZopePageTemplate``.
+  [malthe]
 
 1.2 - 2010-08-30
 ~~~~~~~~~~~~~~~~

Modified: five.pt/trunk/README.txt
===================================================================
--- five.pt/trunk/README.txt	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/README.txt	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,8 +1,9 @@
 Overview
 ========
 
-The five.pt package brings the Chameleon template engine to Zope 2. It's a
-drop-in replacement, providing bridges to the most common API.
+The five.pt package brings the Chameleon template engine to the Zope 2
+platform. It's a drop-in replacement, providing bridges to the most
+common API.
 
 Support for browser pages, viewlets and viewlet managers is included.
 

Modified: five.pt/trunk/bootstrap.py
===================================================================
--- five.pt/trunk/bootstrap.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/bootstrap.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2006 Zope Corporation and Contributors.
+# Copyright (c) 2006 Zope Foundation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -16,37 +16,104 @@
 Simply run this script in a directory containing a buildout.cfg.
 The script accepts buildout command-line options, so you can
 use the -c option to specify an alternate configuration file.
-
-$Id: bootstrap.py 71627 2006-12-20 16:46:11Z jim $
 """
 
 import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
 
 tmpeggs = tempfile.mkdtemp()
 
-ez = {}
-exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
-                     ).read() in ez
-ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+is_jython = sys.platform.startswith('java')
 
-import pkg_resources
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+                          help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+                   action="store_true", dest="distribute", default=False,
+                   help="Use Disribute rather than Setuptools.")
 
-cmd = 'from setuptools.command.easy_install import main; main()'
+parser.add_option("-c", None, action="store", dest="config_file",
+                   help=("Specify the path to the buildout configuration "
+                         "file to be used."))
+
+options, args = parser.parse_args()
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+    args += ['-c', options.config_file]
+
+if options.version is not None:
+    VERSION = '==%s' % options.version
+else:
+    VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+    import pkg_resources
+    if not hasattr(pkg_resources, '_distribute'):
+        to_reload = True
+        raise ImportError
+except ImportError:
+    ez = {}
+    if USE_DISTRIBUTE:
+        exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+                         ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+    else:
+        exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                             ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    if to_reload:
+        reload(pkg_resources)
+    else:
+        import pkg_resources
+
 if sys.platform == 'win32':
-    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
 
-ws = pkg_resources.working_set
-assert os.spawnle(
-    os.P_WAIT, sys.executable, sys.executable,
-    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
-    dict(os.environ,
-         PYTHONPATH=
-         ws.find(pkg_resources.Requirement.parse('setuptools')).location
-         ),
-    ) == 0
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
 
+if USE_DISTRIBUTE:
+    requirement = 'distribute'
+else:
+    requirement = 'setuptools'
+
+if is_jython:
+    import subprocess
+
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+           quote(tmpeggs), 'zc.buildout' + VERSION],
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse(requirement)).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse(requirement)).location
+            ),
+        ) == 0
+
 ws.add_entry(tmpeggs)
-ws.require('zc.buildout')
+ws.require('zc.buildout' + VERSION)
 import zc.buildout.buildout
-zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+zc.buildout.buildout.main(args)
 shutil.rmtree(tmpeggs)

Modified: five.pt/trunk/buildout.cfg
===================================================================
--- five.pt/trunk/buildout.cfg	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/buildout.cfg	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,39 +1,20 @@
 [buildout]
-extends = http://download.zope.org/zope3.4/3.4.0/versions.cfg
-    versions.cfg
+extends = versions.cfg
 
-find-links =
-    http://dist.repoze.org/zope2/2.10/
-
 develop = .
 
 parts =
-    lxml
     test
-    checkversions
 
 eggs =
-   five.pt
-   zopelib
+    five.pt
+    Zope2
 
 versions = versions
 
 allow-picked-versions = false
 
-[lxml]
-recipe = z3c.recipe.staticlxml
-egg = lxml>=2.1.5
-
 [test]
-recipe = zc.recipe.testrunner<1.1dev
+recipe = zc.recipe.testrunner
 eggs = ${buildout:eggs}
 defaults = ['-m', 'five.pt']
-environment = test-environment
-
-[test-environment]
-CHAMELEON_DEBUG = 1
-CHAMELEON_CACHE = 0
-
-[checkversions]
-recipe = zc.recipe.egg
-eggs = z3c.checkversions[buildout]

Modified: five.pt/trunk/setup.py
===================================================================
--- five.pt/trunk/setup.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/setup.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '1.3.4'
+version = '2.0-dev'
 
 setup(name='five.pt',
       version=version,
@@ -25,9 +25,10 @@
       zip_safe=False,
       install_requires=[
           'setuptools',
-          'z3c.pt>=1.2.1',
-          'Chameleon>=1.2.11',
+          'z3c.pt>=2.0-dev',
+          'Chameleon>=2.0-dev',
           'sourcecodegen',
+          'sourcecodegen',
       ],
       entry_points="""
       [z3c.autoinclude.plugin]

Modified: five.pt/trunk/src/five/pt/__init__.py
===================================================================
--- five.pt/trunk/src/five/pt/__init__.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/__init__.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -2,9 +2,9 @@
 
 
 def initialize(site):
-    import chameleon.core.config
+    import chameleon.config
 
-    if chameleon.core.config.EAGER_PARSING:
+    if chameleon.config.EAGER_PARSING:
         import gc
 
         # this only deals with the page template classes provided by

Modified: five.pt/trunk/src/five/pt/configure.zcml
===================================================================
--- five.pt/trunk/src/five/pt/configure.zcml	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/configure.zcml	2011-02-21 15:12:07 UTC (rev 120503)
@@ -5,22 +5,6 @@
   <include package="z3c.pt" />
   <include package="five.pt" file="meta.zcml" />
 
-  <utility
-      name="path"
-      component=".expressions.path_translator" />
-
-  <utility
-      name="python"
-      component=".expressions.python_translator" />
-
-  <utility
-      name="exists"
-      component=".expressions.exists_translator" />
-
-  <utility
-      name="provider"
-      component=".expressions.provider_translator" />
-
   <five:registerPackage package="." initialize=".initialize" />
 
 </configure>

Modified: five.pt/trunk/src/five/pt/expressions.py
===================================================================
--- five.pt/trunk/src/five/pt/expressions.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/expressions.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,20 +1,21 @@
-from compiler import parse
+from ast import Assign
+from ast import NodeTransformer
+from compiler import parse as ast24_parse
 
-from z3c.pt.expressions import PathTranslator
-from z3c.pt.expressions import ExistsTranslator
-from z3c.pt.expressions import ZopeExistsTraverser
-from z3c.pt.expressions import ProviderTranslator
-from chameleon.zpt.expressions import PythonTranslator
-from chameleon.core import types
-from sourcecodegen import generate_code
-
 from Acquisition import aq_base
 from OFS.interfaces import ITraversable
 from Products.PageTemplates import ZRPythonExpr
 from zExceptions import NotFound, Unauthorized
+
+from zope import component
+from zope.proxy import removeAllProxies
+from zope.traversing.adapters import traversePathElement
+from zope.traversing.interfaces import TraversalError
+from zope.contentprovider.interfaces import IContentProvider
+from zope.contentprovider.interfaces import ContentProviderLookupError
+
 from RestrictedPython.RestrictionMutator import RestrictionMutator
 from RestrictedPython import MutatingWalker
-from RestrictedPython.Guards import safe_builtins
 
 from AccessControl.ZopeGuards import guarded_getattr
 from AccessControl.ZopeGuards import guarded_getitem
@@ -22,13 +23,16 @@
 from AccessControl.ZopeGuards import guarded_iter
 from AccessControl.ZopeGuards import protected_inplacevar
 
-from zope import component
-from zope.proxy import removeAllProxies
-from zope.traversing.adapters import traversePathElement
-from zope.traversing.interfaces import TraversalError
-from zope.contentprovider.interfaces import IContentProvider
-from zope.contentprovider.interfaces import ContentProviderLookupError
+from chameleon.astutil import Symbol
+from chameleon.astutil import Static
+from chameleon.astutil import parse
+from chameleon.codegen import template
+from chameleon.tales import TalesExpr
+from chameleon.utils import decode_htmlentities
+from chameleon.exc import ExpressionError
+from sourcecodegen import generate_code
 
+from z3c.pt import expressions
 
 _marker = object()
 
@@ -39,6 +43,16 @@
     AQ_WRAP_CP = False
 
 
+zope2_exceptions = NameError, \
+                   ValueError, \
+                   AttributeError, \
+                   LookupError, \
+                   TypeError, \
+                   NotFound, \
+                   Unauthorized, \
+                   TraversalError
+
+
 def render(ob, request):
     """Calls the object, possibly a document template, or just returns
     it if not callable.  (From Products.PageTemplates.Expressions.py)
@@ -103,20 +117,23 @@
         return base
 
 
-class PathTranslator(PathTranslator):
-    path_traverse = FiveTraverser()
+class PathExpr(expressions.PathExpr):
+    exceptions = zope2_exceptions
 
+    traverser = Static(
+        template("cls()", cls=Symbol(FiveTraverser), mode="eval")
+        )
 
-class FiveExistsTraverser(ZopeExistsTraverser):
-    exceptions = AttributeError, LookupError, TypeError, \
-                 NotFound, Unauthorized, TraversalError
 
+class NocallExpr(expressions.NocallExpr, PathExpr):
+    pass
 
-class ExistsTranslator(ExistsTranslator):
-    path_traverse = FiveExistsTraverser()
 
+class ExistsExpr(expressions.ExistsExpr):
+    exceptions = zope2_exceptions
 
-class FiveContentProviderTraverser(object):
+
+class ContentProviderTraverser(object):
     def __call__(self, context, request, view, name):
         cp = component.queryMultiAdapter(
             (context, request, view), IContentProvider, name=name)
@@ -132,13 +149,13 @@
         return cp.render()
 
 
-class FiveProviderTranslator(ProviderTranslator):
-    content_provider_traverser = FiveContentProviderTraverser()
+class ProviderExpr(expressions.ProviderExpr):
+    traverser = Static(
+        template("cls()", cls=Symbol(ContentProviderTraverser), mode="eval")
+        )
 
 
-class FivePythonTranslator(PythonTranslator):
-    rm = RestrictionMutator()
-
+class RestrictionTransform(NodeTransformer):
     secured = {
         '_getattr_': guarded_getattr,
         '_getitem_': guarded_getitem,
@@ -147,38 +164,34 @@
         '_inplacevar_': protected_inplacevar,
     }
 
-    def translate(self, string, escape=None):
-        """We use the ``parser`` module to determine if
-        an expression is a valid python expression.
+    def visit_Name(self, node):
+        value = self.secured.get(node.id)
+        if value is not None:
+            return Symbol(value)
 
-        Make sure the formatted syntax error exception contains the
-        expression string.
+        return node
 
-        >>> from traceback import format_exc
-        >>> translate = PythonTranslator().translate
-        >>> try: translate('abc:def:ghi')
-        ... except SyntaxError, e: 'abc:def:ghi' in format_exc(e)
-        True
-        """
 
-        if isinstance(string, unicode):
-            string = string.encode('utf-8')
+class PythonExpr(TalesExpr):
+    rm = RestrictionMutator()
+    rt = RestrictionTransform()
 
-        if string:
-            expression = string.strip()
-            node = parse(expression, 'eval').node
-            MutatingWalker.walk(node, self.rm)
-            string = generate_code(node)
+    def __init__(self, expression):
+        self.expression = expression
 
-            if isinstance(string, str):
-                string = string.decode('utf-8')
+    def __call__(self, target, engine):
+        string = self.expression.strip().replace('\n', ' ')
+        decoded = decode_htmlentities(string)
 
-            value = types.value(string.strip())
-            value.symbol_mapping.update(self.secured)
+        node = ast24_parse(decoded, 'eval').node
+        MutatingWalker.walk(node, self.rm)
+        string = generate_code(node)
 
-            return value
+        try:
+            value = parse(string, 'eval').body
+        except SyntaxError as exc:
+            raise ExpressionError(exc.msg, decoded)
 
-python_translator = FivePythonTranslator()
-path_translator = PathTranslator()
-exists_translator = ExistsTranslator()
-provider_translator = FiveProviderTranslator()
+        self.rt.visit(value)
+
+        return [Assign([target], value)]

Modified: five.pt/trunk/src/five/pt/pagetemplate.py
===================================================================
--- five.pt/trunk/src/five/pt/pagetemplate.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/pagetemplate.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -9,9 +9,20 @@
 from AccessControl import getSecurityManager
 from Products.PageTemplates.Expressions import SecureModuleImporter
 
+from chameleon.tales import StringExpr
+from chameleon.tales import NotExpr
+from chameleon.tales import PythonExpr
+
 from z3c.pt import pagetemplate
+from z3c.pt import expressions
 
+from .expressions import PathExpr
+from .expressions import ProviderExpr
+from .expressions import NocallExpr
+from .expressions import ExistsExpr
+from .expressions import PythonExpr as SecurePythonExpr
 
+
 def get_physical_root(context):
     method = aq_get(context, 'getPhysicalRoot', None)
     if method is not None:
@@ -41,6 +52,16 @@
     utility_builtins = {}
     encoding = 'utf-8'
 
+    expression_types = {
+        'python': SecurePythonExpr,
+        'string': StringExpr,
+        'not': NotExpr,
+        'exists': ExistsExpr,
+        'path': PathExpr,
+        'provider': ProviderExpr,
+        'nocall': NocallExpr,
+        }
+
     def render_macro(self, macro, parameters=None, **kw):
         context = self._pt_get_context(None, None)
 
@@ -64,8 +85,6 @@
                 nothing=None,
                 same_type=same_type,
                 test=test,
-                path=pagetemplate.evaluate_path,
-                exists=pagetemplate.evaluate_exists,
                 root=get_physical_root(context),
                 user=getSecurityManager().getUser(),
                 modules=SecureModuleImporter,
@@ -84,6 +103,16 @@
 
 class ViewPageTemplate(pagetemplate.ViewPageTemplate):
 
+    expression_types = {
+        'python': PythonExpr,
+        'string': StringExpr,
+        'not': NotExpr,
+        'exists': ExistsExpr,
+        'path': PathExpr,
+        'provider': ProviderExpr,
+        'nocall': NocallExpr,
+        }
+
     encoding = 'UTF-8'
 
     def _pt_get_context(self, view, request, kwargs):
@@ -110,8 +139,6 @@
                 here=context,
                 container=context,
                 nothing=None,
-                path=pagetemplate.evaluate_path,
-                exists=pagetemplate.evaluate_exists,
                 root=get_physical_root(context),
                 user=getSecurityManager().getUser(),
                 modules=SecureModuleImporter,

Modified: five.pt/trunk/src/five/pt/patches.py
===================================================================
--- five.pt/trunk/src/five/pt/patches.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/patches.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -71,16 +71,16 @@
 
 def call_template(self, *args, **kw):
     template = getattr(self, '_v_template', _marker)
-    if template is _marker or self._text != template.body:
-        self._v_template = template = BaseTemplate(self._text)
+    if template is _marker or self._text != template.source:
+        self._v_template = template = BaseTemplate(self._text, keep_source=True)
 
     return template(self, *args, **kw)
 
 
 def call_template_and_wrap(self, *args, **kw):
     template = getattr(self, '_v_template', _marker)
-    if template is _marker or self._text != template.body:
-        self._v_template = template = BaseTemplate(self._text)
+    if template is _marker or self._text != template.source:
+        self._v_template = template = BaseTemplate(self._text, keep_source=True)
 
     if IAcquirer.providedBy(template):
         template = template.__of__(aq_parent(self))

Modified: five.pt/trunk/src/five/pt/tests/secure.pt
===================================================================
--- five.pt/trunk/src/five/pt/tests/secure.pt	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/tests/secure.pt	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,4 +1,5 @@
 <div xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal">
-  <span tal:replace="python: modules['cgi'].escape(view.tagsoup())" />
+  <span tal:define="soup view/tagsoup | options/soup"
+        tal:replace="python: modules['cgi'].escape(soup)" />
 </div>

Modified: five.pt/trunk/src/five/pt/tests/simple.pt
===================================================================
--- five.pt/trunk/src/five/pt/tests/simple.pt	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/tests/simple.pt	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,6 +1,5 @@
 <div xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
-     meta:interpolation="true"
      tal:define="name string:world">
     Hello ${name}!
 </div>

Added: five.pt/trunk/src/five/pt/tests/test_basetemplatefile.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/test_basetemplatefile.py	                        (rev 0)
+++ five.pt/trunk/src/five/pt/tests/test_basetemplatefile.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -0,0 +1,41 @@
+from Testing.ZopeTestCase import ZopeTestCase
+from five.pt.pagetemplate import BaseTemplateFile
+
+
+class TestPageTemplateFile(ZopeTestCase):
+    def afterSetUp(self):
+        from Products.Five import zcml
+        import Products.Five
+        import z3c.pt
+        import five.pt
+        zcml.load_config("configure.zcml", Products.Five)
+        zcml.load_config("configure.zcml", five.pt)
+        zcml.load_config("configure.zcml", z3c.pt)
+
+    def test_locals_base(self):
+        template = BaseTemplateFile('locals_base.pt')
+        result = template()
+        self.failUnless('here==context:True' in result)
+        self.failUnless('container==None:True' in result)
+        self.failUnless("nothing:None" in result)
+
+    def test_simple(self):
+        template = BaseTemplateFile("simple.pt")
+        result = template()
+        self.failUnless('Hello world!' in result)
+
+    def test_secure(self):
+        soup = '<foo></bar>'
+        template = BaseTemplateFile("secure.pt")
+        from zExceptions import Unauthorized
+        try:
+            result = template(soup=soup)
+        except Unauthorized:
+            pass
+        else:
+            self.fail("Expected unauthorized.")
+
+        from AccessControl.SecurityInfo import allow_module
+        allow_module("cgi")
+        result = template(soup=soup)
+        self.failUnless('&lt;foo&gt;&lt;/bar&gt;' in result)

Added: five.pt/trunk/src/five/pt/tests/test_patches.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/test_patches.py	                        (rev 0)
+++ five.pt/trunk/src/five/pt/tests/test_patches.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -0,0 +1,62 @@
+import os
+import unittest
+
+from Testing.ZopeTestCase import ZopeTestCase
+from Testing.ZopeTestCase.sandbox import Sandboxed
+
+path = os.path.dirname(__file__)
+
+class TestPatches(Sandboxed, ZopeTestCase):
+    def afterSetUp(self):
+        from Products.Five import zcml
+        import Products.Five
+        import z3c.pt
+        import five.pt.patches
+        zcml.load_config("configure.zcml", Products.Five)
+        zcml.load_config("configure.zcml", five.pt)
+        zcml.load_config("configure.zcml", z3c.pt)
+
+    def test_pagetemplate(self):
+        from Products.PageTemplates.PageTemplate import PageTemplate
+        template = PageTemplate()
+
+        # test rendering engine
+        template.write(open(os.path.join(path, "simple.pt")).read())
+        self.assertTrue('world' in template())
+
+        # test arguments
+        template.write(open(os.path.join(path, "options.pt")).read())
+        self.assertTrue('Hello world' in template(
+            greeting='Hello world'))
+
+    def test_pagetemplatefile(self):
+        from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+
+        # test rendering engine
+        template = PageTemplateFile(os.path.join(path, "simple.pt"))
+        template = template.__of__(self.folder)
+        self.assertTrue('world' in template())
+
+    def test_zopepagetemplate(self):
+        from Products.PageTemplates.ZopePageTemplate import manage_addPageTemplate
+        template = manage_addPageTemplate(self.folder, 'test')
+
+        # aq-wrap before we proceed
+        template = template.__of__(self.folder)
+
+        # test rendering engine
+        template.write(open(os.path.join(path, "simple.pt")).read())
+        self.assertTrue('world' in template())
+
+        # test arguments
+        template.write(open(os.path.join(path, "options.pt")).read())
+        self.assertTrue('Hello world' in template(
+            greeting='Hello world'))
+
+        # test commit
+        import transaction
+        transaction.commit()
+
+def test_suite():
+    import sys
+    return unittest.findTestCases(sys.modules[__name__])

Modified: five.pt/trunk/src/five/pt/tests/test_viewpagetemplatefile.py
===================================================================
--- five.pt/trunk/src/five/pt/tests/test_viewpagetemplatefile.py	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/src/five/pt/tests/test_viewpagetemplatefile.py	2011-02-21 15:12:07 UTC (rev 120503)
@@ -4,7 +4,6 @@
 from Testing.ZopeTestCase import ZopeTestCase
 
 from five.pt.pagetemplate import ViewPageTemplateFile
-from five.pt.pagetemplate import BaseTemplateFile
 
 
 class SimpleView(BrowserView):
@@ -18,11 +17,6 @@
     index = ViewPageTemplateFile('locals.pt')
 
 
-class LocalsBaseView(BrowserView):
-
-    index = BaseTemplateFile('locals_base.pt')
-
-
 class OptionsView(BrowserView):
     index = ViewPageTemplateFile('options.pt')
 
@@ -61,15 +55,10 @@
         try:
             result = view.index()
         except Unauthorized:
-            pass
+            self.fail("Unexpected exception.")
         else:
-            self.fail("Expected unauthorized.")
+            self.failUnless('&lt;foo&gt;&lt;/bar&gt;' in result)
 
-        from AccessControl.SecurityInfo import allow_module
-        allow_module("cgi")
-        result = view.index()
-        self.failUnless('&lt;foo&gt;&lt;/bar&gt;' in result)
-
     def test_locals(self):
         view = LocalsView(self.folder, self.folder.REQUEST)
         result = view.index()
@@ -82,13 +71,6 @@
         self.failUnless("nothing:None" in result)
         self.failUnless("rfc822" in result)
 
-    def test_locals_base(self):
-        view = LocalsBaseView(self.folder, self.folder.REQUEST)
-        result = view.index()
-        self.failUnless('here==context:True' in result)
-        self.failUnless('container==None:True' in result)
-        self.failUnless("nothing:None" in result)
-
     def test_options(self):
         view = OptionsView(self.folder, self.folder.REQUEST)
         options = dict(

Modified: five.pt/trunk/versions.cfg
===================================================================
--- five.pt/trunk/versions.cfg	2011-02-21 12:57:12 UTC (rev 120502)
+++ five.pt/trunk/versions.cfg	2011-02-21 15:12:07 UTC (rev 120503)
@@ -1,17 +1,155 @@
+[buildout]
+versions = versions
+
 [versions]
-chameleon.core = 1.0.4
-chameleon.zpt = 1.1.3
-Chameleon = 1.3.0-rc1
-z3c.pt = 1.2.1
-zope.testing = 3.7.1
-zope.i18n = 3.6.0
-lxml = 2.1.5
-zopelib = 2.10.7.0
+Zope2 = 2.12.10
+Acquisition = 2.13.3
+buildout.dumppickedversions = 0.4
+ClientForm = 0.2.10
+DateTime = 2.12.4
+distribute = 0.6.14
+docutils = 0.6
+ExtensionClass = 2.13.2
+five.formlib = 1.0.3
+initgroups = 2.13.0
+Jinja2 = 2.4.1
+lxml = 2.2.6
+mechanize = 0.1.11
+Missing = 2.13.1
+MultiMapping = 2.13.0
+Persistence = 2.13.2
+Pygments = 1.3.1
+python-gettext = 1.0
+pytz = 2010h
+Products.ZSQLMethods = 2.13.2
+Record = 2.13.0
+RestrictedPython = 3.5.2
+roman = 1.4.0
+setuptools = 0.6c11
+Sphinx = 0.6.7
+tempstorage = 2.11.3
+ThreadLock = 2.13.0
+transaction = 1.0.0
+z3c.checkversions = 0.2
+zc.buildout = 1.4.3
+zc.lockfile = 1.0.0
+zc.recipe.egg = 1.2.2
+zc.recipe.testrunner = 1.2.0
+ZConfig = 2.7.1
+zdaemon = 2.0.4
+zLOG = 2.11.1
+ZODB3 = 3.9.5
+zodbcode = 3.4.0
+ZopeUndo = 2.12.0
+zope.annotation = 3.5.0
+zope.app.apidoc = 3.6.6  # 3.6.7 has incompatible changes
+zope.app.applicationcontrol = 3.5.1  # 3.5.2 has incompatible changes
+zope.app.appsetup = 3.11
+zope.app.authentication = 3.6.1  # 3.6.2 has incompatible changes
+zope.app.basicskin = 3.4.1
+zope.app.broken = 3.5.0
+zope.app.cache = 3.6.0
+zope.app.catalog = 3.8.0  # 3.8.1 has incompatible changes
+zope.app.component = 3.8.3  # 3.8.4 has incompatible changes
+zope.app.container = 3.8.0  # 3.8.1 has incompatible changes
+zope.app.content = 3.4.0
+zope.app.dav = 3.5.1  # 3.5.2 has incompatible changes
+zope.app.debug = 3.4.1
+zope.app.dependable = 3.4.0
+zope.app.dtmlpage = 3.5.0
+zope.app.error = 3.5.2
+zope.app.exception = 3.5.0
+zope.app.file = 3.5.0  # 3.5.1 has incompatible changes
+zope.app.folder = 3.5.1
+zope.app.form = 3.8.1
+zope.app.generations = 3.5.0  # 3.5.1 has incompatible changes
+zope.app.http = 3.6.0  # 3.6.1 has incompatible changes
+zope.app.i18n = 3.6.2
+zope.app.interface = 3.5.0
+zope.app.intid = 3.7.1
+zope.app.locales = 3.6.1
+zope.app.localpermission = 3.7.2
+zope.app.pagetemplate = 3.7.1
+zope.app.principalannotation = 3.7.0
+zope.app.publication = 3.8.1
+zope.app.publisher = 3.8.4
+zope.app.renderer = 3.5.1
+zope.app.rotterdam = 3.5.0  # 3.5.1 has incompatible changes
+zope.app.schema = 3.5.0
+zope.app.security = 3.7.3  # 3.7.5 has incompatible changes
+zope.app.securitypolicy = 3.5.1  # # 3.5.2 has incompatible changes
+zope.app.server = 3.4.2
+zope.app.session = 3.6.1
+zope.app.testing = 3.7.3  # 3.7.4 has incompatible changes
+zope.app.traversing = 3.4.0
+zope.app.undo = 3.5.0
+zope.app.wsgi = 3.6.1
+zope.app.zapi = 3.4.1
+zope.app.zcmlfiles = 3.5.5
+zope.app.zopeappgenerations = 3.5.0
+zope.app.zptpage = 3.5.0  # 3.5.1 has incompatible changes
+zope.authentication = 3.7.1
+zope.broken = 3.6.0
+zope.browser = 1.3
+zope.cachedescriptors = 3.5.1
+zope.catalog = 3.8.1
+zope.component = 3.7.1
+zope.componentvocabulary = 1.0
+zope.configuration = 3.6.0
+zope.container = 3.8.2  # 3.8.3 has incompatible changes
+zope.contentprovider = 3.5.0
+zope.contenttype = 3.4.3
+zope.copy = 3.5.0
+zope.copypastemove = 3.5.2
+zope.datetime = 3.4.0
+zope.decorator = 3.4.0
+zope.deferredimport = 3.5.2
+zope.deprecation = 3.4.0
+zope.documenttemplate = 3.4.2
+zope.dottedname = 3.4.6
+zope.dublincore = 3.4.3
+zope.error = 3.6.0
+zope.event = 3.4.1
+zope.exceptions = 3.5.2
+zope.filerepresentation = 3.5.0
+zope.formlib = 3.7.0
+zope.hookable = 3.4.1
+zope.i18n = 3.7.3
+zope.i18nmessageid = 3.5.2
+zope.index = 3.6.0
+zope.interface = 3.5.3
+zope.intid = 3.7.2
+zope.keyreference = 3.6.2
+zope.lifecycleevent = 3.6.1
+zope.location = 3.6.0
+zope.minmax = 1.1.2
+zope.mkzeoinstance = 3.9.4
+zope.modulealias = 3.4.0
+zope.pagetemplate = 3.5.1
+zope.password = 3.5.1
+zope.principalannotation = 3.6.1
+zope.principalregistry = 3.7.0
+zope.processlifetime = 1.0
+zope.proxy = 3.6.0
+zope.publisher = 3.8.0
+zope.schema = 3.5.4
+zope.security = 3.7.3
+zope.securitypolicy = 3.6.1
+zope.sendmail = 3.5.1
+zope.sequencesort = 3.4.0
+zope.server = 3.5.0
+zope.session = 3.9.2
+zope.site = 3.6.1  # 3.6.2 has incompatible changes
+zope.size = 3.4.1
+zope.structuredtext = 3.4.0
+zope.tal = 3.5.2
+zope.tales = 3.4.0
+zope.testbrowser = 3.6.0a2
+zope.testing = 3.9.4
+zope.thread = 3.4
+zope.traversing = 3.7.1  # 3.7.2 has incompatible changes
+zope.viewlet = 3.6.1
+
 sourcecodegen = 0.6.12
-elementtree = 1.2.7-20070827-preview
-repoze.recipe.egg = 0.3
-distribute = 0.6.12
-zc.buildout = 1.4.3
-z3c.recipe.staticlxml = 0.7.1
-zc.recipe.cmmi = 1.3.1
-z3c.checkversions = 0.2
+ordereddict = 1.1
+Zope2 = 2.12.14
\ No newline at end of file



More information about the checkins mailing list