forked from timotheus/ebaysdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_dictionary.py
More file actions
95 lines (76 loc) · 2.11 KB
/
Copy pathrequest_dictionary.py
File metadata and controls
95 lines (76 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import sys
sys.path.insert(0, '%s/../' % os.path.dirname(__file__))
from ebaysdk.utils import dict2xml
dict1 = {'a': 'b'}
assert(dict2xml(dict1)=='<a>b</a>')
''' dict2 XML Output
<tag attr2="attr2value" site="US">222</tag>
'''
dict2 = {
'tag': {
'#text': 222,
'@attrs': {'site': 'US', 'attr2': 'attr2value'}
}
}
assert(dict2xml(dict2)=='<tag attr2="attr2value" site="US">222</tag>')
''' dict3 XML Output
<itemFilter>
<name>Condition</name>
<value>Used</value>
</itemFilter>
<itemFilter>
<name>LocatedIn</name>
<value>GB</value>
</itemFilter>
<itemFilter>
<name>More</name>
<value>more</value>
</itemFilter>
'''
dict3 = {
'itemFilter': [
{'name': 'Condition', 'value': 'Used'},
{'name': 'LocatedIn', 'value': 'GB'},
{'name': 'More', 'value': 'more'},
]
}
assert(dict2xml(dict3)=='<itemFilter><name>Condition</name><value>Used</value></itemFilter><itemFilter><name>LocatedIn</name><value>GB</value></itemFilter><itemFilter><name>More</name><value>more</value></itemFilter>')
''' dict4 XML Output
<tag1 attr2="attr2value" site="US">
<tag2>tag2 value</tag2>
</tag1>
'''
dict4 = {
'tag1': {
'#text': {'tag2': 'tag2 value'},
'@attrs': {'site': 'US', 'attr2': 'attr2value'}
}
}
assert(dict2xml(dict4)=='<tag1 attr2="attr2value" site="US"><tag2>tag2 value</tag2></tag1>')
''' dict5 XML Output
<tag1 site="US" tag1attr="myvalue">
<tag2 tag2attr="myvalue">tag2 value</tag2>
</tag1>
'''
dict5 = {
'tag1': {
'#text': {'tag2': {
'#text': 'tag2 value',
'@attrs': {'tag2attr': 'myvalue'}
}},
'@attrs': {'site': 'US', 'tag1attr': 'myvalue'}
}
}
assert(dict2xml(dict5)=='<tag1 site="US" tag1attr="myvalue"><tag2 tag2attr="myvalue">tag2 value</tag2></tag1>')
''' dict6 outputSelector
<outputSelector>SellerInfo</outputSelector>
<outputSelector>GalleryInfo</outputSelector>
'''
dict6 = {
'outputSelector': [
'SellerInfo',
'GalleryInfo'
]
}
assert(dict2xml(dict6)=='<outputSelector>SellerInfo</outputSelector><outputSelector>GalleryInfo</outputSelector>')