[Checkins] SVN: z3c.jsonrpcproxy/ Move implementation form private repos to svn.zope.org

Roger Ineichen roger at projekt01.ch
Sat Feb 16 11:01:57 EST 2008


Log message for revision 83891:
  Move implementation form private repos to svn.zope.org

Changed:
  A   z3c.jsonrpcproxy/branches/
  A   z3c.jsonrpcproxy/tags/
  A   z3c.jsonrpcproxy/trunk/
  A   z3c.jsonrpcproxy/trunk/CHANGES.txt
  A   z3c.jsonrpcproxy/trunk/README.txt
  A   z3c.jsonrpcproxy/trunk/bootstrap.py
  A   z3c.jsonrpcproxy/trunk/buildout.cfg
  A   z3c.jsonrpcproxy/trunk/setup.py
  A   z3c.jsonrpcproxy/trunk/src/
  A   z3c.jsonrpcproxy/trunk/src/z3c/
  A   z3c.jsonrpcproxy/trunk/src/z3c/__init__.py
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/SETUP.cfg
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/__init__.py
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/configure.zcml
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/layer.py
  A   z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/z3c.jsonrpcproxy-configure.zcml

-=-
Added: z3c.jsonrpcproxy/trunk/CHANGES.txt
===================================================================
--- z3c.jsonrpcproxy/trunk/CHANGES.txt	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/CHANGES.txt	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,8 @@
+=======
+CHANGES
+=======
+
+Version 0.5.0 (unreleased)
+-------------------------
+
+- Initial Release


Property changes on: z3c.jsonrpcproxy/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/README.txt
===================================================================
--- z3c.jsonrpcproxy/trunk/README.txt	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/README.txt	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,4 @@
+This package provides an JSON-RPC (javascript) proxy used for Zope3. But the 
+javascript itself does not depend on any zope library and can be used with any
+other JSON-RPC server. Note the xmlhttp request javascript library form
+z3c.xmlhttp is required for this implementation


Property changes on: z3c.jsonrpcproxy/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/bootstrap.py
===================================================================
--- z3c.jsonrpcproxy/trunk/bootstrap.py	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/bootstrap.py	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 75940 2007-05-24 14:45:00Z srichter $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                     ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+    os.P_WAIT, sys.executable, sys.executable,
+    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+    dict(os.environ,
+         PYTHONPATH=
+         ws.find(pkg_resources.Requirement.parse('setuptools')).location
+         ),
+    ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)


Property changes on: z3c.jsonrpcproxy/trunk/bootstrap.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/buildout.cfg
===================================================================
--- z3c.jsonrpcproxy/trunk/buildout.cfg	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/buildout.cfg	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,11 @@
+[buildout]
+develop = .
+parts = test coverage
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.jsonrpcproxy [test]
+
+[coverage]
+recipe = zc.recipe.egg
+eggs = z3c.coverage

Added: z3c.jsonrpcproxy/trunk/setup.py
===================================================================
--- z3c.jsonrpcproxy/trunk/setup.py	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/setup.py	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup (
+    name='z3c.jsonrpcproxy',
+    version='0.5.0',
+    author = "Roger Ineichen and the Zope Community",
+    author_email = "zope3-dev at zope.org",
+    description = "JSON RPC (javascript) proxy implementation for Zope3",
+    long_description=(
+        read('README.txt')
+        + '\n\n' +
+        read('CHANGES.txt')
+        ),
+    license = "ZPL 2.1",
+    keywords = "zope3 z3c json rpc json-rpc javascript proxy",
+    classifiers = [
+        'Development Status :: 4 - Beta',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Zope Public License',
+        'Programming Language :: Python',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Topic :: Internet :: WWW/HTTP',
+        'Framework :: Zope3'],
+    url = 'http://cheeseshop.python.org/pypi/z3c.jsonrpcproxy',
+    packages = find_packages('src'),
+    include_package_data = True,
+    package_dir = {'':'src'},
+    namespace_packages = ['z3c'],
+    extras_require = dict(
+        test = [
+            'z3c.coverage',
+            ],
+        ),
+    install_requires = [
+        'setuptools',
+        ],
+    zip_safe = False,
+)
\ No newline at end of file


Property changes on: z3c.jsonrpcproxy/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/__init__.py
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/__init__.py	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/__init__.py	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+    import pkg_resources
+    pkg_resources.declare_namespace(__name__)
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/SETUP.cfg
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/SETUP.cfg	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/SETUP.cfg	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,3 @@
+<data-files zopeskel/etc/package-includes>
+  z3c.jsonrpcproxy-*.zcml
+</data-files>

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/__init__.py
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/__init__.py	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/__init__.py	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1 @@
+# Make a package.


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+
+from zope.viewlet.viewlet import JavaScriptViewlet
+from zope.viewlet.interfaces import IViewletManager
+
+
+class IJavaScript(IViewletManager):
+    """JavaScript viewlet manager."""
+
+
+JSONRPCProxyJavaScriptViewlet = JavaScriptViewlet('jsonrpcproxy.js')


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,27 @@
+<configure
+    xmlns:zope="http://namespaces.zope.org/zope"
+    xmlns="http://namespaces.zope.org/browser"
+    xmlns:i18n="http://namespaces.zope.org/i18n"
+    i18n_domain="z3c">
+
+
+  <!-- javascript resource files for z3c.jsonrpc layer -->
+  <resource
+      name="jsonrpcproxy.js"
+      file="js/jsonrpcproxy-0.5.0.js"
+      layer="z3c.jsonrpcproxy.layer.IJSONRPCBrowserLayer"
+      />
+
+
+  <!-- javascript viewlets for z3c.jsonrpc layer -->
+  <viewlet
+      name="jsonrpcproxy.js"
+      for="*"
+      manager="z3c.jsonrpcproxy.browser.IJavaScript"
+      class=".browser.JSONRPCProxyJavaScriptViewlet"
+      permission="zope.Public"
+      layer="z3c.jsonrpcproxy.layer.IJSONRPCBrowserLayer"
+      weight="100"
+      />
+
+</configure>


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/configure.zcml
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/configure.zcml	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/configure.zcml	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,12 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    i18n_domain="z3c">
+
+  <interface
+      interface="z3c.jsonrpcproxy.layer.IJSONRPCBrowserLayer"
+      type="zope.publisher.interfaces.browser.IBrowserSkinType"
+      />
+
+  <include file="browser.zcml" />
+
+</configure>


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,212 @@
+//----------------------------------------------------------------------------
+/** 
+ * @fileoverview JSON-RPC client implementation 
+ * @author Roger Ineichen dev at projekt01 dot ch
+ * @version Initial, not documented 
+ */
+//----------------------------------------------------------------------------
+
+function JSONRPC(url) {
+    this._url = url;
+    this._methods = new Array();
+    this._user = null;
+    this._password = null;
+}
+
+function getJSONRPCProxy(url) {
+    return new JSONRPC(url);
+}
+
+JSONRPC.prototype.addMethod = function(name, callback, requestId) {
+    if (typeof(requestId) == 'undefined') {
+        requestId = "jsonRequest";
+    }
+    var self = this;
+    if(!self[name]){
+        var method = new JSONRPCMethod(this._url, name, callback, requestId, this._user, this._password);
+        self[name] = method;
+        this._methods.push(method);
+    }
+}
+
+JSONRPC.prototype.setAuthentication = function(user, pass) {
+    this._user = user;
+    this._password = pass;
+    for(var i=0;i<this._methods.length;i++){
+        this._methods[i].setAuthentication(user, pass);
+    }
+}
+
+function JSONRPCMethod(url, methodName, callback, requestId, user, pass) {
+    this.methodName = methodName;
+    this.callback = callback;
+    this.requestId = requestId;
+    this.url = url;
+    this.user = user;
+    this.password = pass;
+    var self = this;
+
+    var fn = function(){
+        var args = new Array();
+        for(var i=0;i<arguments.length;i++){
+            args.push(arguments[i]);
+        }
+        if(self.callback) {
+            var data = self.jsonRequest(self.requestId, self.methodName, args);
+            self.postData(self.url, self.user, self.password, data, function(resp){
+                var res = null;
+                var exc =null;
+                try{
+                    res = self.handleResponse(resp);
+                }catch(e){
+                    exc = e;
+                }
+                try{
+                    callback(res, self.requestId, exc);
+                }catch(e){
+                    alert("except callback");
+                }
+                args = null;
+                resp = null;
+            });
+        }
+        else{
+            var data = self.jsonRequest(self.requestId, self.methodName, args);
+            var resp = self.postData(self.url, self.user, self.password, data);
+            return self.handleResponse(resp);
+        }
+    }
+    return fn;
+
+}
+
+JSONRPCMethod.prototype.postData = function(url, user, pass, data, callback) {
+    var xmlhttp = new XMLHttp(url);
+    var header = new Array()
+    header["Content-Type"] = "application/json";
+    xmlhttp.setHeaders(header);
+    xmlhttp.user = user;
+    xmlhttp.password = pass;
+    xmlhttp.argString = data;
+    if(callback == null){
+        return xmlhttp.post();
+    }else{
+        xmlhttp.post(callback);
+    }
+}
+
+JSONRPCMethod.prototype.jsonRequest = function(id, methodName, args){
+    var ji = toJSON(id);
+    var jm = toJSON(methodName);
+    var ja = toJSON(args);
+    return '{"id":' + ji + ', "method":' + jm + ', "params":' + ja + "}";
+}
+
+JSONRPCMethod.prototype.setAuthentication = function(user, pass){
+    this.user = user;
+    this.password = pass;
+}
+
+JSONRPCMethod.prototype.notify = function(){
+    var args=new Array();
+    for(var i=0;i<arguments.length;i++){
+        args.push(arguments[i]);
+    }
+    var data = this.jsonRequest(null, this.methodName, args);
+    this.postData(this.url, this.user, this.password, data, function(resp){});
+}
+
+JSONRPCMethod.prototype.handleResponse = function(resp){
+    var status=null;
+    try{
+        status = resp.status;
+    }catch(e){
+    }
+    if(status == 200){
+        var respTxt = "";
+        try{
+            respTxt=resp.responseText;
+        }catch(e){
+        }
+        if(respTxt == null || respTxt == ""){
+            alert("The server responded with an empty document.");
+        }else{
+            var res = this.unmarshall(respTxt);
+            if(res.error != null){
+                alert("error " + res.error);
+            }
+            else if (res.requestId != self.requestId) {
+                alert("wrong json id returned");
+            }
+            else{
+                return res.result;
+            }
+        }
+    }else{
+        alert("error " + status);
+    }
+}
+
+JSONRPCMethod.prototype.unmarshall = function(source){
+    try {
+        var obj;
+        eval("obj=" + source);
+        return obj;
+    }catch(e){
+        alert("The server's response could not be parsed.");
+    }
+}
+
+function escapeJSONChar(c) {
+    if(c == "\"" || c == "\\") return "\\" + c;
+    else if (c == "\b") return "\\b";
+    else if (c == "\f") return "\\f";
+    else if (c == "\n") return "\\n";
+    else if (c == "\r") return "\\r";
+    else if (c == "\t") return "\\t";
+    var hex = c.charCodeAt(0).toString(16);
+    if(hex.length == 1) return "\\u000" + hex;
+    else if(hex.length == 2) return "\\u00" + hex;
+    else if(hex.length == 3) return "\\u0" + hex;
+    else return "\\u" + hex;
+}
+
+function escapeJSONString(s) {
+    var parts = s.split("");
+    for(var i=0; i < parts.length; i++) {
+	var c =parts[i];
+	if(c == '"' ||
+	   c == '\\' ||
+	   c.charCodeAt(0) < 32 ||
+	   c.charCodeAt(0) >= 128)
+	    parts[i] = escapeJSONChar(parts[i]);
+    }
+    return "\"" + parts.join("") + "\"";
+}
+
+function toJSON(o) {
+    if(o == null) {
+    	return "null";
+    } else if(o.constructor == String) {
+	    return escapeJSONString(o);
+    } else if(o.constructor == Number) {
+	    return o.toString();
+    } else if(o.constructor == Boolean) {
+	    return o.toString();
+    } else if(o.constructor == Date) {
+	    return o.valueOf().toString();
+    } else if(o.constructor == Array) {
+    	var v = [];
+    	for(var i = 0; i < o.length; i++) v.push(toJSON(o[i]));
+    	return "[" + v.join(", ") + "]";
+    }
+    else {
+    	var v = [];
+    	for(attr in o) {
+    	    if(o[attr] == null) v.push("\"" + attr + "\": null");
+    	    else if(typeof o[attr] == "function"); // skip
+    	    else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr]));
+    	}
+    	return "{" + v.join(", ") + "}";
+    }
+}

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/layer.py
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/layer.py	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/layer.py	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+
+from zope.publisher.interfaces import browser
+
+
+class IJSONRPCBrowserLayer(browser.IBrowserRequest):
+    """Layer for JSONRPC javascript."""


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/layer.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/z3c.jsonrpcproxy-configure.zcml
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/z3c.jsonrpcproxy-configure.zcml	                        (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/z3c.jsonrpcproxy-configure.zcml	2008-02-16 16:01:57 UTC (rev 83891)
@@ -0,0 +1 @@
+<include package="z3c.jsonrpcproxy" />


Property changes on: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/z3c.jsonrpcproxy-configure.zcml
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list