How to use the zeep.xsd function in zeep

To help you get started, we’ve selected a few zeep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mvantellingen / python-zeep / tests / test_xsd_signatures.py View on Github external
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}))"
    )
github mvantellingen / python-zeep / tests / test_wsdl_arrays.py View on Github external
def test_simple_type_nested_inline_type(transport):
    schema = xsd.Schema(
        load_xml(
            """
    
      
      
        
          
        
      

github mvantellingen / python-zeep / tests / test_xsd_indicators_choice.py View on Github external
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)
github mvantellingen / python-zeep / tests / test_xsd_attributes.py View on Github external
def test_anyattribute():
    schema = xsd.Schema(
        load_xml(
            """
        
        
          <element name="container">
            
              
                <element name="foo">
              </element>
              
            
          </element>
github mvantellingen / python-zeep / src / zeep / wsdl / messages / soap.py View on Github external
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)
        )
github StackStorm-Exchange / stackstorm-algosec / etc / action_generate.py View on Github external
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})
github mvantellingen / python-zeep / src / zeep / helpers.py View on Github external
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()
github utkarshohm / mf-platform-bse / api.py View on Github external
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
github mvantellingen / python-zeep / src / zeep / wsdl / messages / base.py View on Github external
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,
            )
github googleads / googleads-python-lib / googleads / common.py View on Github external
"""
    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