Luigi 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?
I would go for a slightly different approach: make your server have a dispatch-method that delegates the calls to the underlying actual implementation. But *before* that happens, extract the information as above, and either - prepend it to the argument list - stuff it into threadlocal variables, and only access these if needed in your implementation. Diez -- http://mail.python.org/mailman/listinfo/python-list