本文整理汇总了Python中soaplib.xml.create_xml_element函数的典型用法代码示例。如果您正苦于以下问题:Python create_xml_element函数的具体用法?Python create_xml_element怎么用?Python create_xml_element使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_xml_element函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_to_schema
def add_to_schema(cls, schemaDict, nsmap):
if not cls.get_datatype(nsmap) in schemaDict:
for k, v in cls.soap_members.items():
v.add_to_schema(schemaDict, nsmap)
schema_node = create_xml_element(
nsmap.get("xs") + "complexType", nsmap)
schema_node.set('name', cls.__name__)
sequence_node = create_xml_subelement(
schema_node, nsmap.get('xs') + 'sequence')
for k, v in cls.soap_members.items():
member_node = create_xml_subelement(
sequence_node, nsmap.get('xs') + 'element')
member_node.set('name', k)
member_node.set('minOccurs', '0')
member_node.set('type',
"%s:%s" % (v.get_namespace_id(), v.get_datatype()))
typeElement = create_xml_element(
nsmap.get('xs') + 'element', nsmap)
typeElement.set('name', cls.__name__)
typeElement.set('type',
"%s:%s" % (cls.get_namespace_id(), cls.__name__))
schemaDict[cls.get_datatype(nsmap)+'Complex'] = schema_node
schemaDict[cls.get_datatype(nsmap)] = typeElement
开发者ID:rjbalest,项目名称:soaplib,代码行数:26,代码来源:clazz.py
示例2: _add_messages_for_methods
def _add_messages_for_methods(self, root, methods, nsmap):
"""
A private method for adding message elements to the wsdl
@param the the root element of the wsdl
@param the list of methods.
"""
messages = []
# make messages
for method in methods:
methodName = method.name
# making in part
inMessage = create_xml_element("message", nsmap)
inMessage.set("name", method.inMessage.typ)
if len(method.inMessage.params) > 0:
inPart = create_xml_subelement(inMessage, "part")
inPart.set("name", method.inMessage.name)
inPart.set("element", "tns:" + method.inMessage.typ)
messages.append(inMessage)
# making out part
outMessage = create_xml_element("message", nsmap)
outMessage.set("name", method.outMessage.typ)
if len(method.outMessage.params) > 0:
outPart = create_xml_subelement(outMessage, "part")
outPart.set("name", method.outMessage.name)
outPart.set("element", "tns:" + method.outMessage.typ)
messages.append(outMessage)
for message in messages:
root.append(message)
开发者ID:rjbalest,项目名称:soaplib,代码行数:32,代码来源:service.py
示例3: _add_messages_for_methods
def _add_messages_for_methods(self, root, methods, nsmap):
'''
A private method for adding message elements to the wsdl
@param the the root element of the wsdl
@param the list of methods.
'''
messages = []
#make messages
for method in methods:
methodName = method.name
# making in part
inMessage = create_xml_element('message', nsmap)
inMessage.set('name', method.inMessage.typ)
inPart = create_xml_subelement(inMessage, 'part')
inPart.set('name', method.inMessage.name)
inPart.set('element', 'tns:' + method.inMessage.typ)
messages.append(inMessage)
# making out part only if necessary
if len(method.outMessage.params) > 0:
outMessage = create_xml_element('message', nsmap)
outMessage.set('name', method.outMessage.typ)
outPart = create_xml_subelement(outMessage, 'part')
outPart.set('name', method.outMessage.name)
outPart.set('element', 'tns:' + method.outMessage.typ)
messages.append(outMessage)
for message in messages:
root.append(message)
开发者ID:Proga,项目名称:soaplib,代码行数:31,代码来源:service.py
示例4: add_to_schema
def add_to_schema(self,schema_dict,nsmap):
typ = self.get_datatype()
self.serializer.add_to_schema(schema_dict, nsmap)
if not schema_dict.has_key(typ):
complexTypeNode = create_xml_element(
nsmap.get('xs') + 'complexType', nsmap)
complexTypeNode.set('name',self.get_datatype())
sequenceNode = create_xml_subelement(
complexTypeNode, nsmap.get('xs') + 'sequence')
elementNode = create_xml_subelement(
sequenceNode, nsmap.get('xs') + 'element')
elementNode.set('minOccurs','0')
elementNode.set('maxOccurs','unbounded')
print self.serializer.get_namespace_id()
elementNode.set('type',
"%s:%s" % (self.serializer.get_namespace_id(), self.serializer.get_datatype()))
elementNode.set('name',self.serializer.get_datatype())
typeElement = create_xml_element(
nsmap.get('xs') + 'element', nsmap)
typeElement.set('name',typ)
typeElement.set('type',
"%s:%s" % (self.namespace_id, self.get_datatype()))
schema_dict['%sElement'%(self.get_datatype(nsmap))] = typeElement
schema_dict[self.get_datatype(nsmap)] = complexTypeNode
开发者ID:finalbattle,项目名称:torweb,代码行数:30,代码来源:primitive.py
示例5: make_soap_fault
def make_soap_fault(faultString, faultCode = 'Server', detail = None,
header_elements = None):
'''
This method populates a soap fault message with the provided
fault string and details.
@param faultString the short description of the error
@param detail the details of the exception, such as a stack trace
@param faultCode defaults to 'Server', but can be overridden
@param header_elements A list of XML elements to add to the fault header.
@returns the element corresponding to the fault message
'''
nsmap = NamespaceLookup()
envelope = create_xml_element(nsmap.get('SOAP-ENV') + 'Envelope', nsmap)
if header_elements:
header = create_xml_subelement(
envelope, nsmap.get('SOAP-ENV') + 'Header')
for element in header_elements:
header.append(element)
body = create_xml_subelement(envelope, nsmap.get('SOAP-ENV') + 'Body')
f = Fault(faultCode,faultString,detail)
body.append(Fault.to_xml(f, nsmap.get('SOAP-ENV') + "Fault", nsmap))
return envelope
开发者ID:finalbattle,项目名称:torweb,代码行数:27,代码来源:soap.py
示例6: to_xml
def to_xml(self, *data):
if len(self.params):
if len(self.params) >= 2:
data = data[0]
if len(data) != len(self.params):
raise Exception(
"Parameter number mismatch expected [%s] "
"got [%s] for response %s" % (len(self.params), len(data), self.name)
)
nsmap = NamespaceLookup(self.ns)
element = create_xml_element(self.name, nsmap, self.ns)
for i in range(0, len(self.params)):
name, serializer = self.params[i]
d = data[i]
e = serializer.to_xml(d, name, nsmap)
if type(e) in (list, tuple):
elist = e
for e in elist:
element.append(e)
elif e == None:
pass
else:
element.append(e)
ElementTree.cleanup_namespaces(element)
return element
开发者ID:vbabiy,项目名称:soaplib,代码行数:28,代码来源:soap.py
示例7: make_soap_envelope
def make_soap_envelope(message, tns='', header_elements=None):
'''
This method takes the results from a soap method call, and wraps them
in the appropriate soap envelope with any specified headers
@param the message of the soap envelope, either an element or
a list of elements
@param any header elements to be included in the soap response
@returns the envelope element
'''
nsmap = NamespaceLookup(tns)
envelope = create_xml_element(nsmap.get('SOAP-ENV') + 'Envelope', nsmap,
tns)
if header_elements:
headerElement = create_xml_subelement(envelope,
nsmap.get('SOAP-ENV') + 'Header')
for h in header_elements:
headerElement.append(h)
body = create_xml_subelement(envelope, nsmap.get('SOAP-ENV') + 'Body')
if type(message) == list:
for m in message:
body.append(m)
elif message != None:
body.append(message)
return envelope
开发者ID:curtainsky,项目名称:soaplib,代码行数:25,代码来源:soap.py
示例8: to_xml
def to_xml(cls, value, name='retval', nsmap=ns):
'''This class method takes the data from the attachment and
base64 encodes it as the text of an Element. An attachment can
specify a filename and if no data is given, it will read the data
from the file
'''
if value.__class__ is not Attachment:
raise Exception("Do not know how to serialize class %s" %
type(value))
element = create_xml_element(name, nsmap)
if value.data:
# the data has already been loaded, just encode
# and return the element
element.text = base64.encodestring(value.data)
elif value.fileName:
# the data hasn't been loaded, but a file has been
# specified
data_string = cStringIO.StringIO()
fileName = value.fileName
file = open(fileName, 'rb')
base64.encode(file, data_string)
file.close()
# go back to the begining of the data
data_string.seek(0)
element.text = str(data_string.read())
else:
raise Exception("Neither data nor a filename has been specified")
return element
开发者ID:edevil,项目名称:soaplib,代码行数:32,代码来源:binary.py
示例9: to_xml
def to_xml(cls, value, name='retval', nsmap=ns):
element = create_xml_element(
nsmap.get(cls.get_namespace_id()) + name, nsmap)
####################################################
# RJBALEST: Added 31-Oct-09
# Because namespaces are not getting output,
# explicitly set xmlns as an attribute.
# Otherwise .NET will reject the message.
#
xmlns = nsmap.nsmap[cls.get_namespace_id()]
element.set('xmlns', xmlns)
####################################################
for k, v in cls.soap_members.items():
member_value = getattr(value, k, None)
subvalue = getattr(value, k, None)
if subvalue is None:
v = Null
subelements = v.to_xml(subvalue, name=k, nsmap=nsmap)
if type(subelements) != list:
subelements = [subelements]
for s in subelements:
element.append(s)
return element
开发者ID:rjbalest,项目名称:soaplib,代码行数:27,代码来源:clazz.py
示例10: add_to_schema
def add_to_schema(self, schemaDict, nsmap):
complexType = create_xml_element(nsmap.get("xs") + "complexType", nsmap)
complexType.set("name", self.typ)
sequence = create_xml_subelement(complexType, nsmap.get("xs") + "sequence")
if self.params:
for name, serializer in self.params:
e = create_xml_subelement(sequence, nsmap.get("xs") + "element")
e.set("name", name)
e.set("type", "%s:%s" % (serializer.get_namespace_id(), serializer.get_datatype()))
element = create_xml_element(nsmap.get("xs") + "element", nsmap)
element.set("name", self.typ)
element.set("type", "%s:%s" % ("tns", self.typ))
schemaDict[self.typ] = complexType
schemaDict[self.typ + "Element"] = element
开发者ID:vbabiy,项目名称:soaplib,代码行数:17,代码来源:soap.py
示例11: _generic_to_xml
def _generic_to_xml(value, name, cls, nsmap):
retval = create_xml_element(name, nsmap)
if value:
retval.text = value
retval.set(
nsmap.get('xsi') + 'type',
"%s:%s" % (cls.get_namespace_id(), cls.get_datatype()))
return retval
开发者ID:finalbattle,项目名称:torweb,代码行数:8,代码来源:primitive.py
示例12: add_to_schema
def add_to_schema(self,schemaDict, nsmap):
complexType = create_xml_element(nsmap.get('xs') + 'complexType', nsmap)
complexType.set('name',self.typ)
sequence = create_xml_subelement(complexType, nsmap.get('xs') + 'sequence')
if self.params:
for name,serializer in self.params:
e = create_xml_subelement(sequence, nsmap.get('xs') + 'element')
e.set('name',name)
e.set('type',
"%s:%s" % (serializer.get_namespace_id(), serializer.get_datatype()))
element = create_xml_element(nsmap.get('xs') + 'element', nsmap)
element.set('name',self.typ)
element.set('type','%s:%s' % ('tns',self.typ))
schemaDict[self.typ] = complexType
schemaDict[self.typ+'Element'] = element
开发者ID:finalbattle,项目名称:torweb,代码行数:18,代码来源:soap.py
示例13: test_utcdatetime
def test_utcdatetime(self):
datestring = '2007-05-15T13:40:44Z'
e = create_xml_element('test', ns)
e.text = datestring
dt = DateTime.from_xml(e)
self.assertEquals(dt.year, 2007)
self.assertEquals(dt.month, 5)
self.assertEquals(dt.day, 15)
datestring = '2007-05-15T13:40:44.003Z'
e = create_xml_element('test', ns)
e.text = datestring
dt = DateTime.from_xml(e)
self.assertEquals(dt.year, 2007)
self.assertEquals(dt.month, 5)
self.assertEquals(dt.day, 15)
开发者ID:pfw,项目名称:soaplib,代码行数:20,代码来源:primitive_test.py
示例14: _unicode_to_xml
def _unicode_to_xml(value, name, cls, nsmap):
retval = create_xml_element(name, nsmap)
if value == None:
return Null.to_xml(value,name,nsmap)
if type(value) == unicode:
retval.text = value
else:
retval.text = unicode(value,string_encoding)
retval.set(
nsmap.get('xsi') + 'type',
"%s:%s" % (cls.get_namespace_id(), cls.get_datatype()))
return retval
开发者ID:finalbattle,项目名称:torweb,代码行数:12,代码来源:primitive.py
示例15: to_xml
def to_xml(self,values,name='retval',nsmap=ns):
res = create_xml_element(name, nsmap)
typ = self.get_datatype(nsmap)
if values == None:
values = []
res.set('type',
"%s:%s" % (self.get_namespace_id(), self.get_datatype()))
for value in values:
serializer = self.serializer
if value == None:
serializer = Null
res.append(
serializer.to_xml(value, serializer.get_datatype(), nsmap))
return res
开发者ID:finalbattle,项目名称:torweb,代码行数:14,代码来源:primitive.py
示例16: to_xml
def to_xml(cls,value,name='retval', nsmap=ns):
element = create_xml_element(
nsmap.get(cls.get_namespace_id()) + name, nsmap)
for k,v in cls.soap_members.items():
member_value = getattr(value,k,None)
subvalue = getattr(value,k,None)
if subvalue is None:
v = Null
subelements = v.to_xml(subvalue,name=k,nsmap=nsmap)
if type(subelements) != list:
subelements = [subelements]
for s in subelements:
element.append(s)
return element
开发者ID:akkmzack,项目名称:RIOS-8.5,代码行数:17,代码来源:clazz.py
示例17: to_xml
def to_xml(cls, value, name='retval', nsmap=ns):
element = create_xml_element(
nsmap.get(cls.get_namespace_id()) + name, nsmap)
# Because namespaces are not getting output, explicitly set xmlns as an
# attribute. Otherwise .NET will reject the message.
if None not in nsmap.nsmap and cls.get_namespace_id() in nsmap.nsmap:
xmlns = nsmap.nsmap[cls.get_namespace_id()]
element.set('xmlns', xmlns)
for k, v in cls.soap_members.items():
subvalue = getattr(value, k, None)
subelements = v.to_xml(subvalue, name=k, nsmap=nsmap)
if type(subelements) != list:
subelements = [subelements]
for s in subelements:
element.append(s)
return element
开发者ID:Proga,项目名称:soaplib,代码行数:18,代码来源:clazz.py
示例18: make_soap_envelope
def make_soap_envelope(message, tns='', header_elements=None):
'''
This method takes the results from a soap method call, and wraps them
in the appropriate soap envelope with any specified headers
@param the message of the soap envelope, either an element or
a list of elements
@param any header elements to be included in the soap response
@returns the envelope element
'''
nsmap = NamespaceLookup(tns)
envelope = create_xml_element(nsmap.get('SOAP-ENV') + 'Envelope', nsmap,
tns)
if header_elements:
headerElement = create_xml_subelement(envelope,
nsmap.get('SOAP-ENV') + 'Header')
for h in header_elements:
headerElement.append(h)
body = create_xml_subelement(envelope, nsmap.get('SOAP-ENV') + 'Body')
######################################
# RJBALEST:
# Get the default namespace
#
xmlns = message.nsmap[None]
######################################
if type(message) == list:
for m in message:
body.append(m)
elif message != None:
body.append(message)
######################################
# RJBALEST:
# Set xmlns as a normal attribute so it doesn't
# get cleanup up and is guaranteed to remain.
#
message.set('xmlns', xmlns)
######################################
return envelope
开发者ID:rjbalest,项目名称:soaplib,代码行数:42,代码来源:soap.py
示例19: wsdl
def wsdl(self, url):
'''
This method generates and caches the wsdl for this object based
on the soap methods designated by the soapmethod or soapdocument
descriptors
@param url the url that this service can be found at. This must be
passed in by the caller because this object has no notion of the
server environment in which it runs.
@returns the string of the wsdl
'''
if not self.__wsdl__ == None:
# return the cached __wsdl__
return self.__wsdl__
url = url.replace('.wsdl', '')
# otherwise build it
serviceName = self.__class__.__name__.split('.')[-1]
tns = self.__tns__
methods = self.methods()
hasCallbacks = self._hasCallbacks()
nsmap = NamespaceLookup(tns, True)
if hasCallbacks:
nsmap.set('wsa',
'http://schemas.xmlsoap.org/ws/2003/03/addressing')
root = create_xml_element(
"definitions", nsmap, 'http://schemas.xmlsoap.org/wsdl/')
root.set('targetNamespace', tns)
root.set('name', serviceName)
types = create_xml_subelement(root, "types")
self._add_schema(types, methods, nsmap)
self._add_messages_for_methods(root, methods, nsmap)
# 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")
wsaSchemaNode.set("elementFormDefault", "qualified")
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)
#.........这里部分代码省略.........
开发者ID:Proga,项目名称:soaplib,代码行数:101,代码来源:service.py
示例20: _add_bindings_for_methods
def _add_bindings_for_methods(self, root, serviceName, methods, nsmap):
"""
A private method for adding bindings to the wsdld
@param the root element of the wsdl
@param the name of this service
@param the methods to be add to the binding node
"""
hasCallbacks = self._hasCallbacks()
# make binding
binding = create_xml_subelement(root, "binding")
binding.set("name", serviceName)
binding.set("type", "tns:%s" % serviceName)
sbinding = create_xml_subelement(binding, nsmap.get("soap") + "binding")
sbinding.set("style", "document")
sbinding.set("transport", "http://schemas.xmlsoap.org/soap/http")
if hasCallbacks:
callbackBinding = create_xml_subelement(root, "binding")
callbackBinding.set("name", "%sCallback" % serviceName)
callbackBinding.set("type", "typens:%sCallback" % serviceName)
sbinding = create_xml_subelement(callbackBinding, nsmap.get("soap") + "binding")
sbinding.set("transport", "http://schemas.xmlsoap.org/soap/http")
for method in methods:
operation = create_xml_element("operation", nsmap)
operation.set("name", method.name)
soapOperation = create_xml_subelement(operation, nsmap.get("soap") + "operation")
soapOperation.set("soapAction", method.soapAction)
soapOperation.set("style", "document")
input = create_xml_subelement(operation, "input")
input.set("name", method.inMessage.typ)
soapBody = create_xml_subelement(input, nsmap.get("soap") + "body")
soapBody.set("use", "literal")
if method.outMessage.params != None and not method.isAsync and not method.isCallback:
output = create_xml_subelement(operation, "output")
output.set("name", method.outMessage.typ)
soapBody = create_xml_subelement(output, nsmap.get("soap") + "body")
soapBody.set("use", "literal")
if method.isCallback:
relatesTo = create_xml_subelement(input, nsmap.get("soap") + "header")
relatesTo.set("message", "tns:RelatesToHeader")
relatesTo.set("part", "RelatesTo")
relatesTo.set("use", "literal")
callbackBinding.append(operation)
else:
if method.isAsync:
rtHeader = create_xml_subelement(input, nsmap.get("soap") + "header")
rtHeader.set("message", "tns:ReplyToHeader")
rtHeader.set("part", "ReplyTo")
rtHeader.set("use", "literal")
midHeader = create_xml_subelement(input, nsmap.get("soap") + "header")
midHeader.set("message", "tns:MessageIDHeader")
midHeader.set("part", "MessageID")
midHeader.set("use", "literal")
binding.append(operation)
开发者ID:rjbalest,项目名称:soaplib,代码行数:64,代码来源:service.py
注:本文中的soaplib.xml.create_xml_element函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论