Package suds :: Package bindings :: Module rpc
[hide private]
[frames] | no frames]

Source Code for Module suds.bindings.rpc

  1  # This program is free software; you can redistribute it and/or modify 
  2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
  3  # published by the Free Software Foundation; either version 3 of the  
  4  # License, or (at your option) any later version. 
  5  # 
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU Library Lesser General Public License for more details at 
 10  # ( http://www.gnu.org/licenses/lgpl.html ). 
 11  # 
 12  # You should have received a copy of the GNU Lesser General Public License 
 13  # along with this program; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 15  # written by: Jeff Ortel ( jortel@redhat.com ) 
 16   
 17  """ 
 18  Provides classes for the (WS) SOAP I{rpc/literal} and I{rpc/encoded} bindings. 
 19  """ 
 20   
 21  from logging import getLogger 
 22  from suds import * 
 23  from suds.mx.encoded import Encoded as MxEncoded 
 24  from suds.umx.encoded import Encoded as UmxEncoded 
 25  from suds.bindings.binding import Binding, envns 
 26  from suds.sax.element import Element 
 27   
 28  log = getLogger(__name__) 
 29   
 30   
 31  encns = ('SOAP-ENC', 'http://schemas.xmlsoap.org/soap/encoding/') 
 32   
33 -class RPC(Binding):
34 """ 35 RPC/Literal binding style. 36 """ 37
38 - def param_defs(self, method):
39 return self.bodypart_types(method)
40
41 - def envelope(self, header, body):
42 env = Binding.envelope(self, header, body) 43 env.addPrefix(encns[0], encns[1]) 44 env.set('%s:encodingStyle' % envns[0], 45 'http://schemas.xmlsoap.org/soap/encoding/') 46 return env
47
48 - def bodycontent(self, method, args, kwargs):
49 n = 0 50 root = self.method(method) 51 for pd in self.param_defs(method): 52 if n < len(args): 53 value = args[n] 54 else: 55 value = kwargs.get(pd[0]) 56 p = self.mkparam(method, pd, value) 57 if p is not None: 58 root.append(p) 59 n += 1 60 return root
61
62 - def replycontent(self, method, body):
63 return body[0].children
64
65 - def method(self, method):
66 """ 67 Get the document root. For I{rpc/(literal|encoded)}, this is the 68 name of the method qualifed by the schema tns. 69 @param method: A service method. 70 @type method: I{service.Method} 71 @return: A root element. 72 @rtype: L{Element} 73 """ 74 ns = method.soap.input.body.namespace 75 if ns[0] is None: 76 ns = ('ns0', ns[1]) 77 method = Element(method.name, ns=ns) 78 return method
79 80
81 -class Encoded(RPC):
82 """ 83 RPC/Encoded (section 5) binding style. 84 """ 85
86 - def marshaller(self):
87 return MxEncoded(self.schema())
88
89 - def unmarshaller(self, typed=True):
90 """ 91 Get the appropriate XML decoder. 92 @return: Either the (basic|typed) unmarshaller. 93 @rtype: L{UmxTyped} 94 """ 95 if typed: 96 return UmxEncoded(self.schema()) 97 else: 98 return RPC.unmarshaller(self, typed)
99