本文整理汇总了Python中soaplib.xml.create_xml_element函数的典型用法代码示例。如果您正苦于以下问题:Python create_xml_element函数的具体用法?Python create_xml_element怎么用?Python create_xml_element使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_xml_element函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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