当前位置: 首页>>代码示例>>Python>>正文


Python utils.load_xml函数代码示例

本文整理汇总了Python中tests.utils.load_xml函数的典型用法代码示例。如果您正苦于以下问题:Python load_xml函数的具体用法?Python load_xml怎么用?Python load_xml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了load_xml函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_xml_empty_xmlns

def test_xml_empty_xmlns():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                elementFormDefault="qualified">
          <complexType name="empty"/>
          <element name="container">
            <complexType>
              <sequence>
                <element ref="schema"/>
                <any/>
              </sequence>
            </complexType>
          </element>
        </schema>
    """))

    container_elm = schema.get_element('{http://tests.python-zeep.org/}container')
    node = load_xml("""
        <container>
            <xs:schema
                xmlns=""
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
              <xs:element name="something" type="xs:string" msdata:foo=""/>
            </xs:schema>
            <something>foo</something>
        </container>
    """)
    item = container_elm.parse(node, schema)
    assert item._value_1 == 'foo'
开发者ID:tobirl,项目名称:python-zeep,代码行数:33,代码来源:test_xsd_integration.py

示例2: test_choice_optional_values

def test_choice_optional_values():
    schema = load_xml("""
        <xsd:schema
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/"
            targetNamespace="http://tests.python-zeep.org/"
            elementFormDefault="qualified">
          <xsd:complexType name="Transport">
            <xsd:sequence>
                <xsd:choice minOccurs="0" maxOccurs="1">
                    <xsd:element name="item" type="xsd:string"/>
                </xsd:choice>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:schema>
    """)
    schema = xsd.Schema(schema)

    node = load_xml("""
        <document>
            <Transport>
            </Transport>
        </document>
    """)
    elm = schema.get_type('ns0:Transport')
    elm.parse_xmlelement(node, schema)
开发者ID:fiebiga,项目名称:python-zeep,代码行数:26,代码来源:test_xsd_choice.py

示例3: test_xml_defaults_parse

def test_xml_defaults_parse():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                elementFormDefault="qualified"
                targetNamespace="http://tests.python-zeep.org/">
          <xsd:element name="container">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="item_1" type="xsd:string" default="hoi" minOccurs="0"/>
              </xsd:sequence>
              <xsd:attribute name="attr_1" type="xsd:string" default="hoi"/>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
    """))

    container_elm = schema.get_element(
        '{http://tests.python-zeep.org/}container')

    node = load_xml("""
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item_1>hoi</ns0:item_1>
        </ns0:container>
    """)
    item = container_elm.parse(node, schema)
    assert item.attr_1 == 'hoi'
开发者ID:tobirl,项目名称:python-zeep,代码行数:29,代码来源:test_xsd_integration.py

示例4: test_xml_complex_type_parsexml

def test_xml_complex_type_parsexml():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                elementFormDefault="qualified">
          <element name="Address">
            <complexType>
              <sequence>
                <element minOccurs="0" maxOccurs="1" name="foo" type="string" />
              </sequence>
            </complexType>
          </element>
        </schema>
    """))

    address_type = schema.get_element('{http://tests.python-zeep.org/}Address')

    input_node = load_xml("""
        <Address xmlns="http://tests.python-zeep.org/">
          <foo>bar</foo>
        </Address>
    """)

    obj = address_type.parse(input_node, None)
    assert obj.foo == 'bar'
开发者ID:tobirl,项目名称:python-zeep,代码行数:27,代码来源:test_xsd_integration.py

示例5: test_parse_check_mixed

def test_parse_check_mixed():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                elementFormDefault="qualified"
                targetNamespace="http://tests.python-zeep.org/">
          <xsd:element name="container">
            <xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema">
              <xsd:sequence>
                <xsd:choice maxOccurs="unbounded">
                  <xsd:element name="item_1" type="xsd:string"/>
                  <xsd:element name="item_2" type="xsd:string"/>
                </xsd:choice>
                <xsd:element name="item_3" type="xsd:string"/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
    """))

    element = schema.get_element('ns0:container')
    expected = load_xml("""
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
          <ns0:item_3>foo</ns0:item_3>
        </ns0:container>
    """)
    element.parse(expected, schema)
开发者ID:mvantellingen,项目名称:python-zeep,代码行数:31,代码来源:test_xsd_choice.py

示例6: test_xml_namespace

def test_xml_namespace():
    xmlns = load_xml("""
        <?xml version="1.0"?>
        <xs:schema
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:xml="http://www.w3.org/XML/1998/namespace"
            targetNamespace="http://www.w3.org/XML/1998/namespace"
            elementFormDefault="qualified">
          <xs:attribute name="lang" type="xs:string"/>
        </xs:schema>
    """)

    transport = DummyTransport()
    transport.bind('http://www.w3.org/2001/xml.xsd', xmlns)

    xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xs:schema
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/"
            targetNamespace="http://tests.python-zeep.org/"
            elementFormDefault="qualified">
          <xs:import namespace="http://www.w3.org/XML/1998/namespace"
                     schemaLocation="http://www.w3.org/2001/xml.xsd"/>
          <xs:element name="container">
            <xs:complexType>
              <xs:sequence/>
              <xs:attribute ref="xml:lang"/>
            </xs:complexType>
          </xs:element>
        </xs:schema>
    """), transport=transport)
开发者ID:ovnicraft,项目名称:python-zeep,代码行数:32,代码来源:test_xsd_schemas.py

示例7: test_xml_sequence_recover_from_missing_element

def test_xml_sequence_recover_from_missing_element():
    schema = xsd.Schema(load_xml("""
        <schema
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/"
            elementFormDefault="qualified"
            targetNamespace="http://tests.python-zeep.org/">
          <complexType name="container">
            <sequence>
              <element name="item_1" type="xsd:string"/>
              <element name="item_2" type="xsd:string"/>
              <element name="item_3" type="xsd:string"/>
              <element name="item_4" type="xsd:string"/>
            </sequence>
          </complexType>
        </schema>
    """), settings=Settings(strict=False))

    xml = load_xml("""
        <tns:container
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:tns="http://tests.python-zeep.org/">
          <tns:item_1>text-1</tns:item_1>
          <tns:item_3>text-3</tns:item_3>
          <tns:item_4>text-4</tns:item_4>
        </tns:container>
    """)
    elm_type = schema.get_type('{http://tests.python-zeep.org/}container')
    result = elm_type.parse_xmlelement(xml, schema)
    assert result.item_1 == 'text-1'
    assert result.item_2 is None
    assert result.item_3 == 'text-3'
    assert result.item_4 == 'text-4'
开发者ID:tobirl,项目名称:python-zeep,代码行数:35,代码来源:test_xsd_indicators_sequence.py

示例8: test_soap_array_parse_remote_ns

def test_soap_array_parse_remote_ns():
    transport = DummyTransport()
    transport.bind(
        'http://schemas.xmlsoap.org/soap/encoding/',
        load_xml(io.open('tests/wsdl_files/soap-enc.xsd', 'r').read().encode('utf-8')))

    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <xsd:schema
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:tns="http://tests.python-zeep.org/"
          xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          targetNamespace="http://tests.python-zeep.org/"
          elementFormDefault="qualified">
          <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
          <xsd:simpleType name="CountryCodeType">
            <xsd:restriction base="xsd:string">
              <xsd:length value="2"/>
              <xsd:pattern value="[a-zA-Z]{2}"/>
            </xsd:restriction>
          </xsd:simpleType>
          <xsd:complexType name="CountryItemType">
            <xsd:sequence>
              <xsd:element name="code" type="tns:CountryCodeType"/>
              <xsd:element name="name" type="xsd:string"/>
            </xsd:sequence>
          </xsd:complexType>
          <xsd:complexType name="CountriesArrayType">
            <xsd:complexContent>
              <xsd:restriction base="soapenc:Array">
                <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="tns:CountryItemType[]"/>
              </xsd:restriction>
            </xsd:complexContent>
          </xsd:complexType>
          <xsd:element name="countries" type="tns:CountriesArrayType"/>
        </xsd:schema>
    """), transport)

    doc = load_xml("""
      <countries
            SOAP-ENC:arrayType="ns1:CountryItemType[1]"
            xsi:type="ns1:CountriesArrayType"
            xmlns:ns1="http://tests.python-zeep.org/"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <item xsi:type="ns1:CountryItemType">
          <code xsi:type="ns1:CountryCodeType">NL</code>
          <name xsi:type="xsd:string">The Netherlands</name>
        </item>
      </countries>
    """)

    elm = schema.get_element('ns0:countries')
    data = elm.parse(doc, schema)

    assert data[0].code == 'NL'
    assert data[0].name == 'The Netherlands'
开发者ID:ovnicraft,项目名称:python-zeep,代码行数:60,代码来源:test_wsdl_arrays.py

示例9: test_xml_unparsed_elements

def test_xml_unparsed_elements():
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/"
                elementFormDefault="qualified">
          <element name="container">
            <complexType>
              <sequence>
                <element minOccurs="0" maxOccurs="1" name="item" type="string" />
              </sequence>
            </complexType>
          </element>
        </schema>
    """))
    schema.settings.strict = False
    schema.set_ns_prefix('tns', 'http://tests.python-zeep.org/')

    expected = load_xml("""
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item>bar</ns0:item>
          <ns0:idontbelonghere>bar</ns0:idontbelonghere>
        </ns0:container>
      </document>
    """)

    container_elm = schema.get_element('tns:container')
    obj = container_elm.parse(expected[0], schema)
    assert obj.item == 'bar'
    assert obj._raw_elements
开发者ID:tobirl,项目名称:python-zeep,代码行数:32,代码来源:test_xsd_complex_types.py

示例10: test_mime_content_serialize_xml

def test_mime_content_serialize_xml():
    wsdl = stub(schema=stub(_prefix_map={}))
    operation = stub(location='my-action', name='foo')

    element_1 = xsd.Element('arg1', xsd.ComplexType([
        xsd.Element('arg1_1', xsd.String())
    ]))
    element_2 = xsd.Element('arg2', xsd.String())
    abstract_message = definitions.AbstractMessage(
        etree.QName('{http://test.python-zeep.org/tests/msg}Method'))
    abstract_message.parts = OrderedDict([
        ('xarg1', definitions.MessagePart(element=element_1, type=None)),
        ('xarg2', definitions.MessagePart(element=element_2, type=None)),
    ])

    msg = messages.MimeContent(
        wsdl=wsdl, name=None, operation=operation, content_type='text/xml',
        part_name=None)

    msg._info = {
        'body': {'namespace': 'http://test.python-zeep.org/tests/rpc'},
        'header': None,
        'headerfault': None
    }
    msg.resolve(wsdl, abstract_message)

    serialized = msg.serialize(xarg1={'arg1_1': 'uh'}, xarg2='bla')
    assert serialized.headers == {
        'Content-Type': 'text/xml'
    }
    assert serialized.path == 'my-action'
    assert_nodes_equal(
        load_xml(serialized.content),
        load_xml(
            "<foo><xarg1><arg1_1>uh</arg1_1></xarg1><xarg2>bla</xarg2></foo>"))
开发者ID:elfixit,项目名称:python-zeep,代码行数:35,代码来源:test_wsdl_messages.py

示例11: test_element_any_parse

def test_element_any_parse():
    node = load_xml("""
        <xsd:schema
            elementFormDefault="qualified"
            targetNamespace="https://tests.python-zeep.org"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <xsd:element name="container">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:any/>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:schema>
    """)

    schema = xsd.Schema(node)

    node = load_xml("""
          <container xmlns="https://tests.python-zeep.org">
            <something>
              <contains>text</contains>
            </something>
          </container>
    """)

    elm = schema.get_element('ns0:container')
    elm.parse(node, schema)
开发者ID:mattpepin,项目名称:python-zeep,代码行数:28,代码来源:test_xsd_integration.py

示例12: test_xml_element_ref_missing_namespace

def test_xml_element_ref_missing_namespace():
    # For buggy soap servers (#170)
    schema = xsd.Schema(load_xml("""
        <?xml version="1.0"?>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:tns="http://tests.python-zeep.org/"
                targetNamespace="http://tests.python-zeep.org/">
          <element name="foo" type="string"/>
          <element name="bar">
            <complexType>
              <sequence>
                <element ref="tns:foo"/>
              </sequence>
            </complexType>
          </element>
        </schema>
    """))

    custom_type = schema.get_element('{http://tests.python-zeep.org/}bar')
    input_xml = load_xml("""
            <ns0:bar xmlns:ns0="http://tests.python-zeep.org/">
                <foo>bar</foo>
            </ns0:bar>
    """)
    item = custom_type.parse(input_xml, schema)
    assert item.foo == 'bar'
开发者ID:tobirl,项目名称:python-zeep,代码行数:26,代码来源:test_xsd_integration.py

示例13: test_sequence_parse_anytype_regression_17

def test_sequence_parse_anytype_regression_17():
    schema_doc = load_xml(b"""
        <?xml version="1.0" encoding="utf-8"?>
        <schema
            xmlns="http://www.w3.org/2001/XMLSchema"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://tests.python-zeep.org/tst"
            elementFormDefault="qualified"
            targetNamespace="http://tests.python-zeep.org/tst">
          <complexType name="CustomField">
            <sequence>
              <element name="parentItemURI" type="xsd:string"/>
              <element name="key" type="xsd:string"/>
              <element name="value" nillable="true"/>
            </sequence>
          </complexType>
          <complexType name="Text">
            <sequence>
              <element name="type" type="xsd:string"/>
              <element name="content" type="xsd:string"/>
              <element name="contentLossy" type="xsd:boolean"/>
            </sequence>
          </complexType>

          <element name="getCustomFieldResponse">
            <complexType>
              <sequence>
                <element name="getCustomFieldReturn" type="tns:CustomField"/>
              </sequence>
            </complexType>
          </element>
        </schema>
    """)

    xml = load_xml(b"""
        <?xml version="1.0" encoding="utf-8"?>
        <tst:getCustomFieldResponse
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:tst="http://tests.python-zeep.org/tst">
          <tst:getCustomFieldReturn>
            <tst:parentItemURI>blabla</tst:parentItemURI>
            <tst:key>solution</tst:key>
            <tst:value xsi:type="tst:Text">
              <tst:type xsi:type="xsd:string">text/html</tst:type>
              <tst:content xsi:type="xsd:string">Test Solution</tst:content>
              <tst:contentLossy xsi:type="xsd:boolean">false</tst:contentLossy>
            </tst:value>
          </tst:getCustomFieldReturn>
        </tst:getCustomFieldResponse>
    """)

    schema = xsd.Schema(schema_doc)
    elm = schema.get_element(
        '{http://tests.python-zeep.org/tst}getCustomFieldResponse'
    )
    result = elm.parse(xml, schema)
    assert result.getCustomFieldReturn.value.content == 'Test Solution'
开发者ID:felipebizz,项目名称:python-zeep,代码行数:58,代码来源:test_xsd_parse.py

示例14: test_mime_content_serialize_text_xml

def test_mime_content_serialize_text_xml():
    wsdl_content = StringIO("""
    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
                 xmlns:tns="http://tests.python-zeep.org/tns"
                 xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
                 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
                 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 targetNamespace="http://tests.python-zeep.org/tns">

      <message name="Input">
        <part name="arg1" type="xsd:string"/>
        <part name="arg2" type="xsd:string"/>
      </message>
      <message name="Output">
        <part name="Body" type="xsd:string"/>
      </message>

      <portType name="TestPortType">
        <operation name="TestOperation">
          <input message="Input"/>
          <output message="Output"/>
        </operation>
      </portType>

      <binding name="TestBinding" type="tns:TestPortType">
        <http:binding verb="POST"/>
        <operation name="TestOperation">
          <http:operation location="test-operation"/>
          <input>
            <mime:content type="text/xml"/>
          </input>
          <output>
            <mime:mimeXml part="Body"/>
          </output>
        </operation>
      </binding>
    </definitions>
    """.strip())

    root = wsdl.Document(wsdl_content, None)

    binding = root.bindings['{http://tests.python-zeep.org/tns}TestBinding']
    operation = binding.get('TestOperation')

    assert operation.input.body.signature(schema=root.types) == 'TestOperation(arg1: xsd:string, arg2: xsd:string)'
    assert operation.input.signature(as_output=False) == 'arg1: xsd:string, arg2: xsd:string'

    assert operation.output.body.signature(schema=root.types) == 'TestOperation(Body: xsd:string)'
    assert operation.output.signature(as_output=True) == 'xsd:string'

    serialized = operation.input.serialize(arg1='ah1', arg2='ah2')
    assert serialized.headers == {'Content-Type': 'text/xml'}
    assert serialized.path == 'test-operation'
    assert_nodes_equal(
        load_xml(serialized.content),
        load_xml("<TestOperation><arg1>ah1</arg1><arg2>ah2</arg2></TestOperation>"))
开发者ID:ovnicraft,项目名称:python-zeep,代码行数:57,代码来源:test_wsdl_messages_http.py

示例15: test_nested_choice

def test_nested_choice():
    schema = xsd.Schema(load_xml("""
            <?xml version="1.0"?>
            <schema xmlns="http://www.w3.org/2001/XMLSchema"
                    xmlns:tns="http://tests.python-zeep.org/"
                    targetNamespace="http://tests.python-zeep.org/"
                    elementFormDefault="qualified">
                <element name="container">
                    <complexType>
                        <sequence>
                            <choice>
                                <choice minOccurs="2" maxOccurs="unbounded">
                                    <element ref="tns:a" />
                                </choice>
                                <element ref="tns:b" />
                            </choice>
                        </sequence>
                    </complexType>
                </element>
                <element name="a" type="string" />
                <element name="b" type="string" />
            </schema>
        """))

    schema.set_ns_prefix('tns', 'http://tests.python-zeep.org/')
    container_type = schema.get_element('tns:container')

    item = container_type(_value_1=[{'a': 'item-1'}, {'a': 'item-2'}])
    assert item._value_1[0] == {'a': 'item-1'}
    assert item._value_1[1] == {'a': 'item-2'}

    expected = load_xml("""
        <document>
           <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
               <ns0:a>item-1</ns0:a>
               <ns0:a>item-2</ns0:a>
           </ns0:container>
        </document>
       """)
    node = render_node(container_type, item)
    assert_nodes_equal(node, expected)

    result = container_type.parse(expected[0], schema)
    assert result._value_1[0] == {'a': 'item-1'}
    assert result._value_1[1] == {'a': 'item-2'}

    expected = load_xml("""
        <container xmlns="http://tests.python-zeep.org/">
          <b>1</b>
        </container>
   """)

    result = container_type.parse(expected, schema)
    assert result.b == '1'
开发者ID:tobirl,项目名称:python-zeep,代码行数:54,代码来源:test_xsd_indicators_choice.py


注:本文中的tests.utils.load_xml函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。