Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xschlef opened this issue Dec 9, 2019 · 0 comments
Open

Comments

@xschlef
Copy link

xschlef commented Dec 9, 2019

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'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant