]> granicus.if.org Git - python/commitdiff
Merged revisions 75333 via svnmerge from
authorSenthil Kumaran <orsenthil@gmail.com>
Sun, 11 Oct 2009 05:35:44 +0000 (05:35 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sun, 11 Oct 2009 05:35:44 +0000 (05:35 +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/urllib2.py
Misc/NEWS

index b83eb4600e90963b6f79b59ca19f4910cc2ea988..677829324051d21204ac5072d230a819e8c58772 100644 (file)
@@ -943,6 +943,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 = urllib2.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 = urllib2.ProxyHandler(dict(https='proxy.example.com:3128'))
index cf7e1fa6b5872c08a8275788451f6b4e0a8e01a1..4763f15e785622280ca87c477425b4605222c3f2 100644 (file)
@@ -111,7 +111,7 @@ from urllib import (unwrap, unquote, splittype, splithost, quote,
      splitattr, ftpwrapper, splituser, splitpasswd, splitvalue)
 
 # support for FileHandler, proxies via environment variables
-from urllib import localhost, url2pathname, getproxies
+from urllib import localhost, url2pathname, getproxies, proxy_bypass
 
 # used in User-Agent header sent
 __version__ = sys.version[:3]
@@ -698,14 +698,20 @@ class ProxyHandler(BaseHandler):
     def proxy_open(self, req, proxy, type):
         orig_type = req.get_type()
         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))
             creds = base64.b64encode(user_pass).strip()
             req.add_header('Proxy-authorization', 'Basic ' + creds)
         hostport = unquote(hostport)
         req.set_proxy(hostport, proxy_type)
+
         if orig_type == proxy_type or orig_type == 'https':
             # let other handlers take care of it
             return None
index 0af2778e3386ab6e4fcbde6008acd6dfa08150ba..b4a2c50a6fd85610c1d28bc1bf309b36a8f51abd 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -124,6 +124,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #6894: Fixed the issue urllib2 doesn't respect "no_proxy" environment 
+
 - Issue #6790: Make it possible again to pass an `array.array` to
   `httplib.HTTPConnection.send`. Patch by Kirk McDonald.