dive into mark

You are here: dive into markArchivesFebruary 2002Ping weblogs.com

Monday, February 4, 2002

Ping weblogs.com

Actually, XML-RPC is easier in Python than almost any other language, because the XML-RPC library uses a very cool feature of Python called “dynamic binding” to create a kind of virtual proxy that lets you call remote functions with exactly the same syntax as calling local functions.

import xmlrpclib
remoteServer = xmlrpclib.Server(”http://rpc.weblogs.com/RPC2″)
remoteServer.weblogUpdates.ping(SITE_NAME, SITE_URL)

This short example pings weblogs.com to tell it that your weblog has changed. I use this script to connect this Greymatter weblog to the weblogs.com community (since Greymatter has no weblogs.com support built in). But the point here is the syntax of that third line: it’s the same syntax as calling a local function. Once the proxy (remoteServer) is set up, the XML-RPC library makes the object act as if it has a weblogUpdates object within it and a ping method within that. It’s all a lie, of course; under the covers it’s constructing an XML-RPC request and sending it off, and then receiving an XML-RPC response and parsing it and returning a native Python object. But I, as a Python developer, don’t have to worry about all that if I don’t want to, and I don’t have to learn a new syntax for calling remote functions.

Filed under , ,

Respond privately

I am no longer accepting public comments on this post, but you can use this form to contact me privately. (Your message will not be published.)



Recent Stuff For You, Special Price Stay Here
  • Greasemonkey Hacks
Good Stuff Buy The Cow Go Away
Dive Into Python
Powered by Google Drink The Milk Don't Steal

 

posts / comments
© 2001-8 Mark Pilgrim