Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_signature_complex_type_choice():
custom_type = xsd.Element(
etree.QName("http://tests.python-zeep.org/", "authentication"),
xsd.ComplexType(
xsd.Choice(
[
xsd.Element(
etree.QName("http://tests.python-zeep.org/", "item_1"),
xsd.String(),
),
xsd.Element(
etree.QName("http://tests.python-zeep.org/", "item_2"),
xsd.String(),
),
]
)
),
)
assert (
custom_type.signature()
== "{http://tests.python-zeep.org/}authentication(({item_1: xsd:string} | {item_2: xsd:string}))"
)
def test_simple_type_nested_inline_type(transport):
schema = xsd.Schema(
load_xml(
"""
xmlns:tns="http://tests.python-zeep.org/"
elementFormDefault="qualified"
targetNamespace="http://tests.python-zeep.org/">
""".strip()
)
schema = xsd.Schema(node)
element = schema.get_element("ns0:container")
value = element(item_1="foo")
assert value.item_1 == "foo"
assert value.item_2 is None
assert value.item_3 is None
expected = """
foo
"""
node = etree.Element("document")
element.render(node, value)
def test_anyattribute():
schema = xsd.Schema(
load_xml(
"""
<element name="container">
<element name="foo">
</element>
</element>
def _create_envelope_element(self):
"""Create combined `envelope` complexType which contains both the
elements from the body and the headers.
"""
all_elements = xsd.Sequence([])
if self.header.type._element:
all_elements.append(
xsd.Element("{%s}header" % self.nsmap["soap-env"], self.header.type)
)
all_elements.append(
xsd.Element(
"{%s}body" % self.nsmap["soap-env"],
self.body.type if self.body else None,
)
)
return xsd.Element(
"{%s}envelope" % self.nsmap["soap-env"], xsd.ComplexType(all_elements)
)
parameter_required = False
parameter_description = ('"Login session cookie. If empty then'
' username/password will be used to login'
' prior to running this operation"')
elif parameter_name == "ffws_header":
# Adding a default value to ffws_header information
parameter_default = '{"version":"1.0", "opaque":""}'
# Ensure that this parameter doesn't conflict with any of the ones
# we have defined in the aciton template
if parameter_name in self.action_template_params:
print("ERROR: Param conflicts with default: {}.{}"
.format(op_name, parameter_name))
# pylint: disable=no-member
if isinstance(input_type_obj, zeep.xsd.types.builtins.BuiltinType):
parameter_type = input_type_obj._default_qname.localname
if parameter_type == "unsignedInt" or parameter_type == "int":
parameter_type = "integer"
elif parameter_type == "date":
parameter_type = "string"
else:
parameter_description = self.get_type_description(input_elem)
parameter_type = 'object'
op_inputs.append({'name': input_name,
'parameter_name': parameter_name,
'parameter_type': parameter_type,
'parameter_description': parameter_description,
'parameter_required': parameter_required,
'parameter_default': parameter_default})
def guess_xsd_type(obj):
"""Return the XSD Type for the given object"""
if isinstance(obj, bool):
return xsd.Boolean()
if isinstance(obj, int):
return xsd.Integer()
if isinstance(obj, float):
return xsd.Float()
if isinstance(obj, datetime.datetime):
return xsd.DateTime()
if isinstance(obj, datetime.date):
return xsd.Date()
return xsd.String()
def soap_set_wsa_headers(method_url, svc_url):
header = zeep.xsd.Element(None, zeep.xsd.ComplexType([
zeep.xsd.Element('{http://www.w3.org/2005/08/addressing}Action', zeep.xsd.String()),
zeep.xsd.Element('{http://www.w3.org/2005/08/addressing}To', zeep.xsd.String())
])
)
header_value = header(Action=method_url, To=svc_url)
return header_value
def signature(self, as_output=False):
if not self.body:
return None
if as_output:
if isinstance(self.body.type, xsd.ComplexType):
try:
if len(self.body.type.elements) == 1:
return self.body.type.elements[0][1].type.signature(
schema=self.wsdl.types, standalone=False
)
except AttributeError:
return None
return self.body.type.signature(schema=self.wsdl.types, standalone=False)
parts = [self.body.type.signature(schema=self.wsdl.types, standalone=False)]
if getattr(self, "header", None):
parts.append(
"_soapheaders={%s}" % self.header.signature(schema=self.wsdl.types),
standalone=False,
)
"""
if self._packer:
data = self._packer.Pack(data, self._version)
if isinstance(data, dict): # Instantiate from simple Python dict
# See if there is a manually specified derived type.
type_override = data.get('xsi_type')
if type_override:
elem_type = self._DiscoverElementTypeFromLocalname(type_override)
else:
elem_type = elem.type
data_formatted = data.items()
packed_result = self._CreateComplexTypeFromData(
elem_type, type_override is not None, data_formatted, set_type_attrs)
elif isinstance(data, zeep.xsd.CompoundValue):
# Here the data is already a SOAP element but we still need to look
# through it in case it has been edited with Python dicts.
elem_type = data._xsd_type
data_formatted = zip(dir(data), [data[k] for k in dir(data)])
packed_result = self._CreateComplexTypeFromData(
elem_type, False, data_formatted, set_type_attrs)
elif isinstance(data, (list, tuple)):
packed_result = [self._PackArgumentsHelper(elem, item, set_type_attrs)
for item in data]
else:
packed_result = data
return packed_result