[Checkins] SVN: Sandbox/malthe/chameleon.core/ Normalize METAL slot names; invalid characters are converted to underscore ('_').

Malthe Borch mborch at gmail.com
Tue Nov 18 20:38:14 EST 2008


Log message for revision 93113:
  Normalize METAL slot names; invalid characters are converted to underscore ('_').

Changed:
  U   Sandbox/malthe/chameleon.core/CHANGES.txt
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py

-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-19 01:29:45 UTC (rev 93112)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-19 01:38:14 UTC (rev 93113)
@@ -4,6 +4,9 @@
 HEAD
 ~~~~
 
+- Normalize METAL slot names to ensure they're valid Python variable
+  names. Non-valid characters are converted to underscore. [malthe]
+
 - Renamed dynamic scope variable to `econtext` in order to reduce
   compatibility issues with ZPT. [malthe]
 

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py	2008-11-19 01:29:45 UTC (rev 93112)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/translation.py	2008-11-19 01:38:14 UTC (rev 93113)
@@ -165,7 +165,7 @@
         # macro slot definition
         if self.define_slot:
             # check if slot has been filled
-            name = self.symbols.slot + self.define_slot
+            name = self.symbols.slot + utils.normalize_slot_name(self.define_slot)
             if name in itertools.chain(*self.stream.scope):
                 _.append(clauses.Condition(
                     types.value('isinstance(%s, basestring)' % name),
@@ -329,7 +329,8 @@
                     # (chrism)
                     continue
 
-                callback = self.symbols.slot+element.node.fill_slot
+                callback = self.symbols.slot + \
+                           utils.normalize_slot_name(element.node.fill_slot)
                 remote_scope = self.symbols.scope+"_remote"
                 kwargs.append((callback, callback))
 

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py	2008-11-19 01:29:45 UTC (rev 93112)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py	2008-11-19 01:38:14 UTC (rev 93113)
@@ -87,6 +87,10 @@
         
     return string
 
+re_normalize = re.compile(r'(^[0-9]|\b[^A-Za-z])')
+def normalize_slot_name(name):
+    return re_normalize.sub('_', name)
+    
 def serialize(element, encoding=None):
     return "".join(serialize_element(element, encoding))
 



More information about the Checkins mailing list