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
3ebef36e
Commit
3ebef36e
authored
Oct 21, 2012
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16250: Fix the invocations of URLError which had misplaced filename attribute for exception
parent
13487470
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
15 deletions
+46
-15
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+30
-2
Lib/urllib/request.py
Lib/urllib/request.py
+13
-13
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_urllib.py
View file @
3ebef36e
...
...
@@ -270,8 +270,36 @@ Content-Type: text/html; charset=iso-8859-1
def
test_missing_localfile
(
self
):
# Test for #10836
with
self
.
assertRaises
(
urllib
.
error
.
URLError
):
with
self
.
assertRaises
(
urllib
.
error
.
URLError
)
as
e
:
urlopen
(
'file://localhost/a/file/which/doesnot/exists.py'
)
self
.
assertTrue
(
e
.
exception
.
filename
)
self
.
assertTrue
(
e
.
exception
.
reason
)
def
test_file_notexists
(
self
):
fd
,
tmp_file
=
tempfile
.
mkstemp
()
tmp_fileurl
=
'file://'
+
tmp_file
self
.
assertTrue
(
os
.
path
.
exists
(
tmp_file
))
self
.
assertTrue
(
urlopen
(
tmp_fileurl
))
os
.
unlink
(
tmp_file
)
self
.
assertFalse
(
os
.
path
.
exists
(
tmp_file
))
with
self
.
assertRaises
(
urllib
.
error
.
URLError
):
urlopen
(
tmp_fileurl
)
def
test_ftp_nohost
(
self
):
test_ftp_url
=
'ftp:///path'
with
self
.
assertRaises
(
urllib
.
error
.
URLError
)
as
e
:
urlopen
(
test_ftp_url
)
self
.
assertFalse
(
e
.
exception
.
filename
)
self
.
assertTrue
(
e
.
exception
.
reason
)
def
test_ftp_nonexisting
(
self
):
with
self
.
assertRaises
(
urllib
.
error
.
URLError
)
as
e
:
urlopen
(
'ftp://localhost/a/file/which/doesnot/exists.py'
)
self
.
assertFalse
(
e
.
exception
.
filename
)
self
.
assertTrue
(
e
.
exception
.
reason
)
def
test_userpass_inurl
(
self
):
self
.
fakehttp
(
b"HTTP/1.0 200 OK
\
r
\
n
\
r
\
n
Hello!"
)
...
...
@@ -305,7 +333,7 @@ Content-Type: text/html; charset=iso-8859-1
def
test_URLopener_deprecation
(
self
):
with
support
.
check_warnings
((
''
,
DeprecationWarning
)):
warn
=
urllib
.
request
.
URLopener
()
urllib
.
request
.
URLopener
()
class
urlretrieve_FileTests
(
unittest
.
TestCase
):
"""Test urllib.urlretrieve() on local files"""
...
...
Lib/urllib/request.py
View file @
3ebef36e
...
...
@@ -1419,9 +1419,9 @@ class FileHandler(BaseHandler):
else
:
origurl
=
'file://'
+
filename
return
addinfourl
(
open
(
localfile
,
'rb'
),
headers
,
origurl
)
except
OSError
as
msg
:
except
OSError
as
exp
:
# users shouldn't expect OSErrors coming from urlopen()
raise
URLError
(
msg
)
raise
URLError
(
exp
)
raise
URLError
(
'file not on local host'
)
def
_safe_gethostbyname
(
host
):
...
...
@@ -1480,8 +1480,8 @@ class FTPHandler(BaseHandler):
headers
+=
"Content-length: %d
\
n
"
%
retrlen
headers
=
email
.
message_from_string
(
headers
)
return
addinfourl
(
fp
,
headers
,
req
.
full_url
)
except
ftplib
.
all_errors
as
msg
:
exc
=
URLError
(
'ftp error: %
s'
%
msg
)
except
ftplib
.
all_errors
as
exp
:
exc
=
URLError
(
'ftp error: %
r'
%
exp
)
raise
exc
.
with_traceback
(
sys
.
exc_info
()[
2
])
def
connect_ftp
(
self
,
user
,
passwd
,
host
,
port
,
dirs
,
timeout
):
...
...
@@ -1876,7 +1876,7 @@ class URLopener:
def
open_file
(
self
,
url
):
"""Use local file or FTP depending on form of URL."""
if
not
isinstance
(
url
,
str
):
raise
URLError
(
'file error
'
,
'
proxy support for file protocol currently not implemented'
)
raise
URLError
(
'file error
:
proxy support for file protocol currently not implemented'
)
if
url
[:
2
]
==
'//'
and
url
[
2
:
3
]
!=
'/'
and
url
[
2
:
12
].
lower
()
!=
'localhost/'
:
raise
ValueError
(
"file:// scheme is supported only on localhost"
)
else
:
...
...
@@ -1912,15 +1912,15 @@ class URLopener:
elif
file
[:
2
]
==
'./'
:
raise
ValueError
(
"local file url may start with / or file:. Unknown url of type: %s"
%
url
)
return
addinfourl
(
open
(
localname
,
'rb'
),
headers
,
urlfile
)
raise
URLError
(
'local file error
'
,
'
not on local host'
)
raise
URLError
(
'local file error
:
not on local host'
)
def
open_ftp
(
self
,
url
):
"""Use FTP protocol."""
if
not
isinstance
(
url
,
str
):
raise
URLError
(
'ftp error
'
,
'
proxy support for ftp protocol currently not implemented'
)
raise
URLError
(
'ftp error
:
proxy support for ftp protocol currently not implemented'
)
import
mimetypes
host
,
path
=
splithost
(
url
)
if
not
host
:
raise
URLError
(
'ftp error
'
,
'
no host given'
)
if
not
host
:
raise
URLError
(
'ftp error
:
no host given'
)
host
,
port
=
splitport
(
host
)
user
,
host
=
splituser
(
host
)
if
user
:
user
,
passwd
=
splitpasswd
(
user
)
...
...
@@ -1969,13 +1969,13 @@ class URLopener:
headers
+=
"Content-Length: %d
\
n
"
%
retrlen
headers
=
email
.
message_from_string
(
headers
)
return
addinfourl
(
fp
,
headers
,
"ftp:"
+
url
)
except
ftperrors
()
as
msg
:
raise
URLError
(
'ftp error
'
,
msg
).
with_traceback
(
sys
.
exc_info
()[
2
])
except
ftperrors
()
as
exp
:
raise
URLError
(
'ftp error
%r'
%
exp
).
with_traceback
(
sys
.
exc_info
()[
2
])
def
open_data
(
self
,
url
,
data
=
None
):
"""Use "data" URL."""
if
not
isinstance
(
url
,
str
):
raise
URLError
(
'data error
'
,
'
proxy support for data protocol currently not implemented'
)
raise
URLError
(
'data error
:
proxy support for data protocol currently not implemented'
)
# ignore POSTed data
#
# syntax of data URLs:
...
...
@@ -2304,7 +2304,7 @@ class ftpwrapper:
conn
,
retrlen
=
self
.
ftp
.
ntransfercmd
(
cmd
)
except
ftplib
.
error_perm
as
reason
:
if
str
(
reason
)[:
3
]
!=
'550'
:
raise
URLError
(
'ftp error
'
,
reason
).
with_traceback
(
raise
URLError
(
'ftp error
: %d'
%
reason
).
with_traceback
(
sys
.
exc_info
()[
2
])
if
not
conn
:
# Set transfer mode to ASCII!
...
...
@@ -2316,7 +2316,7 @@ class ftpwrapper:
try
:
self
.
ftp
.
cwd
(
file
)
except
ftplib
.
error_perm
as
reason
:
raise
URLError
(
'ftp error
'
,
reason
)
from
reason
raise
URLError
(
'ftp error
: %d'
%
reason
)
from
reason
finally
:
self
.
ftp
.
cwd
(
pwd
)
cmd
=
'LIST '
+
file
...
...
Misc/NEWS
View file @
3ebef36e
...
...
@@ -59,6 +59,9 @@ Core and Builtins
Library
-------
-
Issue
#
16250
:
Fix
the
invocations
of
URLError
which
had
misplaced
filename
attribute
for
exception
.
-
Issue
#
10836
:
Fix
exception
raised
when
file
not
found
in
urlretrieve
Initial
patch
by
Ezio
Melotti
.
...
...
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