Merge lp:~leonardr/lazr.restful/wsgi.improvements.1 into lp:lazr.restful

Proposed by Leonard Richardson
Status: Merged
Merged at revision: not available
Proposed branch: lp:~leonardr/lazr.restful/wsgi.improvements.1
Merge into: lp:lazr.restful
Diff against target: None lines
To merge this branch: bzr merge lp:~leonardr/lazr.restful/wsgi.improvements.1
Reviewer Review Type Date Requested Status
Deryck Hodge (community) Approve
Review via email: mp+9652@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

This branch does some minor cleanup of lazr.restful to reduce the amount of code in the example web services.

1. I changed some README files to point to the lazr.restful.example.wsgi README, which is the best place to get started learning about lazr.restful. (This was something gary requested while reviewing an earlier branch, that I didn't carry out.)

2. I removed example/wsgi/initialize.py, which wasn't used anywhere.

3. I changed SimplePublication into a mixin, and created a new SimplePublication that included it along with the WebServicePublicationMixin. This removed the need to create new publication classes that included both SimplePublication and WebServicePublicationMixin. I got rid of now-redundant publication classes in lazr.restful.example.wsgi, and slightly simplified the publication class in lazr.restful.testing.webservice.

(Why make SimplePublication a mixin? Why not just make it mix in WebServicePublicationMixin? Because SP.traverseName() expects to be the super() of WSPM. If SP mixes in WSPM, WSPM.traverseName() will be the super() of SP.traverseName(), and the code won't work.)

47. By Leonard Richardson

Removed unneeded code from test_integration.py.

Revision history for this message
Deryck Hodge (deryck) wrote :

Hi, Leonard.

This is a nice looking clean up branch. Cheers,

deryck

review: Approve
Revision history for this message
Leonard Richardson (leonardr) wrote :

Here's the incremental diff for a follow-up that creates a SimpleRequest to match SimplePublication, and uses it to replace WSGIExampleWebServiceRequest and WebServiceTestRequest.

https://pastebin.canonical.com/20760/

Revision history for this message
Deryck Hodge (deryck) wrote :

> Here's the incremental diff for a follow-up that creates a SimpleRequest to
> match SimplePublication, and uses it to replace WSGIExampleWebServiceRequest
> and WebServiceTestRequest.
>
> https://pastebin.canonical.com/20760/

This incremental diff looks fine, too.

Cheers,
deryck

review: Approve
48. By Leonard Richardson

Replaced miscellaneous request classes with SimpleRequest.

Revision history for this message
Leonard Richardson (leonardr) wrote :

And here's the incremental diff for a change that refactors a lot of the basic runtime ZCML into basic-site.zcml, used by numerous tests and examples:

https://pastebin.canonical.com/20767/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.txt'
2--- README.txt 2009-04-29 15:34:56 +0000
3+++ README.txt 2009-08-04 14:46:24 +0000
4@@ -15,4 +15,5 @@
5 You should have received a copy of the GNU Lesser General Public License
6 along with lazr.restful. If not, see <http://www.gnu.org/licenses/>.
7
8-Please see the package README for an introduction.
9+Please see the package README for an introduction. For a quick start,
10+look at example/wsgi/README.txt within the package.
11
12=== modified file 'src/lazr/restful/README.txt'
13--- src/lazr/restful/README.txt 2009-04-29 15:34:56 +0000
14+++ src/lazr/restful/README.txt 2009-08-04 14:17:40 +0000
15@@ -21,16 +21,25 @@
16 RESTful web service. To tell lazr.restful which objects you want
17 exposed and how, you annotate your existing Zope interfaces.
18
19-The example web service
20-=======================
21-
22-The example web service is the best place to start understanding
23-lazr.restful. The web service is in src/lazr/restful/example. It
24-defines a simple application serving information about cookbooks and
25-recipes. The interfaces (interfaces.py) are annotated with
26-lazr.restful decorators that say which fields and methods to publish
27-from IRecipe, ICookbook, and so on. The implementations of those
28-interfaces are in root.py.
29+
30+The WSGI example web service
31+============================
32+
33+The example web service in src/lazr/restful/example/wsgi/ is the best
34+place to start understanding lazr.restful. It's a very simple web
35+service that uses a subset of lazr.restful's features and can be run
36+as a standalone WSGI application. An explanation of the code can be
37+found in src/lazr/restful/example/wsgi/README.txt
38+
39+The full example web service
40+============================
41+
42+To understand all of lazr.restful, you should look at the web service
43+defined in src/lazr/restful/example/. It defines a simple application
44+serving information about cookbooks and recipes. The interfaces
45+(interfaces.py) are annotated with lazr.restful decorators that say
46+which fields and methods to publish from IRecipe, ICookbook, and so
47+on. The implementations of those interfaces are in root.py.
48
49 The machinery of lazr.restful takes the decorators in interfaces.py,
50 and generates an interface that maps incoming HTTP requests to
51
52=== removed file 'src/lazr/restful/example/wsgi/initialize.py'
53--- src/lazr/restful/example/wsgi/initialize.py 2009-07-07 14:58:36 +0000
54+++ src/lazr/restful/example/wsgi/initialize.py 1970-01-01 00:00:00 +0000
55@@ -1,15 +0,0 @@
56-"""Web service initialization."""
57-
58-__metaclass__ = type
59-__all__ = [
60- 'initialize',
61- ]
62-
63-
64-from zope.configuration import xmlconfig
65-
66-
67-def initialize():
68- """Initialize the admin web service and the Zope Component Architecture."""
69- import lazr.restful.example.wsgi
70- xmlconfig.file('configure.zcml', lazr.restful.example.wsgi)
71
72=== removed file 'src/lazr/restful/example/wsgi/publication.py'
73--- src/lazr/restful/example/wsgi/publication.py 2009-07-07 18:56:50 +0000
74+++ src/lazr/restful/example/wsgi/publication.py 1970-01-01 00:00:00 +0000
75@@ -1,13 +0,0 @@
76-"""Module stuff."""
77-
78-__metaclass__ = type
79-__all__ = [
80- 'WSGIExampleWebServicePublication',
81- ]
82-
83-from lazr.restful.publisher import (
84- SimplePublication, WebServicePublicationMixin)
85-
86-class WSGIExampleWebServicePublication(
87- WebServicePublicationMixin, SimplePublication):
88- """A publication that mixes in the necessary web service stuff."""
89
90=== modified file 'src/lazr/restful/example/wsgi/tests/test_integration.py'
91--- src/lazr/restful/example/wsgi/tests/test_integration.py 2009-07-07 18:56:50 +0000
92+++ src/lazr/restful/example/wsgi/tests/test_integration.py 2009-08-04 14:46:24 +0000
93@@ -16,18 +16,10 @@
94
95 from lazr.restful.example.wsgi.root import WSGIExampleWebServiceRootResource
96 from lazr.restful.interfaces import IWebServiceConfiguration
97-from lazr.restful.publisher import (
98- WebServicePublicationMixin, SimplePublication)
99+from lazr.restful.publisher import SimplePublication
100 from lazr.restful.testing.webservice import WebServiceApplication
101
102
103-class WSGIExampleWebServiceTestPublication(
104- WebServicePublicationMixin, SimplePublication):
105-
106- def getApplication(self, request):
107- return WSGIExampleWebServiceRootResource()
108-
109-
110 DOCTEST_FLAGS = (
111 doctest.ELLIPSIS |
112 doctest.NORMALIZE_WHITESPACE |
113@@ -39,6 +31,12 @@
114 zcml_layer(FunctionalLayer)
115
116
117+class WSGIExampleWebServiceTestPublication(SimplePublication):
118+
119+ def getApplication(self, request):
120+ return WSGIExampleWebServiceRootResource()
121+
122+
123 class WSGILayer(FunctionalLayer):
124 @classmethod
125 def make_application(self):
126
127=== modified file 'src/lazr/restful/example/wsgi/webservice.py'
128--- src/lazr/restful/example/wsgi/webservice.py 2009-07-07 19:23:03 +0000
129+++ src/lazr/restful/example/wsgi/webservice.py 2009-08-04 14:46:24 +0000
130@@ -20,7 +20,7 @@
131 from lazr.restful.publisher import WebServiceRequestTraversal
132
133
134-from lazr.restful.example.wsgi.publication import WSGIExampleWebServicePublication
135+from lazr.restful.publisher import SimplePublication
136 from lazr.restful.example.wsgi.root import WSGIExampleWebServiceRootResource
137
138
139@@ -41,7 +41,7 @@
140 method = environ.get('REQUEST_METHOD', 'GET').upper()
141 service_root = WSGIExampleWebServiceRootResource()
142 request = WSGIExampleWebServiceRequest(environ['wsgi.input'], environ)
143- request.setPublication(WSGIExampleWebServicePublication(service_root))
144+ request.setPublication(SimplePublication(service_root))
145 # Support post-mortem debugging.
146 handle_errors = environ.get('wsgi.handleErrors', True)
147 # The request returned by the publisher may in fact be different than
148
149=== modified file 'src/lazr/restful/publisher.py'
150--- src/lazr/restful/publisher.py 2009-07-08 14:09:00 +0000
151+++ src/lazr/restful/publisher.py 2009-08-04 14:46:24 +0000
152@@ -181,7 +181,7 @@
153 return value
154
155
156-class SimplePublication(object):
157+class SimplePublicationMixin(object):
158 """A very simple implementation of `IPublication`.
159
160 The object passed to the constructor is returned by getApplication().
161@@ -268,6 +268,10 @@
162 endInteraction()
163
164
165+class SimplePublication(WebServicePublicationMixin, SimplePublicationMixin):
166+ pass
167+
168+
169 class TraverseWithGet(object):
170 """An implementation of `IPublishTraverse` that uses the get() method.
171
172
173=== modified file 'src/lazr/restful/testing/webservice.py'
174--- src/lazr/restful/testing/webservice.py 2009-07-07 18:30:11 +0000
175+++ src/lazr/restful/testing/webservice.py 2009-08-04 14:46:24 +0000
176@@ -124,7 +124,7 @@
177 implements(IWebServiceLayer)
178
179
180-class WebServiceTestPublication(WebServicePublicationMixin, SimplePublication):
181+class WebServiceTestPublication(SimplePublication):
182 """Test publication that mixes in the necessary web service stuff."""
183
184 def wrapTraversedObject(self, ob):

Subscribers

People subscribed via source and target branches