[Soap-Python] Default values for parameters
Burak Arslan
burak.arslan at arskom.com.tr
Tue Sep 27 00:43:13 CEST 2011
hello,
you're asking good questions :)
On 09/26/11 20:08, azurIt wrote:
> Hi,
>
> how can i set default values for arguments ? Standard python way is not working:
> @rpc(String, String, _returns=String)
> def testf(self, first, second=u"aaa"):
> ....
>
that won't work. the ideal way would be to have a default keyword (e.g.
String(default='something')) but such a thing is not implemented. use if
val is None: val = some_value idiom. if you need this bad, add it to the
issue tracker so that i can work on it when I have some free time.
> Thx.
>
> Btw, rpclib seems to not check parameters count. If function is taking two parameters and i send only one, everything is processed without error (and second parameters gets None). The similar thing will happen if i send more than 2 params.
>
the wisdom in the it world says: "be liberal in what you receive and
conservative on what you send", so validation is an opt-in feature in
rpclib.
if you're using soap, you can use strict ('lxml') or 'soft' validation.
httprpc only supports 'soft' validation.
This is how you should instantiate your application:
Application(services, 'some.tns', Wsdl11(), Soap11(validator='lxml'),
Soap11())
'lxml' validation will complain about the slightest irregularity in the
input. soft validation will only validate the designated values and
ignore the rest.
now that you have validation enabled, you must make parameters
mandatory. you should set, e.g. Integer(min_occurs=1, nillable=False) or
String(min_occurs=1, nillable=False, min_len=1). see the api reference
to see which type accepts which constraints.
also see here as a shortcut to specifying all that:
https://github.com/arskom/rpclib/blob/master/src/rpclib/model/primitive.py#L466
hth
burak
> azur
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap
More information about the Soap
mailing list