[Checkins] SVN: grok/trunk/src/grok/ remove remnants from the REST code that moved to grokcore.rest
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Wed Jan 12 08:17:35 EST 2011
Log message for revision 119532:
remove remnants from the REST code that moved to grokcore.rest
Changed:
D grok/trunk/src/grok/publication.py
D grok/trunk/src/grok/rest.py
-=-
Deleted: grok/trunk/src/grok/publication.py
===================================================================
--- grok/trunk/src/grok/publication.py 2011-01-12 12:21:32 UTC (rev 119531)
+++ grok/trunk/src/grok/publication.py 2011-01-12 13:17:35 UTC (rev 119532)
@@ -1,77 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Grok publication factories and classes.
-
-These factories, and the publication classes they return, make Grok
-security different from the way that security normal operates during
-Zope publication. Instead of security proxies being wrapped around
-every object generated during traversal, and then wrapped around the
-final object before it is viewed, only a single security check is done
-when Grok is in charge: a check to see whether the view selected at the
-end of the traversal process is, in fact, permitted to display the
-object.
-
-"""
-from grok.rest import GrokMethodNotAllowed
-from grokcore.view.publication import ZopePublicationSansProxy
-
-from zope import component
-from zope.security.checker import selectChecker
-from zope.publisher.publish import mapply
-from zope.publisher.interfaces.http import IHTTPException
-
-from zope.app.publication.http import BaseHTTPPublication, HTTPPublication
-
-
-class GrokHTTPPublication(ZopePublicationSansProxy, HTTPPublication):
- """Combines `HTTPPublication` with the Grok sans-proxy mixin.
-
- Because `HTTPPublication` provides its own, special `callObject()`
- implementation, this subclass does the same, providing what is
- basically the same call (you can verify, in fact, that most of its
- lines were copied directly from the superclass's version) but with a
- few extra lines added so that - as with the simpler `callObject()`
- method in `ZopePublicationSansProxy` - it quickly places a security
- proxy around the object, makes sure that this HTTP method is
- permitted, and finally passes the bare object to the view that will
- render it.
-
- """
- def callObject(self, request, ob):
- orig = ob
- if not IHTTPException.providedBy(ob):
- ob = component.queryMultiAdapter((ob, request),
- name=request.method)
- checker = selectChecker(ob)
- if checker is not None:
- checker.check(ob, '__call__')
- ob = getattr(ob, request.method, None)
- if ob is None:
- raise GrokMethodNotAllowed(orig, request)
- return mapply(ob, request.getPositionalArguments(), request)
-
-
-class GrokHTTPFactory(HTTPFactory):
- """Returns the classes Grok uses for HTTP requests and publication.
-
- When an instance of this class is called, it returns a 2-element
- tuple containing:
-
- - The request class that Grok uses for HTTP requests.
- - The publication class that Grok uses to publish to HTTP.
-
- """
- def __call__(self):
- request, publication = super(GrokHTTPFactory, self).__call__()
- return request, GrokHTTPPublication
Deleted: grok/trunk/src/grok/rest.py
===================================================================
--- grok/trunk/src/grok/rest.py 2011-01-12 12:21:32 UTC (rev 119531)
+++ grok/trunk/src/grok/rest.py 2011-01-12 13:17:35 UTC (rev 119532)
@@ -1,108 +0,0 @@
-"""Default REST view for Grok.
-
-The views provided by this module get invoked when an object receives an
-HTTP request in a REST skin for which no more-specific REST behavior has
-been defined. These all return the HTTP response Method Not Allowed.
-
-"""
-import grok
-from grok.interfaces import IRESTSkinType
-
-from zope import component
-from zope.component.interfaces import ComponentLookupError
-from zope.traversing.interfaces import TraversalError
-from zope.traversing.namespace import view
-from zope.interface import Interface
-from zope.publisher.interfaces.http import IHTTPRequest
-from zope.app.publication.http import MethodNotAllowed
-from zope.publisher.browser import applySkin
-
-
-class GrokMethodNotAllowed(MethodNotAllowed):
- """Exception indicating that an attempted REST method is not allowed."""
-
-
-class MethodNotAllowedView(grok.MultiAdapter):
- """View rendering a REST GrokMethodNotAllowed exception over HTTP.
-
- Not only does this view render the REST error as an HTTP status of
- 405 (Method Not Allowed) and a simple text message as the document
- body, but also offers an ``Allow:`` HTTP header listing any methods
- that can, in fact, succeed. It constructs this list by testing the
- current object to see which methods it supports; if none of the
- standard methods succeed, then the ``Allow:`` header is still
- provided, but its value will be empty.
-
- """
- grok.adapts(GrokMethodNotAllowed, IHTTPRequest)
- grok.name('index.html')
- grok.implements(Interface)
-
- def __init__(self, error, request):
- self.error = error
- self.request = request
- self.allow = self._getAllow()
-
- def _getAllow(self):
- allow = []
- # List methods here in the same order that they should appear in
- # the "Allow:" header.
- for method in 'DELETE', 'GET', 'POST', 'PUT':
- view = component.queryMultiAdapter(
- (self.error.object, self.error.request),
- name=method)
- if view is not None:
- is_not_allowed = getattr(view, 'is_not_allowed', False)
- if not is_not_allowed:
- allow.append(method)
- return allow
-
- def __call__(self):
- self.request.response.setHeader('Allow', ', '.join(self.allow))
- self.request.response.setStatus(405)
- return 'Method Not Allowed'
-
-
-class rest_skin(view):
- """A rest skin.
-
- This used to be supported by zope.traversing but the change was
- backed out. We need it for our REST support.
-
- """
- def traverse(self, name, ignored):
- self.request.shiftNameToApplication()
- try:
- skin = component.getUtility(IRESTSkinType, name)
- except ComponentLookupError:
- raise TraversalError("++rest++%s" % name)
- applySkin(self.request, skin)
- return self.context
-
-
-class NotAllowedREST(grok.REST):
- """Default REST view, whose methods all raise Not Allowed errors.
-
- By binding itself to ``Interface``, this becomes the most general
- available REST view, and will be called into service for objects
- that have not had more specific REST views registered. This means
- that such objects can at least return attractive refusals when
- clients attempt to assail them with unwanted HTTP methods.
-
- """
- grok.layer(grok.IRESTLayer)
- grok.context(Interface)
-
- is_not_allowed = True
-
- def GET(self):
- raise GrokMethodNotAllowed(self.context, self.request)
-
- def POST(self):
- raise GrokMethodNotAllowed(self.context, self.request)
-
- def PUT(self):
- raise GrokMethodNotAllowed(self.context, self.request)
-
- def DELETE(self):
- raise GrokMethodNotAllowed(self.context, self.request)
More information about the checkins
mailing list