[Zope-CVS] CVS: Products/CompositePage - slotexpr.py:1.3

Shane Hathaway shane at zope.com
Mon Mar 8 15:04:15 EST 2004


Update of /cvs-repository/Products/CompositePage
In directory cvs.zope.org:/tmp/cvs-serv533

Modified Files:
	slotexpr.py 
Log Message:
Slot expressions now use a particular order: "name(class) 'title'"


=== Products/CompositePage/slotexpr.py 1.2 => 1.3 ===
--- Products/CompositePage/slotexpr.py:1.2	Fri Mar  5 18:03:29 2004
+++ Products/CompositePage/slotexpr.py	Mon Mar  8 15:03:45 2004
@@ -19,13 +19,13 @@
 
 import re
 
-from Products.PageTemplates.TALES import CompilerError, Default, _valid_name
+from Products.PageTemplates.TALES import CompilerError, Default
 
 from interfaces import IComposite
 
-
-# Match a slot_name, (class_name), or 'title'.
-_token_re = re.compile("([a-zA-Z][a-zA-Z0-9_]*)|[(]([^)]+)[)]|[']([^']+)[']")
+name_re = re.compile("\s*([a-zA-Z][a-zA-Z0-9_]*)")
+class_name_re = re.compile("\s*[(]([a-zA-Z][a-zA-Z0-9_]*)[)]")
+title_re = re.compile("\s*[']([^']+)[']")
 
 
 class SlotExpr:
@@ -34,36 +34,32 @@
     Provides a concise syntax for specifying composite slots in
     ZPT.  An example slot expression, in context of ZPT:
 
-    <div tal:replace="slot: slot_name (class_name) 'Title'" />
+    <div tal:replace="slot: slot_name(class_name) 'Title'" />
     """
 
     def __init__(self, name, expr, engine):
-        self._s = expr
-        # pattern we are aiming for is 
-        # id 'Title' (my_slot_class_id) 
-        # or any variation.  first id, title, and slot class are used without
-        # throwing an error if there are any more, but slot class and id must
-        # be valid names
-        self._name = None
-        self._class_name = None
-        self._title = None
-        for n, c, t in _token_re.findall(expr):
-            if n:
-                if not _valid_name(n):
-                    raise CompilerError('Invalid slot name "%s"' % n)
-                if self._name:
-                    raise CompilerError('Multiple slot names')
-                self._name = n
-            if c:
-                if not _valid_name(c):
-                    raise CompilerError('Invalid slot class "%s"' % c)
-                if self._class_name:
-                    raise CompilerError('Multiple class names')
-                self._class_name = c
-            if t:
-                if self._title:
-                    raise CompilerError('Multiple titles')
-                self._title = t
+        self._s = s = expr
+        mo = name_re.match(s)
+        if mo is None:
+            raise CompilerError('Invalid slot expression "%s"' % s)
+        self._name = mo.group(1)
+        s = s[mo.end():]
+        mo = class_name_re.match(s)
+        if mo is not None:
+            self._class_name = mo.group(1)
+            s = s[mo.end():]
+        else:
+            self._class_name = None
+        mo = title_re.match(s)
+        if mo is not None:
+            self._title = mo.group(1)
+            s = s[mo.end():]
+        else:
+            self._title = None
+        if s.strip():
+            # Can't interpret some of the expression
+            raise CompilerError(
+                'Slot expression syntax error near %s' % repr(s))
     
     def __call__(self, econtext):
         context = econtext.contexts.get('here')




More information about the Zope-CVS mailing list