本文整理汇总了Python中pysimplesoap.simplexml.SimpleXMLElement.unmarshall方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLElement.unmarshall方法的具体用法?Python SimpleXMLElement.unmarshall怎么用?Python SimpleXMLElement.unmarshall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysimplesoap.simplexml.SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement.unmarshall方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: desserializar
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def desserializar(xml):
"Analiza un XML y devuelve un diccionario"
xml = SimpleXMLElement(xml)
dic = xml.unmarshall(XML_FORMAT, strict=True)
regs = []
for dic_comprobante in dic['comprobantes']:
reg = {
'detalles': [],
'ivas': [],
'tributos': [],
'permisos': [],
'cmps_asocs': [],
}
comp = dic_comprobante['comprobante']
mapear(reg, comp, MAP_ENC)
reg['forma_pago']= ''.join([d['formapago']['descripcion'] for d in comp['formaspago']])
for detalles in comp['detalles']:
det = detalles['detalle']
reg['detalles'].append(mapear({}, det, MAP_DET))
for ivas in comp['ivas']:
iva = ivas['iva']
reg['ivas'].append(mapear({}, iva, MAP_IVA))
for tributos in comp['tributos']:
tributo = tributos['tributo']
reg['tributos'].append(mapear({}, tributo, MAP_TRIB))
regs.append(reg)
return regs
示例2: test_multiple_element_unmarshall_one
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def test_multiple_element_unmarshall_one(self):
xml = """
<results>
<foo>bar</foo>
</results>
"""
span = SimpleXMLElement(xml)
d = {'results': {'foo': [str]}}
e = {'results': {'foo': ['bar']}}
self.eq(span.unmarshall(d), e)
示例3: test_unmarshall
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def test_unmarshall(self):
span = SimpleXMLElement('<span><name>foo</name><value>3</value></span>')
d = {'span': {'name': str, 'value': int}}
e = {'span': {'name': 'foo', 'value': 3}}
self.eq(span.unmarshall(d), e)
span = SimpleXMLElement('<span><name>foo</name><name>bar</name></span>')
d = {'span': [{'name': str}]}
e = {'span': [{'name': 'foo'}, {'name': 'bar'}]}
self.eq(span.unmarshall(d), e)
span = SimpleXMLElement('<activations><items><number>01234</number><status>1</status></items><items><number>04321</number><status>0</status></items></activations>')
d = {'activations': [
{'items': {
'number': str,
'status': int
}}
]}
e = {'activations': [{'items': {'number': '01234', 'status': 1}}, {'items': {'number': '04321', 'status': 0}}]}
self.eq(span.unmarshall(d), e)
示例4: test_adv_unmarshall
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def test_adv_unmarshall(self):
xml = """
<activations>
<items>
<number>01234</number>
<status>1</status>
<properties>
<name>foo</name>
<value>3</value>
</properties>
<properties>
<name>bar</name>
<value>4</value>
</properties>
</items>
<items>
<number>04321</number>
<status>0</status>
</items>
</activations>
"""
span = SimpleXMLElement(xml)
d = {'activations': [
{'items': {
'number': str,
'status': int,
'properties': ({
'name': str,
'value': int
}, )
}}
]}
e = {'activations': [
{'items': {'number': '01234', 'status': 1, 'properties': ({'name': 'foo', 'value': 3}, {'name': 'bar', 'value': 4})}},
{'items': {'number': '04321', 'status': 0}}
]}
self.eq(span.unmarshall(d), e)
示例5: test_basic
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def test_basic(self):
span = SimpleXMLElement('<span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba></span>')
span1 = SimpleXMLElement('<span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a></span>')
self.eq([str(a) for a in span1.a()], ['google', 'yahoo', 'hotmail'])
span1.add_child('a', 'altavista')
span1.b = "ex msn"
d = {'href': 'http://www.bing.com/', 'alt': 'Bing'}
span1.b[:] = d
self.eq(sorted([(k, v) for k, v in span1.b[:]]), sorted(d.items()))
xml = '<?xml version="1.0" encoding="UTF-8"?><span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a><a>altavista</a><b alt="Bing" href="http://www.bing.com/">ex msn</b></span>'
self.eq(span1.as_xml(), xml)
self.assertTrue('b' in span1)
span.import_node(span1)
xml = '<?xml version="1.0" encoding="UTF-8"?><span><a href="python.org.ar">pyar</a><prueba><i>1</i><float>1.5</float></prueba><span><a href="google.com">google</a><a>yahoo</a><a>hotmail</a><a>altavista</a><b alt="Bing" href="http://www.bing.com/">ex msn</b></span></span>'
self.eq(span.as_xml(), xml)
types = {'when': datetime.datetime}
when = datetime.datetime.now()
dt = SimpleXMLElement('<when>%s</when>' % when.isoformat())
self.eq(dt.unmarshall(types)['when'], when)
示例6: test_tuple_unmarshall
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def test_tuple_unmarshall(self):
xml = """
<foo>
<boo>
<bar>abc</bar>
<baz>1</baz>
</boo>
<boo>
<bar>qwe</bar>
<baz>2</baz>
</boo>
</foo>
"""
span = SimpleXMLElement(xml)
d = {'foo': {
'boo': ({'bar': str, 'baz': int}, )
}}
e = {'foo': {
'boo': (
{'bar': 'abc', 'baz': 1},
{'bar': 'qwe', 'baz': 2},
)}}
self.eq(span.unmarshall(d), e)
示例7: test_unmarshall_cdata
# 需要导入模块: from pysimplesoap.simplexml import SimpleXMLElement [as 别名]
# 或者: from pysimplesoap.simplexml.SimpleXMLElement import unmarshall [as 别名]
def test_unmarshall_cdata(self):
span = SimpleXMLElement('<span><name><![CDATA[foo<name/>]]></name><value>3</value></span>')
d = {'span': {'name': str, 'value': int}}
e = {'span': {'name': 'foo<name/>', 'value': 3}}
self.eq(span.unmarshall(d), e)