[Freeipa-devel] argument passing
Rob Crittenden
rcritten at redhat.com
Wed Aug 22 15:43:00 UTC 2007
John Dennis wrote:
> On Wed, 2007-08-22 at 11:13 -0400, Rob Crittenden wrote:
>> So how to handle the arguments is not obvious, particularly optional
>> ones. The argument name is not included in the XML-RPC request, just
>> the
>> data type and value(s). So how do we know which argument is which
>> when
>> there are optional ones?
>
> There are several ways to skin this cat in Python, it would help if you
> could give a few code snipets so I could better understand the problem
> you're trying to solve.
Ok, there is just a lot of stuff going on.
A raw XML-RPC request looks like:
<?xml version='1.0'?>
<methodCall>
<methodName>find_users</methodName>
<params>
<param>
<value><string>rcrit</string></value>
</param>
<param>
<value><array><data>
<value><string>dn</string></value>
<value><string>uid</string></value>
<value><string>cn</string></value>
<value><string>homeDirectory</string></value>
</data></array></value>
</param>
<param>
<value><string>ou=users,ou=default</string></value>
</param>
</params>
</methodCall>
In this case I want to call the function find_users with the arguments
"rcrit", ['dn', 'uid', 'cn', 'homeDirectory'], "ou=users,ou=default"
The current declaration of find_users (in my tree) is:
def find_users (self, args, sattrs=None,
user_container="ou=users,ou=default", opts=None):
xmlrpclib.py declares the function loads() which converts incoming
arguments into Python objects and returns it as a tuple. It then passes
this tuple and a dict named opts along to whatever function needs to be
called, in this case find_users().
The call sort-of works now because most of the arguments allow None (or
set a default).
Problem 1 has to do with optional arguments. In this case args is set to
a tuple of ("rcrit", ['dn', 'uid', 'cn', 'homeDirectory'],
"ou=users,ou=default") and sattrs contains the value of opts. So I need
to do some reformatting to get the values into the right places.
The secondary problem is that this function may be called directly and
optional arguments work just peachy.
You don't want to see my first crack at this, really :-)
rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3245 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20070822/91120f31/attachment.bin>
More information about the Freeipa-devel
mailing list