您的位置:首页 > 编程语言 > Python开发

使用python xml-rpc client & server 来提供metaweblog服务

2012-01-24 13:33 741 查看
server.py

#encoding=utf-8
#!/usr/bin/env python
from SimpleXMLRPCServer import SimpleXMLRPCServer
import os

server = SimpleXMLRPCServer(('localhost', 9000))
# Expose a function with an alternate name
def list_contents(dir_name):
return os.listdir(dir_name)
server.register_function(list_contents, 'dir')

def get_users_blogs(blogid,user,password):
return [{'url': 'http://www.cnblogs.com/lexus/', 'blogid': '25231', 'blogName': u'\u6717\u5fd7\u5de5\u4f5c\u5ba4(Langzhi Studio)'}]
server.register_function(get_users_blogs, 'blogger.getUsersBlogs')

try:
print 'Use Control-C to exit'
server.serve_forever()
except KeyboardInterrupt:
print 'Exiting'

client.py

#encoding=utf-8
#!/usr/bin/env python
import xmlrpclib

#proxy = xmlrpclib.Server('http://www.cnblogs.com/aa/services/metaweblog.aspx')
proxy = xmlrpclib.Server('http://localhost:9000')
print proxy.blogger.getUsersBlogs("23451","aa","bb")

reference:
http://www.doughellmann.com/PyMOTW/SimpleXMLRPCServer/#module-SimpleXMLRPCServer http://docs.python.org/library/simplexmlrpcserver.html http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html http://www.tutorialspoint.com/xml-rpc/xml_rpc_examples.htm http://docs.python.org/library/xmlrpclib.html https://github.com/huafengxi/pblog http://www.allyourpixel.com/tag/Django/ http://www.cppblog.com/ronliu/services/metaweblog.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: