本文整理汇总了Python中suds.byte_str函数的典型用法代码示例。如果您正苦于以下问题:Python byte_str函数的具体用法?Python byte_str怎么用?Python byte_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了byte_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_DocumentCache
def test_DocumentCache(tmpdir):
cacheFolder = tmpdir.join("puffy").strpath
cache = suds.cache.DocumentCache(cacheFolder)
assert isinstance(cache, suds.cache.FileCache)
assert cache.get("unga1") is None
# TODO: DocumentCache class interface seems silly. Its get() operation
# returns an XML document while its put() operation takes an XML element.
# The put() operation also silently ignores passed data of incorrect type.
# TODO: Update this test to no longer depend on the exact input XML data
# formatting. We currently expect it to be formatted exactly as what gets
# read back from the DocumentCache.
content = suds.byte_str("""\
<xsd:element name="Elemento">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="alfa"/>
<xsd:enumeration value="beta"/>
<xsd:enumeration value="gamma"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>""")
xml = suds.sax.parser.Parser().parse(suds.BytesIO(content))
cache.put("unga1", xml.getChildren()[0])
readXML = cache.get("unga1")
assert isinstance(readXML, suds.sax.document.Document)
readXMLElements = readXML.getChildren()
assert len(readXMLElements) == 1
readXMLElement = readXMLElements[0]
assert isinstance(readXMLElement, suds.sax.element.Element)
assert suds.byte_str(str(readXMLElement)) == content
示例2: test_avoid_imported_WSDL_fetching
def test_avoid_imported_WSDL_fetching(self):
# Prepare data.
url_imported = "suds://wsdl_imported"
wsdl_import_wrapper = wsdl_import_wrapper_format % (url_imported,)
wsdl_import_wrapper = suds.byte_str(wsdl_import_wrapper)
wsdl_imported = suds.byte_str(wsdl_imported_format % ("",))
# Add to cache.
cache = MockCache()
store1 = MockDocumentStore(wsdl=wsdl_import_wrapper,
wsdl_imported=wsdl_imported)
c1 = suds.client.Client("suds://wsdl", cachingpolicy=1,
cache=cache, documentStore=store1, transport=MockTransport())
assert store1.mock_log == ["suds://wsdl", "suds://wsdl_imported"]
assert len(cache.mock_data) == 1
wsdl_object_id, wsdl_object = cache.mock_data.items()[0]
assert wsdl_object.__class__ is suds.wsdl.Definitions
# Reuse from cache.
cache.mock_operation_log = []
store2 = MockDocumentStore(wsdl=wsdl_import_wrapper)
c2 = suds.client.Client("suds://wsdl", cachingpolicy=1,
cache=cache, documentStore=store2, transport=MockTransport())
assert cache.mock_operation_log == [("get", [wsdl_object_id])]
assert store2.mock_log == []
示例3: test_imported_WSDL_transport
def test_imported_WSDL_transport(self, url):
wsdl_import_wrapper = wsdl_import_wrapper_format % (url,)
wsdl_imported = suds.byte_str(wsdl_imported_format % ("",))
store = MockDocumentStore(wsdl=suds.byte_str(wsdl_import_wrapper))
t = MockTransport(open_data=wsdl_imported)
suds.client.Client("suds://wsdl", cache=None, documentStore=store, transport=t)
assert t.mock_log == [("open", [url])]
示例4: test_avoid_external_XSD_fetching
def test_avoid_external_XSD_fetching(self):
# Prepare document content.
xsd_target_namespace = "balancana"
wsdl = tests.wsdl("""\
<xsd:import schemaLocation="suds://imported_xsd"/>
<xsd:include schemaLocation="suds://included_xsd"/>""",
xsd_target_namespace=xsd_target_namespace)
external_xsd_format = """\
<?xml version='1.0' encoding='UTF-8'?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="external%d" type="string"/>
</schema>"""
external_xsd1 = suds.byte_str(external_xsd_format % (1,))
external_xsd2 = suds.byte_str(external_xsd_format % (2,))
# Add to cache.
cache = MockCache()
store1 = MockDocumentStore(wsdl=wsdl, imported_xsd=external_xsd1,
included_xsd=external_xsd2)
c1 = suds.client.Client("suds://wsdl", cachingpolicy=1,
cache=cache, documentStore=store1, transport=MockTransport())
assert store1.mock_log == ["suds://wsdl", "suds://imported_xsd",
"suds://included_xsd"]
assert len(cache.mock_data) == 1
wsdl_object_id, wsdl_object = cache.mock_data.items()[0]
assert wsdl_object.__class__ is suds.wsdl.Definitions
# Reuse from cache.
cache.mock_operation_log = []
store2 = MockDocumentStore(wsdl=wsdl)
c2 = suds.client.Client("suds://wsdl", cachingpolicy=1,
cache=cache, documentStore=store2, transport=MockTransport())
assert cache.mock_operation_log == [("get", [wsdl_object_id])]
assert store2.mock_log == []
示例5: open
def open(self, request):
if "?wsdl" in request.url:
return suds.BytesIO(suds.byte_str(WSDL))
elif "?xsd" in request.url:
return suds.BytesIO(suds.byte_str(XSD))
pytest.fail("No supported open request url: {}".format(request.url))
示例6: test_accessing_DocumentStore_content
def test_accessing_DocumentStore_content():
content1 = suds.byte_str("one")
content2 = suds.byte_str("two")
content1_1 = suds.byte_str("one one")
store = suds.store.DocumentStore({"1":content1})
assert len(store) == 2
__test_default_DocumentStore_content(store)
__test_open(store, "1", content1)
store = suds.store.DocumentStore({"1":content1, "2":content2})
assert len(store) == 3
__test_default_DocumentStore_content(store)
__test_open(store, "1", content1)
__test_open(store, "2", content2)
store = suds.store.DocumentStore(uno=content1, due=content2)
assert len(store) == 3
__test_default_DocumentStore_content(store)
__test_open(store, "uno", content1)
__test_open(store, "due", content2)
store = suds.store.DocumentStore({"1 1":content1_1})
assert len(store) == 2
__test_default_DocumentStore_content(store)
__test_open(store, "1 1", content1_1)
store = suds.store.DocumentStore({"1":content1, "1 1":content1_1})
assert len(store) == 3
__test_default_DocumentStore_content(store)
__test_open(store, "1", content1)
__test_open(store, "1 1", content1_1)
示例7: test_wrapped_sequence_output
def test_wrapped_sequence_output():
client = testutils.lxmlclient_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result1" type="xsd:string"/>
<xsd:element name="result2" type="xsd:string"/>
<xsd:element name="result3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"))
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<result1>Uno</result1>
<result2>Due</result2>
<result3>Tre</result3>
</Wrapper>
</Body>
</Envelope>""")))
# Check response content.
assert len(response) == 3
assert response.result1 == "Uno"
assert response.result2 == "Due"
assert response.result3 == "Tre"
assert_lxml_string_value(response.result1)
assert_lxml_string_value(response.result2)
assert_lxml_string_value(response.result3)
client = testutils.lxmlclient_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result1" type="xsd:string"/>
<xsd:element name="result2" type="xsd:string"/>
<xsd:element name="result3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"))
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
</Wrapper>
</Body>
</Envelope>""")))
# Check response content.
assert len(response) == 3
assert response.result1 is None
assert response.result2 is None
assert response.result3 is None
示例8: test_string_representation_with_no_message
def test_string_representation_with_no_message(self):
url = "look at my silly little URL"
headers = {suds.byte_str("yuck"): suds.byte_str("ptooiii...")}
request = Request(url)
request.headers = headers
expected = u("""\
URL: %s
HEADERS: %s""") % (url, request.headers)
assert text_type(request) == expected
if sys.version_info < (3,):
assert str(request) == expected.encode("utf-8")
示例9: test_disabling_automated_simple_interface_unwrapping
def test_disabling_automated_simple_interface_unwrapping():
client = testutils.client_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Elemento" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>""", output="Wrapper"), unwrap=False)
assert not _isOutputWrapped(client, "f")
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<Elemento>La-di-da-da-da</Elemento>
</Wrapper>
</Body>
</Envelope>""")))
assert response.__class__.__name__ == "Wrapper"
assert len(response.__class__.__bases__) == 1
assert response.__class__.__bases__[0] is suds.sudsobject.Object
assert response.Elemento.__class__ is suds.sax.text.Text
assert response.Elemento == "La-di-da-da-da"
示例10: construct_XML
def construct_XML(element_name="Elemento"):
"""
Construct XML content and an Element wrapping it.
Constructed content may be parametrized with the given element name.
"""
# TODO: Update the tests in this group to no longer depend on the exact
# input XML data formatting. They currently expect it to be formatted
# exactly as what gets read back from their DocumentCache.
content = suds.byte_str("""\
<xsd:element name="%s">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="alfa"/>
<xsd:enumeration value="beta"/>
<xsd:enumeration value="gamma"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>""" % (element_name,))
xml = suds.sax.parser.Parser().parse(suds.BytesIO(content))
children = xml.getChildren()
assert len(children) == 1
assert children[0].__class__ is suds.sax.element.Element
return content, children[0]
示例11: test_fault_reply_with_unicode_faultstring
def test_fault_reply_with_unicode_faultstring(monkeypatch):
monkeypatch.delitem(locals(), "e", False)
unicode_string = "€ Jurko Gospodnetić ČĆŽŠĐčćžšđ"
fault_xml = suds.byte_str("""\
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault>
<faultcode>env:Client</faultcode>
<faultstring>%s</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
""" % unicode_string)
client = tests.client_from_wsdl(_wsdl__simple, faults=True)
inject = dict(reply=fault_xml, status=http.client.INTERNAL_SERVER_ERROR)
e = pytest.raises(suds.WebFault, client.service.f, __inject=inject).value
assert e.fault.faultstring == unicode_string
assert e.document.__class__ is suds.sax.document.Document
client = tests.client_from_wsdl(_wsdl__simple, faults=False)
status, fault = client.service.f(__inject=dict(reply=fault_xml,
status=http.client.INTERNAL_SERVER_ERROR))
assert status == http.client.INTERNAL_SERVER_ERROR
assert fault.faultstring == unicode_string
示例12: test_SOAP_headers
def test_SOAP_headers():
"""Rudimentary 'soapheaders' option usage test."""
wsdl = suds.byte_str("""\
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions targetNamespace="my-target-namespace"
xmlns:tns="my-target-namespace"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified"
targetNamespace="my-target-namespace">
<s:element name="MyHeader">
<s:complexType>
<s:sequence>
<s:element name="Freaky" type="s:hexBinary"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="myOperationHeader">
<wsdl:part name="MyHeader" element="tns:MyHeader"/>
</wsdl:message>
<wsdl:portType name="MyWSSOAP">
<wsdl:operation name="my_operation"/>
</wsdl:portType>
<wsdl:binding name="MyWSSOAP" type="tns:MyWSSOAP">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="my_operation">
<soap:operation soapAction="my-SOAP-action" style="document"/>
<wsdl:input>
<soap:header message="tns:myOperationHeader" part="MyHeader"
use="literal"/>
</wsdl:input>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyWS">
<wsdl:port name="MyWSSOAP" binding="tns:MyWSSOAP">
<soap:address location="protocol://my-WS-URL"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
""")
header_data = "fools rush in where angels fear to tread"
client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True)
client.options.soapheaders = header_data
_assert_request_content(client.service.my_operation(), """\
<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header>
<MyHeader xmlns="my-target-namespace">%s</MyHeader>
</Header>
<Body/>
</Envelope>""" % (header_data,))
示例13: _wsdl_with_no_input_data
def _wsdl_with_no_input_data(url):
"""
Return a WSDL schema with a single operation f taking no parameters.
Included operation returns no values. Externally specified URL is used as
the web service location.
"""
return suds.byte_str(u"""\
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions targetNamespace="myNamespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="myNamespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:portType name="Port">
<wsdl:operation name="f"/>
</wsdl:portType>
<wsdl:binding name="Binding" type="tns:Port">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="f"/>
</wsdl:binding>
<wsdl:service name="Service">
<wsdl:port name="Port" binding="tns:Binding">
<soap:address location="%s"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>""" % (url,))
示例14: test_fault_reply_with_unicode_faultstring
def test_fault_reply_with_unicode_faultstring(monkeypatch):
monkeypatch.delitem(locals(), "e", False)
unicode_string = u("\\u20AC Jurko Gospodneti\\u0107 "
"\\u010C\\u0106\\u017D\\u0160\\u0110"
"\\u010D\\u0107\\u017E\\u0161\\u0111")
fault_xml = suds.byte_str(u("""\
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault>
<faultcode>env:Client</faultcode>
<faultstring>%s</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
""") % (unicode_string,))
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True)
inject = dict(reply=fault_xml, status=http_client.INTERNAL_SERVER_ERROR)
e = pytest.raises(suds.WebFault, client.service.f, __inject=inject).value
try:
assert e.fault.faultstring == unicode_string
assert e.document.__class__ is suds.sax.document.Document
finally:
del e # explicitly break circular reference chain in Python 3
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False)
status, fault = client.service.f(__inject=dict(reply=fault_xml,
status=http_client.INTERNAL_SERVER_ERROR))
assert status == http_client.INTERNAL_SERVER_ERROR
assert fault.faultstring == unicode_string
示例15: test_enum
def test_enum():
client = testutils.lxmlclient_from_wsdl(testutils.wsdl("""\
<xsd:element name="Wrapper">
<xsd:element name="Size">
<xsd:simpleType name="DataSize">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="1" />
<xsd:enumeration value="2"/>
<xsd:enumeration value="3"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:element>""", output="Wrapper"))
response = client.service.f(__inject=dict(reply=suds.byte_str("""\
<?xml version="1.0"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<Wrapper xmlns="my-namespace">
<DataSize>1</DataSize>
</Wrapper>
</Body>
</Envelope>""")))
# Check response content.
assert len(response) == 1
assert response.size == 1