[Checkins] SVN: zope.tal/branches/haufe-legacy-integration/ - Launchpad #374720: added 'mltext' (markup langugate text) directive

Andreas Jung andreas at andreas-jung.com
Mon May 11 05:02:45 EDT 2009


Log message for revision 99839:
  - Launchpad #374720: added 'mltext' (markup langugate text) directive
  

Changed:
  U   zope.tal/branches/haufe-legacy-integration/CHANGES.txt
  U   zope.tal/branches/haufe-legacy-integration/src/zope/tal/taldefs.py
  U   zope.tal/branches/haufe-legacy-integration/src/zope/tal/talgenerator.py
  U   zope.tal/branches/haufe-legacy-integration/src/zope/tal/talinterpreter.py
  U   zope.tal/branches/haufe-legacy-integration/src/zope/tal/tests/test_talinterpreter.py

-=-
Modified: zope.tal/branches/haufe-legacy-integration/CHANGES.txt
===================================================================
--- zope.tal/branches/haufe-legacy-integration/CHANGES.txt	2009-05-11 08:50:08 UTC (rev 99838)
+++ zope.tal/branches/haufe-legacy-integration/CHANGES.txt	2009-05-11 09:02:45 UTC (rev 99839)
@@ -5,9 +5,10 @@
 3.6.0 (unreleased)
 ------------------
 
-- Launchpad #3742721 - 'structure' directive support within
+- Launchpad #3742721: 'structure' directive support within
   tal:attributes
 
+- Launchpad #374720: added 'mltext' (markup langugate text) directive
 
 
 3.5.1 (2009-03-08)

Modified: zope.tal/branches/haufe-legacy-integration/src/zope/tal/taldefs.py
===================================================================
--- zope.tal/branches/haufe-legacy-integration/src/zope/tal/taldefs.py	2009-05-11 08:50:08 UTC (rev 99838)
+++ zope.tal/branches/haufe-legacy-integration/src/zope/tal/taldefs.py	2009-05-11 09:02:45 UTC (rev 99839)
@@ -112,7 +112,7 @@
 
 
 _attr_re = re.compile(r"\s*([^\s]+)\s+(?:(text|structure)\s+)?([^\s].*)\Z", re.S)
-_subst_re = re.compile(r"\s*(?:(text|structure)\s+)?(.*)\Z", re.S)
+_subst_re = re.compile(r"\s*(?:(text|structure|mltext)\s+)?(.*)\Z", re.S)
 
 def parseAttributeReplacements(arg, xml):
     dict = {}

Modified: zope.tal/branches/haufe-legacy-integration/src/zope/tal/talgenerator.py
===================================================================
--- zope.tal/branches/haufe-legacy-integration/src/zope/tal/talgenerator.py	2009-05-11 08:50:08 UTC (rev 99838)
+++ zope.tal/branches/haufe-legacy-integration/src/zope/tal/talgenerator.py	2009-05-11 09:02:45 UTC (rev 99839)
@@ -277,6 +277,8 @@
         cexpr = self.compileExpression(expr)
         if key == "text":
             self.emit("insertText", cexpr, [])
+        elif key == "mltext":
+            self.emit("insertMltext", cexpr, [])
         else:
             assert key == "structure"
             self.emit("insertStructure", cexpr, {}, [])
@@ -308,6 +310,8 @@
         program = self.popProgram()
         if key == "text":
             self.emit("insertText", cexpr, program)
+        elif key == "mltext":
+            self.emit("insertMltext", cexpr, program)
         else:
             assert key == "structure"
             self.emit("insertStructure", cexpr, attrDict, program)
@@ -319,6 +323,8 @@
         program = self.popProgram()
         if key == "text":
             self.emit("insertI18nText", cexpr, program)
+        elif key == "mltext":
+            self.emit("insertI18nMltext", cexpr, program)
         else:
             assert key == "structure"
             self.emit("insertI18nStructure", cexpr, attrDict, program)

Modified: zope.tal/branches/haufe-legacy-integration/src/zope/tal/talinterpreter.py
===================================================================
--- zope.tal/branches/haufe-legacy-integration/src/zope/tal/talinterpreter.py	2009-05-11 08:50:08 UTC (rev 99838)
+++ zope.tal/branches/haufe-legacy-integration/src/zope/tal/talinterpreter.py	2009-05-11 09:02:45 UTC (rev 99839)
@@ -607,11 +607,15 @@
         self.interpret(stuff[1])
     bytecode_handlers["insertText"] = do_insertText
     bytecode_handlers["insertI18nText"] = do_insertText
+    bytecode_handlers["insertMltext"] = do_insertText
+    bytecode_handlers["insertI18nMltext"] = do_insertText
 
-    def _writeText(self, text):
+    def _writeText(self, text, quote_amp=True):
         # '&' must be done first!
-        s = text.replace(
-            "&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
+        s = (
+            (quote_amp and text.replace( "&", "&amp;") or text)
+            .replace("<", "&lt;").replace(">", "&gt;")
+            )
         self._stream_write(s)
         i = s.rfind('\n')
         if i < 0:
@@ -619,7 +623,7 @@
         else:
             self.col = len(s) - (i + 1)
 
-    def do_insertText_tal(self, stuff):
+    def do_insertXText_tal(self, stuff, quote_amp):
         text = self.engine.evaluateText(stuff[0])
         if text is None:
             return
@@ -629,9 +633,15 @@
         if isinstance(text, I18nMessageTypes):
             # Translate this now.
             text = self.translate(text)
-        self._writeText(text)
+        self._writeText(text, quote_amp)
 
-    def do_insertI18nText_tal(self, stuff):
+    def do_insertText_tal(self, stuff):
+        return self.do_insertXText_tal(stuff, True)
+
+    def do_insertMltext_tal(self, stuff):
+        return self.do_insertXText_tal(stuff, False)
+
+    def do_insertI18nXText_tal(self, stuff, quote_amp):
         # TODO: Code duplication is BAD, we need to fix it later
         text = self.engine.evaluateText(stuff[0])
         if text is not None:
@@ -640,8 +650,14 @@
             else:
                 if isinstance(text, TypesToTranslate):
                     text = self.translate(text)
-                self._writeText(text)
+                self._writeText(text, quote_amp)
 
+    def do_insertI18nText_tal(self, stuff):
+        return self.do_insertI18nXText_tal(stuff, True)
+
+    def do_insertI18nMltext_tal(self, stuff):
+        return self.do_insertI18nXText_tal(stuff, False)
+
     def do_i18nVariable(self, stuff):
         varname, program, expression, structure = stuff
         if expression is None:
@@ -994,7 +1010,9 @@
     bytecode_handlers_tal["insertStructure"] = do_insertStructure_tal
     bytecode_handlers_tal["insertI18nStructure"] = do_insertI18nStructure_tal
     bytecode_handlers_tal["insertText"] = do_insertText_tal
+    bytecode_handlers_tal["insertMltext"] = do_insertMltext_tal
     bytecode_handlers_tal["insertI18nText"] = do_insertI18nText_tal
+    bytecode_handlers_tal["insertI18nMltext"] = do_insertI18nMltext_tal
     bytecode_handlers_tal["loop"] = do_loop_tal
     bytecode_handlers_tal["onError"] = do_onError_tal
     bytecode_handlers_tal["<attrAction>"] = attrAction_tal

Modified: zope.tal/branches/haufe-legacy-integration/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- zope.tal/branches/haufe-legacy-integration/src/zope/tal/tests/test_talinterpreter.py	2009-05-11 08:50:08 UTC (rev 99838)
+++ zope.tal/branches/haufe-legacy-integration/src/zope/tal/tests/test_talinterpreter.py	2009-05-11 09:02:45 UTC (rev 99839)
@@ -202,17 +202,30 @@
 
     def test_text_translate(self):
         program, macros = self._compile(
-            '<span tal:content="string:BaR"/>')
-        self._check(program, '<span>BaR</span>')
+            '<span tal:content="string:&amp;BaR"/>')
+        self._check(program, '<span>&amp;BaR</span>')
 
         program, macros = self._compile(
-            '<span i18n:translate="" tal:content="string:BaR"/>')
-        self._check(program, '<span>BAR</span>')
+            '<span i18n:translate="" tal:content="string:&amp;BaR"/>')
+        self._check(program, '<span>&amp;BAR</span>')
 
         program, macros = self._compile(
-            '<span i18n:translate="" tal:replace="string:BaR"/>')
-        self._check(program, 'BAR')
+            '<span i18n:translate="" tal:replace="string:&amp;BaR"/>')
+        self._check(program, '&amp;BAR')
 
+    def test_mltext_translate(self):
+        program, macros = self._compile(
+            '<span tal:content="mltext string:&lt;&amp;amp;&gt;BaR"/>')
+        self._check(program, '<span>&lt;&amp;&gt;BaR</span>')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:content="mltext string:&lt;&amp;amp;&gt;BaR"/>')
+        self._check(program, '<span>&lt;&AMP;&gt;BAR</span>')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:replace="mltext string:&lt;&amp;amp;&gt;BaR"/>')
+        self._check(program, '&lt;&AMP;&gt;BAR')
+
     def test_structure_text_variable_translate(self):
         program, macros = self._compile(
             '<span tal:content="structure bar"/>')



More information about the Checkins mailing list