[ZCM] [ZC] 809/ 1 Request "Proposed new API method: 'absolute_path'"
Collector: Zope Bugs, Features, and Patches ...
zope-coders-admin@zope.org
Sat, 15 Feb 2003 07:50:48 -0500
Issue #809 Update (Request) "Proposed new API method: 'absolute_path'"
Status Pending, Zope/feature+solution medium
To followup, visit:
http://collector.zope.org/Zope/809
==============================================================
= Request - Entry #1 by shh on Feb 15, 2003 7:50 am
Problem:
It is often desirable to get at the absolute path of a Zope object, i.e. the absolute url with the protocol and server parts removed. However, there is no easy way.
In particular, absolute_url(1) does *not* return a path from the server root, but a path relative to a virtual root! Worse yet, the common idiom '/'+absolute_url(1) to get the absolute path even works in most cases, but breaks once certain types of virtual hosting come into play.
Specifically, it is inside-out hosting that breaks. When you are serving a Zope site from a virtual host's subdirectory and use '_vh_xyz' in your VHM rewrite rules to reinsert 'xyz' into the path, you will find that a path returned by absolute_url(1) fails to include 'xyz'.
Proposed Solution:
Add a new API method to Traversable named 'absolute_path' to safely cover this common requirement. An implementation of 'absolute_path' could look like:
def absolute_path(self):
"""
Returns the absolute path of an object, i.e.
the absolute url with the protocol and server
parts removed but including the leading '/'.
"""
req = self.REQUEST
url = self.absolute_url()
url = url[len(req.SERVER_URL):]
return url
Related:
You might want to consider this together with
http://collector.zope.org/Zope/797
==============================================================