Esempio n. 1
0
def test_sequence_parse_anytype_obj():
    value_type = xsd.ComplexType(
        xsd.Sequence([
            xsd.Element('{http://tests.python-zeep.org/}value', xsd.Integer()),
        ]))

    schema = Schema(
        etree.Element('{http://www.w3.org/2001/XMLSchema}Schema',
                      targetNamespace='http://tests.python-zeep.org/'))

    root = list(schema._schemas.values())[0]
    root.register_type('{http://tests.python-zeep.org/}something', value_type)

    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'container'),
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'item_1'),
                    xsd.AnyType()),
            ])))
    expected = etree.fromstring("""
        <ns0:container
            xmlns:ns0="http://tests.python-zeep.org/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns0:item_1 xsi:type="ns0:something">
            <ns0:value>100</ns0:value>
          </ns0:item_1>
        </ns0:container>
    """)
    obj = custom_type.parse(expected, schema)
    assert obj.item_1.value == 100
Esempio n. 2
0
def parse_schema_node(node):
    parser_context = ParserContext()
    schema = Schema(node=node,
                    transport=None,
                    location=None,
                    parser_context=parser_context)
    return schema
Esempio n. 3
0
def test_sequence_parse_anytype_obj():
    value_type = xsd.ComplexType(
        xsd.Sequence(
            [xsd.Element("{http://tests.python-zeep.org/}value", xsd.Integer())]
        )
    )

    schema = Schema(
        etree.Element(
            "{http://www.w3.org/2001/XMLSchema}Schema",
            targetNamespace="http://tests.python-zeep.org/",
        )
    )

    root = schema.root_document
    root.register_type("{http://tests.python-zeep.org/}something", value_type)

    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "container"),
        xsd.ComplexType(
            xsd.Sequence(
                [
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "item_1"),
                        xsd.AnyType(),
                    )
                ]
            )
        ),
    )
    expected = etree.fromstring(
        """
        <ns0:container
            xmlns:ns0="http://tests.python-zeep.org/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns0:item_1 xsi:type="ns0:something">
            <ns0:value>100</ns0:value>
          </ns0:item_1>
        </ns0:container>
    """
    )
    obj = custom_type.parse(expected, schema)
    assert obj.item_1.value == 100
Esempio n. 4
0
def parse_schema_node(node):
    schema = Schema(
        node=node,
        transport=None,
        location=None)
    return schema
Esempio n. 5
0
def schema_visitor():
    schema = Schema()
    return visitor.SchemaVisitor(schema)
Esempio n. 6
0
    def parse(self, xmlelement, schema, context=None):
        from zeep.xsd.schema import Schema

        schema = Schema(xmlelement, schema._transport)
        context.schemas.append(schema)
        return schema
Esempio n. 7
0
    def clone(self, qname, min_occurs=1, max_occurs=1):
        return self.__class__()

    def parse_kwargs(self, kwargs, name, available_kwargs):
        if name in available_kwargs:
            value = kwargs[name]
            available_kwargs.remove(name)
            return {name: value}
        return {}

    def parse(self, xmlelement, schema, context=None):
        from zeep.xsd.schema import Schema
        schema = Schema(xmlelement, schema._transport)
        context.schemas.append(schema)
        return schema

    def parse_xmlelements(self, xmlelements, schema, name=None, context=None):
        if xmlelements[0].tag == self.qname:
            xmlelement = xmlelements.popleft()
            result = self.parse(xmlelement, schema, context=context)
            return result

    def resolve(self):
        return self


default_elements = {
    xsd_ns('schema'): Schema(),
}
Esempio n. 8
0
    qname = '{http://www.w3.org/2001/XMLSchema}schema'

    def clone(self, qname, min_occurs=1, max_occurs=1):
        return self.__class__()

    def parse_kwargs(self, kwargs, name=None):
        if name in kwargs:
            value = kwargs.pop(name)
            return {name: value}, kwargs
        return {}, kwargs

    def parse(self, xmlelement, schema, context=None):
        from zeep.xsd.schema import Schema
        schema = Schema(xmlelement, schema._transport)
        context.schemas.append(schema)
        return schema

    def parse_xmlelements(self, xmlelements, schema, name=None, context=None):
        if xmlelements[0].tag == self.qname:
            xmlelement = xmlelements.pop(0)
            result = self.parse(xmlelement, schema, context=context)
            return result

    def resolve(self):
        return self


default_elements = {
    '{http://www.w3.org/2001/XMLSchema}schema': Schema(),
}