diff options
author | Andreas Jung <yet@gmx.de> | 2009-05-11 09:02:45 +0000 |
---|---|---|
committer | Andreas Jung <yet@gmx.de> | 2009-05-11 09:02:45 +0000 |
commit | 944194fb5f7cec72af31b3d99d7c231c5303240b (patch) | |
tree | 4a5ea1dffbbc7ae9de3cfd6855afa1f38e9923d6 | |
parent | eac40552db16e2c67e1eb3e0de028601d32e7c1d (diff) | |
download | zope-tal-haufe-legacy-integration.tar.gz |
- Launchpad #374720: added 'mltext' (markup langugate text) directivehaufe-legacy-integration
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | src/zope/tal/taldefs.py | 2 | ||||
-rw-r--r-- | src/zope/tal/talgenerator.py | 6 | ||||
-rw-r--r-- | src/zope/tal/talinterpreter.py | 32 | ||||
-rw-r--r-- | src/zope/tal/tests/test_talinterpreter.py | 25 |
5 files changed, 53 insertions, 15 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 6e9f59f..ee053fc 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,9 +5,10 @@ CHANGES 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) diff --git a/src/zope/tal/taldefs.py b/src/zope/tal/taldefs.py index ffd7eb8..aeb0633 100644 --- a/src/zope/tal/taldefs.py +++ b/src/zope/tal/taldefs.py @@ -112,7 +112,7 @@ class ErrorInfo(object): _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 = {} diff --git a/src/zope/tal/talgenerator.py b/src/zope/tal/talgenerator.py index fcff484..c1e8f65 100644 --- a/src/zope/tal/talgenerator.py +++ b/src/zope/tal/talgenerator.py @@ -277,6 +277,8 @@ class TALGenerator(object): 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 @@ class TALGenerator(object): 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 @@ class TALGenerator(object): 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) diff --git a/src/zope/tal/talinterpreter.py b/src/zope/tal/talinterpreter.py index 98b0ed1..e0c9854 100644 --- a/src/zope/tal/talinterpreter.py +++ b/src/zope/tal/talinterpreter.py @@ -607,11 +607,15 @@ class TALInterpreter(object): 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( - "&", "&").replace("<", "<").replace(">", ">") + s = ( + (quote_amp and text.replace( "&", "&") or text) + .replace("<", "<").replace(">", ">") + ) self._stream_write(s) i = s.rfind('\n') if i < 0: @@ -619,7 +623,7 @@ class TALInterpreter(object): 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 @@ class TALInterpreter(object): 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,7 +650,13 @@ class TALInterpreter(object): 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 @@ -994,7 +1010,9 @@ class TALInterpreter(object): 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 diff --git a/src/zope/tal/tests/test_talinterpreter.py b/src/zope/tal/tests/test_talinterpreter.py index 6d9bb3f..441f95c 100644 --- a/src/zope/tal/tests/test_talinterpreter.py +++ b/src/zope/tal/tests/test_talinterpreter.py @@ -202,16 +202,29 @@ class I18NCornerTestCaseBase(TestCaseBase): def test_text_translate(self): program, macros = self._compile( - '<span tal:content="string:BaR"/>') - self._check(program, '<span>BaR</span>') + '<span tal:content="string:&BaR"/>') + self._check(program, '<span>&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:&BaR"/>') + self._check(program, '<span>&BAR</span>') program, macros = self._compile( - '<span i18n:translate="" tal:replace="string:BaR"/>') - self._check(program, 'BAR') + '<span i18n:translate="" tal:replace="string:&BaR"/>') + self._check(program, '&BAR') + + def test_mltext_translate(self): + program, macros = self._compile( + '<span tal:content="mltext string:<&amp;>BaR"/>') + self._check(program, '<span><&>BaR</span>') + + program, macros = self._compile( + '<span i18n:translate="" tal:content="mltext string:<&amp;>BaR"/>') + self._check(program, '<span><&>BAR</span>') + + program, macros = self._compile( + '<span i18n:translate="" tal:replace="mltext string:<&amp;>BaR"/>') + self._check(program, '<&>BAR') def test_structure_text_variable_translate(self): program, macros = self._compile( |