From: <wa...@us...> - 2008-05-14 21:26:46
|
Revision: 1449 http://pywebsvcs.svn.sourceforge.net/pywebsvcs/?rev=1449&view=rev Author: warnes Date: 2008-05-14 14:26:53 -0700 (Wed, 14 May 2008) Log Message: ----------- Patch for supporting SOAP cookies, submitted by Paul Pacheco Modified Paths: -------------- trunk/SOAPpy/SOAPpy/Client.py Property Changed: ---------------- trunk/SOAPpy/SOAPpy/ Property changes on: trunk/SOAPpy/SOAPpy ___________________________________________________________________ Name: svn:externals - wstools https://svn.sourceforge.net/svnroot/pywebsvcs/trunk/wstools + wstools https://pywebsvcs.svn.sourceforge.net/svnroot/pywebsvcs/trunk/wstools Modified: trunk/SOAPpy/SOAPpy/Client.py =================================================================== --- trunk/SOAPpy/SOAPpy/Client.py 2008-05-14 21:23:50 UTC (rev 1448) +++ trunk/SOAPpy/SOAPpy/Client.py 2008-05-14 21:26:53 UTC (rev 1449) @@ -50,6 +50,7 @@ from types import * import re import base64 +import Cookie # SOAPpy modules from Errors import * @@ -112,6 +113,11 @@ class HTTPTransport: + + + def __init__(self): + self.cookies = Cookie.SimpleCookie(); + def getNS(self, original_namespace, data): """Extract the (possibly extended) namespace from the returned SOAP message.""" @@ -126,6 +132,23 @@ else: return original_namespace + def __addcookies(self, r): + '''Add cookies from self.cookies to request r + ''' + for cname, morsel in self.cookies.items(): + attrs = [] + value = morsel.get('version', '') + if value != '' and value != '0': + attrs.append('$Version=%s' % value) + attrs.append('%s=%s' % (cname, morsel.coded_value)) + value = morsel.get('path') + if value: + attrs.append('$Path=%s' % value) + value = morsel.get('domain') + if value: + attrs.append('$Domain=%s' % value) + r.putheader('Cookie', "; ".join(attrs)) + # Need a Timeout someday? def call(self, addr, data, namespace, soapaction = None, encoding = None, http_proxy = None, config = Config): @@ -160,7 +183,8 @@ t += '; charset="%s"' % encoding r.putheader("Content-type", t) r.putheader("Content-length", str(len(data))) - + self.__addcookies(r); + # if user is not a user:passwd format # we'll receive a failure from the server. . .I guess (??) if addr.user != None: @@ -200,9 +224,14 @@ # read response line code, msg, headers = r.getreply() + self.cookies = Cookie.SimpleCookie(); if headers: content_type = headers.get("content-type","text/xml") content_length = headers.get("Content-length") + + for cookie in headers.getallmatchingheaders("Set-Cookie"): + self.cookies.load(cookie); + else: content_type=None content_length=None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |