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
c661b30f
Commit
c661b30f
authored
May 19, 2019
by
Xtreak
Committed by
Berker Peksag
May 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36948: Fix NameError in urllib.request.URLopener.retrieve (GH-13389)
parent
a5119e7d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
6 deletions
+26
-6
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+19
-1
Lib/urllib/request.py
Lib/urllib/request.py
+5
-5
Misc/NEWS.d/next/Library/2019-05-17-21-42-58.bpo-36948.vnUDvk.rst
...S.d/next/Library/2019-05-17-21-42-58.bpo-36948.vnUDvk.rst
+2
-0
No files found.
Lib/test/test_urllib.py
View file @
c661b30f
...
...
@@ -1445,7 +1445,7 @@ class Utility_Tests(unittest.TestCase):
self
.
assertIsInstance
(
urllib
.
request
.
thishost
(),
tuple
)
class
URLopener_Tests
(
unittest
.
TestCase
):
class
URLopener_Tests
(
FakeHTTPMixin
,
unittest
.
TestCase
):
"""Testcase to test the open method of URLopener class."""
def
test_quoted_open
(
self
):
...
...
@@ -1463,6 +1463,24 @@ class URLopener_Tests(unittest.TestCase):
"spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/"
),
"//c:|windows%/:=&?~#+!$,;'@()*[]|/path/"
)
@
support
.
ignore_warnings
(
category
=
DeprecationWarning
)
def
test_urlopener_retrieve_file
(
self
):
with
support
.
temp_dir
()
as
tmpdir
:
fd
,
tmpfile
=
tempfile
.
mkstemp
(
dir
=
tmpdir
)
os
.
close
(
fd
)
fileurl
=
"file:"
+
urllib
.
request
.
pathname2url
(
tmpfile
)
filename
,
_
=
urllib
.
request
.
URLopener
().
retrieve
(
fileurl
)
self
.
assertEqual
(
filename
,
tmpfile
)
@
support
.
ignore_warnings
(
category
=
DeprecationWarning
)
def
test_urlopener_retrieve_remote
(
self
):
url
=
"http://www.python.org/file.txt"
self
.
fakehttp
(
b"HTTP/1.1 200 OK
\
r
\
n
\
r
\
n
Hello!"
)
self
.
addCleanup
(
self
.
unfakehttp
)
filename
,
_
=
urllib
.
request
.
URLopener
().
retrieve
(
url
)
self
.
assertEqual
(
os
.
path
.
splitext
(
filename
)[
1
],
".txt"
)
# Just commented them out.
# Can't really tell why keep failing in windows and sparc.
# Everywhere else they work ok, but on those machines, sometimes
...
...
Lib/urllib/request.py
View file @
c661b30f
...
...
@@ -1783,7 +1783,7 @@ class URLopener:
fp
=
self
.
open_local_file
(
url1
)
hdrs
=
fp
.
info
()
fp
.
close
()
return
url2pathname
(
splithost
(
url1
)[
1
]),
hdrs
return
url2pathname
(
_
splithost
(
url1
)[
1
]),
hdrs
except
OSError
as
msg
:
pass
fp
=
self
.
open
(
url
,
data
)
...
...
@@ -1792,10 +1792,10 @@ class URLopener:
if
filename
:
tfp
=
open
(
filename
,
'wb'
)
else
:
garbage
,
path
=
splittype
(
url
)
garbage
,
path
=
splithost
(
path
or
""
)
path
,
garbage
=
splitquery
(
path
or
""
)
path
,
garbage
=
splitattr
(
path
or
""
)
garbage
,
path
=
_
splittype
(
url
)
garbage
,
path
=
_
splithost
(
path
or
""
)
path
,
garbage
=
_
splitquery
(
path
or
""
)
path
,
garbage
=
_
splitattr
(
path
or
""
)
suffix
=
os
.
path
.
splitext
(
path
)[
1
]
(
fd
,
filename
)
=
tempfile
.
mkstemp
(
suffix
)
self
.
__tempfiles
.
append
(
filename
)
...
...
Misc/NEWS.d/next/Library/2019-05-17-21-42-58.bpo-36948.vnUDvk.rst
0 → 100644
View file @
c661b30f
Fix :exc:`NameError` in :meth:`urllib.request.URLopener.retrieve`. Patch by
Karthikeyan Singaravelan.
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