•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,600 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,443 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 771 | Replies: 2
![]() |
•
•
Join Date: Aug 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
I cannot figure out the correct way to de-serialize a string passed via xml-rpc. If I print out the string I get
I could split the string, and then drop unwanted characters. But, that seems like the wrong way.
Any help would be appreciated.
{'params': ['123', 3], 'methodName': 'function'}I could split the string, and then drop unwanted characters. But, that seems like the wrong way.
Any help would be appreciated.
•
•
Join Date: Jul 2006
Posts: 562
Reputation:
Rep Power: 4
Solved Threads: 72
I'm mostly ignorant of these matters, but it looks to me like your string is just a dictionary. So:
So now you've deserialized it to a dictionary containing the function call and the parameters. To make the call, you could then do:
So we turn the function call into a string and then evaluate it.
HOWEVER, comma,
I am 99.9% certain that the xmlrpclib already has some function to execute the return string for you, probably with appropriate safety measures to keep malicious remote function calls from occurring. Poke around the xmlrpclib file and see.
Jeff
Python Syntax (Toggle Plain Text)
>>> s = "{'params': ['123', 3], 'methodName': 'function'}" >>> result = eval(s) >>> result {'methodName': 'function', 'params': "('123', 3)"} >>> print result['params'] ['123', 3] >>> print result['methodName'] function
So now you've deserialized it to a dictionary containing the function call and the parameters. To make the call, you could then do:
Python Syntax (Toggle Plain Text)
def function(a,b): print a,b # setup for testing only >>> result["params"] = '(' + str(result["params"])[1:-1] + ')' >>> result["params"] # just to see "('123', 3)" >>> result["methodName"] + result["params"] "function('123', 3)" >>> return_val = eval(result["methodName"]+result["params"]) 123 3
So we turn the function call into a string and then evaluate it.
HOWEVER, comma,
I am 99.9% certain that the xmlrpclib already has some function to execute the return string for you, probably with appropriate safety measures to keep malicious remote function calls from occurring. Poke around the xmlrpclib file and see.
Jeff
•
•
Join Date: Aug 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Thank you for the help. It will come in handy.
I was luckily enough to be the one working on both the xmlrpc call and the parsing. I was able to found a short cut around it though.
I was using c++ and the XmlRpc++ library. I assigned each variable each own parameter ( param1, param2, param3, etc. It ended up sending a string that looked just like a data list type.
I thought was cool, because all I had to do was declare a new data list and call out the variables.
I will have to look into securing the xmlrpc server. I was thinking about using twisted.
I was luckily enough to be the one working on both the xmlrpc call and the parsing. I was able to found a short cut around it though.
I was using c++ and the XmlRpc++ library. I assigned each variable each own parameter ( param1, param2, param3, etc. It ended up sending a string that looked just like a data list type.
{'param1': '123', 'param2': '3' , 'methodName': 'function'}I thought was cool, because all I had to do was declare a new data list and call out the variables.
python Syntax (Toggle Plain Text)
def subtractCredit(self, arg): d2 = arg[0] print "Recieved Arg:", arg[0] print "methodName:", d2['methodName'] print "pin:", d2['param1'] print "amount:", d2['param2']
I will have to look into securing the xmlrpc server. I was thinking about using twisted.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- How to call a PHP function from Javascript and return the results back into Javascrip (PHP)
- learning php (PHP)
- parsing a string (xml) in C (C)
- Parse XML from ASP!!! (ASP)
- DaniWeb Blog and GnomeBlogger (Getting Started and Choosing a Distro)
- Recording time stamp (PHP)
- ASP, Java and XML-RPC (ASP)
- What is Parser? (Java)
Other Threads in the Python Forum
- Previous Thread: How do I declare a class member function in another class?
- Next Thread: any tips on how to get the program to display the first name in the final print strin


Linear Mode