Commit 12f4f35f authored by Jeremy Hylton's avatar Jeremy Hylton

Fix SF bug #575360

Subclasses of Exception that define an __init__ must call
Exception.__init__ or define self.args.  Otherwise, str() will fail.

Bug fix candidate.
parent d46aa37d
...@@ -889,6 +889,8 @@ if hasattr(socket, 'ssl'): ...@@ -889,6 +889,8 @@ if hasattr(socket, 'ssl'):
class HTTPException(Exception): class HTTPException(Exception):
# Subclasses that define an __init__ must call Exception.__init__
# or define self.args. Otherwise, str() will fail.
pass pass
class NotConnected(HTTPException): class NotConnected(HTTPException):
...@@ -899,6 +901,7 @@ class InvalidURL(HTTPException): ...@@ -899,6 +901,7 @@ class InvalidURL(HTTPException):
class UnknownProtocol(HTTPException): class UnknownProtocol(HTTPException):
def __init__(self, version): def __init__(self, version):
self.args = version,
self.version = version self.version = version
class UnknownTransferEncoding(HTTPException): class UnknownTransferEncoding(HTTPException):
...@@ -909,6 +912,7 @@ class UnimplementedFileMode(HTTPException): ...@@ -909,6 +912,7 @@ class UnimplementedFileMode(HTTPException):
class IncompleteRead(HTTPException): class IncompleteRead(HTTPException):
def __init__(self, partial): def __init__(self, partial):
self.args = partial,
self.partial = partial self.partial = partial
class ImproperConnectionState(HTTPException): class ImproperConnectionState(HTTPException):
...@@ -925,6 +929,7 @@ class ResponseNotReady(ImproperConnectionState): ...@@ -925,6 +929,7 @@ class ResponseNotReady(ImproperConnectionState):
class BadStatusLine(HTTPException): class BadStatusLine(HTTPException):
def __init__(self, line): def __init__(self, line):
self.args = line,
self.line = line self.line = line
# for backwards compatibility # for backwards compatibility
...@@ -1073,6 +1078,7 @@ def test(): ...@@ -1073,6 +1078,7 @@ def test():
r = c.getresponse() r = c.getresponse()
except BadStatusLine, err: except BadStatusLine, err:
print "strict mode failed as expected" print "strict mode failed as expected"
print err
else: else:
print "XXX strict mode should have failed" print "XXX strict mode should have failed"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment