[Checkins] SVN: z3c.pt/trunk/src/z3c/pt/ Make ZCML actions pickleable and test.

Chris McDonough chrism at plope.com
Fri Aug 22 11:18:09 EDT 2008


Log message for revision 90132:
  Make ZCML actions pickleable and test.
  
  Add a few docstrings.
  

Changed:
  U   z3c.pt/trunk/src/z3c/pt/configure.zcml
  U   z3c.pt/trunk/src/z3c/pt/expressions.py
  U   z3c.pt/trunk/src/z3c/pt/generation.py
  U   z3c.pt/trunk/src/z3c/pt/genshi.py
  U   z3c.pt/trunk/src/z3c/pt/template.py
  U   z3c.pt/trunk/src/z3c/pt/testing.py
  U   z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py
  U   z3c.pt/trunk/src/z3c/pt/zpt.py

-=-
Modified: z3c.pt/trunk/src/z3c/pt/configure.zcml
===================================================================
--- z3c.pt/trunk/src/z3c/pt/configure.zcml	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/configure.zcml	2008-08-22 15:18:08 UTC (rev 90132)
@@ -4,11 +4,11 @@
   
   <utility
      name="python"
-     component=".expressions.PythonTranslation" />
+     component=".expressions.python_translation" />
 
   <utility
      name="path"
-     component=".expressions.PathTranslation" />
+     component=".expressions.path_translation" />
 
   <adapter
      name="string"

Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -495,7 +495,7 @@
 
         return types.value(string)
 
-PythonTranslation = PythonTranslation()
+python_translation = PythonTranslation()
 
 class StringTranslation(ExpressionTranslation):
     zope.component.adapts(interfaces.IExpressionTranslation)
@@ -577,7 +577,7 @@
     def definitions(self, string):
         """
         
-        >>> definitions = StringTranslation(PythonTranslation).definitions
+        >>> definitions = StringTranslation(python_translation).definitions
         
         Semi-colon literal.
         
@@ -598,7 +598,7 @@
             raise SyntaxError(
                 "Semi-colons in string-expressions must be escaped.")
         return string.replace(';;', ';')
-        
+
 class PathTranslation(ExpressionTranslation):
     path_regex = re.compile(
         r'^((nocall|not):\s*)*([A-Za-z_][A-Za-z0-9_]*)'+
@@ -698,4 +698,4 @@
 
         return value
 
-PathTranslation = PathTranslation()
+path_translation = PathTranslation()

Modified: z3c.pt/trunk/src/z3c/pt/generation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/generation.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/generation.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -66,7 +66,7 @@
     return (out, out.write)
 
 def initialize_traversal():
-    return expressions.PathTranslation.traverse
+    return expressions.path_translation.traverse
 
 class BufferIO(list):
     write = list.append

Modified: z3c.pt/trunk/src/z3c/pt/genshi.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/genshi.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/genshi.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -10,7 +10,7 @@
     Implements the Genshi subset of the attribute template language.
     """
 
-    translator = expressions.PythonTranslation
+    translator = expressions.python_translation
     
     class node(translation.Node):
         @property
@@ -177,7 +177,7 @@
     py_for = utils.attribute(
         utils.py_attr('for'), lambda p: p.definition)
     py_with = utils.attribute(utils.py_attr('with'),
-        lambda p: expressions.PythonTranslation.definitions)
+        lambda p: expressions.python_translation.definitions)
     py_choose = utils.attribute(
         utils.py_attr('choose'), lambda p: p.expression)
     py_when = utils.attribute(
@@ -206,7 +206,7 @@
 
 class PyWithElement(PyElement):
     py_with = utils.attribute(
-        "vars", lambda p: expressions.PythonTranslation.definitions)
+        "vars", lambda p: expressions.python_translation.definitions)
 
 class PyDefElement(PyElement):
     py_def = utils.attribute("function", lambda p: p.method)
@@ -215,6 +215,7 @@
     py_match = utils.attribute("path")
     
 class GenshiParser(etree.Parser):
+    """ The parser implementation for Genshi templates """
     element_mapping = {
         config.XHTML_NS: {None: XHTMLElement},
         config.META_NS: {None: XHTMLElement},

Modified: z3c.pt/trunk/src/z3c/pt/template.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/template.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -9,7 +9,9 @@
 
 class BaseTemplate(object):
     """ Constructs a template object.  Must be passed an input string
-    as ``body``. ``default_expression`` is the default expression
+    as ``body``. ``parser`` is the parser implementation
+    (``ZopeePageTemplateParser`` or ``GenshiParser`` as of this
+    writing). ``default_expression`` is the default expression
     namespace for any ``TALES`` expressions included in the template
     (typically either the string ``path`` or the string ``python``);
     ``python`` is the default if nothing is passed."""

Modified: z3c.pt/trunk/src/z3c/pt/testing.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/testing.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/testing.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -12,7 +12,7 @@
 from StringIO import StringIO
 
 def pyexp(string):
-    return expressions.PythonTranslation.expression(string)
+    return expressions.python_translation.expression(string)
 
 def setup_stream():
     class symbols(translation.Node.symbols):
@@ -69,7 +69,7 @@
         return macro.Macros(render)
 
 class MockElement(translation.Element, translation.VariableInterpolation):
-    translator = expressions.PythonTranslation
+    translator = expressions.python_translation
     
     def update(self):
         translation.VariableInterpolation.update(self)

Modified: z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_edgecases.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -88,6 +88,30 @@
         c = unicode('\xc2\xa9', 'utf-8')
         self.assertEqual(norm(t.render(foo=c)), norm(expected))
 
+class TestZCMLActionsPickleable(unittest.TestCase, PlacelessSetup):
+    # see also
+    # http://groups.google.com/group/z3c_pt/browse_thread/thread/bd0cc94b5fd40ae0?hl=en
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+
+    def tearDown(self):
+        PlacelessSetup.tearDown(self)
+            
+    def test_registry_actions_can_be_pickled_and_unpickled(self):
+        from z3c import pt as package
+        from zope.configuration import config
+        from zope.configuration import xmlconfig
+        context = config.ConfigurationMachine()
+        xmlconfig.registerCommonDirectives(context)
+        context.package = package
+        xmlconfig.include(context, 'configure.zcml', package)
+        context.execute_actions(clear=False)
+        actions = context.actions
+        import pickle
+        dumped = pickle.dumps(actions, -1)
+        new = pickle.loads(dumped)
+        self.assertEqual(len(actions), len(new))
+
 def norm(s):
     return s.replace(' ', '').replace('\n', '')
 

Modified: z3c.pt/trunk/src/z3c/pt/zpt.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/zpt.py	2008-08-22 14:59:59 UTC (rev 90131)
+++ z3c.pt/trunk/src/z3c/pt/zpt.py	2008-08-22 15:18:08 UTC (rev 90132)
@@ -183,6 +183,7 @@
     metal_defineslot = utils.attribute('define-slot')
 
 class ZopePageTemplateParser(etree.Parser):
+    """ The parser implementation for ZPT """
     element_mapping = {
         config.XHTML_NS: {None: XHTMLElement},
         config.META_NS: {None: XHTMLElement},



More information about the Checkins mailing list