Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d8e24f1f
Commit
d8e24f1f
authored
Apr 14, 2014
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert urllib.request parse_proxy doctests to unittests.
parent
01bafdcc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
45 deletions
+39
-45
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+38
-1
Lib/urllib/request.py
Lib/urllib/request.py
+1
-44
No files found.
Lib/test/test_urllib2.py
View file @
d8e24f1f
...
@@ -10,7 +10,7 @@ import sys
...
@@ -10,7 +10,7 @@ import sys
import
urllib.request
import
urllib.request
# The proxy bypass method imported below has logic specific to the OSX
# The proxy bypass method imported below has logic specific to the OSX
# proxy config data structure but is testable on all platforms.
# 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
,
_p
arse_proxy
,
_p
roxy_bypass_macosx_sysconf
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
import
urllib.error
import
urllib.error
...
@@ -1467,6 +1467,43 @@ class MiscTests(unittest.TestCase):
...
@@ -1467,6 +1467,43 @@ class MiscTests(unittest.TestCase):
expected_errmsg
=
'HTTP Error %s: %s'
%
(
err
.
code
,
err
.
msg
)
expected_errmsg
=
'HTTP Error %s: %s'
%
(
err
.
code
,
err
.
msg
)
self
.
assertEqual
(
str
(
err
),
expected_errmsg
)
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@proxy.example.com'
,
(
None
,
'joe'
,
'password'
,
'proxy.example.com'
)),
(
'joe:password@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
RequestTests
(
unittest
.
TestCase
):
class
PutRequest
(
Request
):
class
PutRequest
(
Request
):
method
=
'PUT'
method
=
'PUT'
...
...
Lib/urllib/request.py
View file @
d8e24f1f
...
@@ -687,50 +687,7 @@ def _parse_proxy(proxy):
...
@@ -687,50 +687,7 @@ def _parse_proxy(proxy):
If a URL is supplied, it must have an authority (host:port) component.
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
According to RFC 3986, having an authority component means the URL must
have two slashes after the scheme:
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@proxy.example.com')
(None, 'joe', 'password', 'proxy.example.com')
>>> _parse_proxy('joe:password@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')
"""
"""
scheme, r_scheme = splittype(proxy)
scheme, r_scheme = splittype(proxy)
if not r_scheme.startswith("
/
"):
if not r_scheme.startswith("
/
"):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment