[Zope3-checkins] CVS: Zope3/src/zope/tal - talgenerator.py:1.6
Fred L. Drake, Jr.
fred@zope.com
Fri, 4 Apr 2003 11:06:15 -0500
Update of /cvs-repository/Zope3/src/zope/tal
In directory cvs.zope.org:/tmp/cvs-serv30618
Modified Files:
talgenerator.py
Log Message:
- make the bytecode generator check that i18n:name values are valid
- check that attributes are not specified more than once in an
i18n:attributes value, and normalize case of the attribute names in
HTML mode
=== Zope3/src/zope/tal/talgenerator.py 1.5 => 1.6 ===
--- Zope3/src/zope/tal/talgenerator.py:1.5 Mon Mar 31 14:15:55 2003
+++ Zope3/src/zope/tal/talgenerator.py Fri Apr 4 11:05:44 2003
@@ -28,6 +28,8 @@
I18N_CONTENT = 2
I18N_EXPRESSION = 3
+_name_rx = re.compile(NAME_RE)
+
class TALGenerator:
@@ -326,6 +328,9 @@
# calculate the contents of the variable, e.g.
# "I live in <span i18n:name="country"
# tal:replace="here/countryOfOrigin" />"
+ m = _name_rx.match(varname)
+ if m is None or m.group() != varname:
+ raise TALError("illegal i18n:name: %r" % varname, self.position)
key = cexpr = None
program = self.popProgram()
if action == I18N_REPLACE:
@@ -644,7 +649,8 @@
else:
repldict = {}
if i18nattrs:
- i18nattrs = _parseI18nAttributes(i18nattrs, self.position)
+ i18nattrs = _parseI18nAttributes(i18nattrs, self.position,
+ self.xml)
else:
i18nattrs = {}
# Convert repldict's name-->expr mapping to a
@@ -776,7 +782,8 @@
if defineMacro:
self.emitDefineMacro(defineMacro)
-def _parseI18nAttributes(i18nattrs, position):
+
+def _parseI18nAttributes(i18nattrs, position, xml):
d = {}
for spec in i18nattrs.split(";"):
parts = spec.split()
@@ -789,6 +796,13 @@
# len(parts) == 1
attr = parts[0]
msgid = None
+ if not xml:
+ attr = attr.lower()
+ if attr in d:
+ raise TALError(
+ "attribute may only be specified once in i18n:attributes: %r"
+ % attr,
+ position)
d[attr] = msgid
return d