[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser - resource.py:1.6 resources.py:1.10

Jim Fulton jim at zope.com
Sun Sep 21 13:32:41 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/publisher/browser
In directory cvs.zope.org:/tmp/cvs-serv14543/src/zope/app/publisher/browser

Modified Files:
	resource.py resources.py 
Log Message:
Change resources to be locations. The resource service
sets the parent and name for resources when they are created so that
resources are located in their resource service.

Resources now include host information in generated resource urls.


=== Zope3/src/zope/app/publisher/browser/resource.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/publisher/browser/resource.py:1.5	Fri Aug 15 20:43:46 2003
+++ Zope3/src/zope/app/publisher/browser/resource.py	Sun Sep 21 13:32:40 2003
@@ -17,47 +17,30 @@
 """
 __metaclass__ = type # All classes are new style when run with Python 2.2+
 
-from zope.component import queryView
-from zope.context import getWrapperContainer, getInnerWrapperData
-from zope.context import ContextMethod
-from zope.app.traversing import joinPath
-from zope.component.interfaces import IResourceService
+from zope.app import zapi
+from zope.app.location import Location
+from zope.app.interfaces.services.service import ISite
+from zope.app.interfaces.traversing import IContainmentRoot
 
-class Resource:
+
+class Resource(Location):
 
     def __init__(self, request):
         self.request = request
 
-    def __call__(wrapped_self):
-        name = getInnerWrapperData(wrapped_self)['name']
+    def __call__(self):
+        name = self.__name__
         if name.startswith('++resource++'):
             name = name[12:]
 
-        service = getWrapperContainer(wrapped_self)
-        while not IResourceService.isImplementedBy(service):
-            name = "%s/%s" % (getInnerWrapperData(service)['name'],
-                              name)
-            service = getWrapperContainer(service)
-
-        site = getWrapperContainer(service)
-
-        skin = wrapped_self.request.getPresentationSkin()
-        if skin:
-            skin = "++skin++%s" % skin
-
-        base_url = wrapped_self.request.getApplicationURL(path_only=True)
-
-        if site is not None:
-            raise NotImplementedError("This code path is not tested")
-            absolute_url = queryView(service,
-                                     'absolute_url',
-                                     wrapped_self.request)
-            if absolute_url is not None:
-                base_url = absolute_url()
-
-        if skin:
-            return joinPath(base_url, skin, '@@', name) # XXX joinPath should
-        else:                                           # XXX eat empty path
-            return joinPath(base_url, '@@', name)       # XXX elements
+        site = self.__parent__
+        while 1:
+            if ISite.isImplementedBy(site):
+                break
+            if IContainmentRoot.isImplementedBy(site):
+                site = None
+                break
+            site = site.__parent__
 
-    __call__ = ContextMethod(__call__)
+        url = str(zapi.getView(site, 'absolute_url', self.request))
+        return "%s/@@/%s" % (url, name)


=== Zope3/src/zope/app/publisher/browser/resources.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/publisher/browser/resources.py:1.9	Sat Jun  7 01:46:02 2003
+++ Zope3/src/zope/app/publisher/browser/resources.py	Sun Sep 21 13:32:40 2003
@@ -21,10 +21,9 @@
 from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.component import getService
 from zope.app.services.servicenames import Resources as ResourceService
-from zope.app.context import ContextWrapper
-from zope.context import ContextMethod
 from zope.exceptions import NotFoundError
 from zope.interface import implements
+from zope.app.location import locate
 
 class Resources(BrowserView):
     """Provide a URL-accessible resource namespace
@@ -32,16 +31,16 @@
 
     implements(IBrowserPublisher)
 
-    def publishTraverse(wrapped_self, request, name):
+    def publishTraverse(self, request, name):
         '''See interface IBrowserPublisher'''
 
-        resource_service = getService(wrapped_self, ResourceService)
-        resource = resource_service.queryResource(wrapped_self, name, request)
+        resource_service = getService(self, ResourceService)
+        resource = resource_service.queryResource(self, name, request)
         if resource is None:
-            raise NotFoundError(wrapped_self, name)
-        return ContextWrapper(resource, resource_service, name=name)
+            raise NotFoundError(self, name)
 
-    publishTraverse = ContextMethod(publishTraverse)
+        locate(resource, resource_service, name)
+        return resource
 
     def browserDefault(self, request):
         '''See interface IBrowserPublisher'''
@@ -50,7 +49,6 @@
     def __getitem__(self, name):
         return self.publishTraverse(self.request, name)
 
-    __getitem__ = ContextMethod(__getitem__)
 
 def empty():
     return ''




More information about the Zope3-Checkins mailing list