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
bc07ac51
Commit
bc07ac51
authored
Jul 22, 2014
by
Senthil Kumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix localhost checking in FileHandler. Raised in #21970.
parent
dfab935c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
2 deletions
+3
-2
Lib/test/test_urllib2.py
Lib/test/test_urllib2.py
+2
-1
Lib/urllib/request.py
Lib/urllib/request.py
+1
-1
No files found.
Lib/test/test_urllib2.py
View file @
bc07ac51
...
@@ -678,7 +678,7 @@ class HandlerTests(unittest.TestCase):
...
@@ -678,7 +678,7 @@ class HandlerTests(unittest.TestCase):
self
.
assertEqual
(
int
(
headers
[
"Content-length"
]),
len
(
data
))
self
.
assertEqual
(
int
(
headers
[
"Content-length"
]),
len
(
data
))
def
test_file
(
self
):
def
test_file
(
self
):
import
email.utils
,
socket
import
email.utils
h
=
urllib
.
request
.
FileHandler
()
h
=
urllib
.
request
.
FileHandler
()
o
=
h
.
parent
=
MockOpener
()
o
=
h
.
parent
=
MockOpener
()
...
@@ -725,6 +725,7 @@ class HandlerTests(unittest.TestCase):
...
@@ -725,6 +725,7 @@ class HandlerTests(unittest.TestCase):
for
url
in
[
for
url
in
[
"file://localhost:80%s"
%
urlpath
,
"file://localhost:80%s"
%
urlpath
,
"file:///file_does_not_exist.txt"
,
"file:///file_does_not_exist.txt"
,
"file://not-a-local-host.com//dir/file.txt"
,
"file://%s:80%s/%s"
%
(
socket
.
gethostbyname
(
'localhost'
),
"file://%s:80%s/%s"
%
(
socket
.
gethostbyname
(
'localhost'
),
os
.
getcwd
(),
TESTFN
),
os
.
getcwd
(),
TESTFN
),
"file://somerandomhost.ontheinternet.com%s/%s"
%
"file://somerandomhost.ontheinternet.com%s/%s"
%
...
...
Lib/urllib/request.py
View file @
bc07ac51
...
@@ -1315,7 +1315,7 @@ class FileHandler(BaseHandler):
...
@@ -1315,7 +1315,7 @@ class FileHandler(BaseHandler):
url
=
req
.
selector
url
=
req
.
selector
if
url
[:
2
]
==
'//'
and
url
[
2
:
3
]
!=
'/'
and
(
req
.
host
and
if
url
[:
2
]
==
'//'
and
url
[
2
:
3
]
!=
'/'
and
(
req
.
host
and
req
.
host
!=
'localhost'
):
req
.
host
!=
'localhost'
):
if
not
req
.
host
i
s
self
.
get_names
():
if
not
req
.
host
i
n
self
.
get_names
():
raise
URLError
(
"file:// scheme is supported only on localhost"
)
raise
URLError
(
"file:// scheme is supported only on localhost"
)
else
:
else
:
return
self
.
open_local_file
(
req
)
return
self
.
open_local_file
(
req
)
...
...
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