[Checkins] SVN: grokcore.view/trunk/src/grokcore/view/ Move ftests
for the 'static' resource dir to grokcore.view and make sure
they pass:
Philipp von Weitershausen
philikon at philikon.de
Tue Jul 22 14:49:07 EDT 2008
Log message for revision 88724:
Move ftests for the 'static' resource dir to grokcore.view and make sure they pass:
In regular Zope 3 we need to define checkers for resources. For now, we just define
public ones.
Changed:
U grokcore.view/trunk/src/grokcore/view/components.py
A grokcore.view/trunk/src/grokcore/view/ftests/staticdir/
U grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py
U grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple_fixture/ellie.py
U grokcore.view/trunk/src/grokcore/view/ftests/test_functional.py
U grokcore.view/trunk/src/grokcore/view/meta.py
U grokcore.view/trunk/src/grokcore/view/util.py
-=-
Modified: grokcore.view/trunk/src/grokcore/view/components.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/components.py 2008-07-22 18:00:29 UTC (rev 88723)
+++ grokcore.view/trunk/src/grokcore/view/components.py 2008-07-22 18:49:07 UTC (rev 88724)
@@ -297,16 +297,14 @@
resource_factories[type] = factory
-class DirectoryResourceFactory(object):
+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 __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):
+ # 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
Copied: grokcore.view/trunk/src/grokcore/view/ftests/staticdir (from rev 88673, grok/branches/grokcore.xxx/src/grok/ftests/staticdir)
Modified: grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/ftests/staticdir/simple.py 2008-07-22 10:04:04 UTC (rev 88673)
+++ grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py 2008-07-22 18:49:07 UTC (rev 88724)
@@ -1,11 +1,11 @@
"""
-If there is a static/ directory inside of a grokked package, its
+If there is a static/ directory inside of a grokcore.viewked package, its
contents will be available as static resources under a URL:
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
- >>> browser.open('http://localhost/@@/grok.ftests.staticdir.simple_fixture/'
+ >>> browser.open('http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/'
... 'file.txt')
>>> print browser.contents
some text
@@ -14,19 +14,19 @@
to resources:
>>> root = getRootFolder()
- >>> from grok.ftests.staticdir.simple_fixture.ellie import Mammoth
+ >>> from grokcore.view.ftests.staticdir.simple_fixture.ellie import Mammoth
>>> root[u'ellie'] = Mammoth()
>>> browser.open('http://localhost/ellie')
>>> print browser.contents
<html>
<body>
- <a href="http://localhost/@@/grok.ftests.staticdir.simple_fixture/file.txt">Some text in a file</a>
+ <a href="http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/file.txt">Some text in a file</a>
</body>
</html>
Static also means that page templates will not be interpreted:
- >>> browser.open('http://localhost/@@/grok.ftests.staticdir.simple_fixture/static.pt')
+ >>> browser.open('http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/static.pt')
>>> print browser.contents
<html>
<body>
@@ -36,7 +36,7 @@
We also support subdirectories for resources:
- >>> browser.open('http://localhost/@@/grok.ftests.staticdir.simple_fixture/subdir/otherfile.txt')
+ >>> browser.open('http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/subdir/otherfile.txt')
>>> print browser.contents
This is yet another file.
Modified: grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple_fixture/ellie.py
===================================================================
--- grok/branches/grokcore.xxx/src/grok/ftests/staticdir/simple_fixture/ellie.py 2008-07-22 10:04:04 UTC (rev 88673)
+++ grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple_fixture/ellie.py 2008-07-22 18:49:07 UTC (rev 88724)
@@ -1,6 +1,6 @@
-import grok
+import grokcore.view as grok
-class Mammoth(grok.Model):
+class Mammoth(grok.Context):
pass
class Index(grok.View):
Modified: grokcore.view/trunk/src/grokcore/view/ftests/test_functional.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/ftests/test_functional.py 2008-07-22 18:00:29 UTC (rev 88723)
+++ grokcore.view/trunk/src/grokcore/view/ftests/test_functional.py 2008-07-22 18:49:07 UTC (rev 88724)
@@ -51,6 +51,6 @@
def test_suite():
suite = unittest.TestSuite()
- for name in ['view']:
+ for name in ['view', 'staticdir']:
suite.addTest(suiteFromPackage(name))
return suite
Modified: grokcore.view/trunk/src/grokcore/view/meta.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/meta.py 2008-07-22 18:00:29 UTC (rev 88723)
+++ grokcore.view/trunk/src/grokcore/view/meta.py 2008-07-22 18:49:07 UTC (rev 88724)
@@ -6,6 +6,7 @@
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.publisher.interfaces.browser import IBrowserSkinType
from zope.security.interfaces import IPermission
+from zope.security.checker import NamesChecker
import martian
from martian import util
@@ -204,6 +205,10 @@
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):
@@ -227,8 +232,11 @@
"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, module_info.dotted_name)
+ resource_path, checker, module_info.dotted_name)
adapts = (IDefaultBrowserLayer, )
provides = interface.Interface
name = module_info.dotted_name
Modified: grokcore.view/trunk/src/grokcore/view/util.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/util.py 2008-07-22 18:00:29 UTC (rev 88723)
+++ grokcore.view/trunk/src/grokcore/view/util.py 2008-07-22 18:49:07 UTC (rev 88724)
@@ -52,4 +52,3 @@
raise GrokError('Undefined permission %r in %r. Use '
'grok.Permission first.'
% (permission, factory), factory)
-
More information about the Checkins
mailing list