本文整理汇总了Python中soaplib.xml.ElementTree.tostring方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.tostring方法的具体用法?Python ElementTree.tostring怎么用?Python ElementTree.tostring使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类soaplib.xml.ElementTree
的用法示例。
在下文中一共展示了ElementTree.tostring方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index_html
# 需要导入模块: from soaplib.xml import ElementTree [as 别名]
# 或者: from soaplib.xml.ElementTree import tostring [as 别名]
def index_html(self, REQUEST, RESPONSE):
"""Handle an incoming SOAP request or a non-SOAP WSDL query."""
if REQUEST.get('SOAPXML', None) == None: # Not a SOAP Request, return WSDL
return self.service_description(REQUEST, RESPONSE)
try:
# Deserialize the Body of the SOAP Request
payload, header = from_soap(REQUEST.SOAPXML)
methodname = payload.tag.split('}')[-1]
# Look-up the method within our class and obtain its SOAP descriptor
# specifying its arguments signature and return type.
try:
func = getattr(self, methodname)
descriptor = func(_soap_descriptor=True)
except AttributeError:
faultstring = 'No Such SOAP Method: %s' % repr(methodname)
faultcode = 'Server'
fault = make_soap_fault(faultstring, faultcode, detail=None)
resp = ElementTree.tostring(fault, encoding=string_encoding)
RESPONSE.setStatus('NotImplemented', reason=faultstring)
RESPONSE.setHeader('Content-Type', 'text/xml')
return resp
except TypeError, e:
if "unexpected keyword argument '_soap_descriptor'" not in str(e):
raise
faultstring = 'Method %s Exists But Not SOAP-Callable' % repr(methodname)
faultcode = 'Server'
fault = make_soap_fault(faultstring, faultcode, detail=None)
resp = ElementTree.tostring(fault, encoding=string_encoding)
RESPONSE.setStatus('BadRequest', reason=faultstring)
RESPONSE.setHeader('Content-Type', 'text/xml')
return resp
# Run the supplied arguments through the arguments signature and catch
# any argument type or count mismatches.
try:
params = descriptor.inMessage.from_xml(payload)
except Exception, e:
faultstring = "%s: Argument Parse Error" % str(e)
faultcode = '%sFault' % methodname
fault = make_soap_fault(faultstring, faultcode, detail=None)
resp = ElementTree.tostring(fault, encoding=string_encoding)
RESPONSE.setStatus('BadRequest', reason=faultstring)
RESPONSE.setHeader('Content-Type', 'text/xml')
return resp
示例2: __call__
# 需要导入模块: from soaplib.xml import ElementTree [as 别名]
# 或者: from soaplib.xml.ElementTree import tostring [as 别名]
def __call__(self):
faultstring = self.request['faultexc'].__class__.__name__
self.request.response.setStatus('InternalServerError', reason=faultstring)
faultcode = 'Server'
fault = make_soap_fault(faultstring, faultcode, detail=None)
self.request.response.setHeader('Content-Type', 'text/xml')
return ElementTree.tostring(fault, encoding=string_encoding)
示例3: wsdl
# 需要导入模块: from soaplib.xml import ElementTree [as 别名]
# 或者: from soaplib.xml.ElementTree import tostring [as 别名]
#.........这里部分代码省略.........
"http://schemas.xmlsoap.org/ws/2003/03/addressing")
importNode.set("schemaLocation",
"http://schemas.xmlsoap.org/ws/2003/03/addressing/")
reltMessage = create_xml_subelement(root, 'message')
reltMessage.set('name', 'RelatesToHeader')
reltPart = create_xml_subelement(reltMessage, 'part')
reltPart.set('name', 'RelatesTo')
reltPart.set('element', 'wsa:RelatesTo')
replyMessage = create_xml_subelement(root, 'message')
replyMessage.set('name', 'ReplyToHeader')
replyPart = create_xml_subelement(replyMessage, 'part')
replyPart.set('name', 'ReplyTo')
replyPart.set('element', 'wsa:ReplyTo')
idHeader = create_xml_subelement(root, 'message')
idHeader.set('name', 'MessageIDHeader')
idPart = create_xml_subelement(idHeader, 'part')
idPart.set('name', 'MessageID')
idPart.set('element', 'wsa:MessageID')
# make portTypes
callbackPortType = create_xml_subelement(root, 'portType')
callbackPortType.set('name', '%sCallback' % serviceName)
cbServiceName = '%sCallback' % serviceName
cbService = create_xml_subelement(root, 'service')
cbService.set('name', cbServiceName)
cbWsdlPort = create_xml_subelement(cbService, 'port')
cbWsdlPort.set('name', cbServiceName)
cbWsdlPort.set('binding', 'tns:%s' % cbServiceName)
cbAddr = create_xml_subelement(cbWsdlPort,
nsmap.get('soap') + 'address')
cbAddr.set('location', url)
serviceName = self.__class__.__name__.split('.')[-1]
portType = create_xml_subelement(root, 'portType')
portType.set('name', serviceName)
for method in methods:
if method.isCallback:
operation = create_xml_subelement(callbackPortType,
'operation')
else:
operation = create_xml_subelement(portType, 'operation')
operation.set('name', method.name)
params = []
for name, param in method.inMessage.params:
params.append(name)
documentation = create_xml_subelement(operation, 'documentation')
documentation.text = method.doc
operation.set('parameterOrder', method.inMessage.typ)
opInput = create_xml_subelement(operation, 'input')
opInput.set('name', method.inMessage.typ)
opInput.set('message', 'tns:%s' % method.inMessage.typ)
if (len(method.outMessage.params) > 0 and
not method.isCallback and not method.isAsync):
opOutput = create_xml_subelement(operation, 'output')
opOutput.set('name', method.outMessage.typ)
opOutput.set('message', 'tns:%s' % method.outMessage.typ)
# make partner link
plink = create_xml_subelement(root,
nsmap.get('plnk') + 'partnerLinkType')
plink.set('name', serviceName)
role = create_xml_subelement(plink,
nsmap.get('plnk') + 'role')
role.set('name', serviceName)
plinkPortType = create_xml_subelement(role,
nsmap.get('plnk') + 'portType')
plinkPortType.set('name', 'tns:%s' % serviceName)
if hasCallbacks:
role = create_xml_subelement(plink, nsmap.get('plnk') + 'role')
role.set('name', '%sCallback' % serviceName)
plinkPortType = create_xml_subelement(role,
nsmap.get('plnk') + 'portType')
plinkPortType.set('name', 'tns:%sCallback' % serviceName)
self._add_bindings_for_methods(root, serviceName, methods, nsmap)
service = create_xml_subelement(root, 'service')
service.set('name', serviceName)
wsdlPort = create_xml_subelement(service, 'port')
wsdlPort.set('name', serviceName)
wsdlPort.set('binding', 'tns:%s' % serviceName)
addr = create_xml_subelement(wsdlPort, nsmap.get('soap') + 'address')
addr.set('location', url)
wsdl = ElementTree.tostring(root)
wsdl = "<?xml version='1.0' encoding='utf-8' ?>%s" % (wsdl)
#cache the wsdl for next time
self.__wsdl__ = wsdl
return self.__wsdl__
示例4: wsdl
# 需要导入模块: from soaplib.xml import ElementTree [as 别名]
# 或者: from soaplib.xml.ElementTree import tostring [as 别名]
#.........这里部分代码省略.........
# add necessary async headers
# WS-Addressing -> RelatesTo ReplyTo MessageID
# callback porttype
if hasCallbacks:
wsaSchemaNode = create_xml_subelement(types, "schema")
wsaSchemaNode.set("targetNamespace", tns + "Callback")
wsaSchemaNode.set("xmlns", "http://www.w3.org/2001/XMLSchema")
importNode = create_xml_subelement(wsaSchemaNode, "import")
importNode.set("namespace", "http://schemas.xmlsoap.org/ws/2003/03/addressing")
importNode.set("schemaLocation", "http://schemas.xmlsoap.org/ws/2003/03/addressing/")
reltMessage = create_xml_subelement(root, "message")
reltMessage.set("name", "RelatesToHeader")
reltPart = create_xml_subelement(reltMessage, "part")
reltPart.set("name", "RelatesTo")
reltPart.set("element", "wsa:RelatesTo")
replyMessage = create_xml_subelement(root, "message")
replyMessage.set("name", "ReplyToHeader")
replyPart = create_xml_subelement(replyMessage, "part")
replyPart.set("name", "ReplyTo")
replyPart.set("element", "wsa:ReplyTo")
idHeader = create_xml_subelement(root, "message")
idHeader.set("name", "MessageIDHeader")
idPart = create_xml_subelement(idHeader, "part")
idPart.set("name", "MessageID")
idPart.set("element", "wsa:MessageID")
# make portTypes
callbackPortType = create_xml_subelement(root, "portType")
callbackPortType.set("name", "%sCallback" % serviceName)
cbServiceName = "%sCallback" % serviceName
cbService = create_xml_subelement(root, "service")
cbService.set("name", cbServiceName)
cbWsdlPort = create_xml_subelement(cbService, "port")
cbWsdlPort.set("name", cbServiceName)
cbWsdlPort.set("binding", "tns:%s" % cbServiceName)
cbAddr = create_xml_subelement(cbWsdlPort, nsmap.get("soap") + "address")
cbAddr.set("location", url)
serviceName = self.__class__.__name__.split(".")[-1]
portType = create_xml_subelement(root, "portType")
portType.set("name", serviceName)
for method in methods:
if method.isCallback:
operation = create_xml_subelement(callbackPortType, "operation")
else:
operation = create_xml_subelement(portType, "operation")
operation.set("name", method.name)
params = []
for name, param in method.inMessage.params:
params.append(name)
documentation = create_xml_subelement(operation, "documentation")
documentation.text = method.doc
operation.set("parameterOrder", method.inMessage.typ)
opInput = create_xml_subelement(operation, "input")
opInput.set("name", method.inMessage.typ)
opInput.set("message", "tns:%s" % method.inMessage.typ)
if method.outMessage.params != None and not method.isCallback and not method.isAsync:
opOutput = create_xml_subelement(operation, "output")
opOutput.set("name", method.outMessage.typ)
opOutput.set("message", "tns:%s" % method.outMessage.typ)
# make partner link
plink = create_xml_subelement(root, nsmap.get("plnk") + "partnerLinkType")
plink.set("name", serviceName)
role = create_xml_subelement(plink, nsmap.get("plnk") + "role")
role.set("name", serviceName)
plinkPortType = create_xml_subelement(role, nsmap.get("plnk") + "portType")
plinkPortType.set("name", "tns:%s" % serviceName)
if hasCallbacks:
role = create_xml_subelement(plink, nsmap.get("plnk") + "role")
role.set("name", "%sCallback" % serviceName)
plinkPortType = create_xml_subelement(role, nsmap.get("plnk") + "portType")
plinkPortType.set("name", "tns:%sCallback" % serviceName)
self._add_bindings_for_methods(root, serviceName, methods, nsmap)
service = create_xml_subelement(root, "service")
service.set("name", serviceName)
wsdlPort = create_xml_subelement(service, "port")
wsdlPort.set("name", serviceName)
wsdlPort.set("binding", "tns:%s" % serviceName)
addr = create_xml_subelement(wsdlPort, nsmap.get("soap") + "address")
addr.set("location", url)
wsdl = ElementTree.tostring(root)
wsdl = "<?xml version='1.0' encoding='utf-8' ?>%s" % (wsdl)
# cache the wsdl for next time
self.__wsdl__ = wsdl
return self.__wsdl__
示例5: make_soap_envelope
# 需要导入模块: from soaplib.xml import ElementTree [as 别名]
# 或者: from soaplib.xml.ElementTree import tostring [as 别名]
envelope = make_soap_envelope(results, tns=self.__tns__)
resp = ElementTree.tostring(envelope, encoding=string_encoding)
RESPONSE.setHeader('Content-Type', 'text/xml')
return resp
except Exception, e:
faultstring = str(e)
if methodname:
faultcode = '%sFault' % methodname
else:
faultcode = 'Server'
fault = make_soap_fault(faultstring, faultcode, detail=None)
resp = ElementTree.tostring(fault, encoding=string_encoding)
RESPONSE.setStatus('InternalServerError', reason=faultstring)
RESPONSE.setHeader('Content-Type', 'text/xml')
return resp
class ISOAPException(IException):
pass
class SOAPException(Exception):
"""Base exception class for all derived exceptions for SOAP"""
implements(ISOAPException)