mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-155358: Use named attributes with urllib.parse module (#155364)
urlparse(), replace: * parts[0] => parts.scheme * parts[1] => parts.netloc * parts[2] => parts.path urlsplit(), replace: * parts[0] => parts.scheme * parts[1] => parts.netloc * parts[2] => parts.path
This commit is contained in:
1 parent
63f662663a
commit
1855c6c40b
5 files changed
+12
-10
No files matched your search
@@ -627,7 +627,7 @@ def request_host(request):
|
||||
|
||||
"""
|
||||
url = request.get_full_url()
|
||||
host = urllib.parse.urlparse(url)[1]
|
||||
host = urllib.parse.urlparse(url).netloc
|
||||
if host == "":
|
||||
host = request.get_header("Host", "")
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class RootedHTTPRequestHandler(SimpleHTTPRequestHandler):
|
||||
|
||||
"""
|
||||
# abandon query parameters
|
||||
path = urllib.parse.urlparse(path)[2]
|
||||
path = urllib.parse.urlparse(path).path
|
||||
path = os.path.normpath(urllib.parse.unquote(path))
|
||||
words = path.split('/')
|
||||
words = filter(None, words)
|
||||
|
||||
@@ -868,7 +868,7 @@ def open_urlresource(url, *args, **kw):
|
||||
|
||||
check = kw.pop('check', None)
|
||||
|
||||
filename = urllib.parse.urlparse(url)[2].split('/')[-1] # '/': it's URL!
|
||||
filename = urllib.parse.urlparse(url).path.split('/')[-1] # '/': it's URL!
|
||||
|
||||
fn = os.path.join(TEST_DATA_DIR, filename)
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ def request_host(request):
|
||||
|
||||
"""
|
||||
url = request.full_url
|
||||
host = urlparse(url)[1]
|
||||
host = urlparse(url).netloc
|
||||
if host == "":
|
||||
host = request.get_header("Host", "")
|
||||
|
||||
@@ -833,11 +833,11 @@ class HTTPPasswordMgr:
|
||||
"""Accept authority or URI and extract only the authority and path."""
|
||||
# note HTTP URLs do not have a userinfo component
|
||||
parts = urlsplit(uri)
|
||||
if parts[1]:
|
||||
if parts.netloc:
|
||||
# URI
|
||||
scheme = parts[0]
|
||||
authority = parts[1]
|
||||
path = parts[2] or '/'
|
||||
scheme = parts.scheme
|
||||
authority = parts.netloc
|
||||
path = parts.path or '/'
|
||||
else:
|
||||
# host or host:port
|
||||
scheme = None
|
||||
@@ -1222,7 +1222,7 @@ class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler):
|
||||
handler_order = 490 # before Basic auth
|
||||
|
||||
def http_error_401(self, req, fp, code, msg, headers):
|
||||
host = urlparse(req.full_url)[1]
|
||||
host = urlparse(req.full_url).netloc
|
||||
retry = self.http_error_auth_reqed('www-authenticate',
|
||||
host, req, headers)
|
||||
self.reset_retry_count()
|
||||
|
||||
@@ -62,7 +62,9 @@ class RobotFileParser:
|
||||
|
||||
if isinstance(url, urllib.request.Request):
|
||||
url = url.full_url
|
||||
self.host, self.path = urllib.parse.urlsplit(url)[1:3]
|
||||
parts = urllib.parse.urlsplit(url)
|
||||
self.host = parts.netloc
|
||||
self.path = parts.path
|
||||
|
||||
def read(self):
|
||||
"""Reads the robots.txt URL and feeds it to the parser."""
|
||||
|
||||
Reference in new issue
Block a user