如何从Python 2.7 documentation改编XML RPC服务器和客户端的示例代码,以便在客户端和服务器之间的传输中使用gzip?以下是示例代码:
服务器
Select-String -Path $hashlistfile -Pattern dc8087c38a0d |ForEach-Object {
$_.Line.Split(" ")[2]
}
客户
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Register a function under a different name
def adder_function(x,y):
return x + y
server.register_function(adder_function, 'add')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()
但是所有这些都保留在非压缩的纯文本中。我一直在阅读xmlrpc库上的文档,它似乎具有gzip压缩的内置选项,但我一直无法弄清楚如何实际使用它。