This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cloverprince
Recipients cloverprince
Date 2008-06-07.16:26:06
SpamBayes Score 0.044928025
Marked as misclassified No
Message-id <1212855971.92.0.424447915547.issue3058@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-06-07 16:26:12cloverprincesetspambayes_score: 0.044928 -> 0.044928025
recipients: + cloverprince
2008-06-07 16:26:12cloverprincesetspambayes_score: 0.044928 -> 0.044928
messageid: <1212855971.92.0.424447915547.issue3058@psf.upfronthosting.co.za>
2008-06-07 16:26:10cloverprincelinkissue3058 messages
2008-06-07 16:26:09cloverprincecreate