python|python xmlrpc实现二进制文件传输的代码,简单的远程调用
把服务器端文件读取到本地
【python|python xmlrpc实现二进制文件传输的代码,简单的远程调用】服务器端
view source print ?
法
#from xmlrpc.server import SimpleXMLRPCServerfrom SimpleXMLRPCServer import SimpleXMLRPCServer
import xmlrpclib
from xmlrpclib import ServerProxyclass KeyValueServer:
_rpc_methods_ = ['get', 'set', 'delete', 'exists', 'keys']
def __init__(self, address):
self._data = https://www.it610.com/article/{}
self._serv = SimpleXMLRPCServer(address, allow_none=True)
for name in self._rpc_methods_:
self._serv.register_function(getattr(self, name))def get(self, name):
return self._data[name]def set(self, name, value):
self._data[name] = valuedef delete(self, name):
del self._data[name]def exists(self, name):
return name in self._datadef keys(self):
return list(self._data)def serve_forever(self):
self._serv.serve_forever()# Example
if __name__ =='__main__':
kvserv = KeyValueServer(('', 15000))
print "xml-rpc running."
kvserv.serve_forever()
client:
>>> from xmlrpclib import ServerProxy
>>> s = ServerProxy('http://localhost:15000', allow_none=True)
>>> s.set('foo', 'bar')
>>> s.set('spam', [1, 2, 3])
>>> s.keys()
['spam', 'foo']
>>> s.get('foo')
'bar'
>>> s.get('spam')
[1, 2, 3]
>>> s.delete('spam')
>>> s.exists('spam')
False
>>>
推荐阅读
- 关于QueryWrapper|关于QueryWrapper,实现MybatisPlus多表关联查询方式
- MybatisPlus使用queryWrapper如何实现复杂查询
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- 孩子不是实现父母欲望的工具——林哈夫
- opencv|opencv C++模板匹配的简单实现
- Node.js中readline模块实现终端输入
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- java中如何实现重建二叉树