]> granicus.if.org Git - python/commitdiff
Merged revisions 75333 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 11 Oct 2009 04:58:55 +0000 (04:58 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 11 Oct 2009 04:58:55 +0000 (04:58 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75333 | senthil.kumaran | 2009-10-11 07:30:07 +0530 (Sun, 11 Oct 2009) | 3 lines

  Fixed Issue6894, urllib2 doesn't respect "no_proxy" environment
........

Lib/test/test_urllib2.py
Lib/urllib/request.py
Misc/NEWS

index 8093f0e2f227f3e7360b00c744f0f1311fdb64f6..f1c478c2debc316bed0e59cb267c5654ed8d24c8 100644 (file)
@@ -947,6 +947,22 @@ class HandlerTests(unittest.TestCase):
         self.assertEqual([(handlers[0], "http_open")],
                          [tup[0:2] for tup in o.calls])
 
+    def test_proxy_no_proxy(self):
+        os.environ['no_proxy'] = 'python.org'
+        o = OpenerDirector()
+        ph = urllib.request.ProxyHandler(dict(http="proxy.example.com"))
+        o.add_handler(ph)
+        req = Request("http://www.perl.org/")
+        self.assertEqual(req.get_host(), "www.perl.org")
+        r = o.open(req)
+        self.assertEqual(req.get_host(), "proxy.example.com")
+        req = Request("http://www.python.org")
+        self.assertEqual(req.get_host(), "www.python.org")
+        r = o.open(req)
+        self.assertEqual(req.get_host(), "www.python.org")
+        del os.environ['no_proxy']
+
+
     def test_proxy_https(self):
         o = OpenerDirector()
         ph = urllib.request.ProxyHandler(dict(https="proxy.example.com:3128"))
index 6bc386ba843ca58e1bd64827239c92ddbd4867c7..67f62eb39f3e3b62d19e26528c93a1d9fd3c7fd6 100644 (file)
@@ -657,6 +657,10 @@ class ProxyHandler(BaseHandler):
         proxy_type, user, password, hostport = _parse_proxy(proxy)
         if proxy_type is None:
             proxy_type = orig_type
+
+        if req.host and proxy_bypass(req.host):
+            return None
+
         if user and password:
             user_pass = '%s:%s' % (unquote(user),
                                    unquote(password))
index 1d4b6782327f4d4ab778aa339d043d1994ac2419..ecd9fc209c465209af7556cbb7936a484926c90f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -87,6 +87,8 @@ C-API
 Library
 -------
 
+- Issue #6894: Fixed the issue urllib2 doesn't respect "no_proxy" environment 
+
 - Issue #7086: Added TCP support to SysLogHandler, and tidied up some
   anachronisms in the code which were a relic of 1.5.2 compatibility.