[Checkins] SVN: z3c.pt/trunk/z3c/pt/ Renamed module.

Malthe Borch mborch at gmail.com
Sun Mar 16 08:16:32 EDT 2008


Log message for revision 84704:
  Renamed module.

Changed:
  U   z3c.pt/trunk/z3c/pt/clauses.py
  D   z3c.pt/trunk/z3c/pt/expressions.py
  A   z3c.pt/trunk/z3c/pt/parsing.py
  U   z3c.pt/trunk/z3c/pt/tests/test_doctests.py
  U   z3c.pt/trunk/z3c/pt/translation.py

-=-
Modified: z3c.pt/trunk/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/z3c/pt/clauses.py	2008-03-16 11:14:32 UTC (rev 84703)
+++ z3c.pt/trunk/z3c/pt/clauses.py	2008-03-16 12:16:30 UTC (rev 84704)
@@ -1,11 +1,10 @@
-from expressions import value
 from utils import unicode_required_flag
-
 from cgi import escape
 
 class Assign(object):
     """
       >>> from z3c.pt.io import CodeIO; stream = CodeIO()
+      >>> from z3c.pt.parsing import value
 
     Simple assignment:
 
@@ -63,7 +62,8 @@
 class Define(object):
     """
       >>> from z3c.pt.io import CodeIO; stream = CodeIO()
-
+      >>> from z3c.pt.parsing import value
+      
     Variable scope:
 
       >>> define = Define("a", value("b"))
@@ -209,7 +209,8 @@
 class Condition(object):
     """
       >>> from z3c.pt.io import CodeIO
-
+      >>> from z3c.pt.parsing import value
+      
     Unlimited scope:
     
       >>> stream = CodeIO()
@@ -325,6 +326,7 @@
 class Tag(object):
     """
       >>> from z3c.pt.io import CodeIO
+      >>> from z3c.pt.parsing import value
       >>> from StringIO import StringIO
       >>> from cgi import escape as _escape
       
@@ -423,6 +425,7 @@
 class Repeat(object):
     """
       >>> from z3c.pt.io import CodeIO; stream = CodeIO()
+      >>> from z3c.pt.parsing import value
 
     We need to set up the repeat object.
 
@@ -447,7 +450,7 @@
         
     def __init__(self, v, e, scope=()):
         self.variable = v
-        self.define = Define(v, value("None"))
+        self.define = Define(v, ("None",))
         self.assign = Assign(e)
 
     def begin(self, stream):
@@ -480,6 +483,7 @@
 class Write(object):
     """
       >>> from z3c.pt.io import CodeIO; stream = CodeIO()
+      >>> from z3c.pt.parsing import value
       >>> from StringIO import StringIO
 
       >>> _out = StringIO()
@@ -536,6 +540,7 @@
 class Out(object):
     """
       >>> from z3c.pt.io import CodeIO; stream = CodeIO()
+      >>> from z3c.pt.parsing import value
       >>> from StringIO import StringIO
       >>> _out = StringIO()
       

Deleted: z3c.pt/trunk/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/z3c/pt/expressions.py	2008-03-16 11:14:32 UTC (rev 84703)
+++ z3c.pt/trunk/z3c/pt/expressions.py	2008-03-16 12:16:30 UTC (rev 84704)
@@ -1,263 +0,0 @@
-import parser
-
-def name(string):
-    return string
-
-def search(string):
-    """
-    Extracts the longest valid Python-expression from the beginning of
-    the provided string..
-    
-      >>> search("'Hello World'")
-      "'Hello World'"
-      
-      >>> search("'Hello World'}")
-      "'Hello World'"
-
-      >>> search("'Hello World' + '")
-      "'Hello World' "
-
-    """
-    
-    left = 0
-    right = left + 1
-
-    current = None
-                    
-    while right <= len(string):
-        expression = string[left:right]
-        
-        try:
-            e = value(expression)
-            current = expression
-        except SyntaxError, e:
-            if right == len(string):
-                if current is not None:
-                    return current
-            
-                raise e
-                    
-        right += 1
-
-    return current
-    
-def value(string):
-    """
-    Specification:
-
-    value :: = python_expression [ |* value ]
-    python_expresion ::= a python expression string
-
-    *) Using | as logical or is not supported.
-
-      >>> value("4 + 5")
-      ['4 + 5']
-
-    Complex expressions:
-
-      >>> value("a.non_defined_method() | 1")
-      ['a.non_defined_method() ', '1']
-
-    Expression with non-semantic horizontal bar.
-
-      >>> value("'|'")
-      ["'|'"]
-
-    Expression with non-semantic horizontal bar and semantic bar.
-
-      >>> value("a.non_defined_method() | '|'")
-      ['a.non_defined_method() ', "'|'"]
-
-    """
-
-    string = string.replace('\n', '').strip()
-
-    if not string:
-        return []
-        
-    expressions = []
-
-    i = j = 0
-    while i < len(string):
-        j = string.find('|', j + 1)
-        if j == -1:
-            j = len(string)
-
-        expr = string[i:j].lstrip()
-
-        try:
-            # we use the ``parser`` module to determine if
-            # an expression is a valid python expression
-            parser.expr(expr.encode('utf-8'))
-        except SyntaxError, e:
-            if j < len(string):
-                continue
-
-            raise e
-            
-        expressions.append(expr)
-        i = j + 1
-
-    return expressions
-
-def variable(string):
-    """
-    Specification:
-    
-    variables :: = variable_name [, variables]
-
-    Single variable:
-
-      >>> variable("variable")
-      ('variable',)
-
-    Multiple variables:
-
-      >>> variable("variable1, variable2")
-      ('variable1', 'variable2')
-      
-    """
-
-    variables = []
-    for var in string.split(', '):
-        var = var.strip()
-
-        if var in ('repeat',):
-            raise ValueError, "Invalid variable name '%s' (reserved)." % variable
-
-        if var.startswith('_') and not var.startswith('_tmp'):
-            raise ValueError(
-                "Invalid variable name '%s' (starts with an underscore)." % var)
-        
-        variables.append(var)
-
-    return tuple(variables)
-
-def mapping(string):
-    """
-
-      >>> mapping("abc def")
-      [('abc', 'def')]
-
-      >>> mapping("abc")
-      [('abc', None)]
-
-      >>> mapping("abc; def ghi")
-      [('abc', None), ('def', 'ghi')]
-
-    """
-
-    defs = string.split(';')
-    mappings = []
-    for d in defs:
-        d = d.strip()
-        while '  ' in d:
-            d = d.replace('  ', ' ')
-
-        parts = d.split(' ')
-        if len(parts) == 1:
-            mappings.append((d, None))
-        elif len(parts) == 2:
-            mappings.append((parts[0], parts[1]))
-        else:
-            raise ValueError, "Invalid mapping (%s)." % string
-
-    return mappings
-    
-def definitions(string):
-    """
-    Specification:
-
-    argument ::= define_var [';' define_var]
-    define_var ::= Name python_expression
-
-    Single define:
-
-      >>> definitions("variable expression")
-      [(['variable'], ['expression'])]
-    
-    Multiple defines:
-
-      >>> definitions("variable1 expression1; variable2 expression2")
-      [(['variable1'], ['expression1']), (['variable2'], ['expression2'])]
-
-    Tuple define:
-
-      >>> definitions("(variable1, variable2) (expression1, expression2)")
-      [(['variable1', 'variable2'], ['(expression1, expression2)'])]
-
-    Use of unescaped semicolon in an expression:
-
-      >>> definitions("variable ';'")
-      [(['variable'], ["';'"])]
-    
-    A define clause that ends in a semicolon:
-
-      >>> definitions("variable expression;")
-      [(['variable'], ['expression'])]
-
-    A define clause with a trivial expression (we do allow this):
-    
-      >>> definitions("variable")
-      [(['variable'], None)]
-
-    A proper define clause following one with a trivial expression:
-
-      >>> definitions("variable1 expression; variable2")
-      [(['variable1'], ['expression']), (['variable2'], None)]
-      
-    """
-
-    string = string.replace('\n', '').strip()
-
-    defines = []
-
-    i = 0
-    while i < len(string):
-        while string[i] == ' ':
-            i += 1
-
-        # get variable definition
-        if string[i] == '(':
-            j = string.find(')', i+1)
-            if j == -1:
-                raise ValueError, "Invalid variable tuple definition (%s)." % string
-            var = variable(string[i+1:j])
-            j += 1
-        else:
-            j = string.find(' ', i + 1)
-            if j == -1:
-                var = variable(string[i:])
-                j = len(string)
-            else:
-                var = variable(string[i:j])
-
-        # get expression
-        i = j
-        while j < len(string):
-            j = string.find(';', j+1)
-            if j == -1:
-                j = len(string)
-
-            try:
-                expr = value(string[i:j])
-            except SyntaxError, e:
-                if j < len(string):
-                    continue
-                raise e
-            break
-        else:
-            expr = None
-
-        defines.append((list(var), expr))
-
-        i = j + 1
-
-    return defines
-
-def definition(string):
-    defs = definitions(string)
-    if len(defs) != 1:
-        raise ValueError, "Multiple definitions not allowed."
-
-    return defs[0]

Copied: z3c.pt/trunk/z3c/pt/parsing.py (from rev 84456, z3c.pt/trunk/z3c/pt/expressions.py)
===================================================================
--- z3c.pt/trunk/z3c/pt/parsing.py	                        (rev 0)
+++ z3c.pt/trunk/z3c/pt/parsing.py	2008-03-16 12:16:30 UTC (rev 84704)
@@ -0,0 +1,263 @@
+import parser
+
+def name(string):
+    return string
+
+def search(string):
+    """
+    Extracts the longest valid Python-expression from the beginning of
+    the provided string..
+    
+      >>> search("'Hello World'")
+      "'Hello World'"
+      
+      >>> search("'Hello World'}")
+      "'Hello World'"
+
+      >>> search("'Hello World' + '")
+      "'Hello World' "
+
+    """
+    
+    left = 0
+    right = left + 1
+
+    current = None
+                    
+    while right <= len(string):
+        expression = string[left:right]
+        
+        try:
+            e = value(expression)
+            current = expression
+        except SyntaxError, e:
+            if right == len(string):
+                if current is not None:
+                    return current
+            
+                raise e
+                    
+        right += 1
+
+    return current
+    
+def value(string):
+    """
+    Specification:
+
+    value :: = python_expression [ |* value ]
+    python_expresion ::= a python expression string
+
+    *) Using | as logical or is not supported.
+
+      >>> value("4 + 5")
+      ['4 + 5']
+
+    Complex expressions:
+
+      >>> value("a.non_defined_method() | 1")
+      ['a.non_defined_method() ', '1']
+
+    Expression with non-semantic horizontal bar.
+
+      >>> value("'|'")
+      ["'|'"]
+
+    Expression with non-semantic horizontal bar and semantic bar.
+
+      >>> value("a.non_defined_method() | '|'")
+      ['a.non_defined_method() ', "'|'"]
+
+    """
+
+    string = string.replace('\n', '').strip()
+
+    if not string:
+        return []
+        
+    expressions = []
+
+    i = j = 0
+    while i < len(string):
+        j = string.find('|', j + 1)
+        if j == -1:
+            j = len(string)
+
+        expr = string[i:j].lstrip()
+
+        try:
+            # we use the ``parser`` module to determine if
+            # an expression is a valid python expression
+            parser.expr(expr.encode('utf-8'))
+        except SyntaxError, e:
+            if j < len(string):
+                continue
+
+            raise e
+            
+        expressions.append(expr)
+        i = j + 1
+
+    return expressions
+
+def variable(string):
+    """
+    Specification:
+    
+    variables :: = variable_name [, variables]
+
+    Single variable:
+
+      >>> variable("variable")
+      ('variable',)
+
+    Multiple variables:
+
+      >>> variable("variable1, variable2")
+      ('variable1', 'variable2')
+      
+    """
+
+    variables = []
+    for var in string.split(', '):
+        var = var.strip()
+
+        if var in ('repeat',):
+            raise ValueError, "Invalid variable name '%s' (reserved)." % variable
+
+        if var.startswith('_') and not var.startswith('_tmp'):
+            raise ValueError(
+                "Invalid variable name '%s' (starts with an underscore)." % var)
+        
+        variables.append(var)
+
+    return tuple(variables)
+
+def mapping(string):
+    """
+
+      >>> mapping("abc def")
+      [('abc', 'def')]
+
+      >>> mapping("abc")
+      [('abc', None)]
+
+      >>> mapping("abc; def ghi")
+      [('abc', None), ('def', 'ghi')]
+
+    """
+
+    defs = string.split(';')
+    mappings = []
+    for d in defs:
+        d = d.strip()
+        while '  ' in d:
+            d = d.replace('  ', ' ')
+
+        parts = d.split(' ')
+        if len(parts) == 1:
+            mappings.append((d, None))
+        elif len(parts) == 2:
+            mappings.append((parts[0], parts[1]))
+        else:
+            raise ValueError, "Invalid mapping (%s)." % string
+
+    return mappings
+    
+def definitions(string):
+    """
+    Specification:
+
+    argument ::= define_var [';' define_var]
+    define_var ::= Name python_expression
+
+    Single define:
+
+      >>> definitions("variable expression")
+      [(['variable'], ['expression'])]
+    
+    Multiple defines:
+
+      >>> definitions("variable1 expression1; variable2 expression2")
+      [(['variable1'], ['expression1']), (['variable2'], ['expression2'])]
+
+    Tuple define:
+
+      >>> definitions("(variable1, variable2) (expression1, expression2)")
+      [(['variable1', 'variable2'], ['(expression1, expression2)'])]
+
+    Use of unescaped semicolon in an expression:
+
+      >>> definitions("variable ';'")
+      [(['variable'], ["';'"])]
+    
+    A define clause that ends in a semicolon:
+
+      >>> definitions("variable expression;")
+      [(['variable'], ['expression'])]
+
+    A define clause with a trivial expression (we do allow this):
+    
+      >>> definitions("variable")
+      [(['variable'], None)]
+
+    A proper define clause following one with a trivial expression:
+
+      >>> definitions("variable1 expression; variable2")
+      [(['variable1'], ['expression']), (['variable2'], None)]
+      
+    """
+
+    string = string.replace('\n', '').strip()
+
+    defines = []
+
+    i = 0
+    while i < len(string):
+        while string[i] == ' ':
+            i += 1
+
+        # get variable definition
+        if string[i] == '(':
+            j = string.find(')', i+1)
+            if j == -1:
+                raise ValueError, "Invalid variable tuple definition (%s)." % string
+            var = variable(string[i+1:j])
+            j += 1
+        else:
+            j = string.find(' ', i + 1)
+            if j == -1:
+                var = variable(string[i:])
+                j = len(string)
+            else:
+                var = variable(string[i:j])
+
+        # get expression
+        i = j
+        while j < len(string):
+            j = string.find(';', j+1)
+            if j == -1:
+                j = len(string)
+
+            try:
+                expr = value(string[i:j])
+            except SyntaxError, e:
+                if j < len(string):
+                    continue
+                raise e
+            break
+        else:
+            expr = None
+
+        defines.append((list(var), expr))
+
+        i = j + 1
+
+    return defines
+
+def definition(string):
+    defs = definitions(string)
+    if len(defs) != 1:
+        raise ValueError, "Multiple definitions not allowed."
+
+    return defs[0]

Modified: z3c.pt/trunk/z3c/pt/tests/test_doctests.py
===================================================================
--- z3c.pt/trunk/z3c/pt/tests/test_doctests.py	2008-03-16 11:14:32 UTC (rev 84703)
+++ z3c.pt/trunk/z3c/pt/tests/test_doctests.py	2008-03-16 12:16:30 UTC (rev 84704)
@@ -9,7 +9,7 @@
 
 def test_suite():
     filesuites = ['README.txt', 'BENCHMARKS.txt', 'translation.txt', 'i18n.txt', 'codegen.txt']
-    testsuites = ['z3c.pt.translation', 'z3c.pt.expressions', 'z3c.pt.clauses']
+    testsuites = ['z3c.pt.translation', 'z3c.pt.parsing', 'z3c.pt.clauses']
 
     return unittest.TestSuite(
         [zope.testing.doctest.DocTestSuite(doctest,

Modified: z3c.pt/trunk/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/z3c/pt/translation.py	2008-03-16 11:14:32 UTC (rev 84703)
+++ z3c.pt/trunk/z3c/pt/translation.py	2008-03-16 12:16:30 UTC (rev 84704)
@@ -4,7 +4,7 @@
 
 import io
 import utils
-import expressions
+import parsing
 import clauses
 
 # set up namespace
@@ -49,7 +49,7 @@
         return None
 
     left = m.start()
-    exp = expressions.search(string[left+3:])
+    exp = parsing.search(string[left+3:])
     right = left+4+len(exp)
 
     m = interpolation_regex.search(string[:right])
@@ -157,7 +157,7 @@
                 format += '%s%s'
                 exp = m.group('expression')
 
-                if len(expressions.value(exp)) == 1:
+                if len(parsing.value(exp)) == 1:
                     terms.extend(("'%s'" % text.replace("'", "\\'"), exp))
                 else:
                     var = stream.save()
@@ -381,35 +381,35 @@
         return attributes
 
     define = attribute(
-        "{http://xml.zope.org/namespaces/tal}define", expressions.definitions)
+        "{http://xml.zope.org/namespaces/tal}define", parsing.definitions)
     condition = attribute(
-        "{http://xml.zope.org/namespaces/tal}condition", expressions.value)
+        "{http://xml.zope.org/namespaces/tal}condition", parsing.value)
     repeat = attribute(
-        "{http://xml.zope.org/namespaces/tal}repeat", expressions.definition)
+        "{http://xml.zope.org/namespaces/tal}repeat", parsing.definition)
     attributes = attribute(
-        "{http://xml.zope.org/namespaces/tal}attributes", expressions.definitions)
+        "{http://xml.zope.org/namespaces/tal}attributes", parsing.definitions)
     content = attribute(
-        "{http://xml.zope.org/namespaces/tal}content", expressions.value)
+        "{http://xml.zope.org/namespaces/tal}content", parsing.value)
     replace = attribute(
-        "{http://xml.zope.org/namespaces/tal}replace", expressions.value)
+        "{http://xml.zope.org/namespaces/tal}replace", parsing.value)
     omit = attribute(
-        "{http://xml.zope.org/namespaces/tal}omit-tag", expressions.value)
+        "{http://xml.zope.org/namespaces/tal}omit-tag", parsing.value)
     i18n_translate = attribute(
-        "{http://xml.zope.org/namespaces/i18n}translate", expressions.name)
+        "{http://xml.zope.org/namespaces/i18n}translate", parsing.name)
     i18n_attributes = attribute(
-        "{http://xml.zope.org/namespaces/i18n}attributes", expressions.mapping)
+        "{http://xml.zope.org/namespaces/i18n}attributes", parsing.mapping)
     i18n_domain = attribute(
-        "{http://xml.zope.org/namespaces/i18n}domain", expressions.name)
+        "{http://xml.zope.org/namespaces/i18n}domain", parsing.name)
     i18n_name = attribute(
-        "{http://xml.zope.org/namespaces/i18n}name", expressions.name)
+        "{http://xml.zope.org/namespaces/i18n}name", parsing.name)
 
 class TALElement(Element):
-    define = attribute("define", expressions.definitions)
-    replace = attribute("replace", expressions.value)
-    repeat = attribute("repeat", expressions.definition)
-    attributes = attribute("attributes", expressions.value)
-    content = attribute("content", expressions.value)
-    omit = attribute("omit-tag", expressions.value, u"")
+    define = attribute("define", parsing.definitions)
+    replace = attribute("replace", parsing.value)
+    repeat = attribute("repeat", parsing.definition)
+    attributes = attribute("attributes", parsing.value)
+    content = attribute("content", parsing.value)
+    omit = attribute("omit-tag", parsing.value, u"")
     
     def _static_attributes(self):
         attributes = {}



More information about the Checkins mailing list