[Python-checkins] cpython (merge 3.4 -> default): merge 3.4
senthil.kumaran
python-checkins at python.org
Mon Apr 14 22:49:18 CEST 2014
http://hg.python.org/cpython/rev/f769925b066f
changeset: 90293:f769925b066f
parent: 90286:e457de60028c
parent: 90292:29d07cd3d91f
user: Senthil Kumaran <senthil at uthcode.com>
date: Mon Apr 14 16:33:21 2014 -0400
summary:
merge 3.4
Convert urllib.request parse_proxy doctests to unittests.
files:
Lib/test/test_urllib2.py | 39 +++++++++++++++++++++++-
Lib/urllib/request.py | 45 +---------------------------
2 files changed, 39 insertions(+), 45 deletions(-)
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -10,7 +10,7 @@
import urllib.request
# The proxy bypass method imported below has logic specific to the OSX
# proxy config data structure but is testable on all platforms.
-from urllib.request import Request, OpenerDirector, _proxy_bypass_macosx_sysconf
+from urllib.request import Request, OpenerDirector, _parse_proxy, _proxy_bypass_macosx_sysconf
from urllib.parse import urlparse
import urllib.error
@@ -1467,6 +1467,43 @@
expected_errmsg = 'HTTP Error %s: %s' % (err.code, err.msg)
self.assertEqual(str(err), expected_errmsg)
+ def test_parse_proxy(self):
+ parse_proxy_test_cases = [
+ ('proxy.example.com',
+ (None, None, None, 'proxy.example.com')),
+ ('proxy.example.com:3128',
+ (None, None, None, 'proxy.example.com:3128')),
+ ('proxy.example.com', (None, None, None, 'proxy.example.com')),
+ ('proxy.example.com:3128',
+ (None, None, None, 'proxy.example.com:3128')),
+ # The authority component may optionally include userinfo
+ # (assumed to be # username:password):
+ ('joe:password at proxy.example.com',
+ (None, 'joe', 'password', 'proxy.example.com')),
+ ('joe:password at proxy.example.com:3128',
+ (None, 'joe', 'password', 'proxy.example.com:3128')),
+ #Examples with URLS
+ ('http://proxy.example.com/',
+ ('http', None, None, 'proxy.example.com')),
+ ('http://proxy.example.com:3128/',
+ ('http', None, None, 'proxy.example.com:3128')),
+ ('http://joe:password@proxy.example.com/',
+ ('http', 'joe', 'password', 'proxy.example.com')),
+ ('http://joe:password@proxy.example.com:3128',
+ ('http', 'joe', 'password', 'proxy.example.com:3128')),
+ # Everything after the authority is ignored
+ ('ftp://joe:password@proxy.example.com/rubbish:3128',
+ ('ftp', 'joe', 'password', 'proxy.example.com')),
+ # Test for no trailing '/' case
+ ('http://joe:password@proxy.example.com',
+ ('http', 'joe', 'password', 'proxy.example.com'))
+ ]
+
+ for tc, expected in parse_proxy_test_cases:
+ self.assertEqual(_parse_proxy(tc), expected)
+
+ self.assertRaises(ValueError, _parse_proxy, 'file:/ftp.example.com'),
+
class RequestTests(unittest.TestCase):
class PutRequest(Request):
method='PUT'
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -687,50 +687,7 @@
If a URL is supplied, it must have an authority (host:port) component.
According to RFC 3986, having an authority component means the URL must
- have two slashes after the scheme:
-
- >>> _parse_proxy('file:/ftp.example.com/')
- Traceback (most recent call last):
- ValueError: proxy URL with no authority: 'file:/ftp.example.com/'
-
- The first three items of the returned tuple may be None.
-
- Examples of authority parsing:
-
- >>> _parse_proxy('proxy.example.com')
- (None, None, None, 'proxy.example.com')
- >>> _parse_proxy('proxy.example.com:3128')
- (None, None, None, 'proxy.example.com:3128')
-
- The authority component may optionally include userinfo (assumed to be
- username:password):
-
- >>> _parse_proxy('joe:password at proxy.example.com')
- (None, 'joe', 'password', 'proxy.example.com')
- >>> _parse_proxy('joe:password at proxy.example.com:3128')
- (None, 'joe', 'password', 'proxy.example.com:3128')
-
- Same examples, but with URLs instead:
-
- >>> _parse_proxy('http://proxy.example.com/')
- ('http', None, None, 'proxy.example.com')
- >>> _parse_proxy('http://proxy.example.com:3128/')
- ('http', None, None, 'proxy.example.com:3128')
- >>> _parse_proxy('http://joe:password@proxy.example.com/')
- ('http', 'joe', 'password', 'proxy.example.com')
- >>> _parse_proxy('http://joe:password@proxy.example.com:3128')
- ('http', 'joe', 'password', 'proxy.example.com:3128')
-
- Everything after the authority is ignored:
-
- >>> _parse_proxy('ftp://joe:password@proxy.example.com/rubbish:3128')
- ('ftp', 'joe', 'password', 'proxy.example.com')
-
- Test for no trailing '/' case:
-
- >>> _parse_proxy('http://joe:password@proxy.example.com')
- ('http', 'joe', 'password', 'proxy.example.com')
-
+ have two slashes after the scheme.
"""
scheme, r_scheme = splittype(proxy)
if not r_scheme.startswith("/"):
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list