From gotcha at swing.be Fri Aug 8 04:55:10 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:18 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - TALInterpreter.py:1.78.8.1
Message-ID: <200308080855.h788tAb11327@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv11159
Modified Files:
Tag: gotcha-talz3_backport-branch
TALInterpreter.py
Log Message:
backport of few fixes from Zope3
=== Zope/lib/python/TAL/TALInterpreter.py 1.78 => 1.78.8.1 ===
--- Zope/lib/python/TAL/TALInterpreter.py:1.78 Mon Apr 7 13:38:27 2003
+++ Zope/lib/python/TAL/TALInterpreter.py Fri Aug 8 04:55:01 2003
@@ -180,18 +180,7 @@
self.macroStack.append([macroName, slots, entering, self.i18nContext])
def popMacro(self):
- stuff = self.macroStack.pop()
- self.i18nContext = stuff[3]
- return stuff
-
- def macroContext(self, what):
- macroStack = self.macroStack
- i = len(macroStack)
- while i > 0:
- i = i-1
- if macroStack[i][0] == what:
- return i
- return -1
+ return self.macroStack.pop()
def __call__(self):
assert self.level == 0
@@ -292,14 +281,21 @@
if _len(item) == 2:
name, s = item
else:
- ok, name, s = attrAction(self, item)
+ # item[2] is the 'action' field:
+ if item[2] in ('metal', 'tal', 'xmlns', 'i18n'):
+ if not self.showtal:
+ continue
+ ok, name, s = self.attrAction(item)
+ else:
+ ok, name, s = attrAction(self, item)
if not ok:
continue
slen = _len(s)
if (wrap and
col >= align and
col + 1 + slen > wrap):
- append("\n" + " "*align)
+ append("\n")
+ append(" "*align)
col = align + slen
else:
append(" ")
@@ -314,8 +310,7 @@
def attrAction(self, item):
name, value, action = item[:3]
- if action == 'insert' or (action in ('metal', 'tal', 'xmlns', 'i18n')
- and not self.showtal):
+ if action == 'insert':
return 0, name, value
macs = self.macroStack
if action == 'metal' and self.metal and macs:
@@ -345,8 +340,6 @@
return 1, name, value
def attrAction_tal(self, item):
- if item[2] in ('metal', 'tal', 'xmlns', 'i18n'):
- return self.attrAction(item)
name, value, action = item[:3]
ok = 1
expr, xlat, msgid = item[3:]
@@ -408,14 +401,6 @@
else:
self.do_optTag(stuff)
bytecode_handlers["optTag"] = do_optTag
-
- def dumpMacroStack(self, prefix, suffix, value):
- sys.stderr.write("+---- %s%s = %s\n" % (prefix, suffix, value))
- for i in range(len(self.macroStack)):
- what, macroName, slots = self.macroStack[i][:3]
- sys.stderr.write("| %2d. %-12s %-12s %s\n" %
- (i, what, macroName, slots and slots.keys()))
- sys.stderr.write("+--------------------------------------\n")
def do_rawtextBeginScope(self, (s, col, position, closeprev, dict)):
self._stream_write(s)
From gotcha at swing.be Fri Aug 8 05:16:17 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:18 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - TALInterpreter.py:1.79
Message-ID: <200308080916.h789GHU14738@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv14663
Modified Files:
TALInterpreter.py
Log Message:
merge from gotcha-talz3_backport-branch
=== Zope/lib/python/TAL/TALInterpreter.py 1.78 => 1.79 ===
--- Zope/lib/python/TAL/TALInterpreter.py:1.78 Mon Apr 7 13:38:27 2003
+++ Zope/lib/python/TAL/TALInterpreter.py Fri Aug 8 05:16:10 2003
@@ -180,18 +180,7 @@
self.macroStack.append([macroName, slots, entering, self.i18nContext])
def popMacro(self):
- stuff = self.macroStack.pop()
- self.i18nContext = stuff[3]
- return stuff
-
- def macroContext(self, what):
- macroStack = self.macroStack
- i = len(macroStack)
- while i > 0:
- i = i-1
- if macroStack[i][0] == what:
- return i
- return -1
+ return self.macroStack.pop()
def __call__(self):
assert self.level == 0
@@ -292,14 +281,21 @@
if _len(item) == 2:
name, s = item
else:
- ok, name, s = attrAction(self, item)
+ # item[2] is the 'action' field:
+ if item[2] in ('metal', 'tal', 'xmlns', 'i18n'):
+ if not self.showtal:
+ continue
+ ok, name, s = self.attrAction(item)
+ else:
+ ok, name, s = attrAction(self, item)
if not ok:
continue
slen = _len(s)
if (wrap and
col >= align and
col + 1 + slen > wrap):
- append("\n" + " "*align)
+ append("\n")
+ append(" "*align)
col = align + slen
else:
append(" ")
@@ -314,8 +310,7 @@
def attrAction(self, item):
name, value, action = item[:3]
- if action == 'insert' or (action in ('metal', 'tal', 'xmlns', 'i18n')
- and not self.showtal):
+ if action == 'insert':
return 0, name, value
macs = self.macroStack
if action == 'metal' and self.metal and macs:
@@ -345,8 +340,6 @@
return 1, name, value
def attrAction_tal(self, item):
- if item[2] in ('metal', 'tal', 'xmlns', 'i18n'):
- return self.attrAction(item)
name, value, action = item[:3]
ok = 1
expr, xlat, msgid = item[3:]
@@ -408,14 +401,6 @@
else:
self.do_optTag(stuff)
bytecode_handlers["optTag"] = do_optTag
-
- def dumpMacroStack(self, prefix, suffix, value):
- sys.stderr.write("+---- %s%s = %s\n" % (prefix, suffix, value))
- for i in range(len(self.macroStack)):
- what, macroName, slots = self.macroStack[i][:3]
- sys.stderr.write("| %2d. %-12s %-12s %s\n" %
- (i, what, macroName, slots and slots.keys()))
- sys.stderr.write("+--------------------------------------\n")
def do_rawtextBeginScope(self, (s, col, position, closeprev, dict)):
self._stream_write(s)
From gotcha at swing.be Fri Aug 8 06:37:43 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:18 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - TALInterpreter.py:1.78.4.1
Message-ID: <200308081037.h78AbhD27545@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv27448
Modified Files:
Tag: Zope-2_7-branch
TALInterpreter.py
Log Message:
merging from gotcha-talz3_backport-branch
=== Zope/lib/python/TAL/TALInterpreter.py 1.78 => 1.78.4.1 ===
--- Zope/lib/python/TAL/TALInterpreter.py:1.78 Mon Apr 7 13:38:27 2003
+++ Zope/lib/python/TAL/TALInterpreter.py Fri Aug 8 06:37:36 2003
@@ -180,18 +180,7 @@
self.macroStack.append([macroName, slots, entering, self.i18nContext])
def popMacro(self):
- stuff = self.macroStack.pop()
- self.i18nContext = stuff[3]
- return stuff
-
- def macroContext(self, what):
- macroStack = self.macroStack
- i = len(macroStack)
- while i > 0:
- i = i-1
- if macroStack[i][0] == what:
- return i
- return -1
+ return self.macroStack.pop()
def __call__(self):
assert self.level == 0
@@ -292,14 +281,21 @@
if _len(item) == 2:
name, s = item
else:
- ok, name, s = attrAction(self, item)
+ # item[2] is the 'action' field:
+ if item[2] in ('metal', 'tal', 'xmlns', 'i18n'):
+ if not self.showtal:
+ continue
+ ok, name, s = self.attrAction(item)
+ else:
+ ok, name, s = attrAction(self, item)
if not ok:
continue
slen = _len(s)
if (wrap and
col >= align and
col + 1 + slen > wrap):
- append("\n" + " "*align)
+ append("\n")
+ append(" "*align)
col = align + slen
else:
append(" ")
@@ -314,8 +310,7 @@
def attrAction(self, item):
name, value, action = item[:3]
- if action == 'insert' or (action in ('metal', 'tal', 'xmlns', 'i18n')
- and not self.showtal):
+ if action == 'insert':
return 0, name, value
macs = self.macroStack
if action == 'metal' and self.metal and macs:
@@ -345,8 +340,6 @@
return 1, name, value
def attrAction_tal(self, item):
- if item[2] in ('metal', 'tal', 'xmlns', 'i18n'):
- return self.attrAction(item)
name, value, action = item[:3]
ok = 1
expr, xlat, msgid = item[3:]
@@ -408,14 +401,6 @@
else:
self.do_optTag(stuff)
bytecode_handlers["optTag"] = do_optTag
-
- def dumpMacroStack(self, prefix, suffix, value):
- sys.stderr.write("+---- %s%s = %s\n" % (prefix, suffix, value))
- for i in range(len(self.macroStack)):
- what, macroName, slots = self.macroStack[i][:3]
- sys.stderr.write("| %2d. %-12s %-12s %s\n" %
- (i, what, macroName, slots and slots.keys()))
- sys.stderr.write("+--------------------------------------\n")
def do_rawtextBeginScope(self, (s, col, position, closeprev, dict)):
self._stream_write(s)
From gotcha at swing.be Fri Aug 15 09:50:31 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:18 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests/output -
test29.html:1.1.6.1 test_metal4.html:1.1.2.1
test_metal5.html:1.1.2.1 test_metal6.html:1.1.2.1
test_metal7.html:1.1.2.1 test_metal1.html:1.5.38.1
Message-ID: <200308151350.h7FDoVA09947@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL/tests/output
In directory cvs.zope.org:/tmp/cvs-serv8434/tests/output
Modified Files:
Tag: gotcha-talz3_backport-branch
test_metal1.html
Added Files:
Tag: gotcha-talz3_backport-branch
test29.html test_metal4.html test_metal5.html test_metal6.html
test_metal7.html
Log Message:
backport of TAL fixes from z3
- i18n and metal interactions
- fix handling of nested translations with tal:content/replace and i18n:name
some reformatting to ease comparisons between 2.x and 3
=== Added File Zope/lib/python/TAL/tests/output/test29.html ===
AT THE TONE THE TIME WILL BE 59 MINUTES AFTER 6 PM... BEEP!
=== Added File Zope/lib/python/TAL/tests/output/test_metal4.html ===
Z3 UI
=== Added File Zope/lib/python/TAL/tests/output/test_metal5.html ===
Z3 UI
=== Added File Zope/lib/python/TAL/tests/output/test_metal6.html ===
Z3 UI
=== Added File Zope/lib/python/TAL/tests/output/test_metal7.html ===
=== Zope/lib/python/TAL/tests/output/test_metal1.html 1.5 => 1.5.38.1 ===
--- Zope/lib/python/TAL/tests/output/test_metal1.html:1.5 Mon Oct 28 15:43:11 2002
+++ Zope/lib/python/TAL/tests/output/test_metal1.html Fri Aug 15 09:50:19 2003
@@ -22,7 +22,7 @@
AAA
-
+ INNER
BBB
@@ -48,7 +48,7 @@
AAA
-
+ INNER
INNERSLOT
@@ -63,7 +63,7 @@
INNER
- INNERSLOT
+ INNERSLOTINNER
@@ -72,8 +72,8 @@
INNER
- INSLOT
+ INSLOT
-INSLOT
+INSLOT
From gotcha at swing.be Fri Aug 15 09:50:46 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:19 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - TALGenerator.py:1.65.4.1
TALInterpreter.py:1.78.8.2
Message-ID: <200308151350.h7FDokY09999@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv8434
Modified Files:
Tag: gotcha-talz3_backport-branch
TALGenerator.py TALInterpreter.py
Log Message:
backport of TAL fixes from z3
- i18n and metal interactions
- fix handling of nested translations with tal:content/replace and i18n:name
some reformatting to ease comparisons between 2.x and 3
=== Zope/lib/python/TAL/TALGenerator.py 1.65 => 1.65.4.1 ===
--- Zope/lib/python/TAL/TALGenerator.py:1.65 Fri Jul 25 14:54:36 2003
+++ Zope/lib/python/TAL/TALGenerator.py Fri Aug 15 09:50:08 2003
@@ -64,6 +64,7 @@
self.source_file = source_file
self.emit("setSourceFile", source_file)
self.i18nContext = TranslationContext()
+ self.i18nLevel = 0
def getCode(self):
assert not self.stack
@@ -73,7 +74,7 @@
def optimize(self, program):
output = []
collect = []
- rawseen = cursor = 0
+ cursor = 0
if self.xml:
endsep = "/>"
else:
@@ -118,7 +119,6 @@
output.append(("rawtextOffset", (text, len(text))))
if opcode != None:
output.append(self.optimizeArgsList(item))
- rawseen = cursor+1
collect = []
return self.optimizeCommonTriple(output)
@@ -180,9 +180,9 @@
output = program[:2]
prev2, prev1 = output
for item in program[2:]:
- if ( item[0] == "beginScope"
- and prev1[0] == "setPosition"
- and prev2[0] == "rawtextColumn"):
+ if ( item[0] == "beginScope"
+ and prev1[0] == "setPosition"
+ and prev2[0] == "rawtextColumn"):
position = output.pop()[1]
text, column = output.pop()[1]
prev1 = None, None
@@ -319,7 +319,7 @@
assert key == "structure"
self.emit("insertStructure", cexpr, attrDict, program)
- def emitI18nVariable(self, varname, action, expression):
+ def emitI18nVariable(self, stuff):
# Used for i18n:name attributes. arg is extra information describing
# how the contents of the variable should get filled in, and it will
# either be a 1-tuple or a 2-tuple. If arg[0] is None, then the
@@ -332,6 +332,7 @@
# calculate the contents of the variable, e.g.
# "I live in "
+ varname, action, expression = stuff
m = _name_rx.match(varname)
if m is None or m.group() != varname:
raise TALError("illegal i18n:name: %r" % varname, self.position)
@@ -525,6 +526,11 @@
varname = i18ndict.get('name')
i18ndata = i18ndict.get('data')
+ if varname and not self.i18nLevel:
+ raise I18NError(
+ "i18n:name can only occur inside a translation unit",
+ position)
+
if i18ndata and not msgid:
raise I18NError("i18n:data must be accompanied by i18n:translate",
position)
@@ -584,7 +590,7 @@
todo["defineSlot"] = defineSlot
if defineSlot or i18ndict:
-
+
domain = i18ndict.get("domain") or self.i18nContext.domain
source = i18ndict.get("source") or self.i18nContext.source
target = i18ndict.get("target") or self.i18nContext.target
@@ -627,22 +633,28 @@
if repeatWhitespace:
self.emitText(repeatWhitespace)
if content:
- todo["content"] = content
- if replace:
+ if varname:
+ todo['i18nvar'] = (varname, I18N_CONTENT, None)
+ todo["content"] = content
+ self.pushProgram()
+ else:
+ todo["content"] = content
+ elif replace:
# tal:replace w/ i18n:name has slightly different semantics. What
# we're actually replacing then is the contents of the ${name}
# placeholder.
if varname:
- todo['i18nvar'] = (varname, replace)
+ todo['i18nvar'] = (varname, I18N_EXPRESSION, replace)
else:
todo["replace"] = replace
self.pushProgram()
# i18n:name w/o tal:replace uses the content as the interpolation
# dictionary values
elif varname:
- todo['i18nvar'] = (varname, None)
+ todo['i18nvar'] = (varname, I18N_REPLACE, None)
self.pushProgram()
if msgid is not None:
+ self.i18nLevel += 1
todo['msgid'] = msgid
if i18ndata:
todo['i18ndata'] = i18ndata
@@ -682,10 +694,12 @@
self.emitStartTag(name, self.replaceAttrs(attrlist, repldict), isend)
if optTag:
self.pushProgram()
- if content:
+ if content and not varname:
self.pushProgram()
if msgid is not None:
self.pushProgram()
+ if content and varname:
+ self.pushProgram()
if todo and position != (None, None):
todo["position"] = position
self.todoPush(todo)
@@ -731,10 +745,7 @@
# If there's no tal:content or tal:replace in the tag with the
# i18n:name, tal:replace is the default.
- i18nNameAction = I18N_REPLACE
if content:
- if varname:
- i18nNameAction = I18N_CONTENT
self.emitSubstitution(content, {})
# If we're looking at an implicit msgid, emit the insertTranslation
# opcode now, so that the end tag doesn't become part of the implicit
@@ -742,8 +753,14 @@
# the opcode after the i18nVariable opcode so we can better handle
# tags with both of them in them (and in the latter case, the contents
# would be thrown away for msgid purposes).
- if msgid is not None and not varname:
- self.emitTranslation(msgid, i18ndata)
+ #
+ # Still, we should emit insertTranslation opcode before i18nVariable
+ # in case tal:content, i18n:translate and i18n:name in the same tag
+ if msgid is not None:
+ if (not varname) or (
+ varname and (varname[1] == I18N_CONTENT)):
+ self.emitTranslation(msgid, i18ndata)
+ self.i18nLevel -= 1
if optTag:
self.emitOptTag(name, optTag, isend)
elif not isend:
@@ -760,20 +777,24 @@
if replace:
self.emitSubstitution(replace, repldict)
elif varname:
- if varname[1] is not None:
- i18nNameAction = I18N_EXPRESSION
# o varname[0] is the variable name
- # o i18nNameAction is either
+ # o varname[1] is either
# - I18N_REPLACE for implicit tal:replace
# - I18N_CONTENT for tal:content
# - I18N_EXPRESSION for explicit tal:replace
- # o varname[1] will be None for the first two actions and the
+ # o varname[2] will be None for the first two actions and the
# replacement tal expression for the third action.
- self.emitI18nVariable(varname[0], i18nNameAction, varname[1])
+ assert (varname[1]
+ in [I18N_REPLACE, I18N_CONTENT, I18N_EXPRESSION])
+ self.emitI18nVariable(varname)
# Do not test for "msgid is not None", i.e. we only want to test for
# explicit msgids here. See comment above.
- if msgid is not None and varname:
- self.emitTranslation(msgid, i18ndata)
+ if msgid is not None:
+ # in case tal:content, i18n:translate and i18n:name in the
+ # same tag insertTranslation opcode has already been
+ # emitted
+ if varname and (varname[1] <> I18N_CONTENT):
+ self.emitTranslation(msgid, i18ndata)
if repeat:
self.emitRepeat(repeat)
if condition:
=== Zope/lib/python/TAL/TALInterpreter.py 1.78.8.1 => 1.78.8.2 ===
--- Zope/lib/python/TAL/TALInterpreter.py:1.78.8.1 Fri Aug 8 04:55:01 2003
+++ Zope/lib/python/TAL/TALInterpreter.py Fri Aug 15 09:50:08 2003
@@ -327,7 +327,7 @@
name = prefix + "use-macro"
value = macs[-1][0] # Macro name
elif suffix == "define-slot":
- name = prefix + "slot"
+ name = prefix + "fill-slot"
elif suffix == "fill-slot":
pass
else:
@@ -418,9 +418,9 @@
def do_rawtextBeginScope_tal(self, (s, col, position, closeprev, dict)):
self._stream_write(s)
self.col = col
- self.position = position
- self.engine.setPosition(position)
engine = self.engine
+ self.position = position
+ engine.setPosition(position)
if closeprev:
engine.endScope()
engine.beginScope()
From gotcha at swing.be Fri Aug 15 09:50:49 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:19 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests -
test_htmltalparser.py:1.33.4.1 test_talinterpreter.py:1.7.2.1
Message-ID: <200308151350.h7FDon910019@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL/tests
In directory cvs.zope.org:/tmp/cvs-serv8434/tests
Modified Files:
Tag: gotcha-talz3_backport-branch
test_htmltalparser.py test_talinterpreter.py
Log Message:
backport of TAL fixes from z3
- i18n and metal interactions
- fix handling of nested translations with tal:content/replace and i18n:name
some reformatting to ease comparisons between 2.x and 3
=== Zope/lib/python/TAL/tests/test_htmltalparser.py 1.33 => 1.33.4.1 ===
--- Zope/lib/python/TAL/tests/test_htmltalparser.py:1.33 Tue Jul 22 09:28:46 2003
+++ Zope/lib/python/TAL/tests/test_htmltalparser.py Fri Aug 15 09:50:11 2003
@@ -614,6 +614,38 @@
('rawtextColumn', ('\n', 0))
])
+ def test_i18n_name_with_content(self):
+ self._run_check('
')
+ self.interpreter = TALInterpreter(program, {}, self.engine,
+ stream=result)
+ self.interpreter()
+ self.assert_('BaRvAlUe' in xlatsvc.data)
+ self.assert_('This is text for ${bar_name}.' in
+ xlatsvc.data)
+ self.assertEqual(
+ '
THIS IS TEXT FOR BARVALUE.
\n',
+ result.getvalue())
+
+
+class I18NErrorsTestCase(TestCaseBase):
+
+ def _check(self, src, msg):
+ try:
+ self._compile(src)
+ except I18NError:
+ pass
+ else:
+ self.fail(msg)
+
+ def test_id_with_replace(self):
+ self._check('',
+ "expected i18n:id with tal:replace to be denied")
+
+ def test_missing_values(self):
+ self._check('',
+ "missing i18n:attributes value not caught")
+ self._check('',
+ "missing i18n:data value not caught")
+ self._check('',
+ "missing i18n:id value not caught")
+
+ def test_id_with_attributes(self):
+ self._check('''''',
+ "expected attribute being both part of tal:attributes" +
+ " and having a msgid in i18n:attributes to be denied")
+
class OutputPresentationTestCase(TestCaseBase):
def check_attribute_wrapping(self):
@@ -159,6 +283,7 @@
suite.addTest(unittest.makeSuite(MacroErrorsTestCase, "check_"))
suite.addTest(unittest.makeSuite(OutputPresentationTestCase, "check_"))
suite.addTest(unittest.makeSuite(InterpolateTestCase, "check_"))
+ suite.addTest(unittest.makeSuite(I18NCornerTestCase))
return suite
From gotcha at swing.be Fri Aug 15 09:50:55 2003
From: gotcha at swing.be (Godefroid Chapelle)
Date: Sun Aug 10 17:05:19 2008
Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests/input -
test29.html:1.1.6.1 test_metal4.html:1.1.2.1
test_metal5.html:1.1.2.1 test_metal6.html:1.1.2.1
test_metal7.html:1.1.2.1 test_metal1.html:1.4.38.1
Message-ID: <200308151350.h7FDoti10031@cvs.baymountain.com>
Update of /cvs-repository/Zope/lib/python/TAL/tests/input
In directory cvs.zope.org:/tmp/cvs-serv8434/tests/input
Modified Files:
Tag: gotcha-talz3_backport-branch
test_metal1.html
Added Files:
Tag: gotcha-talz3_backport-branch
test29.html test_metal4.html test_metal5.html test_metal6.html
test_metal7.html
Log Message:
backport of TAL fixes from z3
- i18n and metal interactions
- fix handling of nested translations with tal:content/replace and i18n:name
some reformatting to ease comparisons between 2.x and 3
=== Added File Zope/lib/python/TAL/tests/input/test29.html ===