diff options
author | Jim Fulton <jim@zope.com> | 2002-07-12 19:28:34 +0000 |
---|---|---|
committer | Jim Fulton <jim@zope.com> | 2002-07-12 19:28:34 +0000 |
commit | 11ab5b76a20c7ec60207f96ce4ca9c4bad60bf62 (patch) | |
tree | 63e52301953c365d97b9699ef74c11b822409727 | |
parent | caf4bf056d6837c5e03bf1ead6637b5df58d9928 (diff) | |
download | zope-traversing-11ab5b76a20c7ec60207f96ce4ca9c4bad60bf62.tar.gz |
Finally added a configuration directive for registering traversal
namespace handlers:
<traversalNamespace name="etc" handler=".EtcNamespace.etc" />
Added a "skin" namespace so you can play with Sidbei's new UI work
by adding ++skin++ZopeTop to the front of your URLs:
http://localhost:8080/++skin++ZopeTop
Added some needed __init__ modules to some of the new ZopeTop packages
and fixed up ZopeTop configure.zcml.
-rw-r--r-- | AcquireNamespace.py | 4 | ||||
-rw-r--r-- | AttrItemNamespaces.py | 21 | ||||
-rw-r--r-- | EtcNamespace.py | 4 | ||||
-rw-r--r-- | Namespaces.py | 16 | ||||
-rw-r--r-- | PhysicalLocationAdapters.py | 6 | ||||
-rw-r--r-- | PresentationNamespaces.py | 6 | ||||
-rw-r--r-- | SkinNamespace.py | 32 | ||||
-rw-r--r-- | configure.zcml | 7 | ||||
-rw-r--r-- | meta.zcml | 10 | ||||
-rw-r--r-- | tests/testNamespaceTrversal.py | 9 | ||||
-rw-r--r-- | tests/testSkin.py | 42 |
11 files changed, 118 insertions, 39 deletions
diff --git a/AcquireNamespace.py b/AcquireNamespace.py index 6d1c5c3..18f1a3f 100644 --- a/AcquireNamespace.py +++ b/AcquireNamespace.py @@ -13,7 +13,7 @@ ############################################################################## """ -$Id: AcquireNamespace.py,v 1.2 2002/06/10 23:28:17 jim Exp $ +$Id: AcquireNamespace.py,v 1.3 2002/07/12 19:28:32 jim Exp $ """ from Namespaces import provideNamespaceHandler @@ -53,5 +53,3 @@ def acquire(name, parameters, pname, ob, request): raise ExcessiveWrapping(origOb, pname) -provideNamespaceHandler('acquire', acquire) - diff --git a/AttrItemNamespaces.py b/AttrItemNamespaces.py index e602804..a3373a6 100644 --- a/AttrItemNamespaces.py +++ b/AttrItemNamespaces.py @@ -13,7 +13,7 @@ ############################################################################## """ -$Id: AttrItemNamespaces.py,v 1.2 2002/06/10 23:28:17 jim Exp $ +$Id: AttrItemNamespaces.py,v 1.3 2002/07/12 19:28:32 jim Exp $ """ from Namespaces import provideNamespaceHandler @@ -24,26 +24,7 @@ def attr(name, parameters, pname, ob, request): raise UnexpectedParameters(parameters) return getattr(ob, name) -provideNamespaceHandler('attribute', attr) - def item(name, parameters, pname, ob, request): if parameters: raise UnexpectedParameters(parameters) return ob[name] - -provideNamespaceHandler('item', item) - - -# YAGNI -# -# def accessor(name, parameters, ob, request): -# if parameters: -# raise UnexpectedParameters(parameters) -# -# method = getattr(ob, name, None) -# if method is None: -# raise NotFound(ob, name, request) -# -# return method() -# -# provideNamespaceHandler('accessor', accessor) diff --git a/EtcNamespace.py b/EtcNamespace.py index 0c0f917..269927f 100644 --- a/EtcNamespace.py +++ b/EtcNamespace.py @@ -13,7 +13,7 @@ ############################################################################## """ -$Id: EtcNamespace.py,v 1.3 2002/07/11 18:21:34 jim Exp $ +$Id: EtcNamespace.py,v 1.4 2002/07/12 19:28:32 jim Exp $ """ from Zope.App.OFS.ApplicationControl.ApplicationControl \ import ApplicationController @@ -50,5 +50,3 @@ def etc(name, parameters, pname, ob, request): raise NotFoundError(ob, pname, request) return method() - -provideNamespaceHandler('etc', etc) diff --git a/Namespaces.py b/Namespaces.py index eb10f65..166e82b 100644 --- a/Namespaces.py +++ b/Namespaces.py @@ -13,17 +13,26 @@ ############################################################################## """ -$Id: Namespaces.py,v 1.3 2002/06/23 17:03:44 jim Exp $ +$Id: Namespaces.py,v 1.4 2002/07/12 19:28:32 jim Exp $ """ from Zope.Exceptions import NotFoundError from Zope.Proxy.ContextWrapper import ContextWrapper +from Zope.Configuration.Action import Action _namespace_handlers = {} def provideNamespaceHandler(ns, handler): _namespace_handlers[ns] = handler +def directive(_context, name, handler): + handler = _context.resolve(handler) + return [Action( + discriminator=("traversalNamespace", name), + callable=provideNamespaceHandler, + args=(name, handler), + )] + def namespaceLookup(name, ns, qname, parameters, object, request=None): """Lookup a value from a namespace @@ -38,8 +47,3 @@ def namespaceLookup(name, ns, qname, parameters, object, request=None): new = ContextWrapper(handler(qname, parameters, name, object, request), object, name=name) return new - -# XXX should get this from zcml -# Register the etc, view, and resource namespaces -import EtcNamespace, PresentationNamespaces, AttrItemNamespaces -import AcquireNamespace diff --git a/PhysicalLocationAdapters.py b/PhysicalLocationAdapters.py index 06b0ac3..63c27b6 100644 --- a/PhysicalLocationAdapters.py +++ b/PhysicalLocationAdapters.py @@ -15,7 +15,7 @@ XXX longer description goes here. -$Id: PhysicalLocationAdapters.py,v 1.1 2002/07/11 18:21:34 jim Exp $ +$Id: PhysicalLocationAdapters.py,v 1.2 2002/07/12 19:28:32 jim Exp $ """ __metaclass__ = type @@ -50,6 +50,10 @@ class WrapperPhysicallyLocatable: container = getAdapter(container, IPhysicallyLocatable) container_path = container.getPhysicalPath() + if name == '.': + # skip + return container_path + return container_path + (name, ) diff --git a/PresentationNamespaces.py b/PresentationNamespaces.py index f753209..9d643c4 100644 --- a/PresentationNamespaces.py +++ b/PresentationNamespaces.py @@ -13,7 +13,7 @@ ############################################################################## """ -$Id: PresentationNamespaces.py,v 1.3 2002/06/13 23:15:44 jim Exp $ +$Id: PresentationNamespaces.py,v 1.4 2002/07/12 19:28:32 jim Exp $ """ from Zope.ComponentArchitecture import getView @@ -34,8 +34,6 @@ def view(name, parameters, pname, ob, request): raise NoRequest(pname) return getView(ob, name, request) -provideNamespaceHandler('view', view) - def resource(name, parameters, pname, ob, request): if parameters: raise UnexpectedParameters(parameters) @@ -48,5 +46,3 @@ def resource(name, parameters, pname, ob, request): return resource -provideNamespaceHandler('resource', resource) - diff --git a/SkinNamespace.py b/SkinNamespace.py new file mode 100644 index 0000000..d23cb08 --- /dev/null +++ b/SkinNamespace.py @@ -0,0 +1,32 @@ +############################################################################## +# +# Copyright (c) 2001, 2002 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +""" + +$Id: SkinNamespace.py,v 1.1 2002/07/12 19:28:32 jim Exp $ +""" + +from Zope.App.OFS.ApplicationControl.ApplicationControl \ + import ApplicationController +from Namespaces import provideNamespaceHandler +from Exceptions import UnexpectedParameters +from Zope.Exceptions import NotFoundError + +def skin(name, parameters, pname, ob, request): + + if parameters: + raise UnexpectedParameters(parameters) + + request.setViewSkin(name) + + return ob diff --git a/configure.zcml b/configure.zcml index ce032df..7e85501 100644 --- a/configure.zcml +++ b/configure.zcml @@ -37,5 +37,12 @@ factory=".PhysicalLocationAdapters.RootPhysicallyLocatable" /> +<traversalNamespace name="etc" handler=".EtcNamespace.etc" /> +<traversalNamespace name="view" handler=".PresentationNamespaces.view" /> +<traversalNamespace name="view" handler=".PresentationNamespaces.resource" /> +<traversalNamespace name="attribute" handler=".AttrItemNamespaces.attr" /> +<traversalNamespace name="item" handler=".AttrItemNamespaces.attr" /> +<traversalNamespace name="acquire" handler=".AcquireNamespace.acquire" /> +<traversalNamespace name="skin" handler=".SkinNamespace.skin" /> </zopeConfigure> diff --git a/meta.zcml b/meta.zcml new file mode 100644 index 0000000..a33bc64 --- /dev/null +++ b/meta.zcml @@ -0,0 +1,10 @@ +<zopeConfigure xmlns='http://namespaces.zope.org/zope'> + + <directives namespace="http://namespaces.zope.org/zope"> + + <directive name="traversalNamespace" attributes="name handler" + handler=".Namespaces.directive" /> + + </directives> + +</zopeConfigure> diff --git a/tests/testNamespaceTrversal.py b/tests/testNamespaceTrversal.py index aaeb28c..f490d2e 100644 --- a/tests/testNamespaceTrversal.py +++ b/tests/testNamespaceTrversal.py @@ -14,7 +14,7 @@ """ Revision information: -$Id: testNamespaceTrversal.py,v 1.2 2002/06/10 23:28:17 jim Exp $ +$Id: testNamespaceTrversal.py,v 1.3 2002/07/12 19:28:33 jim Exp $ """ from unittest import TestCase, TestSuite, main, makeSuite @@ -29,6 +29,13 @@ c=C() class Test(CleanUp, TestCase): + def setUp(self): + from Zope.App.Traversing.Namespaces import provideNamespaceHandler + from Zope.App.Traversing.AttrItemNamespaces import attr, item + provideNamespaceHandler('attribute', attr) + provideNamespaceHandler('item', item) + + def testAttr(self): from Zope.App.Traversing.Traverser import Traverser traverser = Traverser(c) diff --git a/tests/testSkin.py b/tests/testSkin.py new file mode 100644 index 0000000..163e0a9 --- /dev/null +++ b/tests/testSkin.py @@ -0,0 +1,42 @@ +############################################################################## +# +# Copyright (c) 2001, 2002 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE +# +############################################################################## +""" + +Revision information: +$Id: testSkin.py,v 1.1 2002/07/12 19:28:33 jim Exp $ +""" + +from unittest import TestCase, TestSuite, main, makeSuite +from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup +from Zope.Publisher.Browser.BrowserRequest import TestRequest + +class Test(CleanUp, TestCase): + + def test(self): + from Zope.App.Traversing.SkinNamespace import skin + + request = TestRequest() + self.assertEqual(request.getPresentationSkin(), '') + ob = object() + ob2 = skin('foo', (), '++skin++foo', ob, request) + self.assertEqual(ob, ob2) + self.assertEqual(request.getPresentationSkin(), 'foo') + +def test_suite(): + return TestSuite(( + makeSuite(Test), + )) + +if __name__=='__main__': + main(defaultTest='test_suite') |