[Checkins] SVN: grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/ - Remove grokker for static resource directory, which don't work under Zope 2. As well, I didn't find any way to overrides it, and if we redefine a grokker for Zope 2 we end up with a conflict. So I propose to move that one to grok package, so we can define a grokker for Zope 2 in five.grok.

Sylvain Viollon sylvain at infrae.com
Sat Aug 23 15:38:31 EDT 2008


Log message for revision 90156:
  
  - Remove grokker for static resource directory, which don't work under Zope 2. As well, I didn't find any way to overrides it, and if we redefine a grokker for Zope 2 we end up with a conflict. So I propose to move that one to grok package, so we can define a grokker for Zope 2 in five.grok.
  
  

Changed:
  U   grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/components.py
  U   grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/meta.py
  D   grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/tests/static/

-=-
Modified: grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/components.py
===================================================================
--- grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/components.py	2008-08-23 19:06:52 UTC (rev 90155)
+++ grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/components.py	2008-08-23 19:38:31 UTC (rev 90156)
@@ -23,9 +23,6 @@
 from zope.publisher.publish import mapply
 from zope.pagetemplate import pagetemplate, pagetemplatefile
 from zope.app.pagetemplate.engine import TrustedAppPT
-from zope.app.publisher.browser import directoryresource
-from zope.app.publisher.browser.pagetemplateresource import \
-    PageTemplateResourceFactory
 
 import martian.util
 from grokcore.view import interfaces, util
@@ -227,27 +224,3 @@
             _prefix = os.path.dirname(module.__file__)
         self.setFromFilename(filename, _prefix)
 
-class DirectoryResource(directoryresource.DirectoryResource):
-    # We subclass this, because we want to override the default factories for
-    # the resources so that .pt and .html do not get created as page
-    # templates
-
-    resource_factories = {}
-    for type, factory in (directoryresource.DirectoryResource.
-                          resource_factories.items()):
-        if factory is PageTemplateResourceFactory:
-            continue
-        resource_factories[type] = factory
-
-
-class DirectoryResourceFactory(directoryresource.DirectoryResourceFactory):
-    # We need this to allow hooking up our own GrokDirectoryResource
-    # and to set the checker to None (until we have our own checker)
-
-    def __call__(self, request):
-        # Override this method for the following line, in which our
-        # custom DirectoryResource class is instantiated.
-        resource = DirectoryResource(self.__dir, request)
-        resource.__Security_checker__ = self.__checker
-        resource.__name__ = self.__name
-        return resource

Modified: grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/meta.py
===================================================================
--- grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/meta.py	2008-08-23 19:06:52 UTC (rev 90155)
+++ grokcore.view/branches/sylvain-five-grok-static/src/grokcore/view/meta.py	2008-08-23 19:38:31 UTC (rev 90156)
@@ -13,11 +13,8 @@
 ##############################################################################
 """Grokkers for the various components."""
 
-import os
-
 import zope.component.interface
 from zope import interface, component
-from zope.security.checker import NamesChecker
 from zope.interface.interface import InterfaceClass
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.publisher.interfaces.browser import IBrowserRequest
@@ -178,49 +175,7 @@
         return True
 
 
-allowed_resource_names = ('GET', 'HEAD', 'publishTraverse', 'browserDefault',
-                          'request', '__call__')
-allowed_resourcedir_names = allowed_resource_names + ('__getitem__', 'get')
 
-class StaticResourcesGrokker(martian.GlobalGrokker):
-
-    def grok(self, name, module, module_info, config, **kw):
-        # we're only interested in static resources if this module
-        # happens to be a package
-        if not module_info.isPackage():
-            return False
-
-        resource_path = module_info.getResourcePath('static')
-        if os.path.isdir(resource_path):
-            static_module = module_info.getSubModuleInfo('static')
-            if static_module is not None:
-                if static_module.isPackage():
-                    raise GrokError(
-                        "The 'static' resource directory must not "
-                        "be a python package.",
-                        module_info.getModule())
-                else:
-                    raise GrokError(
-                        "A package can not contain both a 'static' "
-                        "resource directory and a module named "
-                        "'static.py'", module_info.getModule())
-
-        # public checker by default
-        checker = NamesChecker(allowed_resourcedir_names)
-
-        resource_factory = components.DirectoryResourceFactory(
-            resource_path, checker, module_info.dotted_name)
-        adapts = (IDefaultBrowserLayer,)
-        provides = interface.Interface
-        name = module_info.dotted_name
-        config.action(
-            discriminator=('adapter', adapts, provides, name),
-            callable=component.provideAdapter,
-            args=(resource_factory, adapts, provides, name),
-            )
-        return True
-
-
 _skin_not_used = object()
 
 class SkinInterfaceDirectiveGrokker(martian.InstanceGrokker):



More information about the Checkins mailing list