On Sep 9, 8:53 am, Luigi <[EMAIL PROTECTED]> wrote: > Dear all, > > I'm writing an XML-RPC server which should be able to modify the > incoming request before dispatching it. In particular I wand to added > two fixed parameters to the method called: one is the client host > address, and the other is the user name provided as for Basic > Authentication (http://[EMAIL PROTECTED]). > > To do this, at the present I've overwritten the do_POST method of > SimpleXMLRPCRequestHandler, including at a certain point this code: > > .... > data = ''.join(L) > > params, method = xmlrpclib.loads(data) > user = "unknown" > if self.headers.has_key('Authorization'): > # handle Basic authentication > (enctype, encstr) = self.headers.get('Authorization').split() > user, password = base64.standard_b64decode(encstr).split(':') > params = list(params) > params.append(self.address_string()) > params.append(user) > params = tuple(params) > data = xmlrpclib.dumps(params, methodname=method) > > (I slightly modified it to make it more readable at mail level) > > It works, but I don't really like it because it completely overwrites > the do_POST method that in the future Python releases is going to > change (I verified it). Do you know a better way to do this? > > Thanks in advance. > > Luigi
I actually wrote a wsgi module for almost this -exact- use case (having to prepend a user/password to the method calls). The simple rpc server and dispatchers didn't give me enough control over the behavior, so I had to reimplement all the logic surround the loads/ dumps calls, and eventually that just turned into the bulk of the whole SimpleXMLRPCServer module. There's a lot of tight coupling in the _dispatch method, so you'll have to override, monkey patch, or reimplement it. -- http://mail.python.org/mailman/listinfo/python-list