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
b17abb1a
Commit
b17abb1a
authored
Apr 13, 2011
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Plain Diff
merge from 3.1
parents
a3e449da
26430419
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
5 deletions
+31
-5
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+10
-0
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+14
-1
Lib/test/test_urllib2net.py
Lib/test/test_urllib2net.py
+1
-1
Lib/urllib/request.py
Lib/urllib/request.py
+6
-3
No files found.
Lib/test/test_urllib.py
View file @
b17abb1a
...
...
@@ -175,6 +175,16 @@ class urlopen_HttpTests(unittest.TestCase):
finally
:
self
.
unfakehttp
()
def
test_url_fragment
(
self
):
# Issue #11703: geturl() omits fragments in the original URL.
url
=
'http://docs.python.org/library/urllib.html#OK'
self
.
fakehttp
(
b"HTTP/1.1 200 OK
\
r
\
n
\
r
\
n
Hello!"
)
try
:
fp
=
urllib
.
request
.
urlopen
(
url
)
self
.
assertEqual
(
fp
.
geturl
(),
url
)
finally
:
self
.
unfakehttp
()
def
test_willclose
(
self
):
self
.
fakehttp
(
b"HTTP/1.1 200 OK
\
r
\
n
\
r
\
n
Hello!"
)
try
:
...
...
Lib/test/test_urllib2.py
View file @
b17abb1a
...
...
@@ -1070,6 +1070,15 @@ class HandlerTests(unittest.TestCase):
o
.
open
(
"http://www.example.com/"
)
self
.
assertFalse
(
hh
.
req
.
has_header
(
"Cookie"
))
def
test_redirect_fragment
(
self
):
redirected_url
=
'http://www.example.com/index.html#OK
\
r
\
n
\
r
\
n
'
hh
=
MockHTTPHandler
(
302
,
'Location: '
+
redirected_url
)
hdeh
=
urllib
.
request
.
HTTPDefaultErrorHandler
()
hrh
=
urllib
.
request
.
HTTPRedirectHandler
()
o
=
build_test_opener
(
hh
,
hdeh
,
hrh
)
fp
=
o
.
open
(
'http://www.example.com'
)
self
.
assertEqual
(
fp
.
geturl
(),
redirected_url
.
strip
())
def
test_proxy
(
self
):
o
=
OpenerDirector
()
ph
=
urllib
.
request
.
ProxyHandler
(
dict
(
http
=
"proxy.example.com:3128"
))
...
...
@@ -1385,12 +1394,16 @@ class RequestTests(unittest.TestCase):
req
=
Request
(
"<URL:http://www.python.org>"
)
self
.
assertEqual
(
"www.python.org"
,
req
.
get_host
())
def
test_url
with
_fragment
(
self
):
def
test_url_fragment
(
self
):
req
=
Request
(
"http://www.python.org/?qs=query#fragment=true"
)
self
.
assertEqual
(
"/?qs=query"
,
req
.
get_selector
())
req
=
Request
(
"http://www.python.org/#fun=true"
)
self
.
assertEqual
(
"/"
,
req
.
get_selector
())
# Issue 11703: geturl() omits fragment in the original URL.
url
=
'http://docs.python.org/library/urllib2.html#OK'
req
=
Request
(
url
)
self
.
assertEqual
(
req
.
get_full_url
(),
url
)
def
test_main
(
verbose
=
None
):
from
test
import
test_urllib2
...
...
Lib/test/test_urllib2net.py
View file @
b17abb1a
...
...
@@ -159,7 +159,7 @@ class OtherNetworkTests(unittest.TestCase):
req
=
urllib
.
request
.
Request
(
urlwith_frag
)
res
=
urllib
.
request
.
urlopen
(
req
)
self
.
assertEqual
(
res
.
geturl
(),
"http://docs.python.org/glossary.html"
)
"http://docs.python.org/glossary.html
#glossary
"
)
def
test_custom_headers
(
self
):
url
=
"http://www.example.com"
...
...
Lib/urllib/request.py
View file @
b17abb1a
...
...
@@ -180,7 +180,7 @@ class Request:
origin_req_host=None, unverifiable=False):
# unwrap('<URL:type://host/path>') --> 'type://host/path'
self.full_url = unwrap(url)
self.full_url, fragment = splittag(self.full_url)
self.full_url,
self.
fragment = splittag(self.full_url)
self.data = data
self.headers = {}
self._tunnel_host = None
...
...
@@ -219,7 +219,10 @@ class Request:
return self.data
def get_full_url(self):
return self.full_url
if self.fragment:
return '%s#%s' % (self.full_url, self.fragment)
else:
return self.full_url
def get_type(self):
return self.type
...
...
@@ -1135,7 +1138,7 @@ class AbstractHTTPHandler(BaseHandler):
except
socket
.
error
as
err
:
raise
URLError
(
err
)
r
.
url
=
req
.
full_url
r
.
url
=
req
.
get_full_url
()
# This line replaces the .msg attribute of the HTTPResponse
# with .headers, because urllib clients expect the response to
# have the reason in .msg. It would be good to mark this
...
...
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