[Checkins] SVN: z3c.rest/trunk/ Use z3c.traverser as the traversal
implementation.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Dec 8 23:38:37 EST 2007
Log message for revision 82207:
Use z3c.traverser as the traversal implementation.
Changed:
U z3c.rest/trunk/TODO.txt
U z3c.rest/trunk/buildout.cfg
U z3c.rest/trunk/setup.py
U z3c.rest/trunk/src/z3c/rest/configure.zcml
U z3c.rest/trunk/src/z3c/rest/traverser.py
U z3c.rest/trunk/src/z3c/rest/traverser.txt
-=-
Modified: z3c.rest/trunk/TODO.txt
===================================================================
--- z3c.rest/trunk/TODO.txt 2007-12-09 04:31:52 UTC (rev 82206)
+++ z3c.rest/trunk/TODO.txt 2007-12-09 04:38:37 UTC (rev 82207)
@@ -5,20 +5,6 @@
For 1.0.0
---------
-- Restructure the default container traverser to use the pluggable traverser
- framework -- ``z3c.traverser`` -- instead.
-
- * Write a custom implementation of the ``PluggableTraverser``, so that it
- does *not* look up a view, if it cannot traverse.
-
- * Register this custom pluggable traverser for *all* objects.
-
- * Implement a custom ``ContainerTraverserPlugin`` that has the same
- semantics as the item traverser in ``z3c/rest/traverser.py``, i.e. be able
- to produce a null resource.
-
- * Register the plugin for all item containers.
-
- Implement a new package called ``z3c.restdemo`` that contains two demos that
show off the new REST framework. All demos must provide a comprehensive
doctest file demonstrating the API using the REST client.
Modified: z3c.rest/trunk/buildout.cfg
===================================================================
--- z3c.rest/trunk/buildout.cfg 2007-12-09 04:31:52 UTC (rev 82206)
+++ z3c.rest/trunk/buildout.cfg 2007-12-09 04:38:37 UTC (rev 82207)
@@ -1,5 +1,6 @@
[buildout]
develop = .
+ ../z3c.traverser
index = http://download.zope.org/zope3.4
parts = demo test coverage
Modified: z3c.rest/trunk/setup.py
===================================================================
--- z3c.rest/trunk/setup.py 2007-12-09 04:31:52 UTC (rev 82206)
+++ z3c.rest/trunk/setup.py 2007-12-09 04:38:37 UTC (rev 82207)
@@ -72,6 +72,7 @@
install_requires = [
'lxml',
'setuptools',
+ 'z3c.traverser',
'zope.publisher',
],
zip_safe = False,
Modified: z3c.rest/trunk/src/z3c/rest/configure.zcml
===================================================================
--- z3c.rest/trunk/src/z3c/rest/configure.zcml 2007-12-09 04:31:52 UTC (rev 82206)
+++ z3c.rest/trunk/src/z3c/rest/configure.zcml 2007-12-09 04:38:37 UTC (rev 82207)
@@ -11,30 +11,25 @@
<!-- Basic Container traversers -->
<view
- for="zope.app.http.interfaces.INullResource"
- name="PUT"
+ for="*"
type=".interfaces.IRESTRequest"
- factory=".null.NullPUT"
- permission="zope.Public"
- allowed_attributes="PUT"
- />
-
- <view
- for="zope.app.container.interfaces.IItemContainer"
- type=".interfaces.IRESTRequest"
provides="zope.publisher.interfaces.IPublishTraverse"
- factory=".traverser.ItemTraverser"
+ factory=".traverser.RESTPluggableTraverser"
permission="zope.Public"
allowed_interface="zope.publisher.interfaces.IPublishTraverse"
/>
+ <subscriber
+ factory=".traverser.ContainerItemTraverserPlugin"
+ provides="z3c.traverser.interfaces.ITraverserPlugin" />
+
<view
- for="zope.app.container.interfaces.ISimpleReadContainer"
+ for="zope.app.http.interfaces.INullResource"
+ name="PUT"
type=".interfaces.IRESTRequest"
- provides="zope.publisher.interfaces.IPublishTraverse"
- factory=".traverser.ItemTraverser"
+ factory=".null.NullPUT"
permission="zope.Public"
- allowed_interface="zope.publisher.interfaces.IPublishTraverse"
+ allowed_attributes="PUT"
/>
<!-- Basic REST publishing setup -->
Modified: z3c.rest/trunk/src/z3c/rest/traverser.py
===================================================================
--- z3c.rest/trunk/src/z3c/rest/traverser.py 2007-12-09 04:31:52 UTC (rev 82206)
+++ z3c.rest/trunk/src/z3c/rest/traverser.py 2007-12-09 04:38:37 UTC (rev 82207)
@@ -16,13 +16,20 @@
$Id$
"""
import zope.interface
-from zope.publisher.interfaces.http import IHTTPPublisher
+from z3c.rest import interfaces, null
+from z3c.traverser import traverser
+from z3c.traverser.interfaces import ITraverserPlugin
from zope.app.container.interfaces import IItemContainer
from zope.publisher.interfaces import NotFound
-from z3c.rest import interfaces, null
-class ItemTraverser(object):
- zope.interface.implements(IHTTPPublisher)
+
+class RESTPluggableTraverser(traverser.BasePluggableTraverser):
+ """A simple REST-compliant pluggable traverser."""
+
+
+class ContainerItemTraverserPlugin(object):
+ """A traverser that knows how to look up objects by name in a container."""
+ zope.interface.implements(ITraverserPlugin)
zope.component.adapts(IItemContainer, interfaces.IRESTRequest)
def __init__(self, container, request):
@@ -30,6 +37,7 @@
self.request = request
def publishTraverse(self, request, name):
+ """See zope.publisher.interfaces.IPublishTraverse"""
try:
return self.context[name]
except KeyError:
Modified: z3c.rest/trunk/src/z3c/rest/traverser.txt
===================================================================
--- z3c.rest/trunk/src/z3c/rest/traverser.txt 2007-12-09 04:31:52 UTC (rev 82206)
+++ z3c.rest/trunk/src/z3c/rest/traverser.txt 2007-12-09 04:38:37 UTC (rev 82207)
@@ -2,13 +2,31 @@
REST Traverser Components
=========================
-The traverser module contains several travreser implementations for common
-scenarios.
+Being able to control and extend traversal is essential to any RESTive
+API. This package uses the pluggable traverser implementation of the
+``z3c.traverser`` package to provide a flexible traversal mechanism.
-Item Container Traverser
+REST Pluggable Traverser
------------------------
+The REST pluggable traverser is registered for all types of components. Its
+implementation is fully tested in the ``z3c.traverser`` package.
+
+ >>> from z3c.rest import traverser
+
+ >>> import StringIO
+ >>> from z3c.rest import rest
+ >>> request = rest.RESTRequest(StringIO.StringIO(), {})
+
+ >>> pluggable = traverser.RESTPluggableTraverser(object(), request)
+ >>> pluggable
+ <z3c.rest.traverser.RESTPluggableTraverser object at ...>
+
+
+Item Container Traverser Plugin
+-------------------------------
+
The item mapping interface -- from which item container inherits -- is the
most minimal mapping interface in Python. Thus, once traversing through this
item container is implemented, it can be used by all other container
@@ -31,16 +49,11 @@
>>> container['sub1'] = SimpleContainer('sub1')
>>> container['sub2'] = SimpleContainer('sub2')
-After creating a traverser instance,
+After creating a traverser plugin instance,
- >>> from z3c.rest import traverser
-
- >>> import StringIO
- >>> from z3c.rest import rest
>>> request = rest.RESTRequest(StringIO.StringIO(), {})
-
- >>> containerTraverser = traverser.ItemTraverser(
+ >>> containerTraverser = traverser.ContainerItemTraverserPlugin(
... container, request)
we can traverse to a sub-object of that container:
More information about the Checkins
mailing list