KenyaDonDraper / pysimplesoap

Automatically exported from code.google.com/p/pysimplesoap
0 stars 0 forks source link

Sequences as a top level element #71

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be good to use a sequence as the top level parameters element in WSDL. 
In such cases SOAP clients (not pythonic) can call web methods in one line (for 
example: WSProxy.sayHello('hi', 'there', 123) - the parameters are matched by 
order.
The same is with results.

The patch is below. It lets use list of dicts in the 'args', 'returns' 
parameters of the dispatcher.register_function().
I am not sure is it a hack or a right way, it may depends on future plans of 
sequences implementation.

diff -ur orig/server.py new/server.py
--- orig/server.py  2012-01-07 14:53:18.000000000 +0300
+++ new/server.py   2012-05-21 13:14:56.186875000 +0400
@@ -18,7 +18,7 @@
 __version__ = "1.02c"

 import logging
-from simplexml import SimpleXMLElement, TYPE_MAP, DateTime, Date, Decimal
+from simplexml import SimpleXMLElement, TYPE_MAP, DateTime, Date, Decimal, 
OrderedDict

 log = logging.getLogger(__name__)
 DEBUG = False
@@ -43,6 +43,16 @@
         self.soap_uri = soap_uri

     def register_function(self, name, fn, returns=None, args=None, doc=None):
+        if isinstance(args, list):
+            l = args
+            args = OrderedDict()
+            for d in l:
+                args.update(d)
+        if isinstance(returns, list):
+            l = returns
+            returns = OrderedDict()
+            for d in l:
+                returns.update(d)
         self.methods[name] = fn, returns, args, doc or getattr(fn,"__doc__","")

     def dispatch(self, xml, action=None):
@@ -250,8 +260,10 @@
                         t = "tns:%s" % n
                     e.add_attribute('type', t)

-            parse_element("%s" % method, args and args.items())
-            parse_element("%sResponse" % method, returns and returns.items())
+            parse_element("%s" % method, args and args.items(), 
+                array=isinstance(args, OrderedDict), complex=isinstance(args, 
OrderedDict))
+            parse_element("%sResponse" % method, returns and returns.items(), 
+                array=isinstance(returns, OrderedDict), 
complex=isinstance(returns, OrderedDict))

             # create messages:
             for m,e in ('Input',''), ('Output','Response'):

Original issue reported on code.google.com by tolix%mo...@gtempaccount.com on 21 May 2012 at 10:01