[z3-checkins] r26026 - z3/jsonserver/branch/zope2_test
reebalazs at codespeak.net
reebalazs at codespeak.net
Thu Apr 20 12:08:26 CEST 2006
Author: reebalazs
Date: Thu Apr 20 12:08:25 2006
New Revision: 26026
Modified:
z3/jsonserver/branch/zope2_test/jsonrpc.py
Log:
Make the IJsonRequest interface bound in Zope 2.9
In 2.9 I realized that the interface binding does not work
somehow directlyProvides attaches the interfact but it disappears
later where I want to use it for an adapter lookup.
Now we provide the interface in the class level and
override __class__ of the request object on the run.
Modified: z3/jsonserver/branch/zope2_test/jsonrpc.py
==============================================================================
--- z3/jsonserver/branch/zope2_test/jsonrpc.py (original)
+++ z3/jsonserver/branch/zope2_test/jsonrpc.py Thu Apr 20 12:08:25 2006
@@ -21,8 +21,10 @@
from zLOG import LOG, INFO, DEBUG, WARNING, ERROR
from cgi import FieldStorage
import ZPublisher.HTTPResponse
-from zope.interface import directlyProvides, directlyProvidedBy
+##from zope.interface import directlyProvides, directlyProvidedBy
+from zope.interface import implements
from interfaces import IJsonRequest
+from ZPublisher.HTTPRequest import HTTPRequest
# this is used to identify incoming requests
request_content_type = 'application/json-rpc'
@@ -198,6 +200,11 @@
# Patching processInputs of ZPublisher.HTTPRequest
# --
+class JsonRpcRequest(HTTPRequest):
+ 'JSON-RPC HTTP request'
+ # this is just used to force the interface on the object
+ implements(IJsonRequest)
+
re_content_type= re.compile(r'charset\s*=\s*([^;]+)')
def processInputs(self, **kw):
@@ -245,9 +252,13 @@
# set the marker that can be used to check if we are in json mode
other['JSON_MODE'] = self.json_mode = True
# also set the request interface
- interfaces = directlyProvidedBy(self)
- interfaces += IJsonRequest
- directlyProvides(self, interfaces)
+ # XXX this would be good but for some reason gets "swallowed"
+ # by the time we get there, so we override the class instead.
+ # This error first manifested in Zope2.9, it was ok. till 2.8.
+ ##interfaces = directlyProvidedBy(self)
+ ##interfaces += IJsonRequest
+ ##directlyProvides(self, interfaces)
+ self.__class__ = JsonRpcRequest
#
response = Response(response, jsonID)
other['RESPONSE'] = self.response = response
@@ -264,7 +275,6 @@
self.stdin.seek(0)
return self._processInputs_jsonrc_patched(**kw)
-from ZPublisher.HTTPRequest import HTTPRequest
def patch_HTTPRequest():
'This will patch HTTPRequest to enable json-rpc handling'
HTTPRequest._processInputs_jsonrc_patched, HTTPRequest.processInputs = \
More information about the z3-checkins
mailing list