Merge lp:~leonardr/lazr.restful/service-request-to-web-request into lp:lazr.restful

Proposed by Leonard Richardson
Status: Rejected
Rejected by: Leonard Richardson
Proposed branch: lp:~leonardr/lazr.restful/service-request-to-web-request
Merge into: lp:lazr.restful
Diff against target: None lines
To merge this branch: bzr merge lp:~leonardr/lazr.restful/service-request-to-web-request
Reviewer Review Type Date Requested Status
Gavin Panella Needs Information
Review via email: mp+7027@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

This branch adds the framework necessary for converting a web service request into a website request. I don't want to land it until I know this is what I need for Launchpad.

Revision history for this message
Gavin Panella (allenap) wrote :

Leonard, is this proposal still active? The branch looks to not have been touched since 3rd June.

review: Needs Information

Unmerged revisions

49. By Leonard Richardson

Merge from trunk.

48. By Leonard Richardson

Removed adapter registration for function that's no longer an adapter.

47. By Leonard Richardson

Cleanup and removed the registration for web_service_request_to_browser_request, which will never be used because it goes from the specific to the general.

46. By Leonard Richardson

Added createWebsiteRequest to IWebServiceConfiguration.

45. By Leonard Richardson

Okay, it appears to work, at any rate.

44. By Leonard Richardson

First stab at implementation.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restful/docs/webservice-request.txt'
--- src/lazr/restful/docs/webservice-request.txt 2009-03-28 14:35:27 +0000
+++ src/lazr/restful/docs/webservice-request.txt 2009-06-01 18:45:20 +0000
@@ -6,15 +6,15 @@
6website neeeds to be treated as a web service request. It's easy to6website neeeds to be treated as a web service request. It's easy to
7adapt an IBrowserRequest into an IIWebServiceClientRequest request.7adapt an IBrowserRequest into an IIWebServiceClientRequest request.
88
9This adapters uses the request factory from the IWebServiceConfiguration9This adapter uses a factory for web service requests defined in
10utility.10IWebServiceConfiguration.createRequest.
1111
12 >>> from lazr.restful.interfaces import (12 >>> from lazr.restful.interfaces import (
13 ... IWebServiceConfiguration, IWebServiceClientRequest)13 ... IWebServiceConfiguration, IWebServiceClientRequest)
14 >>> from lazr.restful.publisher import (14 >>> from lazr.restful.publisher import (
15 ... browser_request_to_web_service_request)15 ... browser_request_to_web_service_request)
16 >>> from lazr.restful.testing.webservice import (16 >>> from lazr.restful.testing.webservice import (
17 ... WebServiceTestPublication, WebServiceTestRequest)17 ... TestPublication, WebServiceTestPublication, WebServiceTestRequest)
18 >>> from zope.interface import implements18 >>> from zope.interface import implements
19 >>> from zope.component import getSiteManager19 >>> from zope.component import getSiteManager
20 >>> from zope.publisher.browser import TestRequest20 >>> from zope.publisher.browser import TestRequest
@@ -28,6 +28,12 @@
28 ... request = WebServiceTestRequest(body_stream, environ)28 ... request = WebServiceTestRequest(body_stream, environ)
29 ... request.setPublication(WebServiceTestPublication(None))29 ... request.setPublication(WebServiceTestPublication(None))
30 ... return request30 ... return request
31 ...
32 ... def createWebsiteRequest(self, body_stream, environ):
33 ... request = TestRequest(body_stream, environ)
34 ... request.setPublication(TestPublication(None))
35 ... return request
36
3137
32 >>> sm = getSiteManager()38 >>> sm = getSiteManager()
33 >>> sm.registerUtility(SimpleWebServiceConfiguration())39 >>> sm.registerUtility(SimpleWebServiceConfiguration())
@@ -40,6 +46,29 @@
40 >>> request.getApplicationURL()46 >>> request.getApplicationURL()
41 'http://cookbooks.dev/api/beta'47 'http://cookbooks.dev/api/beta'
4248
49Adapting a web service request into a browser request
50*****************************************************
51
52Sometimes it goes the other way: a web service request needs to be
53treated as a browser request. The reverse transformation is also easy.
54
55This adapter uses a factory for website requests defined in
56IWebServiceConfiguration.createWebsiteRequest.
57
58 >>> from lazr.restful.publisher import (
59 ... web_service_request_to_browser_request)
60 >>> from cStringIO import StringIO
61
62 >>> service_request = WebServiceTestRequest(
63 ... StringIO(""), {'SERVER_URL': "http://cookbooks.dev/"})
64
65 >>> website_request = web_service_request_to_browser_request(
66 ... service_request)
67 >>> website_request
68 <zope.publisher.browser.TestRequest...>
69 >>> website_request.getApplicationURL()
70 'http://cookbooks.dev'
71
43==============72==============
44The JSON Cache73The JSON Cache
45==============74==============
4675
=== modified file 'src/lazr/restful/interfaces/_rest.py'
--- src/lazr/restful/interfaces/_rest.py 2009-04-15 19:05:23 +0000
+++ src/lazr/restful/interfaces/_rest.py 2009-06-01 18:07:47 +0000
@@ -435,6 +435,19 @@
435 :param environ: A dict containing the request environment.435 :param environ: A dict containing the request environment.
436 """436 """
437437
438 def createWebsiteRequest(body_instream, environ):
439 """A factory method that creates a request for the website.
440
441 This is necessary when converting web service requests into
442 website requests.
443
444 It should have the correct publication set for the application.
445
446 :param body_instream: A file-like object containing the request
447 input stream.
448 :param environ: A dict containing the request environment.
449 """
450
438 def get_request_user():451 def get_request_user():
439 """The user who made the current web service request.452 """The user who made the current web service request.
440453
441454
=== modified file 'src/lazr/restful/publisher.py'
--- src/lazr/restful/publisher.py 2009-03-27 04:25:34 +0000
+++ src/lazr/restful/publisher.py 2009-06-01 18:43:23 +0000
@@ -11,6 +11,7 @@
11 'browser_request_to_web_service_request',11 'browser_request_to_web_service_request',
12 'WebServicePublicationMixin',12 'WebServicePublicationMixin',
13 'WebServiceRequestTraversal',13 'WebServiceRequestTraversal',
14 'web_service_request_to_browser_request',
14 ]15 ]
1516
16import urllib17import urllib
@@ -250,3 +251,19 @@
250 names=[config.path_override, config.service_version_uri_prefix])251 names=[config.path_override, config.service_version_uri_prefix])
251 web_service_request._vh_root = website_request.getVirtualHostRoot()252 web_service_request._vh_root = website_request.getVirtualHostRoot()
252 return web_service_request253 return web_service_request
254
255
256def web_service_request_to_browser_request(web_service_request):
257 """An adapter from a web service request to a browser request.
258
259 Used when generating XHTML representations (and, in the future,
260 the web_link for JSON representations).
261 """
262 config = getUtility(IWebServiceConfiguration)
263 body = web_service_request.bodyStream.getCacheStream().read()
264 environ = dict(web_service_request.environment)
265 # Zope picks up on SERVER_URL when setting the _app_server attribute
266 # of the new request.
267 environ['SERVER_URL'] = web_service_request.getApplicationURL()
268 website_request = config.createWebsiteRequest(body, environ)
269 return website_request

Subscribers

People subscribed via source and target branches