XMLRPC and keyword arguments
![](https://secure.gravatar.com/avatar/d2e9187dfb91088836a3691dba80e9cb.jpg?s=120&d=mm&r=g)
I've made a simple extension to XMLRPC, and I was wondering if it is something that I should contribute back to Twisted or if I should keep it to myself. In other words, would others find this useful? The idea is that RPC methods might need to get at information in the request. For example, an RPC method might need to know what IP address the request comes from or it might need to know if HTTP basic authentication is set. I'm sure I could come up with more examples. Here how it's used: class SomeXMLRPCClass(XMLRPC): def keywords(self, request): return {'client': request.client} def xmlrpc_echo(self, x, **kwds): client = kwds['client'] # [do what you need to with client here] return x Anyway, implementing this is incredibly simple, and I needed it for a project I'm working on. If it would be useful to others, I'd be happy to create a ticket and post a patch. Thanks. -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Mon, 10 Mar 2008 10:15:17 -0600, Andrew McNabb <amcnabb@mcnabbs.org> wrote:
I've made a simple extension to XMLRPC, and I was wondering if it is something that I should contribute back to Twisted or if I should keep it to myself. In other words, would others find this useful?
The idea is that RPC methods might need to get at information in the request. For example, an RPC method might need to know what IP address the request comes from or it might need to know if HTTP basic authentication is set. I'm sure I could come up with more examples.
Here how it's used:
class SomeXMLRPCClass(XMLRPC): def keywords(self, request): return {'client': request.client}
def xmlrpc_echo(self, x, **kwds): client = kwds['client'] # [do what you need to with client here] return x
Anyway, implementing this is incredibly simple, and I needed it for a project I'm working on. If it would be useful to others, I'd be happy to create a ticket and post a patch.
This seems like a slightly round-about API. What would you think of having another prefix which included the request as the first argument? Or the same prefix could be used and the function could have an attribute indicating it wants the request. Jean-Paul
![](https://secure.gravatar.com/avatar/d2e9187dfb91088836a3691dba80e9cb.jpg?s=120&d=mm&r=g)
On Mon, Mar 10, 2008 at 12:09:19PM -0500, Jean-Paul Calderone wrote:
This seems like a slightly round-about API. What would you think of having another prefix which included the request as the first argument? Or the same prefix could be used and the function could have an attribute indicating it wants the request.
I don't particularly like the idea of having another prefix, but the second idea seems pretty straightforward. It would probably make sense to include a decorator that set the attribute. Anyway, if you like the idea, I'll write it. Thanks. -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
![](https://secure.gravatar.com/avatar/d2e9187dfb91088836a3691dba80e9cb.jpg?s=120&d=mm&r=g)
On Mon, Mar 10, 2008 at 11:20:35AM -0600, Andrew McNabb wrote:
Anyway, if you like the idea, I'll write it.
I have posted a simple patch at http://twistedmatrix.com/trac/ticket/3073 Enjoy. -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
![](https://secure.gravatar.com/avatar/426d6dbf6554a9b3fca1fd04e6b75f38.jpg?s=120&d=mm&r=g)
Anyway, implementing this is incredibly simple, and I needed it for a project I'm working on. If it would be useful to others, I'd be happy to create a ticket and post a patch.
This seems like a slightly round-about API. What would you think of having another prefix which included the request as the first argument? Or the same prefix could be used and the function could have an attribute indicating it wants the request.
Yes please! Much nicer - kind of like the pb.Viewable and view_ method.
![](https://secure.gravatar.com/avatar/5bd935f17a824b2ac0f9293b033ac2b4.jpg?s=120&d=mm&r=g)
Andrew McNabb wrote:
I've made a simple extension to XMLRPC, and I was wondering if it is something that I should contribute back to Twisted or if I should keep it to myself. In other words, would others find this useful?
I certainly would -- please contribute!
The idea is that RPC methods might need to get at information in the request. For example, an RPC method might need to know what IP address the request comes from or it might need to know if HTTP basic authentication is set.
Just my situation -- how'd you know? Tnx, -- Don Dwiggins Advanced Publishing Technology
participants (4)
-
Andrew McNabb
-
Don Dwiggins
-
Jean-Paul Calderone
-
Phil Mayers