1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Provides classes for the (WS) SOAP I{document/literal}.
19 """
20
21 from logging import getLogger
22 from suds import *
23 from suds.bindings.binding import Binding
24 from suds.sax.element import Element
25
26 log = getLogger(__name__)
27
28
30 """
31 The document/literal style. Literal is the only (@use) supported
32 since document/encoded is pretty much dead.
33 Although the soap specification supports multiple documents within the soap
34 <body/>, it is very uncommon. As such, suds presents an I{RPC} view of
35 service methods defined with a single document parameter. This is done so
36 that the user can pass individual parameters instead of one, single document.
37 To support the complete specification, service methods defined with multiple documents
38 (multiple message parts), must present a I{document} view for that method.
39 """
40
41 - def bodycontent(self, method, args, kwargs):
42
43
44
45
46
47
48 if not len(method.soap.input.body.parts):
49 return ()
50 wrapped = method.soap.input.body.wrapped
51 if wrapped:
52 pts = self.bodypart_types(method)
53 root = self.document(pts[0])
54 else:
55 root = []
56 n = 0
57 for pd in self.param_defs(method):
58 if n < len(args):
59 value = args[n]
60 else:
61 value = kwargs.get(pd[0])
62 n += 1
63 p = self.mkparam(method, pd, value)
64 if p is None:
65 continue
66 if not wrapped:
67 ns = pd[1].namespace('ns0')
68 p.setPrefix(ns[0], ns[1])
69 root.append(p)
70 return root
71
72 - def replycontent(self, method, body):
73 wrapped = method.soap.output.body.wrapped
74 if wrapped:
75 return body[0].children
76 else:
77 return body.children
78
80 """
81 Get the document root. For I{document/literal}, this is the
82 name of the wrapper element qualifed by the schema tns.
83 @param wrapper: The method name.
84 @type wrapper: L{xsd.sxbase.SchemaObject}
85 @return: A root element.
86 @rtype: L{Element}
87 """
88 tag = wrapper[1].name
89 ns = wrapper[1].namespace('ns0')
90 d = Element(tag, ns=ns)
91 return d
92
93 - def mkparam(self, method, pdef, object):
106
108
109
110
111
112
113
114
115 pts = self.bodypart_types(method)
116 wrapped = method.soap.input.body.wrapped
117 if not wrapped:
118 return pts
119 result = []
120
121 for p in pts:
122 resolved = p[1].resolve()
123 for child, ancestry in resolved:
124 if child.isattr():
125 continue
126 if self.bychoice(ancestry):
127 log.debug(
128 '%s\ncontained by <choice/>, excluded as param for %s()',
129 child,
130 method.name)
131 continue
132 result.append((child.name, child))
133 return result
134
148
150 """
151 The ancestry contains a <choice/>
152 @param ancestry: A list of ancestors.
153 @type ancestry: list
154 @return: True if contains <choice/>
155 @rtype: boolean
156 """
157 for x in ancestry:
158 if x.choice():
159 return True
160 return False
161