[z3-checkins] r29661 - in z3/jsonserver/trunk: . jsolait tests
jwashin at codespeak.net
jwashin at codespeak.net
Thu Jul 6 04:26:56 CEST 2006
Author: jwashin
Date: Thu Jul 6 04:26:50 2006
New Revision: 29661
Modified:
z3/jsonserver/trunk/CHANGES.txt
z3/jsonserver/trunk/README.txt
z3/jsonserver/trunk/configure.zcml
z3/jsonserver/trunk/interfaces.py
z3/jsonserver/trunk/jsolait/install_jsolait.py
z3/jsonserver/trunk/jsoncomponent.py
z3/jsonserver/trunk/jsonrpc.py
z3/jsonserver/trunk/minjson.py
z3/jsonserver/trunk/tests/test_json.py
z3/jsonserver/trunk/tests/test_jsonrpcpublication.py
Log:
updates for 3.3
Modified: z3/jsonserver/trunk/CHANGES.txt
==============================================================================
--- z3/jsonserver/trunk/CHANGES.txt (original)
+++ z3/jsonserver/trunk/CHANGES.txt Thu Jul 6 04:26:50 2006
@@ -17,4 +17,8 @@
Upgrade to this version of jsolait using the installer is optional.
20060511 Removed gzip support, since that can be done more elegantly by other
- means. Preliminary support for json-rpc 1.1.
\ No newline at end of file
+ means. Preliminary support for json-rpc 1.1.
+
+20060619 Fixed a few license headers. Everything is pure ZPL now. Updated
+ to match trunk, particularly ctheune's method from xmlrpc for removing proxies.
+
\ No newline at end of file
Modified: z3/jsonserver/trunk/README.txt
==============================================================================
--- z3/jsonserver/trunk/README.txt (original)
+++ z3/jsonserver/trunk/README.txt Thu Jul 6 04:26:50 2006
@@ -18,8 +18,9 @@
Dependencies:
-------------
-This package will work with (unreleased) zope3 version 3.2 or greater, currently
-the development version available at svn://svn.zope.org/repos/main/Zope3/trunk
+This package will work with Zope 3 version 3.3 or greater. The svn version of
+jsonserver tries hard to keep up with Zope 3's development version available at
+svn://svn.zope.org/repos/main/Zope3/trunk.
jsolait from http://jsolait.net is the recommended client-side javascript
library. Installation of jsolait is covered in the README.txt file in this
@@ -136,7 +137,7 @@
or other json implementations have functions for reading and writing
JSON objects.
-The text of a JSON-RPC request looks like:
+The text of a JSON-RPC request (v1.0) looks like:
::
@@ -166,6 +167,17 @@
reader. Hint: Use the minjson.write(object) and minjson.read(string)
methods for conversion before and after transport.
+Dojo
+----
+
+JSON-RPC in Dojo should work out-of-the-box with jsonserver, since it provides the
+proper content-type, application/jsonrpc. A preliminary package that serves a
+per-object ".smd" file is available at dojosupport.
+
+Dojo is available at http://dojotoolkit.org.
+
+dojosupport is available at http://zif.hill-street.net/dojosupport
+
Page Templates, Form Variables, and Named Parameters:
_______________________________________________________
Modified: z3/jsonserver/trunk/configure.zcml
==============================================================================
--- z3/jsonserver/trunk/configure.zcml (original)
+++ z3/jsonserver/trunk/configure.zcml Thu Jul 6 04:26:50 2006
@@ -55,6 +55,21 @@
permission="zope.Public"
/>
+ <adapter
+ for="list"
+ factory=".jsonrpc.ListPreMarshaller"
+ />
+
+ <adapter
+ for="tuple"
+ factory=".jsonrpc.ListPreMarshaller"
+ />
+
+ <adapter
+ factory=".jsonrpc.DictPreMarshaller"
+ for="dict"
+ />
+
<!--register a default view for errors, but we do not create the named
view, so errors from IException are handled by the publisher.-->
<defaultView
@@ -75,12 +90,15 @@
name="jsolaitlibws"
directory="./jsolait/libws"
/>
-
- <help:register
+
+ <!-- Register with API DOC -->
+ <configure xmlns:apidoc="http://namespaces.zope.org/apidoc"
+ xmlns:zcml="http://namespaces.zope.org/zcml"
+ zcml:condition="have apidoc">
+ <apidoc:bookchapter
id="json_rpc"
- title="JSON RPC"
+ title="jsonserver (JSON-RPC)"
doc_path="README.txt"
- class="zope.app.onlinehelp.onlinehelptopic.RESTOnlineHelpTopic"
/>
-
+ </configure>
</configure>
Modified: z3/jsonserver/trunk/interfaces.py
==============================================================================
--- z3/jsonserver/trunk/interfaces.py (original)
+++ z3/jsonserver/trunk/interfaces.py Thu Jul 6 04:26:50 2006
@@ -16,6 +16,8 @@
#2005-08-16 A few changes needed after a zope3 trunk change
#2005-11-07 Allowed IDefaultBrowserLayer in JSONRPCRequest. This permits skin
# lookups
+#2006-06-19 Removed reference to IPresentation and added interface for
+# Premarshaller jmw
from zope.publisher.interfaces import IPublishTraverse
from zope.publisher.interfaces.http import IHTTPApplicationRequest,\
@@ -67,12 +69,12 @@
# the one in zope.app.publisher.xmlrpc
# """
-class IJSONRPCPresentation(IPresentation):
- """JSONRPC Presentation
- like zope.app.publisher.interfaces.xmlrpc.IXMLRPCPresentation
- """
-
-class IJSONRPCView(IJSONRPCPresentation,IView):
+class IJSONRPCView(IView):
"""JSONRPC View
like zope.app.publisher.interfaces.xmlrpc.IXMLRPCView
"""
+
+class IJSONRPCPremarshaller(Interface):
+ """Premarshaller to remove security proxies"""
+ def __call__():
+ """return the object without proxies"""
Modified: z3/jsonserver/trunk/jsolait/install_jsolait.py
==============================================================================
--- z3/jsonserver/trunk/jsolait/install_jsolait.py (original)
+++ z3/jsonserver/trunk/jsolait/install_jsolait.py Thu Jul 6 04:26:50 2006
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2005 Jim Washington and Contributors.
+# Copyright (c) 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
Modified: z3/jsonserver/trunk/jsoncomponent.py
==============================================================================
--- z3/jsonserver/trunk/jsoncomponent.py (original)
+++ z3/jsonserver/trunk/jsoncomponent.py Thu Jul 6 04:26:50 2006
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2005 Jim Washington and Contributors.
+# Copyright (c) 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
Modified: z3/jsonserver/trunk/jsonrpc.py
==============================================================================
--- z3/jsonserver/trunk/jsonrpc.py (original)
+++ z3/jsonserver/trunk/jsonrpc.py Thu Jul 6 04:26:50 2006
@@ -21,12 +21,13 @@
#2005-10-09 unicode handling update
#2006-03-09 enabled gzip compression for large responses
#2006-05-10 removed gzip compression and (prematurely) enabled json-rpc 1.1 jmw
+#2006-06-19 updated with ctheune's xmlrpc solution for removing proxies jmw
__docformat__ = 'restructuredtext'
from zope.app.publication.http import BaseHTTPPublication
from interfaces import IMethodPublisher, IJSONRPCView, IJSONRPCPublisher,\
- IJSONRPCRequest, IJSONReader, IJSONWriter
+ IJSONRPCRequest, IJSONReader, IJSONWriter, IJSONRPCPremarshaller
from zope.interface import implements
#from zope.publisher.http import IResult
from zope.location.location import Location
@@ -239,30 +240,69 @@
logger.log(DEBUG,"Exception: %s" % result)
self.setStatus(200)
-def premarshal_dict(data):
- """return a non-proxied dict"""
- return dict([(premarshal(k), premarshal(v))
- for (k, v) in data.items()])
-
-def premarshal_list(data):
- """return a non-proxied list"""
- return map(premarshal, data)
-
-#note: no dates or datetimes in json, though supported by xmlrpc
-premarshal_dispatch_table = {
- dict: premarshal_dict,
- list: premarshal_list,
- tuple: premarshal_list,
- }
+# premarshal code adapted from zope.publisher.xmlrpc.py 20060619
+# should just use XMLRPC premarshaling after we do not have to worry about
+# code not being in the standard library. This probably will originate in 3.3.
+
+class PreMarshallerBase(object):
+ """Abstract base class for pre-marshallers."""
+ implements(IJSONRPCPremarshaller)
-premarshal_dispatch = premarshal_dispatch_table.get
+ def __init__(self, data):
+ self.data = data
+
+ def __call__(self):
+ raise Exception, "Not implemented"
+
+class DictPreMarshaller(PreMarshallerBase):
+ """Pre-marshaller for dicts"""
+
+ def __call__(self):
+ return dict([(premarshal(k), premarshal(v))
+ for (k, v) in self.data.items()])
+
+class ListPreMarshaller(PreMarshallerBase):
+ """Pre-marshaller for list"""
+
+ def __call__(self):
+ return map(premarshal, self.data)
def premarshal(data):
- premarshaller = premarshal_dispatch(data.__class__)
+ """Premarshal data before handing it to xmlrpclib for marhalling
+
+ The initial purpose of this function is to remove security proxies
+ without resorting to removeSecurityProxy. This way, we can avoid
+ inadvertently providing access to data that should be protected.
+ """
+ premarshaller = IJSONRPCPremarshaller(data, alternate=None)
if premarshaller is not None:
- return premarshaller(data)
+ return premarshaller()
return data
+#def premarshal_dict(data):
+ #"""return a non-proxied dict"""
+ #return dict([(premarshal(k), premarshal(v))
+ #for (k, v) in data.items()])
+
+#def premarshal_list(data):
+ #"""return a non-proxied list"""
+ #return map(premarshal, data)
+
+##note: no dates or datetimes in json, though supported by xmlrpc
+#premarshal_dispatch_table = {
+ #dict: premarshal_dict,
+ #list: premarshal_list,
+ #tuple: premarshal_list,
+ #}
+
+#premarshal_dispatch = premarshal_dispatch_table.get
+
+#def premarshal(data):
+ #premarshaller = premarshal_dispatch(data.__class__)
+ #if premarshaller is not None:
+ #return premarshaller(data)
+ #return data
+
class JSONRPCView(object):
"""A base JSON-RPC view that can be used as mix-in for JSON-RPC views.
Modified: z3/jsonserver/trunk/minjson.py
==============================================================================
--- z3/jsonserver/trunk/minjson.py (original)
+++ z3/jsonserver/trunk/minjson.py Thu Jul 6 04:26:50 2006
@@ -1,6 +1,6 @@
##############################################################################
#
-# Copyright (c) 2005 Jim Washington and Contributors.
+# Copyright (c) 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
Modified: z3/jsonserver/trunk/tests/test_json.py
==============================================================================
--- z3/jsonserver/trunk/tests/test_json.py (original)
+++ z3/jsonserver/trunk/tests/test_json.py Thu Jul 6 04:26:50 2006
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
-# Copyright (c) 2005 Jim Washington and Contributors.
+# Copyright (c) 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
Modified: z3/jsonserver/trunk/tests/test_jsonrpcpublication.py
==============================================================================
--- z3/jsonserver/trunk/tests/test_jsonrpcpublication.py (original)
+++ z3/jsonserver/trunk/tests/test_jsonrpcpublication.py Thu Jul 6 04:26:50 2006
@@ -15,6 +15,8 @@
modified from zope.app.publication.tests.test_xmlrpcpublication.py jwashin 2005-06-06
+removed references to JSONRPCPresentation 20060619 jmw
+
"""
import unittest
@@ -25,7 +27,6 @@
from zope.interface import Interface, implements
from zope.proxy import removeAllProxies
from zope.publisher.interfaces import NotFound
-from jsonserver.interfaces import IJSONRPCPresentation
from jsonserver.interfaces import IJSONRPCRequest
from jsonserver.interfaces import IJSONRPCPublisher
from jsonserver.jsonrpc import TestRequest
@@ -71,19 +72,19 @@
class V(object):
def __init__(self, context, request):
pass
- implements(IJSONRPCPresentation)
+ implements(IJSONRPCPublisher)
ob = C()
r = self._createRequest('/foo', pub)
- ztapi.provideView(I, IJSONRPCPresentation, Interface, 'view', V)
- ztapi.setDefaultViewName(I, 'view', type=IJSONRPCPresentation)
+ ztapi.provideView(I, IJSONRPCPublisher, Interface, 'view', V)
+ ztapi.setDefaultViewName(I, 'view', type=IJSONRPCPublisher)
self.assertRaises(NotFound, pub.traverseName, r, ob, 'foo')
def testTraverseNameView(self):
pub = self.klass(self.db)
-
+ from jsonserver.jsonrpc import IJSONRPCPublisher
class I(Interface):
pass
@@ -95,7 +96,7 @@
class V(object):
def __init__(self, context, request):
pass
- implements(IJSONRPCPresentation)
+ implements(IJSONRPCPublisher)
# Register the simple traverser so we can traverse without @@
More information about the z3-checkins
mailing list