]> granicus.if.org Git - python/commitdiff
Issue #23439: Add missing entries to http.client.__all__.
authorBerker Peksag <berker.peksag@gmail.com>
Fri, 20 Feb 2015 07:39:38 +0000 (09:39 +0200)
committerBerker Peksag <berker.peksag@gmail.com>
Fri, 20 Feb 2015 07:39:38 +0000 (09:39 +0200)
Also, document the LineTooLong exception since it can be raised by
the members of public API (e.g. http.client.HTTPResponse).

Patch by Martin Panter.

Doc/library/http.client.rst
Lib/http/client.py
Lib/test/test_httplib.py

index a3f2e355d5fca66b722e087cdd49d8afa8ae617f..b6e78b520eb65fe74ab27d339fce1eee64a9e29d 100644 (file)
@@ -169,6 +169,12 @@ The following exceptions are raised as appropriate:
    status code that we don't understand.
 
 
+.. exception:: LineTooLong
+
+   A subclass of :exc:`HTTPException`.  Raised if an excessively long line
+   is received in the HTTP protocol from the server.
+
+
 The constants defined in this module are:
 
 .. data:: HTTP_PORT
index 6de4b0e73cf5a17aa7635cf275c3589cbf1adf4e..d3d9b30c6c3162bb1e1a34f8bd486cd642ba29f5 100644 (file)
@@ -74,12 +74,14 @@ import socket
 import collections
 from urllib.parse import urlsplit
 
+# HTTPMessage, parse_headers(), and the HTTP status code constants are
+# intentionally omitted for simplicity
 __all__ = ["HTTPResponse", "HTTPConnection",
            "HTTPException", "NotConnected", "UnknownProtocol",
            "UnknownTransferEncoding", "UnimplementedFileMode",
            "IncompleteRead", "InvalidURL", "ImproperConnectionState",
            "CannotSendRequest", "CannotSendHeader", "ResponseNotReady",
-           "BadStatusLine", "error", "responses"]
+           "BadStatusLine", "LineTooLong", "error", "responses"]
 
 HTTP_PORT = 80
 HTTPS_PORT = 443
index 3fc34665da4047b9e46b5d50762e2cdc8c41e144..d0a0e8de8136643f1608a8632e3985f75a1f2568 100644 (file)
@@ -708,7 +708,22 @@ class BasicTest(TestCase):
         self.assertTrue(response.closed)
         self.assertTrue(conn.sock.file_closed)
 
+
 class OfflineTest(TestCase):
+    def test_all(self):
+        # Documented objects defined in the module should be in __all__
+        expected = {"responses"}  # White-list documented dict() object
+        # HTTPMessage, parse_headers(), and the HTTP status code constants are
+        # intentionally omitted for simplicity
+        blacklist = {"HTTPMessage", "parse_headers"}
+        for name in dir(client):
+            if name in blacklist:
+                continue
+            module_object = getattr(client, name)
+            if getattr(module_object, "__module__", None) == "http.client":
+                expected.add(name)
+        self.assertCountEqual(client.__all__, expected)
+
     def test_responses(self):
         self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")