[Checkins] SVN: z3c.ptcompat/trunk/ Upgrade to Chameleon 2.

Malthe Borch mborch at gmail.com
Wed Sep 21 09:16:18 EST 2011


Log message for revision 122872:
  Upgrade to Chameleon 2.

Changed:
  U   z3c.ptcompat/trunk/CHANGES.txt
  U   z3c.ptcompat/trunk/README.txt
  U   z3c.ptcompat/trunk/buildout.cfg
  U   z3c.ptcompat/trunk/setup.py
  U   z3c.ptcompat/trunk/src/z3c/ptcompat/__init__.py
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/config.py
  A   z3c.ptcompat/trunk/src/z3c/ptcompat/configure.zcml
  A   z3c.ptcompat/trunk/src/z3c/ptcompat/engine.py
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/meta.zcml
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/patches/
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/testing.py
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/tests/
  A   z3c.ptcompat/trunk/src/z3c/ptcompat/tests.py
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py
  D   z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.txt

-=-
Modified: z3c.ptcompat/trunk/CHANGES.txt
===================================================================
--- z3c.ptcompat/trunk/CHANGES.txt	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/CHANGES.txt	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,12 +1,21 @@
 Changelog
 =========
 
-0.5.8 (unreleased)
-------------------
+1.0 (unreleased)
+----------------
 
-- Nothing changed yet.
+- Update implementation to use component-based template engine
+  configuration, plugging directly into the Zope Toolkit framework.
 
+  The package no longer provides template classes, or ZCML directives;
+  you should import directly from the ZTK codebase.
 
+  Also, note that the ``PREFER_Z3C_PT`` environment option has been
+  rendered obsolete; instead, this is now managed via component
+  configuration.
+
+- Upgrade to Chameleon 2.x.
+
 0.5.7 (2010-11-25)
 ------------------
 

Modified: z3c.ptcompat/trunk/README.txt
===================================================================
--- z3c.ptcompat/trunk/README.txt	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/README.txt	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,45 +1,16 @@
 Overview
 ========
 
-This package implements a compatibility-layer between the following
-Zope Page Template engines:
+This package provides a page template engine implementation based on
+Chameleon. It plugs into the `zope.pagetemplate
+<http://pypi.python.org/pypi/zope.pagetemplate>`_ package and has an
+explicit dependency on this package.
 
- * z3c.pt
- * zope.pagetemplate
+You can use the package to replace Zope's reference template engine
+with Chameleon in an application based on the Zope Toolkit.
 
-If the environment-variable ``PREFER_Z3C_PT`` is set to a true value,
-the ``z3c.pt`` engine will be used instead of ``zope.pagetemplate``.
+Configuration
+-------------
 
-Note: This package superseeds and replaces the old z3c.pt.compat,
-please use z3c.ptcompat instead.
+The package is configured via ZCML.
 
-Usage
------
-
-When writing new code or modifying existing code, import page template
-classes from the ``z3c.ptcompat`` package:
-
-  >>> from z3c.ptcompat import PageTemplateFile
-  >>> from z3c.ptcompat import ViewPageTemplateFile
-
-Two methods are available to bind templates and template macros to a
-view:
-
-   >>> from z3c.ptcompat import bind_template
-   >>> from z3c.ptcompat import bind_macro
-
-Both function return render-methods that accept keyword arguments
-which will be passed to the template.
-   
-   >>> render = bind_template(template, view)
-   >>> render = bind_macro(template, view, request, macro)
-
-Patches
--------
-
-By loading the ``patches`` module, Zope view page template classes
-will be monkey-patched to use the ``z3c.pt`` rendering facilities:
-
-  <include package="z3c.ptcompat.patches" />
-
-This is an alternative to changing module import locations.

Modified: z3c.ptcompat/trunk/buildout.cfg
===================================================================
--- z3c.ptcompat/trunk/buildout.cfg	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/buildout.cfg	2011-09-21 14:16:17 UTC (rev 122872)
@@ -4,16 +4,10 @@
 versions = versions
 
 [versions]
-z3c.pt = 1.2.1
-Chameleon = 1.2.13
+z3c.pt = 2.1.4
+Chameleon = 2.4.5
 
 [test]
 recipe = zc.recipe.testrunner
-environment = test-environment
-eggs =
-   z3c.ptcompat [test]
+eggs = z3c.ptcompat
 
-[test-environment]
-PREFER_Z3C_PT = True
-CHAMELEON_DEBUG = True
-CHAMELEON_CACHE = False

Modified: z3c.ptcompat/trunk/setup.py
===================================================================
--- z3c.ptcompat/trunk/setup.py	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/setup.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,34 +1,25 @@
+import os
+
 from setuptools import setup, find_packages
-import sys, os
 
 
 def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
 
-version = '0.5.8dev'
+version = '1.0-dev'
 
 tests_require = [
-    'lxml',
-    'z3c.pt',
-    'zope.app.form',
-    'zope.app.pagetemplate',
-    'zope.app.publisher',
-    'zope.tal',
-    'zope.testing',
-    'zope.viewlet',
     ],
 
 
 setup(name='z3c.ptcompat',
       version=version,
-      description="Compatibility-layer for Zope Page Template engines.",
+      description="Zope-compatible page template engine based on Chameleon.",
       long_description=(
         ".. contents::\n\n" +
         read('README.txt')
         + "\n\n" +
-        read('src', 'z3c', 'ptcompat', 'zcml.txt')
-        + "\n\n" +
         read("CHANGES.txt")
         ),
       classifiers=[
@@ -50,12 +41,9 @@
       zip_safe=False,
       install_requires=[
           'setuptools',
+          'z3c.pt >= 2.1',
+          'zope.testing',
+          'zope.pagetemplate >= 3.6.2',
           ],
-      extras_require = dict(
-        zpt = ['zope.app.pagetemplate', 'zope.tal'],
-        z3cpt = ['z3c.pt'],
-        test = tests_require, # used by buildout.cfg testrunner
-        ),
-      tests_require = tests_require,
-      test_suite="z3c.ptcompat.tests.test_doctests.test_suite",
+      # test_suite="z3c.ptcompat.tests.test_doctests.test_suite",
       )

Modified: z3c.ptcompat/trunk/src/z3c/ptcompat/__init__.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/__init__.py	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/__init__.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -11,54 +11,6 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
-$Id: __init__.py 81270 2007-10-31 14:02:39Z jukart $
-"""
+
 __docformat__ = "reStructuredText"
 
-from StringIO import StringIO
-import config
-
-if config.PREFER_Z3C_PT:
-    from z3c.pt.pagetemplate import ViewPageTemplateFile
-    from z3c.pt.pagetemplate import PageTemplateFile
-
-    def bind_template(pt, view):
-        return pt.bind(view)
-
-    def bind_macro(template, view, request, macro):
-        return template.bind(
-            view, request=request, macro=macro)
-    
-else:
-    from zope.tal.talinterpreter import TALInterpreter
-    from zope.pagetemplate.pagetemplatefile import PageTemplateFile
-    from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile    
-    from zope.app.pagetemplate.viewpagetemplatefile import BoundPageTemplate as \
-         bind_template
-
-    def bind_macro(template, view, request, macro):
-        program = template.macros[macro]
-
-        def render(content_type=None, **kwargs):
-            output = StringIO(u'')
-            namespace = template.pt_getContext(
-                view, request, options=kwargs)
-            context = template.pt_getEngineContext(namespace)
-            TALInterpreter(program, None,
-                           context, output, tal=True, showtal=False,
-                           strictinsert=0, sourceAnnotations=False)()
-            if not request.response.getHeader("Content-Type"):
-                request.response.setHeader(
-                    "Content-Type", content_type)
-            return output.getvalue()
-
-        return render
-
-class ViewPageTemplateFile(ViewPageTemplateFile):
-    """View page template file."""
-
-    def __new__(cls, *args, **kwargs):
-        inst = object.__new__(cls)
-        config.REGISTRY[inst] = (args, kwargs)
-        return inst

Deleted: z3c.ptcompat/trunk/src/z3c/ptcompat/config.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/config.py	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/config.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,44 +0,0 @@
-import os
-import logging
-import z3c.ptcompat
-import weakref
-
-REGISTRY = weakref.WeakKeyDictionary()
-
-PREFER_Z3C_PT = os.environ.get("PREFER_Z3C_PT", 'false').lower() in \
-                ('y', 'yes', 't', 'true', 'on', '1')
-
-if PREFER_Z3C_PT:
-    try:
-        import z3c.pt
-    except ImportError:
-        logging.getLogger('z3c.ptcompat').warn(
-            "Unable to import ``z3c.pt``.")
-        PREFER_Z3C_PT = False
-
-def enable():
-    global PREFER_Z3C_PT
-    PREFER_Z3C_PT = True
-    reload(z3c.ptcompat)
-
-    for inst, (args, kwargs) in REGISTRY.items():
-        migrate(inst, args, kwargs)
-
-def disable():
-    global PREFER_Z3C_PT
-    PREFER_Z3C_PT = False
-    reload(z3c.ptcompat)
-
-    for inst, (args, kwargs) in REGISTRY.items():
-        migrate(inst, args, kwargs)
-
-def migrate(inst, args, kwargs):
-    cls = inst.__class__
-    new_cls = getattr(z3c.ptcompat, cls.__name__)
-    inst.__class__ = new_cls
-    inst.__dict__.clear()
-    try:
-        inst.__init__(*args, **kwargs)
-    except (OSError, ValueError):
-        # remove broken templates from registry
-        REGISTRY.pop(inst, None)

Added: z3c.ptcompat/trunk/src/z3c/ptcompat/configure.zcml
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/configure.zcml	                        (rev 0)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/configure.zcml	2011-09-21 14:16:17 UTC (rev 122872)
@@ -0,0 +1,7 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <include package="z3c.pt" />
+  <include package="zope.traversing" />
+  <utility component=".engine.Program" />
+
+</configure>
\ No newline at end of file

Added: z3c.ptcompat/trunk/src/z3c/ptcompat/engine.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/engine.py	                        (rev 0)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/engine.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+__docformat__ = "reStructuredText"
+
+
+from zope.interface import implements
+from zope.interface import classProvides
+from zope.pagetemplate.interfaces import IPageTemplateEngine
+from zope.pagetemplate.interfaces import IPageTemplateProgram
+
+from z3c.pt.pagetemplate import PageTemplate as ChameleonPageTemplate
+from chameleon.tal import RepeatDict
+
+
+class Program(object):
+    implements(IPageTemplateProgram)
+    classProvides(IPageTemplateEngine)
+
+    def __init__(self, template):
+        self.template = template
+
+    def __call__(self, context, macros, tal=True, **options):
+        if tal is False:
+            return self.template.body
+
+        context.vars['repeat'] = RepeatDict(context.repeat_vars)
+
+        return self.template.render(**context.vars)
+
+    @classmethod
+    def cook(cls, source_file, text, engine, content_type):
+        template = ChameleonPageTemplate(
+            text, filename=source_file, keep_body=True,
+            )
+
+        return cls(template), template.macros

Deleted: z3c.ptcompat/trunk/src/z3c/ptcompat/meta.zcml
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/meta.zcml	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/meta.zcml	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,119 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    xmlns:meta="http://namespaces.zope.org/meta"
-    xmlns:zcml="http://namespaces.zope.org/zcml">
-
-  <meta:directives namespace="http://namespaces.zope.org/browser">
-
-    <!-- browser pages -->
-
-    <meta:directive
-	name="page"
-	schema="zope.app.publisher.browser.metadirectives.IPageDirective"
-	handler=".zcml.page_directive"
-	/>
-
-    <meta:complexDirective
-        name="pages"
-        schema="zope.app.publisher.browser.metadirectives.IPagesDirective"
-        handler=".zcml.pages_directive"
-        >
-
-      <meta:subdirective
-          name="page"
-          schema="zope.app.publisher.browser.metadirectives.IPagesPageSubdirective"
-          />
-
-    </meta:complexDirective>
-
-    <meta:directive
-	name="viewlet"
-	schema="zope.viewlet.metadirectives.IViewletDirective"
-	handler=".zcml.viewlet_directive"
-	/>
-
-    <meta:directive
-	name="viewletManager"
-	schema="zope.viewlet.metadirectives.IViewletManagerDirective"
-	handler=".zcml.viewlet_manager_directive"
-	/>
-
-
-    <configure zcml:condition="installed zope.app.form">
-
-      <!-- Those directives are only registered if zope.app.form is
-           available, to avoid a hard dependency -->
-
-      <meta:complexDirective
-	  name="form"
-	  schema="zope.app.form.browser.metadirectives.IFormDirective"
-	  handler=".zcml.FormDirective"
-	  >
-
-	<meta:subdirective
-	    name="widget"
-	    schema="zope.app.form.browser.metadirectives.IWidgetSubdirective"
-	    />
-
-      </meta:complexDirective>
-
-
-      <meta:complexDirective
-	  name="editform"
-	  schema="zope.app.form.browser.metadirectives.IEditFormDirective"
-	  handler=".zcml.EditFormDirective"
-	  >
-
-	<meta:subdirective
-	    name="widget"
-	    schema="zope.app.form.browser.metadirectives.IWidgetSubdirective"
-	    />
-
-      </meta:complexDirective>
-
-
-      <meta:complexDirective
-	  name="subeditform"
-	  schema="zope.app.form.browser.metadirectives.ISubeditFormDirective"
-	  handler=".zcml.SubeditFormDirective"
-	  >
-
-	<meta:subdirective
-	    name="widget"
-	    schema="zope.app.form.browser.metadirectives.IWidgetSubdirective"
-	    />
-
-      </meta:complexDirective>
-
-
-      <meta:complexDirective
-	  name="addform"
-	  schema="zope.app.form.browser.metadirectives.IAddFormDirective"
-	  handler=".zcml.AddFormDirective"
-	  >
-
-	<meta:subdirective
-	    name="widget"
-	    schema="zope.app.form.browser.metadirectives.IWidgetSubdirective"
-	    />
-
-      </meta:complexDirective>
-
-
-      <meta:complexDirective
-	  name="schemadisplay"
-	  schema="zope.app.form.browser.metadirectives.ISchemaDisplayDirective"
-	  handler=".zcml.SchemaDisplayDirective">
-
-	<meta:subdirective
-	    name="widget"
-	    schema="zope.app.form.browser.metadirectives.IWidgetSubdirective"
-	    />
-
-      </meta:complexDirective>
-
-    </configure>
-
-  </meta:directives>
-
-</configure>

Deleted: z3c.ptcompat/trunk/src/z3c/ptcompat/testing.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/testing.py	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/testing.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,90 +0,0 @@
-import doctest as pythondoctest
-
-import lxml.etree
-import lxml.doctestcompare
-
-import re
-
-class OutputChecker(lxml.doctestcompare.LHTMLOutputChecker):
-    """Doctest output checker which is better equippied to identify
-    HTML markup than the checker from the ``lxml.doctestcompare``
-    module. It also uses the text comparison function from the
-    built-in ``doctest`` module to allow the use of ellipsis."""
-    
-    _repr_re = re.compile(r'^<([A-Z]|[^>]+ (at|object) |[a-z]+ \'[A-Za-z0-9_.]+\'>)')
-
-    def __init__(self, doctest=pythondoctest):
-        self.doctest = doctest
-
-        # make sure these optionflags are registered
-        doctest.register_optionflag('PARSE_HTML')
-        doctest.register_optionflag('PARSE_XML')
-        doctest.register_optionflag('NOPARSE_MARKUP')
-        
-    def _looks_like_markup(self, s):
-        s = s.replace('<BLANKLINE>', '\n').strip()
-        return (s.startswith('<')
-                and not self._repr_re.search(s))
-
-    def text_compare(self, want, got, strip):
-        if want is None: want = ""
-        if got is None: got = ""
-        checker = self.doctest.OutputChecker()
-        return checker.check_output(
-            want, got, self.doctest.ELLIPSIS|self.doctest.NORMALIZE_WHITESPACE)
-
-    def get_parser(self, want, got, optionflags):
-        NOPARSE_MARKUP = self.doctest.OPTIONFLAGS_BY_NAME.get(
-            "NOPARSE_MARKUP", 0)
-        PARSE_HTML = self.doctest.OPTIONFLAGS_BY_NAME.get(
-            "PARSE_HTML", 0)
-        PARSE_XML = self.doctest.OPTIONFLAGS_BY_NAME.get(
-            "PARSE_XML", 0)
-        
-        parser = None
-        if NOPARSE_MARKUP & optionflags:
-            return None
-        if PARSE_HTML & optionflags:
-            parser = lxml.doctestcompare.html_fromstring
-        elif PARSE_XML & optionflags:
-            parser = lxml.etree.XML
-        elif (want.strip().lower().startswith('<html')
-              and got.strip().startswith('<html')):
-            parser = lxml.doctestcompare.html_fromstring
-        elif (self._looks_like_markup(want)
-              and self._looks_like_markup(got)):
-            parser = self.get_default_parser()
-        return parser
-
-def render(view, xpath='.'):
-    method = getattr(view, 'render', None)
-    if method is None:
-        method = view.__call__
-
-    string = method()
-    if string == "":
-        return string
-
-    try:
-        root = lxml.etree.fromstring(string)
-    except lxml.etree.XMLSyntaxError:
-        root = lxml.html.fromstring(string)
-        
-    output = ""
-    for node in root.xpath(
-        xpath, namespaces={'xmlns': 'http://www.w3.org/1999/xhtml'}):
-        s = lxml.etree.tounicode(node, pretty_print=True)
-        s = s.replace(' xmlns="http://www.w3.org/1999/xhtml"', ' ')
-        output += s
-
-    if not output:
-        raise ValueError("No elements matched by %s." % repr(xpath))
-
-    # let's get rid of blank lines
-    output = output.replace('\n\n', '\n')
-
-    # self-closing tags are more readable with a space before the
-    # end-of-tag marker
-    output = output.replace('"/>', '" />')
-
-    return output

Added: z3c.ptcompat/trunk/src/z3c/ptcompat/tests.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/tests.py	                        (rev 0)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/tests.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -0,0 +1,23 @@
+import unittest
+
+from zope.pagetemplate.tests import test_htmltests as reference
+
+
+def test_suite():
+    return unittest.makeSuite(HTMLTests)
+
+
+class HTMLTests(reference.HTMLTests):
+    def setUp(self):
+        import z3c.ptcompat
+        import zope.component.testing
+        import zope.configuration.xmlconfig
+        zope.component.testing.setUp(self)
+        zope.configuration.xmlconfig.XMLConfig(
+            'configure.zcml', z3c.ptcompat)()
+
+        super(HTMLTests, self).setUp()
+
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())

Deleted: z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.py	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,190 +0,0 @@
-import os
-import sys
-from new import function
-
-from zope.interface import classImplements
-from zope.viewlet import viewlet
-from zope.viewlet import manager
-from zope.viewlet import metaconfigure as viewletmeta
-from zope.viewlet.interfaces import IViewletManager
-from zope.app.publisher.browser import viewmeta
-from zope.app.pagetemplate import simpleviewclass
-
-from z3c.ptcompat import ViewPageTemplateFile
-from z3c.ptcompat import config
-
-def package_home(gdict):
-    filename = gdict["__file__"]
-    return os.path.dirname(filename)
-
-def clone_and_replace_globals(func, new_globals):
-    func_globals = func.func_globals.copy()
-    func_globals.update(new_globals)
-    func_defaults = func.func_defaults or ()
-    new_func = function(func.func_code, func_globals,
-                        func.func_name, func_defaults)
-    new_func.__doc__ = getattr(func, '__doc__', '')
-    func_dict = getattr(func, '__dict__', None)
-    if func_dict is not None:
-        new_func.__dict__ = func_dict.copy()
-    return new_func
-
-def SimpleViewClass(src, offering=None, used_for=None, bases=(), name=u''):
-    if offering is None:
-        offering = sys._getframe(1).f_globals
-
-    if isinstance(offering, dict):
-        offering = package_home(offering)
-
-    bases += (simpleviewclass.simple, )
-
-    class_ = type("SimpleViewClass from %s" % src, bases,
-                  {'index': ViewPageTemplateFile(src, offering),
-                   '__name__': name})
-
-    if used_for is not None:
-        class_.__used_for__ = used_for
-
-    return class_
-
-def SimpleViewletClass(src, offering=None, bases=(),
-                       attributes=None, name=u''):
-    if offering is None:
-        offering = sys._getframe(1).f_globals
-
-    if isinstance(offering, dict):
-        offering = package_home(offering)
-
-    # Create the base class hierarchy
-    bases += (viewlet.simple, viewlet.ViewletBase)
-
-    attrs = {'index' : ViewPageTemplateFile(src, offering),
-             '__name__' : name}
-    if attributes:
-        attrs.update(attributes)
-
-    # Generate a derived view class.
-    class_ = type("SimpleViewletClass from %s" % src, bases, attrs)
-
-    return class_
-
-def ViewletManager(name, interface, template=None, bases=()):
-    attrs = {'__name__' : name}
-    if template is not None:
-        attrs['template'] = ViewPageTemplateFile(template)
-
-    if manager.ViewletManagerBase not in bases:
-        # Make sure that we do not get a default viewlet manager mixin, if the
-        # provided base is already a full viewlet manager implementation.
-        if not (len(bases) == 1 and
-                IViewletManager.implementedBy(bases[0])):
-            bases = bases + (manager.ViewletManagerBase,)
-
-    ViewletManager = type(
-        '<ViewletManager providing %s>' % interface.getName(), bases, attrs)
-    classImplements(ViewletManager, interface)
-    return ViewletManager
-
-def page_directive(_context, name, *args, **kwargs):
-    class_ = kwargs.get('class_')
-    template = kwargs.get('template')
-
-    if template:
-        bases = class_ and (class_,) or ()
-        kwargs['class_'] = SimpleViewClass(str(template), bases=bases,
-                                           name=name)
-        del kwargs['template']
-
-    return viewmeta.page(_context, name, *args, **kwargs)
-
-new_page_globals = dict(page=page_directive)
-class pages_directive(viewmeta.pages):
-
-    page = clone_and_replace_globals(viewmeta.pages.page.im_func,
-                                     new_page_globals)
-
-def viewlet_directive(_context, name, *args, **kwargs):
-    class_ = kwargs.get('class_')
-    template = kwargs.get('template')
-
-    if template:
-        bases = class_ and (class_,) or ()
-        kwargs['class_'] = SimpleViewletClass(str(template),
-                                              bases=bases, name=name)
-        del kwargs['template']
-
-    return viewletmeta.viewletDirective(_context, name, *args, **kwargs)
-
-def viewlet_manager_directive(_context, name, *args, **kwargs):
-    class_ = kwargs.get('class_')
-    template = kwargs.get('template')
-    provides = kwargs.setdefault('provides', IViewletManager)
-
-    if template:
-        bases = class_ and (class_,) or ()
-        kwargs['class_'] = ViewletManager(
-            name, provides, template=str(template), bases=bases)
-        del kwargs['template']
-
-    return viewletmeta.viewletManagerDirective(_context, name, *args, **kwargs)
-
-try:
-    # Make zope.app.form a soft-dependency. We only register custom
-    # directives if it is available.
-    from zope.app.form.browser import metaconfigure as formmeta
-except ImportError:
-    pass
-else:
-    if config.PREFER_Z3C_PT:
-        # Replace globals in *Factory by the ones from our package, cloning
-        # the existing functions so we don't have to re-define them.
-        new_factory_globals = dict(ViewPageTemplateFile=ViewPageTemplateFile,
-                                   SimpleViewClass=SimpleViewClass)
-
-        AddViewFactory = clone_and_replace_globals(formmeta.AddViewFactory,
-                                                   new_factory_globals)
-        EditViewFactory = clone_and_replace_globals(formmeta.EditViewFactory,
-                                                    new_factory_globals)
-        DisplayViewFactory = clone_and_replace_globals(formmeta.DisplayViewFactory,
-                                                       new_factory_globals)
-
-        # Now, replace globals in the directive handlers' __call__ by our own
-        # factories that were cloned right above.
-        new_form_globals = dict(AddViewFactory=AddViewFactory,
-                                EditViewFactory=EditViewFactory,
-                                DisplayViewFactory=DisplayViewFactory)
-
-        class AddFormDirective(formmeta.AddFormDirective):
-            __call__ = clone_and_replace_globals(
-                formmeta.AddFormDirective.__call__.im_func,
-                new_form_globals)
-
-        class EditFormDirective(formmeta.EditFormDirective):
-            __call__ = clone_and_replace_globals(
-                formmeta.EditFormDirective.__call__.im_func,
-                new_form_globals)
-
-        class FormDirective(formmeta.FormDirective):
-            __call__ = clone_and_replace_globals(
-                formmeta.FormDirective.__call__.im_func,
-                new_form_globals)
-
-        class SubeditFormDirective(formmeta.SubeditFormDirective):
-            __call__ = clone_and_replace_globals(
-                formmeta.SubeditFormDirective.__call__.im_func,
-                new_form_globals)
-
-        class SchemaDisplayDirective(formmeta.SchemaDisplayDirective):
-            __call__ = clone_and_replace_globals(
-                formmeta.SchemaDisplayDirective.__call__.im_func,
-                new_form_globals)
-    else:
-        AddViewFactory = formmeta.AddViewFactory
-        EditViewFactory = formmeta.EditViewFactory
-        DisplayViewFactory = formmeta.DisplayViewFactory
-
-        AddFormDirective = formmeta.AddFormDirective
-        EditFormDirective = formmeta.EditFormDirective
-        FormDirective = formmeta.FormDirective
-        SubeditFormDirective = formmeta.SubeditFormDirective
-        SchemaDisplayDirective = formmeta.SchemaDisplayDirective

Deleted: z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.txt
===================================================================
--- z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.txt	2011-09-21 10:35:28 UTC (rev 122871)
+++ z3c.ptcompat/trunk/src/z3c/ptcompat/zcml.txt	2011-09-21 14:16:17 UTC (rev 122872)
@@ -1,344 +0,0 @@
-Directives
-==========
-
-We'll use a configuration machine to carry out actions; note that when
-actions are executed, the configuration machine is emptied.
-
-  >>> from zope.configuration import config
-  >>> context = config.ConfigurationMachine()
-
-Pages
------
-
-  >>> from z3c.ptcompat import zcml
-  >>> zcml.page_directive(
-  ...    context, "test1", "zope.View", None,
-  ...    template=os.path.join(path, "test.pt"))
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (interface.Interface, IDefaultBrowserLayer),
-  ...     interface.Interface, name="test1")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the view on an existing class.
-
-  >>> class View(object):
-  ...     pass
-
-  >>> zcml.page_directive(
-  ...    context, "test2", "zope.View", None,
-  ...    class_=View, template=os.path.join(path, "test.pt"))
-
-  >>> context.execute_actions()
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (interface.Interface, IDefaultBrowserLayer),
-  ...     interface.Interface, name="test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, View)
-  True
-
-Forms
-=====
-
-Define a simple schema that we will use for those directives:
-
-  >>> from zope.interface import Interface
-  >>> from zope.schema import TextLine
-
-  >>> class Schema(Interface):
-  ...     title = TextLine(title=u'Some Title')
-
-
-Add Form
---------
-
-  >>> from z3c.ptcompat import zcml
-  >>> zcml.AddFormDirective(
-  ...    context, name="add-test1", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="add-test1")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the view on an existing class.
-
-  >>> class View(object):
-  ...     pass
-
-  >>> zcml.AddFormDirective(
-  ...    context, name="add-test2", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    class_=View, template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="add-test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, View)
-  True
-
-Edit Form
----------
-
-  >>> from z3c.ptcompat import zcml
-  >>> zcml.EditFormDirective(
-  ...    context, name="edit-test1", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="edit-test1")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the view on an existing class.
-
-  >>> class View(object):
-  ...     pass
-
-  >>> zcml.EditFormDirective(
-  ...    context, name="edit-test2", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    class_=View, template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="edit-test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, View)
-  True
-
-Subedit Form
-------------
-
-  >>> from z3c.ptcompat import zcml
-  >>> zcml.SubeditFormDirective(
-  ...    context, name="subedit-test1", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="subedit-test1")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the view on an existing class.
-
-  >>> class View(object):
-  ...     pass
-
-  >>> zcml.SubeditFormDirective(
-  ...    context, name="subedit-test2", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    class_=View, template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="subedit-test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, View)
-  True
-
-Form
-----
-
-We can base the view on an existing class.
-
-  >>> class View(object):
-  ...     pass
-
-  >>> zcml.FormDirective(
-  ...    context, name="form-test2", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    class_=View, template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="form-test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, View)
-  True
-
-Schema Display
---------------
-
-  >>> from z3c.ptcompat import zcml
-  >>> zcml.SchemaDisplayDirective(
-  ...    context, name="schema-display-test1", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="schema-display-test1")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the view on an existing class.
-
-  >>> class View(object):
-  ...     pass
-
-  >>> zcml.SchemaDisplayDirective(
-  ...    context, name="schema-display-test2", permission="zope.View",
-  ...    schema=Schema, for_=Schema,
-  ...    class_=View, template=os.path.join(path, "test.pt"))()
-
-  >>> context.execute_actions()
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (Schema, IDefaultBrowserLayer),
-  ...     interface.Interface, name="schema-display-test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, View)
-  True
-
-Viewlet managers
-----------------
-
-  >>> zcml.viewlet_manager_directive(
-  ...    context, "test1", "zope.View",
-  ...    template=os.path.join(path, "test.pt"))
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-  >>> from zope.publisher.interfaces.browser import IBrowserView
-  >>> from zope.viewlet.interfaces import IViewletManager
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (interface.Interface, IDefaultBrowserLayer, IBrowserView),
-  ...     IViewletManager, name="test1")
-
-  >>> factory.template
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the viewlet manager on an existing class.
-
-  >>> class ViewletManager(object):
-  ...     pass
-
-  >>> zcml.viewlet_manager_directive(
-  ...    context, "test2", "zope.View",
-  ...    class_=ViewletManager, template=os.path.join(path, "test.pt"))
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (interface.Interface, IDefaultBrowserLayer, IBrowserView),
-  ...     IViewletManager, name="test2")
-
-  >>> factory.template
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, ViewletManager)
-  True
-
-Viewlets
---------
-
-  >>> zcml.viewlet_directive(
-  ...    context, "test1", "zope.View",
-  ...    template=os.path.join(path, "test.pt"))
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (interface.Interface, IDefaultBrowserLayer, IBrowserView, IViewletManager),
-  ...     interface.Interface, name="test1")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-We can base the viewlet on an existing class.
-
-  >>> class Viewlet(object):
-  ...     pass
-
-  >>> zcml.viewlet_directive(
-  ...    context, "test2", "zope.View",
-  ...    class_=Viewlet, template=os.path.join(path, "test.pt"))
-
-  >>> context.execute_actions()
-
-Verify that page has been registered as a component.
-
-  >>> factory = component.getSiteManager().adapters.lookup(
-  ...     (interface.Interface, IDefaultBrowserLayer, IBrowserView, IViewletManager),
-  ...     interface.Interface, name="test2")
-
-  >>> factory.index
-  <ViewPageTemplateFile .../z3c/ptcompat/tests/test.pt>
-
-  >>> issubclass(factory, Viewlet)
-  True



More information about the checkins mailing list