[Twisted-web] URL generation for resources
John Porter Simons
coolcucumber at gmail.com
Sun Nov 22 21:44:17 EST 2009
I need to, given an IResource object that's in a site's resource tree, get
its full URL (in order to generate links to it). Looking in
twisted/web/resource.py, it appears that URL traversal is strictly one-way,
with resources having no idea what their path component is, nor what their
parent resource is.
157 def putChild(self, path, child):
158 """Register a static child.
160 You almost certainly don't want '/' in your path. If you
161 intended to have the root of a folder, e.g. /foo/, you want
162 path to be ''.
164 self.children[path] = child
165 child.server = self.server
If putChild were extended a little bit, it could set some info on the child
whenever it's "placed" into the tree, i.e.
165+ child.parent = self
165+ child.path = path
This would make possible a "getFullPath" method that iterates up the tree to
the root, concatenating the parts with "/".
Does anyone see the value of this, if I were to subject such a patch?
Obviously this is only relevant for statically-routed resources.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-web