diff --git a/src/SOAPpy/Client.py b/src/SOAPpy/Client.py index 81838ae..8dfd1e8 100644 --- a/src/SOAPpy/Client.py +++ b/src/SOAPpy/Client.py @@ -52,7 +52,7 @@ from .types import * import re import base64 import socket, http.client -from http.client import HTTPConnection, HTTP +from http.client import HTTPConnection import http.cookies # SOAPpy modules @@ -61,7 +61,8 @@ from .Config import Config from .Parser import parseSOAPRPC from .SOAPBuilder import buildSOAP from .Utilities import * -from .Types import faultType, simplify +from .types import faultType, simplify + import collections ################################################################################ @@ -73,6 +74,98 @@ def SOAPUserAgent(): return "SOAPpy " + __version__ + " (pywebsvcs.sf.net)" +class HTTP: + "Compatibility class with httplib.py from 1.5." + + _http_vsn = 10 + _http_vsn_str = 'HTTP/1.0' + + debuglevel = 0 + + _connection_class = HTTPConnection + + def __init__(self, host='', port=None, strict=None): + "Provide a default host, since the superclass requires one." + + # some joker passed 0 explicitly, meaning default port + if port == 0: + port = None + + # Note that we may pass an empty string as the host; this will raise + # an error when we attempt to connect. Presumably, the client code + # will call connect before then, with a proper host. + self._setup(self._connection_class(host, port, strict)) + + def _setup(self, conn): + self._conn = conn + + # set up delegation to flesh out interface + self.send = conn.send + self.putrequest = conn.putrequest + self.putheader = conn.putheader + self.endheaders = conn.endheaders + self.set_debuglevel = conn.set_debuglevel + + conn._http_vsn = self._http_vsn + conn._http_vsn_str = self._http_vsn_str + + self.file = None + + def connect(self, host=None, port=None): + "Accept arguments to set the host/port, since the superclass doesn't." + + if host is not None: + (self._conn.host, self._conn.port) = self._conn._get_hostport(host, port) + self._conn.connect() + + def getfile(self): + "Provide a getfile, since the superclass' does not use this concept." + return self.file + + def getreply(self, buffering=False): + """Compat definition since superclass does not define it. + + Returns a tuple consisting of: + - server status code (e.g. '200' if all goes well) + - server "reason" corresponding to status code + - any RFC822 headers in the response from the server + """ + try: + if not buffering: + response = self._conn.getresponse() + else: + #only add this keyword if non-default for compatibility + #with other connection classes + response = self._conn.getresponse(buffering) + except BadStatusLine as e: + ### hmm. if getresponse() ever closes the socket on a bad request, + ### then we are going to have problems with self.sock + + ### should we keep this behavior? do people use it? + # keep the socket open (as a file), and return it + self.file = self._conn.sock.makefile('rb', 0) + + # close our socket -- we want to restart after any protocol error + self.close() + + self.headers = None + return -1, e.line, None + + self.headers = response.msg + self.file = response.fp + return response.status, response.reason, response.msg + + def close(self): + self._conn.close() + + # note that self.file == response.fp, which gets closed by the + # superclass. just clear the object ref here. + ### hmm. messy. if status==-1, then self.file is owned by us. + ### well... we aren't explicitly closing, but losing this ref will + ### do it + self.file = None + + class SOAPAddress: def __init__(self, url, config = Config): proto, uri = urllib.parse.splittype(url) diff --git a/src/SOAPpy/Config.py b/src/SOAPpy/Config.py index 6ec9c2d..ddf09bf 100644 --- a/src/SOAPpy/Config.py +++ b/src/SOAPpy/Config.py @@ -50,10 +50,10 @@ class SOAPConfig: __readonly = ('SSLserver', 'SSLclient', 'GSIserver', 'GSIclient') class SSLconfig: __slots__ = ('key_file', 'cert_file') - key_file = None - cert_file = None def __init__(self, config = None, **kw): + self.key_file = None + self.cert_file = None d = self.__dict__ if config: diff --git a/src/SOAPpy/Errors.py b/src/SOAPpy/Errors.py index 4bc8a0e..97e92cc 100644 --- a/src/SOAPpy/Errors.py +++ b/src/SOAPpy/Errors.py @@ -42,8 +42,10 @@ ident = '$Id: Errors.py 921 2005-02-15 16:32:23Z warnes $' from .version import __version__ - -import exceptions +try: + import exceptions +except ImportError: + import builtins as exceptions ################################################################################ # Exceptions diff --git a/src/SOAPpy/Parser.py b/src/SOAPpy/Parser.py index 30b3ef9..ad398dc 100644 --- a/src/SOAPpy/Parser.py +++ b/src/SOAPpy/Parser.py @@ -1,7 +1,7 @@ # SOAPpy modules import traceback from .Config import Config -from .Types import * +from .types import * from .NS import NS from .Utilities import * diff --git a/src/SOAPpy/SOAPBuilder.py b/src/SOAPpy/SOAPBuilder.py index 6847af4..5cbc22b 100644 --- a/src/SOAPpy/SOAPBuilder.py +++ b/src/SOAPpy/SOAPBuilder.py @@ -42,7 +42,7 @@ from wstools.XMLname import toXMLname, fromXMLname # SOAPpy modules from .Config import Config from .NS import NS -from .Types import * +from .types import * # Test whether this Python version has Types.BooleanType # If it doesn't have it, then False and True are serialized as integers diff --git a/src/SOAPpy/Server.py b/src/SOAPpy/Server.py index 49df756..c315e30 100644 --- a/src/SOAPpy/Server.py +++ b/src/SOAPpy/Server.py @@ -56,7 +56,7 @@ import _thread # SOAPpy modules from .Parser import parseSOAPRPC from .Config import Config -from .Types import faultType, voidType, simplify +from .types import faultType, voidType, simplify from .NS import NS from .SOAPBuilder import buildSOAP from .Utilities import debugHeader, debugFooter diff --git a/src/SOAPpy/__init__.py b/src/SOAPpy/__init__.py index 35d6d22..2a170fb 100644 --- a/src/SOAPpy/__init__.py +++ b/src/SOAPpy/__init__.py @@ -2,14 +2,14 @@ ident = '$Id: __init__.py 541 2004-01-31 04:20:06Z warnes $' from .version import __version__ -from .Client import * -from .Config import * -from .Errors import * -from .NS import * -from .Parser import * +from .Client import * +from .Config import * +from .Errors import * +from .NS import * +from .Parser import * from .SOAPBuilder import * -from .Server import * -from .Types import * -from .Utilities import * +from .Server import * +from .types import * +from .Utilities import * import wstools from . import WSDL