1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Provides encoded I{marshaller} classes.
19 """
20
21 from logging import getLogger
22 from suds import *
23 from suds.mx import *
24 from suds.mx.literal import Literal
25 from suds.mx.typer import Typer
26 from suds.sudsobject import Factory, Object
27 from suds.xsd.query import TypeQuery
28
29 log = getLogger(__name__)
30
31
32
33
34
35 Content.extensions.append('aty')
36
37
39 """
40 A SOAP section (5) encoding marshaller.
41 This marshaller supports rpc/encoded soap styles.
42 """
43
44 - def start(self, content):
60
61 - def end(self, parent, content):
62
63
64
65
66
67 Literal.end(self, parent, content)
68 if content.aty is None:
69 return
70 tag, aty = content.aty
71 ns0 = ('at0', aty[1])
72 ns1 = ('at1', 'http://schemas.xmlsoap.org/soap/encoding/')
73 array = content.value.item
74 child = parent.getChild(tag)
75 child.addPrefix(ns0[0], ns0[1])
76 child.addPrefix(ns1[0], ns1[1])
77 name = '%s:arrayType' % ns1[0]
78 value = '%s:%s[%d]' % (ns0[0], aty[0], len(array))
79 child.set(name, value)
80
81 - def encode(self, node, content):
93
94 - def cast(self, content):
95 """
96 Cast the I{untyped} list items found in content I{value}.
97 Each items contained in the list is checked for XSD type information.
98 Items (values) that are I{untyped}, are replaced with suds objects and
99 type I{metadata} is added.
100 @param content: The content holding the collection.
101 @type content: L{Content}
102 @return: self
103 @rtype: L{Encoded}
104 """
105 aty = content.aty[1]
106 resolved = content.type.resolve()
107 array = Factory.object(resolved.name)
108 array.item = []
109 query = TypeQuery(aty)
110 ref = query.execute(self.schema)
111 if ref is None:
112 raise TypeNotFound(qref)
113 for x in content.value:
114 if isinstance(x, (list, tuple)):
115 array.item.append(x)
116 continue
117 if isinstance(x, Object):
118 md = x.__metadata__
119 md.sxtype = ref
120 array.item.append(x)
121 continue
122 if isinstance(x, dict):
123 x = Factory.object(ref.name, x)
124 md = x.__metadata__
125 md.sxtype = ref
126 array.item.append(x)
127 continue
128 x = Factory.property(ref.name, x)
129 md = x.__metadata__
130 md.sxtype = ref
131 array.item.append(x)
132 content.value = array
133 return self
134