/* Modification information for LGPL compliance r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm r4085 - 2005-04-13 17:30:42 -0700 (Wed, 13 Apr 2005) - robert - adding meeting scheduler and accept/decline */ Module("xmlrpc","1.3.3",function(mod){var xmlext=importModule("xml");var urllib=importModule("urllib");mod.InvalidServerResponse=Class("InvalidServerResponse",mod.Exception,function(publ,supr){publ.init=function(status){supr(this).init("The server did not respond with a status 200 (OK) but with: "+status);this.status=status;} publ.status;}) mod.MalformedXmlRpc=Class("MalformedXmlRpc",mod.Exception,function(publ,supr){publ.init=function(msg,xml,trace){supr(this).init(msg,trace);this.xml=xml;} publ.xml;}) mod.Fault=Class("Fault",mod.Exception,function(publ,supr){publ.init=function(faultCode,faultString){supr(this).init("XML-RPC Fault: "+faultCode+"\n\n"+faultString);this.faultCode=faultCode;this.faultString=faultString;} publ.faultCode;publ.faultString;}) mod.marshall=function(obj){if(obj.toXmlRpc){return obj.toXmlRpc();}else{var s="";for(var attr in obj){if(typeof obj[attr]!="function"){s+=""+attr+""+mod.marshall(obj[attr])+"";}} s+="";return s;}} mod.unmarshall=function(xml){try{var doc=xmlext.parseXML(xml);}catch(e){throw new mod.MalformedXmlRpc("The server's response could not be parsed.",xml,e);} var rslt=mod.unmarshallDoc(doc,xml);doc=null;return rslt;} mod.unmarshallDoc=function(doc,xml){try{var node=doc.documentElement;if(node==null){throw new mod.MalformedXmlRpc("No documentElement found.",xml);} switch(node.tagName){case"methodResponse":return parseMethodResponse(node);case"methodCall":return parseMethodCall(node);default:throw new mod.MalformedXmlRpc("'methodCall' or 'methodResponse' element expected.\nFound: '"+node.tagName+"'",xml);}}catch(e){if(e instanceof mod.Fault){throw e;}else{throw new mod.MalformedXmlRpc("Unmarshalling of XML failed.",xml,e);}}} var parseMethodResponse=function(node){try{for(var i=0;i';if(args.length>0){data+="";for(var i=0;i'+mod.marshall(args[i])+'';} data+='';} data+='';return data;} publ.init=function(url,methodName,user,pass){var fn=function(){if(typeof arguments[arguments.length-1]!="function"){var data=getXML(fn.methodName,arguments);var resp=postData(fn.url,fn.user,fn.password,data);return handleResponse(resp);}else{var args=new Array();for(var i=0;i0){var tryIntrospection=false;}else{var tryIntrospection=true;}}else{pass=user;user=methodNames;methodNames=[];var tryIntrospection=true;} this._url=url;this._user=user;this._password=pass;this._addMethodNames(methodNames);if(tryIntrospection){try{this._introspect();}catch(e){}}} publ._addMethodNames=function(methodNames){for(var i=0;i"+this.replace(/&/g,"&").replace(/";} Number.prototype.toXmlRpc=function(){if(this==parseInt(this)){return""+this+"";}else if(this==parseFloat(this)){return""+this+"";}else{return false.toXmlRpc();}} Boolean.prototype.toXmlRpc=function(){if(this==true){return"1";}else{return"0";}} Date.prototype.toXmlRpc=function(){var padd=function(s,p){s=p+s return s.substring(s.length-p.length)} var y=padd(this.getUTCFullYear(),"0000");var m=padd(this.getUTCMonth()+1,"00");var d=padd(this.getUTCDate(),"00");var h=padd(this.getUTCHours(),"00");var min=padd(this.getUTCMinutes(),"00");var s=padd(this.getUTCSeconds(),"00");var isodate=y+m+d+"T"+h+":"+min+":"+s return""+isodate+"";} Array.prototype.toXmlRpc=function(){var retstr="";for(var i=0;i"+mod.marshall(this[i])+"";} return retstr+"";} mod.test=function(){print("creating ServiceProxy object using introspection for method construction...\n");var s=new mod.ServiceProxy("http://localhost/testx.py");print("%s created\n".format(s));print("creating and marshalling test data:\n");var o=[1.234,5,{a:"Hello & < ",b:new Date()}];print(mod.marshall(o));print("\ncalling echo() on remote service...\n");var r=s.echo(o);print("service returned data(marshalled again):\n") print(mod.marshall(r));}})