FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-123599: Match `file:` URL hostname against machine hostname in urllib by barneygale · Pull Request #132523 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions Doc/library/urllib.request.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ The :mod:`urllib.request` module defines the following functions:

.. versionchanged:: next
This function calls :func:`socket.gethostbyname` if the URL authority
isn't empty or ``localhost``. If the authority resolves to a local IP
address then it is discarded; otherwise, on Windows a UNC path is
returned (as before), and on other platforms a
isn't empty, ``localhost``, or the machine hostname. If the authority
resolves to a local IP address then it is discarded; otherwise, on
Windows a UNC path is returned (as before), and on other platforms a
:exc:`~urllib.error.URLError` is raised.

.. versionchanged:: next
Expand Down
9 changes: 9 additions & 0 deletions Lib/urllib/request.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,17 @@ def open_local_file(self, req):
file_open = open_local_file

def _is_local_authority(authority):
# Compare hostnames
if not authority or authority == 'localhost':
return True
try:
hostname = socket.gethostname()
except (socket.gaierror, AttributeError):
pass
else:
if authority == hostname:
return True
# Compare IP addresses
try:
address = socket.gethostbyname(authority)
except (socket.gaierror, AttributeError):
Expand Down

Back | FazBrowse Home | New Git URL