[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
samwyse samw...@gmail.com added the comment: More importantly, the dispatch method is now part of the SimpleXMLRPCDispatcher, which (as a mix-in class) has no direct access to the RequestHandler instance that comprises the request. This breaks Victor's and my idea, unless one is willing to subclass SimpleXMLRPCRequestHandler to provide a_dispatch method. The ability to do this, however, is only provided for backward compatibility and I doubt it could be part of a general solution. On Thu, Jul 8, 2010 at 11:33 PM, Terry J. Reedy rep...@bugs.python.orgwrote: Terry J. Reedy tjre...@udel.edu added the comment: In 3.x, class SimpleXMLRPCServer lives in module xmlrpc.server -- nosy: +tjreedy versions: +Python 3.2 -Python 2.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ -- Added file: http://bugs.python.org/file17956/unnamed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___More importantly, the dispatch method is now part of the SimpleXMLRPCDispatcher, which (as a mix-in class) has no direct access to the span class=Apple-style-span style=font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; RequestHandler instance that comprises the request.  This breaks Victor#39;s and my idea, unless one is willing to subclass SimpleXMLRPCRequestHandler to provide a_dispatch method.  The ability to do this, however, is only provided for backward compatibility and I doubt it could be part of a general solution./spanbr brdiv class=gmail_quoteOn Thu, Jul 8, 2010 at 11:33 PM, Terry J. Reedy span dir=ltrlt;a href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;/span wrote:brblockquote class=gmail_quote style=margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex; br Terry J. Reedy lt;a href=mailto:tjre...@udel.edu;tjre...@udel.edu/agt; added the comment:br br In 3.x, class  SimpleXMLRPCServer lives in module xmlrpc.serverbr br --br nosy: +tjreedybr versions: +Python 3.2 -Python 2.5br divdiv/divdiv class=h5br ___br Python tracker lt;a href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;br lt;a href=http://bugs.python.org/issue3058; target=_blankhttp://bugs.python.org/issue3058/agt;br ___br /div/div/blockquote/divbr ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
Terry J. Reedy tjre...@udel.edu added the comment: I am taking your comment as a suggestion to close this. -- resolution: - out of date status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
Terry J. Reedy tjre...@udel.edu added the comment: In 3.x, class SimpleXMLRPCServer lives in module xmlrpc.server -- nosy: +tjreedy versions: +Python 3.2 -Python 2.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
STINNER Victor victor.stin...@haypocalc.com added the comment: client_address is not interresting, but I prefer the handler object (SimpleXMLRPCRequestHandler instance). The handler contains more information: * handler.address_string() gives the FQDN * handler.connection.getpeername() gives the client address * handler.connection.getsockanem() gives the server address, useful is the server is listening to multiple addresses * etc. If the server uses SSL, it would be possible to get more information about SSL from handler(.connection). Your patch breaks the API for all (service) callbacks. Add an option to register_function() would allow a smoother transition (don't break API): you don't have to inherit from a new class. Eg. server.register_function(whoami, with_handler=True). -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
STINNER Victor victor.stin...@haypocalc.com added the comment: Oops, I mean client_address is interresting, but ... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
STINNER Victor victor.stin...@haypocalc.com added the comment: Oops oops oops, samwyse wrote exactly the same idea than me in the first comment! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
andrew cooke and...@acooke.org added the comment: Came here wondering how best to solve this myself. I already subclass the request handler to do client validation (password etc) and it stuck me that a simpler solution would be to use thread local storage. This avoids having to modify dispatch. The disadvantage is that this uses a single global scope. I don't think it's a better solution than that suggested by samwyse for a final solution, but I thought I'd note it here because it's a simpler alternative for people needing to add a work-around, and I suspect many people aren't aware of the possibility. import _threading_local ; help(_threading_local) If this wouldn't work (maybe I've misunderstood the server threading?) then I'd appreciate someone correcting me. Thanks. -- nosy: +acooke ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
samwyse samw...@gmail.com added the comment: A more general solution would be to pass the RequestHandler instance as a parameter to the dispatch function. This would allow the function to pick out more than just the client address. To avoid breaking pre-existing code, this should be made optional, perhaps by adding a keyword to the register_function method. Something like this: def __init__(...): self._include_request = set() def register_function(..., include_request=False): self._include_request.add(method) Later, the dispatch function would be invoked like this: kwds = {} if method in self._include_request: kwds.update(request=self) [...] return self.instance._dispatch(method, params, **kwds) [...] return func(client_address, *params, **kwds) -- nosy: +samwyse ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3058 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3058] Let SimpleXMLRPCServer pass client_address to called functions.
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:;) 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