[Zope-Checkins] CVS: Packages/OFS - Application.py:1.197
Traversable.py:1.23
Evan Simpson
evan at 4-am.com
Wed Dec 10 12:53:17 EST 2003
Update of /cvs-repository/Packages/OFS
In directory cvs.zope.org:/tmp/cvs-serv13873/lib/python/OFS
Modified Files:
Application.py Traversable.py
Log Message:
Collector #809: Added and documented Traversable.py methods absolute_url_path and virtual_url_path, and reverted earlier change to absolute_url behaviour.
=== Packages/OFS/Application.py 1.196 => 1.197 ===
--- Packages/OFS/Application.py:1.196 Fri Nov 28 11:45:25 2003
+++ Packages/OFS/Application.py Wed Dec 10 12:52:46 2003
@@ -137,21 +137,24 @@
test_url=ZopeAttributionButton
def absolute_url(self, relative=0):
- '''Return a canonical URL for this object based on its
- physical containment path, possibly modified by virtual hosting.
- If the optional 'relative' argument is true, only return the
- path portion of the URL.'''
+ '''The absolute URL of the root object is BASE1 or "/".'''
+ if relative: return ''
try:
- # We need a REQUEST that uses physicalPathToURL to create
- # BASE1 and BASEPATH1, so probe for it.
- req = self.REQUEST
- req.physicalPathToURL
- except AttributeError:
- return ''
- # Take advantage of computed URL cache
- if relative:
- return req['BASEPATH1'][1:]
- return req['BASE1']
+ # Take advantage of computed URL cache
+ return self.REQUEST['BASE1']
+ except (AttributeError, KeyError):
+ return '/'
+
+ def absolute_url_path(self):
+ '''The absolute URL path of the root object is BASEPATH1 or "/".'''
+ try:
+ return self.REQUEST['BASEPATH1']
+ except (AttributeError, KeyError):
+ return '/'
+
+ def virtual_url_path(self):
+ '''The virtual URL path of the root object is empty.'''
+ return ''
def getPhysicalPath(self):
'''Returns a path that can be used to access this object again
=== Packages/OFS/Traversable.py 1.22 => 1.23 ===
--- Packages/OFS/Traversable.py:1.22 Fri Nov 28 11:45:44 2003
+++ Packages/OFS/Traversable.py Wed Dec 10 12:52:46 2003
@@ -31,20 +31,63 @@
absolute_url__roles__=None # Public
def absolute_url(self, relative=0):
- '''Return a canonical URL for this object based on its
- physical containment path, possibly modified by virtual hosting.
- If the optional 'relative' argument is true, only return the
- path portion of the URL.'''
+ """
+ Return the absolute URL of the object.
+
+ This a canonical URL based on the object's physical
+ containment path. It is affected by the virtual host
+ configuration, if any, and can be used by external
+ agents, such as a browser, to address the object.
+
+ If the relative argument is provided, with a true value, then
+ the value of virtual_url_path() is returned.
+
+ Some Products incorrectly use '/'+absolute_url(1) as an
+ absolute-path reference. This breaks in certain virtual
+ hosting situations, and should be changed to use
+ absolute_url_path() instead.
+ """
+ if relative:
+ return self.virtual_url_path()
+
spp = self.getPhysicalPath()
try:
toUrl = self.REQUEST.physicalPathToURL
except AttributeError:
- return '/'.join(map(quote, spp[1:]))
- if relative:
- # Remove leading slash for backward compatibility sake.
- return toUrl(spp, relative)[1:]
+ return path2url(spp[1:])
return toUrl(spp)
+ absolute_url_path__roles__=None # Public
+ def absolute_url_path(self):
+ """
+ Return the path portion of the absolute URL of the object.
+
+ This includes the leading slash, and can be used as an
+ 'absolute-path reference' as defined in RFC 2396.
+ """
+ spp = self.getPhysicalPath()
+ try:
+ toUrl = self.REQUEST.physicalPathToURL
+ except AttributeError:
+ return path2url(spp) or '/'
+ return toUrl(spp, relative=1) or '/'
+
+ virtual_url_path__roles__=None # Public
+ def virtual_url_path(self):
+ """
+ Return a URL for the object, relative to the site root.
+
+ If a virtual host is configured, the URL is a path relative to
+ the virtual host's root object. Otherwise, it is the physical
+ path. In either case, the URL does not begin with a slash.
+ """
+ spp = self.getPhysicalPath()
+ try:
+ toVirt = self.REQUEST.physicalPathToVirtualPath
+ except AttributeError:
+ return path2url(spp[1:])
+ return path2url(toVirt(spp))
+
getPhysicalRoot__roles__=() # Private
getPhysicalRoot=Acquired
@@ -159,4 +202,7 @@
restrictedTraverse__roles__=None # Public
def restrictedTraverse(self, path, default=_marker):
+
+def path2url(path):
+ return '/'.join(map(quote, path))
return self.unrestrictedTraverse(path, default, restricted=1)
More information about the Zope-Checkins
mailing list