In file transport/__init__.py maybe change the class def to this?
class TransportError(Exception):
def __init__(self, reason, httpcode, fp=None):
"""
A transport exception
@param reason: Human-readable text message
@type reason: str
@param httpcode: 3-decimal-digit HTTP status code (RFC 2616)
@type httpcode: str
@param fp: either a file-like object, containing (?what?), or None
@type fp: stream
"""
Exception.__init__(self, reason)
self.httpcode = httpcode
self.fp = fp
I have not yet figured out exactly *what* is in the fp element, when it is not None. Anybody know offhand?
The Python Library Reference, section 2.3, says Exception is derived from BaseException and that raising BaseException
with a single argument -- as here -- makes that argument available both as the str() and unicode() values of the exception
and as the message attribute of the exception. "All arguments are also stored in args as a tuple, but it will eventually be
deprecated and thus its use is discouraged."
In Suds as it now stands, the only places that raise TransportError are in the open and send methods of the
HttpTransport class, in file transport/http.py. Both cases are in except u2.HTTPError clauses, where u2 is bound to
urllib2 from the stdlib:
For open:
except u2.HTTPError, e:
raise TransportError(str(e), e.code, e.fp)
For send:
except u2.HTTPError, e:
if e.code in (202,204):
result = None
else:
raise TransportError(e.msg, e.code, e.fp)
Why does open use str(e) where send uses e.msg ?
From the source code for HTTPError, it looks to me like e.msg and str(e) differ, in a way that would make it harder than
necessary to write a single handler for both versions of the exception. Am I missing something? Is there a good reason for
the difference?
I was tempted to open a ticket for this, but (a) the proposed changes seemed too trivial and (b) I thought I'd have a better
chance of getting my questions answered if I posted to the List instead.
I'm digging deeper into exactly how HTTPError works in urllib2 so I'll be able to make TransportError work as uniformly
as possible across the Suds-provided Transport and alternatives based on httplib2 and urllib3.
It might help my understanding, if I could look at a few cases that actually use TransportError non-trivially. Anyone have
any to share?