From: Facundo Batista Date: Mon, 23 Apr 2007 17:08:31 +0000 (+0000) Subject: As specified in RFC 2616, 2xx code indicates that the client's X-Git-Tag: v2.6a1~1824 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fab9f103f21b42ffafc87ff5a4ce970735a7b17;p=python As specified in RFC 2616, 2xx code indicates that the client's request was successfully received, understood, and accepted. Now in these cases no error is raised. Also fixed tests. --- diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index a23d61e043..1a2986a5ff 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -766,16 +766,24 @@ class HandlerTests(unittest.TestCase): url = "http://example.com/" req = Request(url) - # 200 OK is passed through + # all 2xx are passed through r = MockResponse(200, "OK", {}, "", url) newr = h.http_response(req, r) self.assert_(r is newr) self.assert_(not hasattr(o, "proto")) # o.error not called + r = MockResponse(202, "Accepted", {}, "", url) + newr = h.http_response(req, r) + self.assert_(r is newr) + self.assert_(not hasattr(o, "proto")) # o.error not called + r = MockResponse(206, "Partial content", {}, "", url) + newr = h.http_response(req, r) + self.assert_(r is newr) + self.assert_(not hasattr(o, "proto")) # o.error not called # anything else calls o.error (and MockOpener returns None, here) - r = MockResponse(201, "Created", {}, "", url) + r = MockResponse(502, "Bad gateway", {}, "", url) self.assert_(h.http_response(req, r) is None) self.assertEqual(o.proto, "http") # o.error called - self.assertEqual(o.args, (req, r, 201, "Created", {})) + self.assertEqual(o.args, (req, r, 502, "Bad gateway", {})) def test_cookies(self): cj = MockCookieJar() diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 046470aa24..7c73f817f8 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -487,7 +487,9 @@ class HTTPErrorProcessor(BaseHandler): def http_response(self, request, response): code, msg, hdrs = response.code, response.msg, response.info() - if code not in (200, 206): + # According to RFC 2616, "2xx" code indicates that the client's + # request was successfully received, understood, and accepted. + if not (200 <= code < 300): response = self.parent.error( 'http', request, response, code, msg, hdrs)