From: Ben Darnell Date: Sun, 8 Apr 2018 15:45:17 +0000 (-0400) Subject: httpclient: Rename HTTPError to HTTPClientError X-Git-Tag: v5.1.0b1~30^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55c440d6ef8fe3cae5526356a0eb98266bc85647;p=thirdparty%2Ftornado.git httpclient: Rename HTTPError to HTTPClientError This avoids collisions in code that must deal with both httpclient.HTTPError and web.HTTPError. --- diff --git a/docs/httpclient.rst b/docs/httpclient.rst index 782316180..cf3bc8e71 100644 --- a/docs/httpclient.rst +++ b/docs/httpclient.rst @@ -24,9 +24,13 @@ Exceptions ---------- - .. autoexception:: HTTPError + .. autoexception:: HTTPClientError :members: + .. exception:: HTTPError + + Alias for `HTTPClientError`. + Command-line interface ---------------------- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 4ed96e4d4..f0a2df887 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -637,7 +637,7 @@ class HTTPResponse(object): return "%s(%s)" % (self.__class__.__name__, args) -class HTTPError(Exception): +class HTTPClientError(Exception): """Exception thrown for an unsuccessful HTTP request. Attributes: @@ -650,12 +650,18 @@ class HTTPError(Exception): Note that if ``follow_redirects`` is False, redirects become HTTPErrors, and you can look at ``error.response.headers['Location']`` to see the destination of the redirect. + + .. versionchanged:: 5.1 + + Renamed from ``HTTPError`` to ``HTTPClientError`` to avoid collisions with + `tornado.web.HTTPError`. The name ``tornado.httpclient.HTTPError`` remains + as an alias. """ def __init__(self, code, message=None, response=None): self.code = code self.message = message or httputil.responses.get(code, "Unknown") self.response = response - super(HTTPError, self).__init__(code, message, response) + super(HTTPClientError, self).__init__(code, message, response) def __str__(self): return "HTTP %d: %s" % (self.code, self.message) @@ -667,6 +673,9 @@ class HTTPError(Exception): __repr__ = __str__ +HTTPError = HTTPClientError + + class _RequestProxy(object): """Combines an object with a dictionary of defaults. diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index cd9df37af..7f053ef06 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -1,8 +1,9 @@ from __future__ import absolute_import, division, print_function from tornado.concurrent import Future -from tornado import gen, httpclient +from tornado import gen from tornado.escape import json_decode, utf8, to_unicode, recursive_unicode, native_str, to_basestring # noqa: E501 +from tornado.httpclient import HTTPClientError from tornado.httputil import format_timestamp from tornado.ioloop import IOLoop from tornado.iostream import IOStream @@ -2332,7 +2333,7 @@ class IncorrectContentLengthTest(SimpleHandlerTestCase): with ExpectLog(gen_log, "(Cannot send error response after headers written" "|Failed to flush partial response)"): - with self.assertRaises(httpclient.HTTPError): + with self.assertRaises(HTTPClientError): self.fetch("/high", raise_error=True) self.assertEqual(str(self.server_error), "Tried to write 40 bytes less than Content-Length") @@ -2345,7 +2346,7 @@ class IncorrectContentLengthTest(SimpleHandlerTestCase): with ExpectLog(gen_log, "(Cannot send error response after headers written" "|Failed to flush partial response)"): - with self.assertRaises(httpclient.HTTPError): + with self.assertRaises(HTTPClientError): self.fetch("/low", raise_error=True) self.assertEqual(str(self.server_error), "Tried to write more data than Content-Length")