Implementing a URL path resolver
Hi guys, I've been tinkling with a function that does what REQUEST.resolve_url does, except without it relying on having a REQUEST instance available. That is, just resolving the path itself, something like this: path ÿstring.split(relative_url, '/') path ÿfilter(None, path) new_path ÿ'%s' % path[0] path ÿpath[1:] for element in path: new_path ÿnew_path + "['%s']" % element return eval("self%s" % new_path) Now, neither []- or .-like evaluation of the path works.. Any ideas? Cheers, Morten
morten@esol.no wrote:
Hi guys,
I've been tinkling with a function that does what REQUEST.resolve_url does, except without it relying on having a REQUEST instance available.
Have you seen the methods restrictedTraverse and unrestrictedTraverse in lib/python/OFS/Traversable.py ? These would seem to do what you need. The methods restrictedTraverse is available from DTML. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
[Steve Alexander] | Have you seen the methods restrictedTraverse and unrestrictedTraverse in | lib/python/OFS/Traversable.py ? Exactly what I needed. Thank you. -Morten
[morten@esol.no] (Bug in the encoding of the message, MHA) | path = string.split(relative_url, '/') | path = filter(None, path) | new_path = '%s' % path[0] | path = path[1:] | | for element in path: | | new_path = new_path + "['%s']" % element | | return eval("self%s" % new_path) -Morten
participants (2)
-
morten@esol.no -
Steve Alexander