changeset 739:6de290dec976 trunk

Another Python 2.3 fix in the wake of #221.
author cmlenz
date Fri, 06 Jun 2008 15:52:33 +0000
parents 3b8a38fcc1ab
children 0c3a2d7bf9a1
files ChangeLog genshi/template/eval.py genshi/template/tests/eval.py
diffstat 3 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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 = []
--- 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):
Copyright (C) 2012-2017 Edgewall Software