From fred at zope.com Fri Apr 4 14:37:59 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates - PageTemplateFile.py:1.25 Message-ID: <200304041937.h34Jbxi26926@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates In directory cvs.zope.org:/tmp/cvs-serv26909 Modified Files: PageTemplateFile.py Log Message: Backport src/zope/pagetemplate/pagetemplatefile.py revision 1.5 from Zope 3: When loading a PageTemplateFile that's not XML, make sure it ends up loaded in text mode. This was a problem for Windows. === Zope/lib/python/Products/PageTemplates/PageTemplateFile.py 1.24 => 1.25 === --- Zope/lib/python/Products/PageTemplates/PageTemplateFile.py:1.24 Fri Mar 21 14:22:00 2003 +++ Zope/lib/python/Products/PageTemplates/PageTemplateFile.py Fri Apr 4 14:37:58 2003 @@ -122,7 +122,13 @@ text = f.read() finally: f.close() - self.pt_edit(text, sniff_type(text)) + t = sniff_type(text) + if t != "text/xml" and "\r" in text: + # For HTML, we really want the file read in text mode: + f = open(self.filename) + text = f.read() + f.close() + self.pt_edit(text, t) self._cook() if self._v_errors: LOG('PageTemplateFile', ERROR, 'Error in template', @@ -134,6 +140,10 @@ """Return expanded document source.""" if RESPONSE is not None: + # Since _cook_check() can cause self.content_type to change, + # we have to make sure we call it before setting the + # Content-Type header. + self._cook_check() RESPONSE.setHeader('Content-Type', 'text/plain') return self.read() From fred at zope.com Mon Apr 7 13:38:29 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests/input - test34.html:1.1 test_failed_attr_translation.html:1.1 Message-ID: <200304071738.h37HcTx18627@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL/tests/input In directory cvs.zope.org:/tmp/cvs-serv18558/TAL/tests/input Added Files: test34.html test_failed_attr_translation.html Log Message: Back-port two features from the Zope 3 version of Page Templates: - avoid normalizing whitespace when using the default text when there is not a matching translation - added support for explicit msgids in the i18n:attributes syntax === Added File Zope/lib/python/TAL/tests/input/test34.html === stuff more stuff stuff more stuff === Added File Zope/lib/python/TAL/tests/input/test_failed_attr_translation.html === From fred at zope.com Mon Apr 7 13:38:29 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests/output - test34.html:1.1 test_failed_attr_translation.html:1.1 Message-ID: <200304071738.h37HcTH18637@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL/tests/output In directory cvs.zope.org:/tmp/cvs-serv18558/TAL/tests/output Added Files: test34.html test_failed_attr_translation.html Log Message: Back-port two features from the Zope 3 version of Page Templates: - avoid normalizing whitespace when using the default text when there is not a matching translation - added support for explicit msgids in the i18n:attributes syntax === Added File Zope/lib/python/TAL/tests/output/test34.html === stuff foobar more stuff STUFF foobar MORE STUFF === Added File Zope/lib/python/TAL/tests/output/test_failed_attr_translation.html === From fred at zope.com Mon Apr 7 13:38:57 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates - GlobalTranslationService.py:1.4 TALES.py:1.37 Message-ID: <200304071738.h37Hcvo18646@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates In directory cvs.zope.org:/tmp/cvs-serv18558/Products/PageTemplates Modified Files: GlobalTranslationService.py TALES.py Log Message: Back-port two features from the Zope 3 version of Page Templates: - avoid normalizing whitespace when using the default text when there is not a matching translation - added support for explicit msgids in the i18n:attributes syntax === Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py 1.3 => 1.4 === --- Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py:1.3 Sun Oct 6 13:21:07 2002 +++ Zope/lib/python/Products/PageTemplates/GlobalTranslationService.py Mon Apr 7 13:38:27 2003 @@ -16,11 +16,19 @@ $Id$ """ +import re + +from DocumentTemplate.DT_Util import ustr +from TAL.TALDefs import NAME_RE + class DummyTranslationService: """Translation service that doesn't know anything about translation.""" def translate(self, domain, msgid, mapping=None, - context=None, target_language=None): - return None + context=None, target_language=None, default=None): + def repl(m, mapping=mapping): + return ustr(mapping[m.group(m.lastindex)]) + cre = re.compile(r'\$(?:(%s)|\{(%s)\})' % (NAME_RE, NAME_RE)) + return cre.sub(repl, default or msgid) # XXX Not all of Zope.I18n.ITranslationService is implemented. translationService = DummyTranslationService() === Zope/lib/python/Products/PageTemplates/TALES.py 1.36 => 1.37 === --- Zope/lib/python/Products/PageTemplates/TALES.py:1.36 Wed Oct 9 10:40:33 2002 +++ Zope/lib/python/Products/PageTemplates/TALES.py Mon Apr 7 13:38:27 2003 @@ -247,12 +247,14 @@ self.position = position def translate(self, domain, msgid, mapping=None, - context=None, target_language=None): + context=None, target_language=None, default=None): if context is None: context = self.contexts.get('here') return getGlobalTranslationService().translate( domain, msgid, mapping=mapping, - context=context, target_language=target_language) + context=context, + default=default, + target_language=target_language) class TALESTracebackSupplement: """Implementation of ITracebackSupplement""" From fred at zope.com Mon Apr 7 13:38:58 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests - test_htmltalparser.py:1.31 Message-ID: <200304071738.h37HcwD18668@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL/tests In directory cvs.zope.org:/tmp/cvs-serv18558/TAL/tests Modified Files: test_htmltalparser.py Log Message: Back-port two features from the Zope 3 version of Page Templates: - avoid normalizing whitespace when using the default text when there is not a matching translation - added support for explicit msgids in the i18n:attributes syntax === Zope/lib/python/TAL/tests/test_htmltalparser.py 1.30 => 1.31 === --- Zope/lib/python/TAL/tests/test_htmltalparser.py:1.30 Wed Sep 18 11:12:48 2002 +++ Zope/lib/python/TAL/tests/test_htmltalparser.py Mon Apr 7 13:38:28 2003 @@ -400,11 +400,11 @@ {'tal:attributes': 'href string:http://www.zope.org; x string:y', 'name': 'bar', 'href': 'foo'}), ('startTag', ('a', - [('href', 'foo', 'replace', '$string:http://www.zope.org$', 0), + [('href', 'foo', 'replace', '$string:http://www.zope.org$', 0, None), ('name', 'name="bar"'), ('tal:attributes', 'href string:http://www.zope.org; x string:y', 'tal'), - ('x', None, 'insert', '$string:y$', 0)])), + ('x', None, 'insert', '$string:y$', 0, None)])), ('endScope', ()), rawtext('link'), ]) @@ -418,7 +418,7 @@ 'tal:replace': 'structure string:'}), ('insertStructure', ('$string:$', - {'src': ('$string:foo.png$', 0)}, + {'src': ('$string:foo.png$', 0, None)}, [('startTag', ('p', [('tal:replace', 'structure string:', 'tal'), ('tal:attributes', 'src string:foo.png', @@ -496,10 +496,27 @@ ('setPosition', (1, 0)), ('beginScope', {'alt': 'foo', 'i18n:attributes': 'alt'}), ('startTag', ('img', - [('alt', 'foo', 'replace', None, 1), + [('alt', 'foo', 'replace', None, 1, None), ('i18n:attributes', 'alt', 'i18n')])), ('endScope', ()), ]) + self._run_check("foo", [ + ('setPosition', (1, 0)), + ('beginScope', {'alt': 'foo', 'i18n:attributes': 'alt foo ; bar'}), + ('startTag', ('img', + [('alt', 'foo', 'replace', None, 1, 'foo'), + ('i18n:attributes', 'alt foo ; bar', 'i18n'), + ('bar', None, 'insert', None, 1, None)])), + ('endScope', ()), + ]) + + def test_i18n_name_bad_name(self): + self._should_error("") + self._should_error("") + + def test_i18n_attributes_repeated_attr(self): + self._should_error("") + self._should_error("") def check_i18n_translate(self): # input/test19.html From fred at zope.com Mon Apr 7 13:38:58 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - DummyEngine.py:1.37 TALDefs.py:1.36 TALGenerator.py:1.63 TALInterpreter.py:1.78 driver.py:1.30 Message-ID: <200304071738.h37Hcwt18661@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL In directory cvs.zope.org:/tmp/cvs-serv18558/TAL Modified Files: DummyEngine.py TALDefs.py TALGenerator.py TALInterpreter.py driver.py Log Message: Back-port two features from the Zope 3 version of Page Templates: - avoid normalizing whitespace when using the default text when there is not a matching translation - added support for explicit msgids in the i18n:attributes syntax === Zope/lib/python/TAL/DummyEngine.py 1.36 => 1.37 === --- Zope/lib/python/TAL/DummyEngine.py:1.36 Thu Jan 30 13:18:43 2003 +++ Zope/lib/python/TAL/DummyEngine.py Mon Apr 7 13:38:27 2003 @@ -206,12 +206,18 @@ def getDefault(self): return Default - def translate(self, domain, msgid, mapping): - return self.translationService.translate(domain, msgid, mapping) - + def translate(self, domain, msgid, mapping, default=None): + return self.translationService.translate(domain, msgid, mapping, + default=default) + class Iterator: + # This is not an implementation of a Python iterator. The next() + # method returns true or false to indicate whether another item is + # available; if there is another item, the iterator instance calls + # setLocal() on the evaluation engine passed to the constructor. + def __init__(self, name, seq, engine): self.name = name self.seq = seq @@ -232,26 +238,33 @@ __implements__ = IDomain def translate(self, msgid, mapping=None, context=None, - target_language=None): + target_language=None, default=None): # This is a fake translation service which simply uppercases non # ${name} placeholder text in the message id. # # First, transform a string with ${name} placeholders into a list of # substrings. Then upcase everything but the placeholders, then glue # things back together. + + # simulate an unknown msgid by returning None + if msgid == "don't translate me": + text = default + else: + text = msgid.upper() + def repl(m, mapping=mapping): return ustr(mapping[m.group(m.lastindex).lower()]) - cre = re.compile(r'\$(?:([_A-Z]\w*)|\{([_A-Z]\w*)\})') - return cre.sub(repl, msgid.upper()) + cre = re.compile(r'\$(?:(%s)|\{(%s)\})' % (NAME_RE, NAME_RE)) + return cre.sub(repl, text) class DummyTranslationService: __implements__ = ITranslationService def translate(self, domain, msgid, mapping=None, context=None, - target_language=None): - # Ignore domain + target_language=None, default=None): return self.getDomain(domain).translate(msgid, mapping, context, - target_language) + target_language, + default=default) def getDomain(self, domain): return DummyDomain() === Zope/lib/python/TAL/TALDefs.py 1.35 => 1.36 === --- Zope/lib/python/TAL/TALDefs.py:1.35 Thu Mar 20 14:58:27 2003 +++ Zope/lib/python/TAL/TALDefs.py Mon Apr 7 13:38:27 2003 @@ -28,7 +28,9 @@ ZOPE_METAL_NS = "http://xml.zope.org/namespaces/metal" ZOPE_I18N_NS = "http://xml.zope.org/namespaces/i18n" -NAME_RE = "[a-zA-Z_][a-zA-Z0-9_]*" +# This RE must exactly match the expression of the same name in the +# zope.i18n.simpletranslationservice module: +NAME_RE = "[a-zA-Z_][-a-zA-Z0-9_]*" KNOWN_METAL_ATTRIBUTES = [ "define-macro", @@ -118,12 +120,12 @@ for part in splitParts(arg): m = _attr_re.match(part) if not m: - raise TALError("Bad syntax in attributes:" + `part`) + raise TALError("Bad syntax in attributes: " + `part`) name, expr = m.group(1, 2) if not xml: name = name.lower() if dict.has_key(name): - raise TALError("Duplicate attribute name in attributes:" + `part`) + raise TALError("Duplicate attribute name in attributes: " + `part`) dict[name] = expr return dict === Zope/lib/python/TAL/TALGenerator.py 1.62 => 1.63 === --- Zope/lib/python/TAL/TALGenerator.py:1.62 Thu Mar 20 14:58:27 2003 +++ Zope/lib/python/TAL/TALGenerator.py Mon Apr 7 13:38:27 2003 @@ -29,6 +29,9 @@ I18N_CONTENT = 2 I18N_EXPRESSION = 3 +_name_rx = re.compile(NAME_RE) + + class TALGenerator: inMacroUse = 0 @@ -329,6 +332,9 @@ # calculate the contents of the variable, e.g. # "I live in " + 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: @@ -458,13 +464,13 @@ for item in attrlist: key = item[0] if repldict.has_key(key): - expr, xlat = repldict[key] - item = item[:2] + ("replace", expr, xlat) + expr, xlat, msgid = repldict[key] + item = item[:2] + ("replace", expr, xlat, msgid) del repldict[key] newlist.append(item) # Add dynamic-only attributes - for key, (expr, xlat) in repldict.items(): - newlist.append((key, None, "insert", expr, xlat)) + for key, (expr, xlat, msgid) in repldict.items(): + newlist.append((key, None, "insert", expr, xlat, msgid)) return newlist def emitStartElement(self, name, attrlist, taldict, metaldict, i18ndict, @@ -651,16 +657,18 @@ else: repldict = {} if i18nattrs: - i18nattrs = i18nattrs.split() + i18nattrs = _parseI18nAttributes(i18nattrs, self.position, + self.xml) else: - i18nattrs = () + i18nattrs = {} # Convert repldict's name-->expr mapping to a # name-->(compiled_expr, translate) mapping for key, value in repldict.items(): - repldict[key] = self.compileExpression(value), key in i18nattrs + ce = self.compileExpression(value) + repldict[key] = ce, key in i18nattrs, i18nattrs.get(key) for key in i18nattrs: if not repldict.has_key(key): - repldict[key] = None, 1 + repldict[key] = None, 1, i18nattrs.get(key) else: repldict = {} if replace: @@ -781,6 +789,30 @@ self.emitUseMacro(useMacro) if defineMacro: self.emitDefineMacro(defineMacro) + + +def _parseI18nAttributes(i18nattrs, position, xml): + d = {} + for spec in i18nattrs.split(";"): + parts = spec.split() + if len(parts) > 2: + raise TALError("illegal i18n:attributes specification: %r" % spec, + position) + if len(parts) == 2: + attr, msgid = parts + else: + # 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 def test(): t = TALGenerator() === Zope/lib/python/TAL/TALInterpreter.py 1.77 => 1.78 === --- Zope/lib/python/TAL/TALInterpreter.py:1.77 Thu Feb 27 11:18:40 2003 +++ Zope/lib/python/TAL/TALInterpreter.py Mon Apr 7 13:38:27 2003 @@ -349,7 +349,7 @@ return self.attrAction(item) name, value, action = item[:3] ok = 1 - expr, msgid = item[3:] + expr, xlat, msgid = item[3:] if self.html and name.lower() in BOOLEAN_HTML_ATTRS: evalue = self.engine.evaluateBoolean(item[3]) if evalue is self.Default: @@ -368,23 +368,18 @@ if evalue is None: ok = 0 value = evalue - if msgid: - value = self.i18n_attribute(value) - if value is None: - value = name - value = '%s="%s"' % (name, escape(value, 1)) + + if ok: + if xlat: + translated = self.translate(msgid or value, value, {}) + if translated is not None: + value = translated + if value is None: + value = name + value = '%s="%s"' % (name, escape(value, 1)) return ok, name, value bytecode_handlers[""] = attrAction - def i18n_attribute(self, s): - # s is the value of an attribute before translation - # it may have been computed - xlated = self.translate(s, {}) - if xlated is None: - return s - else: - return xlated - def no_tag(self, start, program): state = self.saveState() self.stream = stream = self.StringIO() @@ -553,36 +548,19 @@ # subnodes, which should /not/ go to the output stream. tmpstream = self.StringIO() self.interpretWithStream(stuff[1], tmpstream) - content = None + default = tmpstream.getvalue() # We only care about the evaluated contents if we need an implicit # message id. All other useful information will be in the i18ndict on # the top of the i18nStack. if msgid == '': - content = tmpstream.getvalue() - msgid = normalize(content) + msgid = normalize(default) self.i18nStack.pop() # See if there is was an i18n:data for msgid if len(stuff) > 2: obj = self.engine.evaluate(stuff[2]) - xlated_msgid = self.translate(msgid, i18ndict, obj) - # If there is no translation available, use evaluated content. - if xlated_msgid is None: - if content is None: - content = tmpstream.getvalue() - # We must do potential substitutions "by hand". - s = interpolate(content, i18ndict) - else: - # XXX I can't decide whether we want to cgi escape the translated - # string or not. OT1H not doing this could introduce a cross-site - # scripting vector by allowing translators to sneak JavaScript into - # translations. OTOH, for implicit interpolation values, we don't - # want to escape stuff like ${name} <= "Timmy". - #s = escape(xlated_msgid) - s = xlated_msgid - # If there are i18n variables to interpolate into this string, better - # do it now. - # XXX efge: actually, this is already done by the translation service. - self._stream_write(s) + xlated_msgid = self.translate(msgid, default, i18ndict, obj) + assert xlated_msgid is not None, self.position + self._stream_write(xlated_msgid) bytecode_handlers['insertTranslation'] = do_insertTranslation def do_insertStructure(self, stuff): @@ -636,23 +614,14 @@ self.interpret(block) bytecode_handlers["loop"] = do_loop - def translate(self, msgid, i18ndict=None, obj=None): - # XXX is this right? - if i18ndict is None: - i18ndict = {} + def translate(self, msgid, default, i18ndict, obj=None): if obj: i18ndict.update(obj) - # XXX need to fill this in with TranslationService calls. For now, - # we'll just do simple interpolation based on a $-strings to %-strings - # algorithm in Mailman. if not self.i18nInterpolate: return msgid - # XXX Mmmh, it seems that sometimes the msgid is None; is that really - # possible? - if msgid is None: - return None # XXX We need to pass in one of context or target_language - return self.engine.translate(self.i18nContext.domain, msgid, i18ndict) + return self.engine.translate(self.i18nContext.domain, + msgid, i18ndict, default=default) def do_rawtextColumn(self, (s, col)): self._stream_write(s) === Zope/lib/python/TAL/driver.py 1.29 => 1.30 === --- Zope/lib/python/TAL/driver.py:1.29 Wed Sep 18 11:12:48 2002 +++ Zope/lib/python/TAL/driver.py Mon Apr 7 13:38:27 2003 @@ -53,7 +53,7 @@ class TestTranslations(DummyTranslationService): def translate(self, domain, msgid, mapping=None, context=None, - target_language=None): + target_language=None, default=None): if msgid == 'timefmt': return '%(minutes)s minutes after %(hours)s %(ampm)s' % mapping elif msgid == 'jobnum': @@ -67,7 +67,8 @@ return '%(name)s was born in %(country)s' % mapping return DummyTranslationService.translate(self, domain, msgid, mapping, context, - target_language) + target_language, + default=default) class TestEngine(DummyEngine): def __init__(self, macros=None): From fred at zope.com Mon Apr 7 14:45:45 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - ITALES.py:1.4 Message-ID: <200304071845.h37Ijjf27569@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL In directory cvs.zope.org:/tmp/cvs-serv27552 Modified Files: ITALES.py Log Message: - add "default" argument for ITALESEngine.translate() - normalize whitespace === Zope/lib/python/TAL/ITALES.py 1.3 => 1.4 === --- Zope/lib/python/TAL/ITALES.py:1.3 Wed Oct 9 10:40:33 2002 +++ Zope/lib/python/TAL/ITALES.py Mon Apr 7 14:45:45 2003 @@ -135,14 +135,14 @@ """ """ - def translate(domain, msgid, mapping): + def translate(domain, msgid, mapping, default=None): """ See ITranslationService.translate() """ class ITALESErrorInfo(Interface): - + type = Attribute("type", "The exception class.") From fred at zope.com Mon Apr 7 15:21:38 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates - PageTemplateFile.py:1.26 Message-ID: <200304071921.h37JLck32636@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates In directory cvs.zope.org:/tmp/cvs-serv32619 Modified Files: PageTemplateFile.py Log Message: - avoid re-reading more data than necessary - remove unused imports - misc. cleanup === Zope/lib/python/Products/PageTemplates/PageTemplateFile.py 1.25 => 1.26 === --- Zope/lib/python/Products/PageTemplates/PageTemplateFile.py:1.25 Fri Apr 4 14:37:58 2003 +++ Zope/lib/python/Products/PageTemplates/PageTemplateFile.py Mon Apr 7 15:21:37 2003 @@ -17,17 +17,16 @@ __version__='$Revision$'[11:-2] -import os, AccessControl, Acquisition, sys +import os, AccessControl from Globals import package_home, DevelopmentMode -from zLOG import LOG, ERROR, INFO -from Shared.DC.Scripts.Script import Script, BindingsUI +from zLOG import LOG, ERROR +from Shared.DC.Scripts.Script import Script from Shared.DC.Scripts.Signature import FuncCode from AccessControl import getSecurityManager from OFS.Traversable import Traversable from PageTemplate import PageTemplate from Expressions import SecureModuleImporter from ComputedAttribute import ComputedAttribute -from ExtensionClass import Base from Acquisition import aq_parent, aq_inner from App.config import getConfiguration @@ -51,7 +50,7 @@ self.ZBindings_edit(self._default_bindings) if _prefix is None: _prefix = getConfiguration().softwarehome - elif type(_prefix) is not type(''): + elif not isinstance(_prefix, str): _prefix = package_home(_prefix) name = kw.get('__name__') if name: @@ -91,7 +90,7 @@ pass # Execute the template in a new security context. - security=getSecurityManager() + security = getSecurityManager() bound_names['user'] = security.getUser() security.addContext(self) try: @@ -119,15 +118,18 @@ return f = open(self.filename, "rb") try: - text = f.read() - finally: + text = f.read(XML_PREFIX_MAX_LENGTH) + except: f.close() + raise t = sniff_type(text) - if t != "text/xml" and "\r" in text: + if t != "text/xml": # For HTML, we really want the file read in text mode: - f = open(self.filename) - text = f.read() f.close() + f = open(self.filename) + text = '' + text += f.read() + f.close() self.pt_edit(text, t) self._cook() if self._v_errors: @@ -179,6 +181,8 @@ "\xfe\xff\0<\0?\0x\0m\0l", # utf-16 big endian w/ byte order mark "\xff\xfe<\0?\0x\0m\0l\0", # utf-16 little endian w/ byte order mark ] + +XML_PREFIX_MAX_LENGTH = max(map(len, XML_PREFIXES)) def sniff_type(text): for prefix in XML_PREFIXES: From fred at zope.com Tue Apr 22 12:16:37 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates/tests - test_ptfile.py:1.2 Message-ID: <200304221616.h3MGGbb21386@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates/tests In directory cvs.zope.org:/tmp/cvs-serv21369 Modified Files: test_ptfile.py Log Message: Make sure we always use a .zpt suffix for the temp file, since PageTemplateFile.__init__() does some weird magic. Without this, the sniffer tests failed on Windows. === Zope/lib/python/Products/PageTemplates/tests/test_ptfile.py 1.1 => 1.2 === --- Zope/lib/python/Products/PageTemplates/tests/test_ptfile.py:1.1 Fri Mar 21 14:22:00 2003 +++ Zope/lib/python/Products/PageTemplates/tests/test_ptfile.py Tue Apr 22 12:16:36 2003 @@ -9,7 +9,7 @@ class TypeSniffingTestCase(unittest.TestCase): - TEMPFILENAME = tempfile.mktemp() + TEMPFILENAME = tempfile.mktemp(".zpt") def tearDown(self): if os.path.exists(self.TEMPFILENAME): From fred at zope.com Tue Apr 22 12:27:47 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates - PageTemplateFile.py:1.27 Message-ID: <200304221627.h3MGRlr22971@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates In directory cvs.zope.org:/tmp/cvs-serv22954 Modified Files: PageTemplateFile.py Log Message: - clean up some filename manipulation to avoid duplicate work and make it more readable - remove unused instance variable === Zope/lib/python/Products/PageTemplates/PageTemplateFile.py 1.26 => 1.27 === --- Zope/lib/python/Products/PageTemplates/PageTemplateFile.py:1.26 Mon Apr 7 15:21:37 2003 +++ Zope/lib/python/Products/PageTemplates/PageTemplateFile.py Tue Apr 22 12:27:46 2003 @@ -37,7 +37,6 @@ func_defaults = None func_code = FuncCode((), 0) - _need__name__=1 _v_last_read=0 _default_bindings = {'name_subpath': 'traverse_subpath'} @@ -53,12 +52,14 @@ elif not isinstance(_prefix, str): _prefix = package_home(_prefix) name = kw.get('__name__') + basepath, ext = os.path.splitext(filename) if name: - self._need__name__ = 0 self.__name__ = name else: - self.__name__ = os.path.splitext(os.path.split(filename)[-1])[0] - if not os.path.splitext(filename)[1]: + self.__name__ = os.path.basename(basepath) + if not ext: + # XXX This is pretty bogus, but can't be removed since + # it's been released this way. filename = filename + '.zpt' self.filename = os.path.join(_prefix, filename) From fred at zope.com Tue Apr 22 12:30:27 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates/tests - __init__.py:1.4 Message-ID: <200304221630.h3MGURo23402@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates/tests In directory cvs.zope.org:/tmp/cvs-serv23385 Modified Files: __init__.py Log Message: remove trailing blank line === Zope/lib/python/Products/PageTemplates/tests/__init__.py 1.3 => 1.4 === --- Zope/lib/python/Products/PageTemplates/tests/__init__.py:1.3 Wed Sep 18 11:12:46 2002 +++ Zope/lib/python/Products/PageTemplates/tests/__init__.py Tue Apr 22 12:30:27 2003 @@ -34,4 +34,3 @@ assert aargs == args, "Harness method arguments" assert akwargs == kwargs, "Harness method keyword args" return result - From fred at zope.com Tue Apr 22 13:48:06 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/Products/PageTemplates - PageTemplateFile.py:1.28 Message-ID: <200304221748.h3MHm6L04207@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/Products/PageTemplates In directory cvs.zope.org:/tmp/cvs-serv4189 Modified Files: PageTemplateFile.py Log Message: - add back _need__name__; it's used by InitializeClass - normalize whitespace === Zope/lib/python/Products/PageTemplates/PageTemplateFile.py 1.27 => 1.28 === --- Zope/lib/python/Products/PageTemplates/PageTemplateFile.py:1.27 Tue Apr 22 12:27:46 2003 +++ Zope/lib/python/Products/PageTemplates/PageTemplateFile.py Tue Apr 22 13:48:05 2003 @@ -15,7 +15,7 @@ Zope object encapsulating a Page Template from the filesystem. """ -__version__='$Revision$'[11:-2] +__version__ = '$Revision$'[11:-2] import os, AccessControl from Globals import package_home, DevelopmentMode @@ -37,7 +37,11 @@ func_defaults = None func_code = FuncCode((), 0) - _v_last_read=0 + _v_last_read = 0 + + # needed by App.class_init.default__class_init__, often imported + # using the alias Globals.InitializeClass + _need__name__ = 1 _default_bindings = {'name_subpath': 'traverse_subpath'} @@ -54,6 +58,7 @@ name = kw.get('__name__') basepath, ext = os.path.splitext(filename) if name: + self._need__name__ = 0 self.__name__ = name else: self.__name__ = os.path.basename(basepath) From evan at zope.com Fri Apr 25 12:31:41 2003 From: evan at zope.com (Evan Simpson) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Releases/Zope/lib/python/ZTUtils - Tree.py:1.6.6.8 Message-ID: <200304251631.h3PGVfd30274@cvs.baymountain.com> Update of /cvs-repository/Releases/Zope/lib/python/ZTUtils In directory cvs.zope.org:/tmp/cvs-serv30103 Modified Files: Tag: Zope-2_6-branch Tree.py Log Message: Fix for Collector #868. It looks like the filterChildren issue was already addressed, so I just improved encodeExpansion()'s compression behavior. === Releases/Zope/lib/python/ZTUtils/Tree.py 1.6.6.7 => 1.6.6.8 === --- Releases/Zope/lib/python/ZTUtils/Tree.py:1.6.6.7 Mon Oct 7 16:03:30 2002 +++ Releases/Zope/lib/python/ZTUtils/Tree.py Fri Apr 25 12:31:41 2003 @@ -271,8 +271,10 @@ node.expansion_number = n n = n + 1 result = ':'.join(steps) - if compress: - result = ':' + b2a(zlib.compress(result, 9)) + if compress and len(result) > 2: + zresult = ':' + b2a(zlib.compress(result, 9)) + if len(zresult) < len(result): + result = zresult return result def decodeExpansion(s, nth=None): From evan at zope.com Fri Apr 25 12:32:03 2003 From: evan at zope.com (Evan Simpson) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Releases/Zope/lib/python/ZTUtils - Tree.py:1.15 Message-ID: <200304251632.h3PGW3r30414@cvs.baymountain.com> Update of /cvs-repository/Releases/Zope/lib/python/ZTUtils In directory cvs.zope.org:/tmp/cvs-serv30284 Modified Files: Tree.py Log Message: Fix for Collector #868. It looks like the filterChildren issue was already addressed, so I just improved encodeExpansion()'s compression behavior. === Releases/Zope/lib/python/ZTUtils/Tree.py 1.14 => 1.15 === --- Releases/Zope/lib/python/ZTUtils/Tree.py:1.14 Mon Oct 7 15:43:14 2002 +++ Releases/Zope/lib/python/ZTUtils/Tree.py Fri Apr 25 12:32:02 2003 @@ -271,8 +271,10 @@ node.expansion_number = n n = n + 1 result = ':'.join(steps) - if compress: - result = ':' + b2a(zlib.compress(result, 9)) + if compress and len(result) > 2: + zresult = ':' + b2a(zlib.compress(result, 9)) + if len(zresult) < len(result): + result = zresult return result def decodeExpansion(s, nth=None): From fred at zope.com Fri Apr 25 14:06:58 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL/tests - test_htmltalparser.py:1.32 Message-ID: <200304251806.h3PI6wc10777@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL/tests In directory cvs.zope.org:/tmp/cvs-serv10743/lib/python/TAL/tests Modified Files: test_htmltalparser.py Log Message: Raise TALError when tal:content is used on an HTML tag that must be empty. === Zope/lib/python/TAL/tests/test_htmltalparser.py 1.31 => 1.32 === --- Zope/lib/python/TAL/tests/test_htmltalparser.py:1.31 Mon Apr 7 13:38:28 2003 +++ Zope/lib/python/TAL/tests/test_htmltalparser.py Fri Apr 25 14:06:56 2003 @@ -478,6 +478,8 @@ self._should_error("

") self._should_error("

") self._should_error("

") + for tag in HTMLTALParser.EMPTY_HTML_TAGS: + self._should_error("<%s tal:content='string:foo'>" % tag) def check_metal_errors(self): exc = METALError From fred at zope.com Fri Apr 25 14:07:27 2003 From: fred at zope.com (Fred L. Drake, Jr.) Date: Sun Aug 10 17:05:18 2008 Subject: [ZPT-CVS] CVS: Zope/lib/python/TAL - HTMLTALParser.py:1.36 Message-ID: <200304251807.h3PI7R710941@cvs.baymountain.com> Update of /cvs-repository/Zope/lib/python/TAL In directory cvs.zope.org:/tmp/cvs-serv10743/lib/python/TAL Modified Files: HTMLTALParser.py Log Message: Raise TALError when tal:content is used on an HTML tag that must be empty. === Zope/lib/python/TAL/HTMLTALParser.py 1.35 => 1.36 === --- Zope/lib/python/TAL/HTMLTALParser.py:1.35 Wed Sep 18 11:12:48 2002 +++ Zope/lib/python/TAL/HTMLTALParser.py Fri Apr 25 14:06:56 2003 @@ -142,6 +142,10 @@ self.scan_xmlns(attrs) tag, attrlist, taldict, metaldict, i18ndict \ = self.process_ns(tag, attrs) + if tag in EMPTY_HTML_TAGS and taldict.get("content"): + raise TALError( + "empty HTML tags cannot use tal:content: %s" % `tag`, + self.getpos()) self.tagstack.append(tag) self.gen.emitStartElement(tag, attrlist, taldict, metaldict, i18ndict, self.getpos()) @@ -154,6 +158,10 @@ tag, attrlist, taldict, metaldict, i18ndict \ = self.process_ns(tag, attrs) if taldict.get("content"): + if tag in EMPTY_HTML_TAGS: + raise TALError( + "empty HTML tags cannot use tal:content: %s" % `tag`, + self.getpos()) self.gen.emitStartElement(tag, attrlist, taldict, metaldict, i18ndict, self.getpos()) self.gen.emitEndElement(tag, implied=-1)