Ticket #5711 defect closed worksforme
In howto/twisted-templates.html listings/element_2.py example doesn't work with FilePath
| Reported by: | lewq | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | web | Keywords: | web template documentation |
| Cc: | jknight | Branch: | |
| Author: | Launchpad Bug: |
Description (last modified by thijs) (diff)
from twisted.web.template import Element, renderer, XMLFile, tags from twisted.python.filepath import FilePath class ExampleElement(Element): loader = XMLFile(FilePath('template-1.xml'))
Causes:
Jumping into debugger for post-mortem of exception 'Exception while flattening:
<ExampleElement object at 0x1b03090>
File "/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/_flatten.py", line 218, in _flattenTree
element = stack[-1].next()
File "/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/_flatten.py", line 189, in _flattenElement
result = root.render(request)
File "/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/_element.py", line 184, in render
return loader.load()
File "/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/template.py", line 397, in load
self._loadedTemplate = self._loadDoc()
File "/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/template.py", line 388, in <lambda>
self._loadDoc = lambda: _flatsaxParse(fobj)
File "/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/template.py", line 335, in _flatsaxParse
parser.parse(fl)
File "/usr/lib/python2.7/xml/sax/expatreader.py", line 102, in parse
source = saxutils.prepare_input_source(source)
File "/usr/lib/python2.7/xml/sax/saxutils.py", line 295, in prepare_input_source
if source.getByteStream() is None:
AttributeError: FilePath instance has no attribute 'getByteStream'
However replacing FilePath with open so that XMLFile is just operating on a file-like object fixes it. Is this the correct fix for the docs?
Change History
Note: See
TracTickets for help on using
tickets.
