Demian Brecht added the comment:
The updated patch addresses comments which I’d somehow missed previously, but
keeps the log fix to the __str__ implementation of HTTPStatus (using
int.__str__ rather than format()).
> Does not changing __str__ to decimal representation (and in this case __str__
> = int.__str__ may be better) lost a part of the point of converting HTTP
> status codes to enums?
I don’t think so. In the case of HTTPStatus in general, I think that the
optimal string representation of an element of the enum is the stringified
version of the status code. If nothing else, it’s consistent with the other
type of status code that can be used (ints).
That does lead me to something that I think is a little odd about IntEnums in
general but I’ll ask that question in python-dev rather than here as to not
conflate this issue.
----------
Added file: http://bugs.python.org/file38191/issue21793_logfix_2.patch
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21793>
_______________________________________
diff -r 46bfddb14cbe Lib/http/__init__.py
--- a/Lib/http/__init__.py Fri Feb 20 10:34:20 2015 -0500
+++ b/Lib/http/__init__.py Fri Feb 20 08:12:24 2015 -0800
@@ -24,6 +24,9 @@
obj.description = description
return obj
+ def __str__(self):
+ return int.__str__(self)
+
# informational
CONTINUE = 100, 'Continue', 'Request received, please continue'
SWITCHING_PROTOCOLS = (101, 'Switching Protocols',
diff -r 46bfddb14cbe Lib/test/test_httpservers.py
--- a/Lib/test/test_httpservers.py Fri Feb 20 10:34:20 2015 -0500
+++ b/Lib/test/test_httpservers.py Fri Feb 20 08:12:24 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
@@ -816,6 +837,7 @@
cwd = os.getcwd()
try:
support.run_unittest(
+ RequestHandlerLoggingTestCase,
BaseHTTPRequestHandlerTestCase,
BaseHTTPServerTestCase,
SimpleHTTPServerTestCase,
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com