Package: python-pysimplesoap                                                    
Version: 1.16-1                                                                 
Severity: normal
Tag: patch

Dear Maintainer,

using a list or dict as return of a SOAP method let to an error:
File "pysimplesoap/server.py", line 372, in parse_element
    if v in TYPE_MAP.keys():
        TypeError: unhashable type: 'list'
resp.
File "pysimplesoap/server.py", line 372, in parse_element
    if v in TYPE_MAP.keys():
        TypeError: unhashable type: 'dict'

server:
-------

from pysimplesoap.server import SoapDispatcher, SOAPHandler
from http.server import HTTPServer

def getlist():
    "Return a list"
    return {'list': [{'col': 'A'}, {'col': 'B'}, {'col': 'C'}]}

dispatcher = SoapDispatcher(
    'my_dispatcher',
    location = "http://localhost:8008/";,
    action = 'http://localhost:8008/', # SOAPAction
    namespace = "http://example.com/sample.wsdl";, prefix="ns0",
    trace = True,
    ns = True)

# register the user function
dispatcher.register_function('GetList', getlist,
                             returns = {'list': [{'col': str}]}, args = {})

print ("Starting server...")
httpd = HTTPServer(("", 8008), SOAPHandler)
httpd.dispatcher = dispatcher
httpd.serve_forever()

client:
-------

from suds.client import Client

client = Client ("http://127.0.0.1:8008/";)
result = client.service.GetList ()
print result

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.3.0-1-amd64 (SMP w/8 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages python-pysimplesoap depends on:
ii  python-httplib2  0.9.1+dfsg-1
ii  python-pycurl    7.21.5-1
pn  python:any       <none>

python-pysimplesoap recommends no packages.

python-pysimplesoap suggests no packages.

-- no debconf information
>From 00fd7b71189996cd5c7769025f8d56fe23156119 Mon Sep 17 00:00:00 2001
From: Benedikt Spranger <b.spran...@linutronix.de>
Date: Wed, 20 Jan 2016 16:08:47 +0100
Subject: [PATCH] reorder type check to avoid a TypeError

Using a list or dict as return of a SOAP method let to an error:
File "pysimplesoap/server.py", line 372, in parse_element
    if v in TYPE_MAP.keys():
    TypeError: unhashable type: 'list'

Reoder the type check and add a comment to avoid this error.

Signed-off-by: Benedikt Spranger <b.spran...@linutronix.de>
---
 pysimplesoap/server.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Index: pysimplesoap-1.16/pysimplesoap/server.py
===================================================================
--- pysimplesoap-1.16.orig/pysimplesoap/server.py	2016-01-22 11:39:27.400682071 +0100
+++ pysimplesoap-1.16/pysimplesoap/server.py	2016-01-22 11:39:27.396682071 +0100
@@ -369,9 +369,11 @@
                     e['name'] = k
                     if array:
                         e[:] = {'minOccurs': "0", 'maxOccurs': "unbounded"}
-                    if v in TYPE_MAP.keys():
-                        t = 'xsd:%s' % TYPE_MAP[v]
-                    elif v is None:
+
+                    # check list and dict first to avoid
+                    # TypeError: unhashable type: 'list' or
+                    # TypeError: unhashable type: 'dict'
+                    if v is None:
                         t = 'xsd:anyType'
                     elif isinstance(v, list):
                         n = "ArrayOf%s%s" % (name, k)
@@ -384,6 +386,8 @@
                         n = "%s%s" % (name, k)
                         parse_element(n, v.items(), complex=True)
                         t = "tns:%s" % n
+                    elif v in TYPE_MAP.keys():
+                        t = 'xsd:%s' % TYPE_MAP[v]
                     else:
                         raise TypeError("unknonw type v for marshalling" % str(v))
                     e.add_attribute('type', t)

Reply via email to