edgewall / genshi

Python toolkit for generation of output for the web
http://genshi.edgewall.org
Other
86 stars 35 forks source link

Python3 templates fail syntax validation for "with x as y" constructs #21

Open xschlef opened 4 years ago

xschlef commented 4 years ago

I'm using debian buster with python 3.7 and genshi 0.7.1. The issue exists for all python 3 versions since 3.4?. At least 3.4 was the first version I tested.

Python3 genshi templates will fail for constructs like this:

try:
    pass
except Exception as err:
    pass

### or
with open(x) as y:
    pass

Will result in an exception like this:

  File "/usr/lib/python3/dist-packages/genshi/template/loader.py", line 236, in load
    filename, encoding=encoding)
  File "/usr/lib/python3/dist-packages/genshi/template/loader.py", line 274, in _instantiate
    allow_exec=self.allow_exec)
  File "/usr/lib/python3/dist-packages/genshi/template/text.py", line 138, in __init__
    loader=loader, encoding=encoding, lookup=lookup)
  File "/usr/lib/python3/dist-packages/genshi/template/base.py", line 418, in __init__
    self._stream = self._parse(source, encoding)
  File "/usr/lib/python3/dist-packages/genshi/template/text.py", line 203, in _parse
    lookup=self.lookup)
  File "/usr/lib/python3/dist-packages/genshi/template/eval.py", line 94, in __init__
    filename=filename, lineno=lineno, xform=xform)
  File "/usr/lib/python3/dist-packages/genshi/template/eval.py", line 464, in _compile
    new_source = ASTCodeGenerator(tree).code
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 43, in __init__
    self.visit(tree)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 91, in visit
    ret = visitor(node)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 98, in visit_Module
    self.visit(n)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 91, in visit
    ret = visitor(node)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 421, in visit_Try
    self.visit(handler)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 91, in visit
    ret = visitor(node)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 385, in visit_ExceptHandler
    self.visit(node.name)
  File "/usr/lib/python3/dist-packages/genshi/template/astutil.py", line 90, in visit
    raise Exception('Unhandled node type %r' % type(node))
None
Unhandled node type <class 'str'>