Home
Home Page
And again about functional programming on Python
Where the Python has come crawling?
Practical application OOP in PHP5
Functional programming in language Python
Approaches of language Python - an amusing example of optimization
Use ext/mysqli: Part I - the Review and the prepared expressions
How to receive the maximal result from registration in catalogues
XML-RPC In language Python
The API-specification of databases of language Python, version 2.0
Programming of the Web-client in language Python
Useful advice for job with XML
Future Web - behind semantics
Whether it is necessary to cancel spaces of names XML?
Use AJAX in ASP.NET
ASP .NET 2.0: Reference pages
Patterns of registration
What is ASP.NET. Installation and the test project.
Anatomy ASP.NET. ASP.NET in operation.
Server elements of management Continuation.
Links
 
topic


XML-RPC In language Python

In recent times problems{tasks} of interaction of systems of automation resulted experts in despondency the complexity. Universal availability of the Internet and simplicity of reports have opened new prospect in this question, and now you need to think not of complexity of a problem{task}, and about that what tool for this purpose to choose.


Two most popular environments, Enterprise JavaBeans and Microsoft COM, are very expressive and reliable, but simultaneously and complex{difficult} enough. They introduce in process a lot of additional job. Other characteristics, for example, ability to work on different platforms and with various languages, only complicate a problem of a choice between them. Not so long ago report SOAP has been submitted to our attention (Simple Object Access Protocol), called to solve many of these problems. Report SOAP already has some incomplete realizations and is already used, however he still is at a stage of changes. Some realizations cannot cooperate with each other yet.



So to do{make} to the developer?


Till this moment developers simply used that today is present near at hand and is capable to work. And worked just XML-RPC. He is simple, effective and consecutive. XML-RPC can quite carry out a role of "glue" to what " the senior brother " - SOAP is unable it{him}. If you search for the large-scale environment for interrelation of diverse servers and the functionality similar to automatic search of services XML-RPC to you will not approach. XML-RPC is fast, idle time in use and reliable means of interaction of the distributed{allocated} systems, not dependent on the languages used by the parties{sides}. XML-RPC represents the hybrid decision. He is not object-oriented in strict sense of this word. " RPC " in an abbreviation means " Remote Procedure Call " (the removed call of procedures). RPC it is very simple - the user sends search on a network and receives the response. If it sounds suspiciously familiarly - so it and is, in fact habitual to us the Internet works under such circuit. On RPC the bell has rung out in even 90kh years. His{its} developers appeared are not capable to standardize structure of the data. Company Sun has really tried to realize the standard in XDR. But he so never completely also has not come in use. With development of object-oriented programming, RPC has fallen into disgrace. With addition RPC with language XML, process has received popular standard structure of data presentation that has inhaled a new life in RPC. But all the same - what for it{him} to use?


The basic and indisputable reason for use XML-RPC will be, that he works, and works well enough. The developer spends a minimum of efforts to installation and use of library xmlrpclib language Python, cooperating with the servers constructed on basis Python, PHP, Java, Perl, C ++ and even COM. The whole chapter{head} devoted XML-RPC in the best seller " Java and XML ", pays big attention XML-RPC. In the world of language Python it is the widest XML-RPC it is used in Zope. Zope could address and respond on XML-RPC from the middle of 1999.

Library xmlrpclib companies PythonWare


As against other languages of his{its} generation, Python always had opportunities for creation of constant objects. The spectrum of these opportunities constantly extends, from standard library packages ("marshall"), preobrazujuhhikh simple objects for storage in flat files, up to a database " Zope Object Database, " which by the opportunities competes to commercial object-oriented databases (OODB). Marshaling represents translation of object from internal performance of one program in a certain independent format. In a context of library xmlrpclib, marshalling object of language Python means his{its} converting in call XML-RPC. Return marshalling (unmarshalling) represents return process.


Written Frederikom Landom from PythonWare, the library xmlrpclib hides all complexity in objects direct and return marshallinga. Details of connection with the server, transfers of search and reception of the answer in the same way disappear.


You can load last version xmlrpclib.py (and to receive the additional information on this library) on page XML-RPC for language Python.

XML-RPC And Meerkat


Rehjl Dornfest, being the basic driving force in promotion XML in PHP environment, has created natural enough interface XML-RPC to Meerkat, the service of open access uniting the news information from set of sources with help RSS. Let's use this available server for our examples. First of all we import the module of a "beautiful" seal (pprint) from Python Standard Library. Some from target data Meerkat are long enough.



>>> from pprint import pprint


After import xmlrpclib, we are connected to the server with the help xmlrpclib, consisting of one line:



>>> meerkatsvr = xmlrpclib.server (" http: // www.oreillynet.com/meerkat/xml-rpc/server.php ")


Here we create an example of XML-RPC server, capable to incorporate, send and receive XML-RPC. With the help rekursii this server can even understand enclosed searches XML-RPC.


Now let's request the list of the methods available on the server:



>>> pprint (meerkatsvr.system.listMethods ())

['meerkat.getChannels',

'meerkat.getCategories',

'meerkat.getChannelsByCategory',

'meerkat.getItems',

'system.listMethods',

'system.methodHelp',

'system.methodSignature']


You just used XML-RPC for connection with the server through the Internet and have received the response. Besides simplicity of such approach, note, that the form of the result returned xmlrpclib, represents the "native" list of language Python.

Reception of the list of channels from Meerkat


Meerkat groups channels in the subjects named categories. For example, the channels concerning to XML, are in a category 23. If you want to receive the list of channels for a specific subject, you can send Meerkat the following search:



>>> pprint (meerkatsvr.meerkat.getChannelsByCategory (23))

[{'title': ' <XML> fr ', 'id': 2991},

{'title': '4xt', 'id': 2559},

{'title': 'Eclectic', 'id': 555},

{'title': 'eXploringXML', 'id': 4471},

{'title': ' eXploringXML Channel ', 'id': 1105},

{'title': ' finetuning com ', 'id': 107},

{'title': 'finetuning.com', 'id': 4628},

{'title': ' Free XML tools', 'id': 906},

{'title': ' JabberCentral Recent Jabber News', 'id': 4655},

{'title': ' Moreover XML and metadata news', 'id': 2243},

{'title': ' moreover... XML and metadata news', 'id': 683},

{'title': ' My Userland ', 'id': 1945},

{'title': " O'Reilly Network XML FAQs ", 'id': 2365},

{'title': 'oreillynet.xml', 'id': 989},

{'title': 'oreillynet.xmldev', 'id': 990},

{'title': ' SOAP Webservices Resource Center ', 'id': 2022},

{'title': ' XML About com ', 'id': 2435},

{'title': ' XML News from PerlXML.com ', 'id': 718},

{'title': ' XML XSL Portal ', 'id': 4460},

{'title': 'XML.com', 'id': 47},

{'title': ' XML.com Resource Guide ', 'id': 4637},

{'title': 'xmlhack', 'id': 724},

{'title': ' xmlTree Newsletter ', 'id': 413}]



Let's have a look even more deeply in XML-RPC and Meerkat


In clause{article} on programming the web-client (see translation Intersoft Lab), I have shown, as it is possible to load easily the list of all Linux-clauses Meerkat with the help of powerful library URLLIB of language Python and very simple script. Let's return to this problem{task}, using xmlrpclib. Having used even more simple script, we can remove some ambiguous and clumsy moments of the previous approach and create more reliable application.


Open new interactive session in language Python, import xmlrpclib and create search of the server (server instance) for interaction with Meerkat server:



>>> import xmlrpclib


>>> meerkatURI = http: // www.oreillynet.com/meerkat/xml-rpc/server.php)

>>> meerkatsvr = xmlrpclib. Server (meerkatURI)


Before we shall start to make a code for our updated decision, let's study some characteristics which have been built - in Rehjlom Dornfestom in Meerkat XML-RPC server for reflection of his{its} opportunities. We already saw system.listMethods (). He returns the current list of methods available on the server. You can receive the signature of a method for any of these methods, having called methodSignature ():



>>> meerkatsvr.system.methodSignature (methodname)


This line returns the two-element file containing the returned size and parameter (parameters) of the specified method. Notice, that you should not include closing brackets after the name of a method.


Dornfest also has suggested the means, allowing to receive the information{inquiry} on any method of the server.



>>> meerkatsvr.system.methodHelp (meerkat.getItems)


To see this and other methods accessible to clients XML-RPC Meerkat, visit test page of interface Meerkat XML-RPC. The choice of item{point} "Self-diagnostics" (introspection) from the dropping out list will allow you to see all available methods together with their documentation. If is present URI, he also tests Meerkat XML-RPC Server server, returning both a call of methods and the answer of the server. Perfectly.



Reception from Meerkat the list of clauses{articles} Linux


As you, probably, remember, a problem{task} of the program in my clause{article} on programming the web-client was reception of links to clauses{articles} Linux from Meerkat in last hour. After creation of the environment of access to the server with help URLLIB, we have generated URI:



http: // www.oreillynet.com/meerkat/? p=5*t=1HOUR and _ fl=minimal and _ de=0 and _ ca=0 and _ ch=0 and _ da=0.


Only present, that the above mentioned line is present in some application! As the tool of updating URI specifies Meerkat to give out to us all text blocks from category Linux which have been registered in last hour, using the minimal configuration. We want to limit even more the information acting as a result of exception of fields, containing the description, a category, the channel and the data. Give produbliruem this functionality with the help xmlrpclib.


Declare the list of parameters, creating the dictionary of language Python (same, as structure in XML-RPC):



>>> params = {

... 'category': 7,

... 'time_period': '1HOUR',

... 'descriptions': 0,

... 'categories': 0,

... 'channels': 0,

... 'dates': 0

}


First two parameters define{determine} a spectrum of the information necessary to us. Last four - work as the switches disconnecting various returned components. Further, for reception of the necessary information we shall call some method of the server:



>>> results = meerkatsvr.meerkat.getItems (params)


This expression returns the list of dictionaries containing simultaneously heading and the HTML-link to all clauses{articles} Linux, appeared in Meerkat in last hour. If your search returns the empty list, increase a timeout (for example, till two o'clock (2HOUR) or one day (1DAY)).


Now let's walk under this list and we shall construct the finished HTML-link to these clauses{articles}:



>>> for d in results:

... print <A HREF = % s> %s </A> % (d [link], d [title])



That we have received


This approach has given us some advantages. We have improved readership of a code. A code began less. The branch of performance from the data has allowed you to choose alternative easily. In the best way that this approach absolutely in spirit of language Python. Due to the functionalities which have been built - in in XML-RPC and xmlrpclib, answer Meerkat today represents the data in language Python, possessing all corresponding flexibility: do{make} with them that want, save them in a database, show in wxPython or in Tkinter. Or even send other client through XML-RPC!