# HG changeset patch # User cmlenz # Date 1212767553 0 # Node ID 6de290dec976352586bac4c1c4650fda5b4b7779 # Parent 3b8a38fcc1ab423424893731fb9a573bfbdaddb5 Another Python 2.3 fix in the wake of #221. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -82,6 +82,9 @@ * The `XHTMLSerializer` now has a `drop_xml_decl` option that defaults to `True`. Setting it to `False` will cause any XML decl in the serialized stream to be included in the output as it would for XML serialization. + * Add support for a protocol that would allow interoperability of different + Python packages that generate and/or consume markup, based on the special + `__html__()` method (ticket #202). Version 0.4.4 diff --git a/genshi/template/eval.py b/genshi/template/eval.py --- a/genshi/template/eval.py +++ b/genshi/template/eval.py @@ -33,14 +33,15 @@ __docformat__ = 'restructuredtext en' # Check for a Python 2.4 bug in the eval loop +has_star_import_bug = False try: class _FakeMapping(object): __getitem__ = __setitem__ = lambda *a: None exec 'from sys import *' in {}, _FakeMapping() -except (SystemError, TypeError): +except SystemError: has_star_import_bug = True -else: - has_star_import_bug = False +except TypeError: + pass # Python 2.3 del _FakeMapping def _star_import_patch(mapping, modname): @@ -519,10 +520,13 @@ # This is a Python 2.4 bug. Only if we have a broken Python # version we have to apply the hack return node - return ast.Discard(ast.CallFunc( + new_node = ast.Discard(ast.CallFunc( ast.Name('_star_import_patch'), [ast.Name('__data__'), ast.Const(node.modname)], None, None - ), lineno=node.lineno) + )) + if hasattr(node, 'lineno'): # No lineno in Python 2.3 + new_node.lineno = node.lineno + return new_node def visitFunction(self, node): args = [] diff --git a/genshi/template/tests/eval.py b/genshi/template/tests/eval.py --- a/genshi/template/tests/eval.py +++ b/genshi/template/tests/eval.py @@ -18,7 +18,7 @@ import unittest from genshi.core import Markup -from genshi.template.base import Context +from genshi.template.base import Context, _ctxt2dict from genshi.template.eval import Expression, Suite, Undefined, UndefinedError, \ UNDEFINED @@ -575,7 +575,7 @@ def test_import_star(self): suite = Suite("from itertools import *") data = Context() - suite.execute(data) + suite.execute(_ctxt2dict(data)) assert 'ifilter' in data def test_for(self):