[Checkins] SVN: z3c.jsonrpcproxy/trunk/ prepare for release
Roger Ineichen
roger at projekt01.ch
Mon Apr 14 21:43:37 EDT 2008
Log message for revision 85361:
prepare for release
Renamed JS file before release,
sorry about that but it follows now the naming pattern for our JS libs
Changed:
U z3c.jsonrpcproxy/trunk/CHANGES.txt
U z3c.jsonrpcproxy/trunk/buildout.cfg
U z3c.jsonrpcproxy/trunk/setup.py
U z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py
U z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml
D z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js
A z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/z3c.jsonrpcproxy-0.5.0.js
-=-
Modified: z3c.jsonrpcproxy/trunk/CHANGES.txt
===================================================================
--- z3c.jsonrpcproxy/trunk/CHANGES.txt 2008-04-15 01:37:14 UTC (rev 85360)
+++ z3c.jsonrpcproxy/trunk/CHANGES.txt 2008-04-15 01:43:37 UTC (rev 85361)
@@ -2,7 +2,7 @@
CHANGES
=======
-Version 0.5.0 (unreleased)
+Version 0.5.0 (2008-04-15)
-------------------------
- Initial Release
Modified: z3c.jsonrpcproxy/trunk/buildout.cfg
===================================================================
--- z3c.jsonrpcproxy/trunk/buildout.cfg 2008-04-15 01:37:14 UTC (rev 85360)
+++ z3c.jsonrpcproxy/trunk/buildout.cfg 2008-04-15 01:43:37 UTC (rev 85361)
@@ -1,11 +1,3 @@
[buildout]
develop = .
-parts = test coverage
-
-[test]
-recipe = zc.recipe.testrunner
-eggs = z3c.jsonrpcproxy [test]
-
-[coverage]
-recipe = zc.recipe.egg
-eggs = z3c.coverage
+parts =
Modified: z3c.jsonrpcproxy/trunk/setup.py
===================================================================
--- z3c.jsonrpcproxy/trunk/setup.py 2008-04-15 01:37:14 UTC (rev 85360)
+++ z3c.jsonrpcproxy/trunk/setup.py 2008-04-15 01:43:37 UTC (rev 85361)
@@ -48,13 +48,10 @@
include_package_data = True,
package_dir = {'':'src'},
namespace_packages = ['z3c'],
- extras_require = dict(
- test = [
- 'z3c.coverage',
- ],
- ),
install_requires = [
'setuptools',
+ 'zope.viewlet',
+ 'z3c.xmlhttp',
],
zip_safe = False,
)
\ No newline at end of file
Modified: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py 2008-04-15 01:37:14 UTC (rev 85360)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.py 2008-04-15 01:43:37 UTC (rev 85361)
@@ -23,4 +23,4 @@
"""JavaScript viewlet manager."""
-JSONRPCProxyJavaScriptViewlet = JavaScriptViewlet('jsonrpcproxy.js')
+JSONRPCProxyJavaScriptViewlet = JavaScriptViewlet('z3c.jsonrpcproxy.js')
Modified: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml 2008-04-15 01:37:14 UTC (rev 85360)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/browser.zcml 2008-04-15 01:43:37 UTC (rev 85361)
@@ -7,15 +7,15 @@
<!-- javascript resource files for z3c.jsonrpc layer -->
<resource
- name="jsonrpcproxy.js"
- file="js/jsonrpcproxy-0.5.0.js"
+ name="z3c.jsonrpcproxy.js"
+ file="js/z3c.jsonrpcproxy-0.5.0.js"
layer="z3c.jsonrpcproxy.layer.IJSONRPCBrowserLayer"
/>
<!-- javascript viewlets for z3c.jsonrpc layer -->
<viewlet
- name="jsonrpcproxy.js"
+ name="z3c.jsonrpcproxy.js"
for="*"
manager="z3c.jsonrpcproxy.browser.IJavaScript"
class=".browser.JSONRPCProxyJavaScriptViewlet"
Deleted: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js 2008-04-15 01:37:14 UTC (rev 85360)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js 2008-04-15 01:43:37 UTC (rev 85361)
@@ -1,212 +0,0 @@
-//----------------------------------------------------------------------------
-/**
- * @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(", ") + "}";
- }
-}
Copied: z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/z3c.jsonrpcproxy-0.5.0.js (from rev 85359, z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/jsonrpcproxy-0.5.0.js)
===================================================================
--- z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/z3c.jsonrpcproxy-0.5.0.js (rev 0)
+++ z3c.jsonrpcproxy/trunk/src/z3c/jsonrpcproxy/js/z3c.jsonrpcproxy-0.5.0.js 2008-04-15 01:43:37 UTC (rev 85361)
@@ -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(", ") + "}";
+ }
+}
More information about the Checkins
mailing list