[Checkins] SVN: z3c.pt/trunk/ Fixed bug in path-expressions; attributes with string-values are now properly traversed to.

Malthe Borch mborch at gmail.com
Tue Aug 12 18:02:49 EDT 2008


Log message for revision 89757:
  Fixed bug in path-expressions; attributes with string-values are now properly traversed to.

Changed:
  U   z3c.pt/trunk/CHANGES.txt
  U   z3c.pt/trunk/src/z3c/pt/expressions.py
  U   z3c.pt/trunk/src/z3c/pt/translation.txt

-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt	2008-08-12 21:34:41 UTC (rev 89756)
+++ z3c.pt/trunk/CHANGES.txt	2008-08-12 22:02:49 UTC (rev 89757)
@@ -4,6 +4,9 @@
 Version 1.0dev
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Fixed bug in path-expressions where string instances would be
+  (attempted) called. [malthe]
+
 - No longer require default namespace. [malthe]
 
 - Changed source code debug mode files to be named <filename>.py instead of

Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py	2008-08-12 21:34:41 UTC (rev 89756)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py	2008-08-12 22:02:49 UTC (rev 89757)
@@ -576,20 +576,28 @@
         return string.replace(';;', ';')
         
 class PathTranslation(ExpressionTranslation):
-    path_regex = re.compile(r'^((nocall|not):\s*)*([A-Za-z_]+)(/[A-Za-z_ at -]+)*$')
+    path_regex = re.compile(
+        r'^((nocall|not):\s*)*([A-Za-z_][A-Za-z0-9_]*)'+
+        r'(/[A-Za-z_ at -][A-Za-z0-9_ at -]*)*$')
 
     @classmethod
     def traverse(cls, base, request, call, *path_items):
         """See ``zope.app.pagetemplate.engine``."""
 
         _callable = callable(base)
-        
+
         for i in range(len(path_items)):
             name = path_items[i]
 
             next = getattr(base, name, _marker)
             if next is not _marker:
-                base = next()
+                _callable = callable(next)
+
+                if _callable:
+                    base = next()
+                else:
+                    base = next
+                    continue
             else:
                 # special-case dicts for performance reasons        
                 if getattr(base, '__class__', None) == dict:

Modified: z3c.pt/trunk/src/z3c/pt/translation.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/translation.txt	2008-08-12 21:34:41 UTC (rev 89756)
+++ z3c.pt/trunk/src/z3c/pt/translation.txt	2008-08-12 22:02:49 UTC (rev 89757)
@@ -295,13 +295,19 @@
 
 :: Using the "path:" expression
 
+  >>> class Test(object):
+  ...     greeting = u'Hello'
+  
   >>> print render("""\
   ... <div xmlns="http://www.w3.org/1999/xhtml"
   ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
-  ...   <span tal:replace="path: test/greeting" />
-  ... </div>""", translate_xml, request=object(), test={'greeting': u'Hello'})
+  ...   <span tal:replace="path: test1/greeting" />
+  ...   <span tal:replace="path: test2/greeting" />
+  ... </div>""", translate_xml, request=object(),
+  ... test1={'greeting': u'Hello'}, test2=Test())
   <div>
     Hello
+    Hello
   </div>
 
 :: Using the "string:" expression



More information about the Checkins mailing list