[issue21793] httplib client/server status refactor

Demian Brecht report at bugs.python.org
Tue Feb 10 16:19:07 CET 2015


Demian Brecht added the comment:

I’ve reverted the patch to use the old format. The main reason being that plain ints can still be used in most cases as values for code, in which case logging will be inconsistent with cases using the enum.

----------
Added file: http://bugs.python.org/file38084/issue21793_logfix_1.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21793>
_______________________________________
-------------- next part --------------
diff -r e548ab4ce71d Lib/http/__init__.py
--- a/Lib/http/__init__.py	Mon Feb 09 19:49:00 2015 +0000
+++ b/Lib/http/__init__.py	Tue Feb 10 07:15:09 2015 -0800
@@ -24,6 +24,11 @@
         obj.description = description
         return obj
 
+    def __str__(self):
+        # this is mainly for backwards compatibility, where constant values
+        # would be output.
+        return '{:d}'.format(self)
+
     # informational
     CONTINUE = 100, 'Continue', 'Request received, please continue'
     SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
diff -r e548ab4ce71d Lib/test/test_httpservers.py
--- a/Lib/test/test_httpservers.py	Mon Feb 09 19:49:00 2015 +0000
+++ b/Lib/test/test_httpservers.py	Tue Feb 10 07:15:09 2015 -0800
@@ -6,7 +6,7 @@
 
 from http.server import BaseHTTPRequestHandler, HTTPServer, \
      SimpleHTTPRequestHandler, CGIHTTPRequestHandler
-from http import server
+from http import server, HTTPStatus
 
 import os
 import sys
@@ -235,6 +235,27 @@
         self.assertEqual(int(res.getheader('Content-Length')), len(data))
 
 
+class RequestHandlerLoggingTestCase(BaseTestCase):
+    class request_handler(BaseHTTPRequestHandler):
+        protocol_version = 'HTTP/1.1'
+        default_request_version = 'HTTP/1.1'
+
+        def do_GET(self):
+            self.send_response(HTTPStatus.OK)
+            self.end_headers()
+
+    def test_get(self):
+        self.con = http.client.HTTPConnection(self.HOST, self.PORT)
+        self.con.connect()
+
+        with support.captured_stderr() as err:
+            self.con.request('GET', '/')
+            self.con.getresponse()
+
+        self.assertTrue(
+            err.getvalue().endswith('"GET / HTTP/1.1" 200 -\n'))
+
+
 class SimpleHTTPServerTestCase(BaseTestCase):
     class request_handler(NoLogRequestHandler, SimpleHTTPRequestHandler):
         pass
@@ -764,6 +785,7 @@
     cwd = os.getcwd()
     try:
         support.run_unittest(
+            LoggingRequestHandlerTestCase,
             BaseHTTPRequestHandlerTestCase,
             BaseHTTPServerTestCase,
             SimpleHTTPServerTestCase,


More information about the Python-bugs-list mailing list