[Zope-Checkins] CVS: Packages/OFS - Application.py:1.192 Traversable.py:1.20

Evan Simpson evan@4-am.com
Tue, 8 Jul 2003 13:03:58 -0400


Update of /cvs-repository/Packages/OFS
In directory cvs.zope.org:/tmp/cvs-serv18985/lib/python/OFS

Modified Files:
	Application.py Traversable.py 
Log Message:
Fix for #797 and #809 -- delegate absolute_url internals to REQUEST and
provide a docstring.


=== Packages/OFS/Application.py 1.191 => 1.192 ===
--- Packages/OFS/Application.py:1.191	Tue Jun 24 09:30:29 2003
+++ Packages/OFS/Application.py	Tue Jul  8 13:03:52 2003
@@ -135,11 +135,21 @@
     test_url=ZopeAttributionButton
 
     def absolute_url(self, relative=0):
-        """Return an absolute url to the object. Note that the url
-        will reflect the acquisition path of the object if the object
-        has been acquired."""
-        if relative: return ''
-        return self.aq_acquire('REQUEST')['BASE1']
+        '''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.'''
+        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']
 
     def getPhysicalPath(self):
         '''Returns a path that can be used to access this object again


=== Packages/OFS/Traversable.py 1.19 => 1.20 ===
--- Packages/OFS/Traversable.py:1.19	Thu Apr 17 13:46:57 2003
+++ Packages/OFS/Traversable.py	Tue Jul  8 13:03:52 2003
@@ -30,23 +30,19 @@
 
     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.'''
+        spp = self.getPhysicalPath()
         try:
-            req = self.REQUEST
+            toUrl = self.REQUEST.physicalPathToURL
         except AttributeError:
-            req = {}
-        rpp = req.get('VirtualRootPhysicalPath', ('',))
-        spp = self.getPhysicalPath()
-        i = 0
-        for name in rpp[:len(spp)]:
-            if spp[i] == name:
-                i = i + 1
-            else:
-                break
-        path = map(quote, spp[i:])
+            return '/'.join(map(quote, spp[1:]))
         if relative:
-            # This is useful for physical path relative to a VirtualRoot
-            return '/'.join(path)
-        return '/'.join([req['SERVER_URL']] + req._script + path)
+            # Remove leading slash for backward compatibility sake.
+            return toUrl(spp, relative)[1:]
+        return toUrl(spp)
 
     getPhysicalRoot__roles__=() # Private
     getPhysicalRoot=Acquired