~barry/lazr.restful/387487-subordinate

« back to all changes in this revision

Viewing changes to src/lazr/restful/publisher.py

  • Committer: Barry Warsaw
  • Date: 2009-07-24 21:16:28 UTC
  • Revision ID: barry@canonical.com-20090724211628-ivyq3opc9pwvknnj
ADdress bug 387487 by extending traversal to subentries.

Add a very simple fake navigation test that flexes the basics.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from zope.interface import alsoProvides, implementer, implements
21
21
from zope.publisher.interfaces import NotFound
22
22
from zope.publisher.interfaces.browser import IBrowserRequest
23
 
from zope.schema.interfaces import IBytes
 
23
from zope.schema.interfaces import IBytes, IObject
24
24
from zope.security.checker import ProxyFactory
25
25
 
26
26
from lazr.uri import URI
27
27
 
 
28
from lazr.restful import (
 
29
    CollectionResource, EntryField, EntryFieldResource, EntryResource,
 
30
    ScopedCollection)
28
31
from lazr.restful.interfaces import (
29
 
    IByteStorage, ICollection, IEntry, IEntryField, IHTTPResource,
30
 
    IWebBrowserInitiatedRequest, IWebServiceClientRequest,
31
 
    IWebServiceConfiguration, ICollectionField)
32
 
from lazr.restful import (
33
 
    CollectionResource, EntryField, EntryFieldResource,
34
 
    EntryResource, ScopedCollection)
 
32
    IByteStorage, ICollection, ICollectionField, IEntry, IEntryField,
 
33
    IHTTPResource, IWebBrowserInitiatedRequest, IWebServiceClientRequest,
 
34
    IWebServiceConfiguration)
35
35
 
36
36
 
37
37
class WebServicePublicationMixin:
38
38
    """A mixin for webservice publication.
39
39
 
40
40
    This should usually be mixed-in with ZopePublication, or Browser,
41
 
    or HTTPPublication"""
42
 
 
 
41
    or HTTPPublication.
 
42
    """
43
43
 
44
44
    def traverseName(self, request, ob, name):
45
45
        """See `zope.publisher.interfaces.IPublication`.
66
66
                elif IBytes.providedBy(field):
67
67
                    return self._traverseToByteStorage(
68
68
                        request, entry, field, name)
 
69
                elif IObject.providedBy(field):
 
70
                    sub_entry = getattr(entry, name, None)
 
71
                    if sub_entry is None:
 
72
                        raise NotFound(ob, name, request)
 
73
                    else:
 
74
                        return sub_entry
69
75
                elif field is not None:
70
76
                    return EntryField(entry, field, name)
71
77
                else: