[Checkins] SVN: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/ do not register resources for the libraries, ++resource++ URLs however still work by registering a traversable HurryResource component inestead.

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed Nov 24 06:45:14 EST 2010


Log message for revision 118548:
  do not register resources for the libraries, ++resource++ URLs however still work by registering a traversable HurryResource component inestead.

Changed:
  U   hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/configure.zcml
  U   hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/interfaces.py
  U   hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zcml.py
  U   hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py

-=-
Modified: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/configure.zcml
===================================================================
--- hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/configure.zcml	2010-11-24 09:31:46 UTC (rev 118547)
+++ hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/configure.zcml	2010-11-24 11:45:13 UTC (rev 118548)
@@ -13,6 +13,4 @@
 
   <subscriber handler=".zopesupport.set_base_url_on_needed_inclusions" />
 
-  <adapter factory=".zopesupport.AbsoluteURL" />
-
 </configure>

Modified: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/interfaces.py
===================================================================
--- hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/interfaces.py	2010-11-24 09:31:46 UTC (rev 118547)
+++ hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/interfaces.py	2010-11-24 11:45:13 UTC (rev 118548)
@@ -4,7 +4,3 @@
 class ISetupHurryZopeResource(Interface):
     pass
 
-
-class IHurryResource(Interface):
-    pass
-

Modified: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zcml.py
===================================================================
--- hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zcml.py	2010-11-24 09:31:46 UTC (rev 118547)
+++ hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zcml.py	2010-11-24 11:45:13 UTC (rev 118548)
@@ -1,34 +1,20 @@
 from zope.interface import Interface
 from zope import component
 from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.security.checker import NamesChecker
 import hurry.resource
-from hurry.zoperesource.zopesupport import HurryDirectoryResourceFactory
+from hurry.zoperesource.zopesupport import HurryResource
 
-def create_resource_factory(library):
-    allowed_names = (
-        'GET',
-        'HEAD',
-        '__call__',
-        '__getitem__',
-        'browserDefault',
-        'get',
-        'publishTraverse',
-        'request',
-        )
-    checker = NamesChecker(allowed_names)
-    return HurryDirectoryResourceFactory(library, checker)
-
 def action_setup(_context):
     """Publish all hurry.resource library entry points as resources.
     """
     for library in hurry.resource.libraries():
-        resource_factory = create_resource_factory(library)
+        def factory(request):
+            return HurryResource(request, library)
         adapts = (IBrowserRequest,)
         provides = Interface
 
         _context.action(
             discriminator = ('adapter', adapts, provides, library.name),
             callable = component.provideAdapter,
-            args = (resource_factory, adapts, provides, library.name))
+            args = (factory, adapts, provides, library.name))
 

Modified: hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py
===================================================================
--- hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py	2010-11-24 09:31:46 UTC (rev 118547)
+++ hurry.zoperesource/branches/janjaapdriessen-wsgi/src/hurry/zoperesource/zopesupport.py	2010-11-24 11:45:13 UTC (rev 118548)
@@ -1,81 +1,38 @@
-# zope integration for hurry.resource
-from zope.browserresource import directory
-from zope.component import adapts, adapter, getMultiAdapter
-from zope.interface import alsoProvides, implements
-from zope.publisher.interfaces import IEndRequestEvent, IRequest
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.site.hooks import getSite
+from zope.interface import implements
+from zope.component import adapter
+from zope.publisher.interfaces import IEndRequestEvent
+from zope.traversing.browser.absoluteurl import absoluteURL
 from zope.traversing.browser.interfaces import IAbsoluteURL
-import zope.browserresource.resource
-import zope.security.management
+from zope.traversing.interfaces import ITraversable
 
 import hurry.resource
-from hurry.zoperesource.interfaces import IHurryResource
 
 @adapter(IEndRequestEvent)
 def set_base_url_on_needed_inclusions(event):
     needed = hurry.resource.get_current_needed_inclusions()
     if not needed.base_url:
-        site_url = str(getMultiAdapter((getSite(), event.request), IAbsoluteURL))
-        needed.base_url = '%s/@@' % site_url
+        needed.base_url = absoluteURL(None, event.request)
 
-# Custom DirectoryResource(Factory) implementations that allow to
-# inject the library object that the IAbsoluteURL adapter can use.
+class HurryResource(object):
 
-def hurrify(resource, library):
-    alsoProvides(resource, IHurryResource)
-    resource.library = library
-    return resource
+    # Hack to get ++resource++foo/bar/baz.jpg paths working in Zope
+    # Pagetemplates.
+    
+    implements(ITraversable, IAbsoluteURL)
 
-class DirectoryResource(directory.DirectoryResource):
-
-    implements(IHurryResource)
-
-    def directory_factory(self, path, checker, name):
-        directory_resource = DirectoryResourceFactory(path, checker, name)
-        return hurrify(directory_resource, self.library)
-        
-    def get(self, name, *args, **kw):
-        resource = super(DirectoryResource, self).get(name, *args, **kw)
-        return hurrify(resource, self.library)
-
-class DirectoryResourceFactory(directory.DirectoryResourceFactory):
-
-    factoryClass = DirectoryResource
-
-    def __call__(self, request):
-        resource = super(DirectoryResourceFactory, self).__call__(request)
-        return hurrify(resource, self.library)
-
-# "Top-level" directory resource factory, that allows us to inject the
-# library object. This, with the custom DirectoryResource(Factory)
-# implementation then is used to inject the libary object as an
-# attribute on all the subsequent resources. The IAbsoluteURL adapter
-# for IHurryResource is thus able to compute library URLs.
-class HurryDirectoryResourceFactory(DirectoryResourceFactory):
-
-    def __init__(self, library, checker):
-        super(HurryDirectoryResourceFactory, self).__init__(
-            library.path, checker, library.name)
+    def __init__(self, request, library, name=''):
+        self.request = request
         self.library = library
+        self.name = name
 
-# Adapter for constructing URLs from page templates using
-# `context/++resource++foo` that may point to the hurry.resource
-# publisher.
-class AbsoluteURL(zope.browserresource.resource.AbsoluteURL):
+    def traverse(self, name, furtherPath):
+        name = '%s/%s' % (self.name, name)
+        # XXX check whether the request resource actually exists and
+        # warn if not.
+        return HurryResource(self.request, self.library, name=name)
 
-    adapts(IHurryResource, IBrowserRequest)
-
     def __str__(self):
         needed = hurry.resource.get_current_needed_inclusions()
-        # The base_url might not have been set just yet.
         if not needed.base_url:
-            site_url = str(getMultiAdapter(
-                (getSite(), self.request), IAbsoluteURL))
-            needed.base_url = '%s/@@' % site_url
-
-        print needed.library_url(self.context.library), self.context.__name__
-
-        # XXX the first path segment of the resource is that
-            
-        return needed.library_url(self.context.library) + self.context.__name__
+            needed.base_url = absoluteURL(None, self.request)
+        return needed.library_url(self.library) + self.name



More information about the checkins mailing list