gdc: handle null values (#43963)

This commit is contained in:
Frédéric Péters 2020-06-12 08:46:33 +02:00
parent f0cb728359
commit ad904629a0
1 changed files with 6 additions and 1 deletions

View File

@ -66,6 +66,9 @@ class Gdc(BaseResource):
for i, arg in enumerate(args):
params.append('<v%(i)s xsi:type="xsd:string">%(value)s</v%(i)s>' % {'i': i + 1, 'value': arg})
for key, value in kwargs.items():
if value is None:
params.append('<%s xsi:null="1"/>' % key)
continue
type_ = 'int' if isinstance(value, int) else 'string'
params.append('<%(key)s xsi:type="xsd:%(type)s">%(value)s</%(key)s>' % {
'key': key, 'type': type_, 'value': value})
@ -74,14 +77,16 @@ class Gdc(BaseResource):
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<%(action)s SOAP-ENC:root="1">
%(params)s
</%(action)s>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>""" % {'action': action, 'params': ''.join(params)}
</SOAP-ENV:Envelope>""" % {'action': action, 'params': '\n'.join(params)}
resp = self.requests.post(self.service_url, data=data)
return ET.ElementTree(ET.fromstring(resp.content))