New submission from Kunshan Wang <[EMAIL PROTECTED]>: I recently wrote a program making use of SimpleXMLRPCServer. It has a function that responds to the caller according to the caller's IP address. However the current SimpleXMLRPCServer does not allow me to do this (directly).
For example: def whoami(): # blah blah blah .... return the_caller_s_ip_address svr.register_function(whoami) The problem is that only SimpleXMLRPCRequestHandler knows the client's IP address. I googled and searched the google group. Many people recommends subclassing the SimpleXMLRPCRequestHandler. I did this, but found that it is not very easy, although possible. I managed to make the RequestHandler pass its member client_address to function _dispatch by subclassing SimpleXMLRPCRequestHandler, copy-and-paste the code from the library, and then add an extra argument to _dispatch. Now _dispatch function looks like this: _dispatch(self, method, params, client_address) By default _dispatch assumes that the first parameter of 'method' is client_address, and then followed by other parameters from the (remote) caller. So if the XMLRPC client calls: s=xmlrpclib.Server("http://localhost:9999") s.whoami() the server actually calls whoami(client_address), where whoami is defined as: def whoami(client_address): return client_address The attachment contains a subclassed version of SimpleXMLRPCServer, named AddressRevealingXMLRPCServer. The code is ugly (because most codes are copied, and is vulnerable to future library changes), but it just works now. However this leads to more problems: Now that client_address can be passed to the called function, it may be needed that more informations could be passed to the called function, such as the HTTP headers, the response time, etc.. My code may not be the best solution. I suggest there may be some mechanism (such as overridable methods) to be added to SimpleXMLRPCServer so that user can specify *what* to pass to the called function. ---------- components: Library (Lib) files: AddressRevealingXMLRPCServer.py messages: 67811 nosy: cloverprince severity: normal status: open title: Let SimpleXMLRPCServer pass client_address to called functions. type: feature request versions: Python 2.5 Added file: http://bugs.python.org/file10545/AddressRevealingXMLRPCServer.py _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3058> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com