[Soap-Python] Default values for parameters

Burak Arslan burak.arslan at arskom.com.tr
Tue Sep 27 11:33:08 CEST 2011


On 27.09.2011 11:25, azurIt wrote:
> Thanks, i created new issue.
>
> That lxml validation fixed few things (for example when i send string to Integer parameter) but parameters count is still a problem. Also String(nillable=True) doesn't seems to have any effect. I tried:
>
> @rpc(String(nillable=False), String(nillable=False), _returns=String)
> def testf(self, first, second):

slightly off-topic remark: the first parameter name should be ctx and 
not self (by convention), as the first parameter is not a ServiceBase 
instance but a MethodContext instance.

> calling (SUDS):
> client.service.testf("aaa", "")
> client.service.testf("aaa", None)
> client.service.testf("aaa")
>
> Everything passes and function gets None as second argument in all cases.

what about this?

from rpclib.model.primitive import Mandatory

@rpc(Mandatory.String, Mandatory.String, _returns=String)
def testf(ctx, first, second):


please provide a full test case in the issue tracker in github so that 
nothing gets lost and we're sure we're on the same page.

thanks
burak


>
> ______________________________________________________________
>> Od: "Burak Arslan"<burak.arslan at arskom.com.tr>
>> Komu: azurIt<azurit at pobox.sk>
>> Dátum: 27.09.2011 00:43
>> Predmet: Re: [Soap-Python] Default values for parameters
>>
>> CC: soap at python.org
>> 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
>>
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap



More information about the Soap mailing list