]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
httpclient: Rename HTTPError to HTTPClientError
authorBen Darnell <ben@bendarnell.com>
Sun, 8 Apr 2018 15:45:17 +0000 (11:45 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 8 Apr 2018 19:25:21 +0000 (15:25 -0400)
This avoids collisions in code that must deal with both
httpclient.HTTPError and web.HTTPError.

docs/httpclient.rst
tornado/httpclient.py
tornado/test/web_test.py

index 782316180ac9cc28a8951410d577fd47a4905be8..cf3bc8e715d1c8511cb0c77379b51e28d43181f0 100644 (file)
 
    Exceptions
    ----------
-   .. autoexception:: HTTPError
+   .. autoexception:: HTTPClientError
       :members:
 
+   .. exception:: HTTPError
+
+      Alias for `HTTPClientError`.
+
    Command-line interface
    ----------------------
 
index 4ed96e4d40551f4bca5c5053a5b683f8cc69a38c..f0a2df887123b26eb3d3ebb1cbc7bfa7e00aa80e 100644 (file)
@@ -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.
 
index cd9df37afde32ca9c1a19e52fcb711fb8202caee..7f053ef063af8deabb18853e7af722bec4483695 100644 (file)
@@ -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")