[Checkins] SVN: grok/trunk/src/grok/ - made static resource
directory work
Christian Theune
ct at gocept.com
Tue Oct 17 15:55:28 EDT 2006
Log message for revision 70763:
- made static resource directory work
- fixed tests
Changed:
U grok/trunk/src/grok/_grok.py
U grok/trunk/src/grok/ftests/static/simple.py
U grok/trunk/src/grok/ftests/test_grok_functional.py
-=-
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py 2006-10-17 19:53:12 UTC (rev 70762)
+++ grok/trunk/src/grok/_grok.py 2006-10-17 19:55:27 UTC (rev 70763)
@@ -29,8 +29,9 @@
IBrowserRequest)
from zope.pagetemplate import pagetemplate
from zope.app.pagetemplate.engine import TrustedAppPT
-from zope.app.publisher.browser.directoryresource import \
- DirectoryResourceFactory
+from zope.app.publisher.browser import directoryresource
+from zope.app.publisher.browser.pagetemplateresource import \
+ PageTemplateResourceFactory
from grok import util, scan
from grok.error import GrokError, GrokImportError
@@ -102,6 +103,13 @@
def grok_tree(module_info):
grok_module(module_info)
+ if not module_info.isPackage():
+ return
+
+ resource_path = module_info.getResourcePath('static')
+ if os.path.isdir(resource_path):
+ register_static_resources(module_info.dotted_name, resource_path)
+
for sub_module_info in module_info.getSubModuleInfos():
grok_tree(sub_module_info)
@@ -184,17 +192,69 @@
template_dir), inline_template)
templates.register(template_name, template)
-def register_static_resources(dotted_name, package_directory):
- path = os.path.join(package_directory, 'static')
- if os.path.exists(path):
-# if not os.path.isdir(path):
-# raise GrokError("")
+class GrokDirectoryResource(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_factory = DirectoryResourceFactory(path, NoProxy, dotted_name)
- component.provideAdapter(resource_factory, (IDefaultBrowserLayer,),
- interface.Interface, name=dotted_name)
+ resource_factories = {}
+ for type, factory in (directoryresource.DirectoryResource.
+ resource_factories.items()):
+ if factory is PageTemplateResourceFactory:
+ continue
+ resource_factories[type] = factory
+
+class GrokDirectoryResourceFactory(object):
+ # We need this to allow hooking up our own GrokDirectoryResource
+ # and to set the checker to None (until we have our own checker)
+
+ def __init__(self, path, name):
+ # XXX we're not sure about the checker=None here
+ self.__dir = directoryresource.Directory(path, None, name)
+ self.__name = name
+
+ def __call__(self, request):
+ resource = GrokDirectoryResource(self.__dir, request)
+ resource.__Security_checker__ = GrokChecker()
+ resource.__name__ = self.__name
+ return resource
+
+class GrokChecker(object):
+ # ME GROK ANGRY.
+ # ME GROK NOT KNOW WHY CHECKER.
+
+ # We have no idea why we need a custom checker here. One hint was
+ # that the DirectoryResource already does something manually with
+ # setting up the 'correct' checker for itself and we seem to interfere
+ # with that. However, we couldn't figure out what's going on and this
+ # solves our problem for now.
+
+ # XXX re-implement this in a sane way.
+
+ def __init__(self):
+ pass
+
+ def check_getattr(self, object, name):
+ pass
+
+ def check_setattr(self, ob, name):
+ pass
+
+ def check(self, ob, operation):
+ pass
+
+ def proxy(self, value):
+ return value
+
+
+def register_static_resources(dotted_name, resource_directory):
+ resource_factory = GrokDirectoryResourceFactory(resource_directory,
+ dotted_name)
+ component.provideAdapter(resource_factory, (IDefaultBrowserLayer,),
+ interface.Interface, name=dotted_name)
+
def register_models(models):
for model in models:
# TODO minimal security here (read: everything is public)
Modified: grok/trunk/src/grok/ftests/static/simple.py
===================================================================
--- grok/trunk/src/grok/ftests/static/simple.py 2006-10-17 19:53:12 UTC (rev 70762)
+++ grok/trunk/src/grok/ftests/static/simple.py 2006-10-17 19:55:27 UTC (rev 70763)
@@ -2,11 +2,12 @@
If there is a static/ directory inside of a grokked package, its
contents will be available as static resources under a URL:
- >>> grok.grok('grok.tests.static.simple_fixture')
+ >>> import grok
+ >>> grok.grok('grok.ftests.static.simple_fixture')
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
- >>> browser.open('http://localhost/++resource++grok.tests.static.simple_fixture/file.txt')
+ >>> browser.open('http://localhost/++resource++grok.ftests.static.simple_fixture/file.txt')
>>> print browser.contents
some text
"""
Modified: grok/trunk/src/grok/ftests/test_grok_functional.py
===================================================================
--- grok/trunk/src/grok/ftests/test_grok_functional.py 2006-10-17 19:53:12 UTC (rev 70762)
+++ grok/trunk/src/grok/ftests/test_grok_functional.py 2006-10-17 19:55:27 UTC (rev 70763)
@@ -56,7 +56,7 @@
def test_suite():
suite = unittest.TestSuite()
- for name in ['view']:
+ for name in ['view', 'static']:
suite.addTest(suiteFromPackage(name))
return suite
More information about the Checkins
mailing list