Opened 6 years ago

Closed 5 years ago

#5711 defect closed worksforme (worksforme)

In howto/twisted-templates.html listings/ example doesn't work with FilePath

Reported by: lewq Owned by:
Priority: normal Milestone:
Component: web Keywords: web template documentation
Cc: jknight Branch:

Description (last modified by Thijs Triemstra)

from twisted.web.template import Element, renderer, XMLFile, tags
from twisted.python.filepath import FilePath

class ExampleElement(Element):
    loader = XMLFile(FilePath('template-1.xml'))


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/", 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/", 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/", 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/", 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/", 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/", line 335, in _flatsaxParse
  File "/usr/lib/python2.7/xml/sax/", line 102, in parse
    source = saxutils.prepare_input_source(source)
  File "/usr/lib/python2.7/xml/sax/", 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 (6)

comment:1 Changed 6 years ago by DefaultCC Plugin

Cc: jknight added

comment:2 Changed 6 years ago by Thijs Triemstra

Description: modified (diff)
Keywords: documentation added

Fixing ticket markup.

comment:3 Changed 5 years ago by Richard Wall

Resolution: invalid
Status: newclosed

Thanks for the bug report.

I think the problem is that you are using an older version of Twisted.

In r33940 XMLFile was updated to accept a FilePath. Passing it a file or string is now deprecated.

You can try the 12.0.0 documentation or you could update to the current Twisted release.

We should probably provide clearer links to the version specific documentation - maybe in footer of the documents themselves.

comment:4 Changed 5 years ago by Jean-Paul Calderone

To be clear, this is a 12.1.0 feature.

comment:5 Changed 5 years ago by Jean-Paul Calderone

Resolution: invalid
Status: closedreopened

comment:6 Changed 5 years ago by Jean-Paul Calderone

Resolution: worksforme
Status: reopenedclosed
Note: See TracTickets for help on using tickets.