~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to partner_address_validation/xml2dic.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##Module that converts the Xml response to dictionary
2
 
from lxml import etree
3
 
 
4
 
 
5
 
def dictlist(node):
6
 
        res = {}
7
 
        res[node.tag] = []
8
 
        xmltodict(node,res[node.tag])
9
 
        reply = {}
10
 
        reply[node.tag] =res[node.tag]
11
 
 
12
 
        return reply
13
 
 
14
 
def xmltodict(node,res):
15
 
        rep = {}
16
 
 
17
 
        if len(node):
18
 
                #n = 0
19
 
                for n in list(node):
20
 
                        rep[node.tag] = []
21
 
                        value = xmltodict(n,rep[node.tag])
22
 
                        if len(n):
23
 
 
24
 
                                value = rep[node.tag]
25
 
                                res.append({n.tag:value})
26
 
                        else :
27
 
 
28
 
                                res.append(rep[node.tag][0])
29
 
 
30
 
        else:
31
 
                value = {}
32
 
                value = node.text
33
 
                res.append({node.tag:value})
34
 
 
35
 
        return
36
 
 
37
 
def main(xml_string):
38
 
        tree = etree.fromstring(xml_string)
39
 
        res = dictlist(tree)
40
 
        return res
41
 
 
42
 
 
43
 
if __name__ == '__main__' :
44
 
        main()