Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
cc2f0421
Kaydet (Commit)
cc2f0421
authored
Eki 27, 2012
tarafından
Senthil Kumaran
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #16250: Fix URLError invocation with proper args
üst
5f9459fb
cad7b314
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
16 deletions
+51
-16
test_urllib.py
Lib/test/test_urllib.py
+34
-1
request.py
Lib/urllib/request.py
+15
-15
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_urllib.py
Dosyayı görüntüle @
cc2f0421
...
@@ -268,6 +268,39 @@ Content-Type: text/html; charset=iso-8859-1
...
@@ -268,6 +268,39 @@ Content-Type: text/html; charset=iso-8859-1
finally
:
finally
:
self
.
unfakehttp
()
self
.
unfakehttp
()
def
test_missing_localfile
(
self
):
# Test for #10836
# 3.3 - URLError is not captured, explicit IOError is raised.
with
self
.
assertRaises
(
IOError
):
urlopen
(
'file://localhost/a/file/which/doesnot/exists.py'
)
def
test_file_notexists
(
self
):
fd
,
tmp_file
=
tempfile
.
mkstemp
()
tmp_fileurl
=
'file://localhost/'
+
tmp_file
.
replace
(
os
.
path
.
sep
,
'/'
)
try
:
self
.
assertTrue
(
os
.
path
.
exists
(
tmp_file
))
with
urlopen
(
tmp_fileurl
)
as
fobj
:
self
.
assertTrue
(
fobj
)
finally
:
os
.
close
(
fd
)
os
.
unlink
(
tmp_file
)
self
.
assertFalse
(
os
.
path
.
exists
(
tmp_file
))
# 3.3 - IOError instead of URLError
with
self
.
assertRaises
(
IOError
):
urlopen
(
tmp_fileurl
)
def
test_ftp_nohost
(
self
):
test_ftp_url
=
'ftp:///path'
# 3.3 - IOError instead of URLError
with
self
.
assertRaises
(
IOError
):
urlopen
(
test_ftp_url
)
def
test_ftp_nonexisting
(
self
):
# 3.3 - IOError instead of URLError
with
self
.
assertRaises
(
IOError
):
urlopen
(
'ftp://localhost/a/file/which/doesnot/exists.py'
)
def
test_userpass_inurl
(
self
):
def
test_userpass_inurl
(
self
):
self
.
fakehttp
(
b
"HTTP/1.0 200 OK
\r\n\r\n
Hello!"
)
self
.
fakehttp
(
b
"HTTP/1.0 200 OK
\r\n\r\n
Hello!"
)
try
:
try
:
...
@@ -300,7 +333,7 @@ Content-Type: text/html; charset=iso-8859-1
...
@@ -300,7 +333,7 @@ Content-Type: text/html; charset=iso-8859-1
def
test_URLopener_deprecation
(
self
):
def
test_URLopener_deprecation
(
self
):
with
support
.
check_warnings
((
''
,
DeprecationWarning
)):
with
support
.
check_warnings
((
''
,
DeprecationWarning
)):
warn
=
urllib
.
request
.
URLopener
()
urllib
.
request
.
URLopener
()
class
urlretrieve_FileTests
(
unittest
.
TestCase
):
class
urlretrieve_FileTests
(
unittest
.
TestCase
):
"""Test urllib.urlretrieve() on local files"""
"""Test urllib.urlretrieve() on local files"""
...
...
Lib/urllib/request.py
Dosyayı görüntüle @
cc2f0421
...
@@ -1413,9 +1413,9 @@ class FileHandler(BaseHandler):
...
@@ -1413,9 +1413,9 @@ class FileHandler(BaseHandler):
else
:
else
:
origurl
=
'file://'
+
filename
origurl
=
'file://'
+
filename
return
addinfourl
(
open
(
localfile
,
'rb'
),
headers
,
origurl
)
return
addinfourl
(
open
(
localfile
,
'rb'
),
headers
,
origurl
)
except
OSError
as
msg
:
except
OSError
as
exp
:
# users shouldn't expect OSErrors coming from urlopen()
# users shouldn't expect OSErrors coming from urlopen()
raise
URLError
(
msg
)
raise
URLError
(
exp
)
raise
URLError
(
'file not on local host'
)
raise
URLError
(
'file not on local host'
)
def
_safe_gethostbyname
(
host
):
def
_safe_gethostbyname
(
host
):
...
@@ -1474,8 +1474,8 @@ class FTPHandler(BaseHandler):
...
@@ -1474,8 +1474,8 @@ class FTPHandler(BaseHandler):
headers
+=
"Content-length:
%
d
\n
"
%
retrlen
headers
+=
"Content-length:
%
d
\n
"
%
retrlen
headers
=
email
.
message_from_string
(
headers
)
headers
=
email
.
message_from_string
(
headers
)
return
addinfourl
(
fp
,
headers
,
req
.
full_url
)
return
addinfourl
(
fp
,
headers
,
req
.
full_url
)
except
ftplib
.
all_errors
as
msg
:
except
ftplib
.
all_errors
as
exp
:
exc
=
URLError
(
'ftp error:
%
s'
%
msg
)
exc
=
URLError
(
'ftp error:
%
r'
%
exp
)
raise
exc
.
with_traceback
(
sys
.
exc_info
()[
2
])
raise
exc
.
with_traceback
(
sys
.
exc_info
()[
2
])
def
connect_ftp
(
self
,
user
,
passwd
,
host
,
port
,
dirs
,
timeout
):
def
connect_ftp
(
self
,
user
,
passwd
,
host
,
port
,
dirs
,
timeout
):
...
@@ -1870,7 +1870,7 @@ class URLopener:
...
@@ -1870,7 +1870,7 @@ class URLopener:
def
open_file
(
self
,
url
):
def
open_file
(
self
,
url
):
"""Use local file or FTP depending on form of URL."""
"""Use local file or FTP depending on form of URL."""
if
not
isinstance
(
url
,
str
):
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/'
:
if
url
[:
2
]
==
'//'
and
url
[
2
:
3
]
!=
'/'
and
url
[
2
:
12
]
.
lower
()
!=
'localhost/'
:
raise
ValueError
(
"file:// scheme is supported only on localhost"
)
raise
ValueError
(
"file:// scheme is supported only on localhost"
)
else
:
else
:
...
@@ -1885,7 +1885,7 @@ class URLopener:
...
@@ -1885,7 +1885,7 @@ class URLopener:
try
:
try
:
stats
=
os
.
stat
(
localname
)
stats
=
os
.
stat
(
localname
)
except
OSError
as
e
:
except
OSError
as
e
:
raise
URLError
(
e
.
errno
,
e
.
strerror
,
e
.
filename
)
raise
URLError
(
e
.
strerror
,
e
.
filename
)
size
=
stats
.
st_size
size
=
stats
.
st_size
modified
=
email
.
utils
.
formatdate
(
stats
.
st_mtime
,
usegmt
=
True
)
modified
=
email
.
utils
.
formatdate
(
stats
.
st_mtime
,
usegmt
=
True
)
mtype
=
mimetypes
.
guess_type
(
url
)[
0
]
mtype
=
mimetypes
.
guess_type
(
url
)[
0
]
...
@@ -1899,22 +1899,22 @@ class URLopener:
...
@@ -1899,22 +1899,22 @@ class URLopener:
return
addinfourl
(
open
(
localname
,
'rb'
),
headers
,
urlfile
)
return
addinfourl
(
open
(
localname
,
'rb'
),
headers
,
urlfile
)
host
,
port
=
splitport
(
host
)
host
,
port
=
splitport
(
host
)
if
(
not
port
if
(
not
port
and
socket
.
gethostbyname
(
host
)
in
(
localhost
(
)
+
thishost
())):
and
socket
.
gethostbyname
(
host
)
in
(
(
localhost
(),
)
+
thishost
())):
urlfile
=
file
urlfile
=
file
if
file
[:
1
]
==
'/'
:
if
file
[:
1
]
==
'/'
:
urlfile
=
'file://'
+
file
urlfile
=
'file://'
+
file
elif
file
[:
2
]
==
'./'
:
elif
file
[:
2
]
==
'./'
:
raise
ValueError
(
"local file url may start with / or file:. Unknown url of type:
%
s"
%
url
)
raise
ValueError
(
"local file url may start with / or file:. Unknown url of type:
%
s"
%
url
)
return
addinfourl
(
open
(
localname
,
'rb'
),
headers
,
urlfile
)
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
):
def
open_ftp
(
self
,
url
):
"""Use FTP protocol."""
"""Use FTP protocol."""
if
not
isinstance
(
url
,
str
):
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
import
mimetypes
host
,
path
=
splithost
(
url
)
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
)
host
,
port
=
splitport
(
host
)
user
,
host
=
splituser
(
host
)
user
,
host
=
splituser
(
host
)
if
user
:
user
,
passwd
=
splitpasswd
(
user
)
if
user
:
user
,
passwd
=
splitpasswd
(
user
)
...
@@ -1963,13 +1963,13 @@ class URLopener:
...
@@ -1963,13 +1963,13 @@ class URLopener:
headers
+=
"Content-Length:
%
d
\n
"
%
retrlen
headers
+=
"Content-Length:
%
d
\n
"
%
retrlen
headers
=
email
.
message_from_string
(
headers
)
headers
=
email
.
message_from_string
(
headers
)
return
addinfourl
(
fp
,
headers
,
"ftp:"
+
url
)
return
addinfourl
(
fp
,
headers
,
"ftp:"
+
url
)
except
ftperrors
()
as
msg
:
except
ftperrors
()
as
exp
:
raise
URLError
(
'ftp error
'
,
msg
)
.
with_traceback
(
sys
.
exc_info
()[
2
])
raise
URLError
(
'ftp error
%
r'
%
exp
)
.
with_traceback
(
sys
.
exc_info
()[
2
])
def
open_data
(
self
,
url
,
data
=
None
):
def
open_data
(
self
,
url
,
data
=
None
):
"""Use "data" URL."""
"""Use "data" URL."""
if
not
isinstance
(
url
,
str
):
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
# ignore POSTed data
#
#
# syntax of data URLs:
# syntax of data URLs:
...
@@ -2298,7 +2298,7 @@ class ftpwrapper:
...
@@ -2298,7 +2298,7 @@ class ftpwrapper:
conn
,
retrlen
=
self
.
ftp
.
ntransfercmd
(
cmd
)
conn
,
retrlen
=
self
.
ftp
.
ntransfercmd
(
cmd
)
except
ftplib
.
error_perm
as
reason
:
except
ftplib
.
error_perm
as
reason
:
if
str
(
reason
)[:
3
]
!=
'550'
:
if
str
(
reason
)[:
3
]
!=
'550'
:
raise
URLError
(
'ftp error
'
,
reason
)
.
with_traceback
(
raise
URLError
(
'ftp error
:
%
d'
%
reason
)
.
with_traceback
(
sys
.
exc_info
()[
2
])
sys
.
exc_info
()[
2
])
if
not
conn
:
if
not
conn
:
# Set transfer mode to ASCII!
# Set transfer mode to ASCII!
...
@@ -2310,7 +2310,7 @@ class ftpwrapper:
...
@@ -2310,7 +2310,7 @@ class ftpwrapper:
try
:
try
:
self
.
ftp
.
cwd
(
file
)
self
.
ftp
.
cwd
(
file
)
except
ftplib
.
error_perm
as
reason
:
except
ftplib
.
error_perm
as
reason
:
raise
URLError
(
'ftp error
'
,
reason
)
from
reason
raise
URLError
(
'ftp error
:
%
d'
%
reason
)
from
reason
finally
:
finally
:
self
.
ftp
.
cwd
(
pwd
)
self
.
ftp
.
cwd
(
pwd
)
cmd
=
'LIST '
+
file
cmd
=
'LIST '
+
file
...
...
Misc/NEWS
Dosyayı görüntüle @
cc2f0421
...
@@ -49,6 +49,8 @@ Core and Builtins
...
@@ -49,6 +49,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #16250: Fix URLError invocation with proper args.
- Issue #16116: Fix include and library paths to be correct when building C
- Issue #16116: Fix include and library paths to be correct when building C
extensions in venvs.
extensions in venvs.
...
...
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