mirror of
https://github.com/python/cpython.git
synced 2025-12-11 11:31:05 +00:00
urllib.request - syntax changes enhancing readability. By Éric Araujo
This commit is contained in:
commit
1a129c882c
1 changed files with 12 additions and 13 deletions
|
|
@ -557,12 +557,11 @@ class HTTPRedirectHandler(BaseHandler):
|
||||||
# For security reasons we don't allow redirection to anything other
|
# For security reasons we don't allow redirection to anything other
|
||||||
# than http, https or ftp.
|
# than http, https or ftp.
|
||||||
|
|
||||||
if not urlparts.scheme in ('http', 'https', 'ftp'):
|
if urlparts.scheme not in ('http', 'https', 'ftp'):
|
||||||
raise HTTPError(newurl, code,
|
raise HTTPError(
|
||||||
msg +
|
newurl, code,
|
||||||
" - Redirection to url '%s' is not allowed" %
|
"%s - Redirection to url '%s' is not allowed" % (msg, newurl),
|
||||||
newurl,
|
headers, fp)
|
||||||
headers, fp)
|
|
||||||
|
|
||||||
if not urlparts.path:
|
if not urlparts.path:
|
||||||
urlparts = list(urlparts)
|
urlparts = list(urlparts)
|
||||||
|
|
@ -727,7 +726,7 @@ class HTTPPasswordMgr:
|
||||||
# uri could be a single URI or a sequence
|
# uri could be a single URI or a sequence
|
||||||
if isinstance(uri, str):
|
if isinstance(uri, str):
|
||||||
uri = [uri]
|
uri = [uri]
|
||||||
if not realm in self.passwd:
|
if realm not in self.passwd:
|
||||||
self.passwd[realm] = {}
|
self.passwd[realm] = {}
|
||||||
for default_port in True, False:
|
for default_port in True, False:
|
||||||
reduced_uri = tuple(
|
reduced_uri = tuple(
|
||||||
|
|
@ -831,7 +830,7 @@ class AbstractBasicAuthHandler:
|
||||||
|
|
||||||
if authreq:
|
if authreq:
|
||||||
scheme = authreq.split()[0]
|
scheme = authreq.split()[0]
|
||||||
if not scheme.lower() == 'basic':
|
if scheme.lower() != 'basic':
|
||||||
raise ValueError("AbstractBasicAuthHandler does not"
|
raise ValueError("AbstractBasicAuthHandler does not"
|
||||||
" support the following scheme: '%s'" %
|
" support the following scheme: '%s'" %
|
||||||
scheme)
|
scheme)
|
||||||
|
|
@ -929,7 +928,7 @@ class AbstractDigestAuthHandler:
|
||||||
scheme = authreq.split()[0]
|
scheme = authreq.split()[0]
|
||||||
if scheme.lower() == 'digest':
|
if scheme.lower() == 'digest':
|
||||||
return self.retry_http_digest_auth(req, authreq)
|
return self.retry_http_digest_auth(req, authreq)
|
||||||
elif not scheme.lower() == 'basic':
|
elif scheme.lower() != 'basic':
|
||||||
raise ValueError("AbstractDigestAuthHandler does not support"
|
raise ValueError("AbstractDigestAuthHandler does not support"
|
||||||
" the following scheme: '%s'" % scheme)
|
" the following scheme: '%s'" % scheme)
|
||||||
|
|
||||||
|
|
@ -1839,7 +1838,7 @@ class URLopener:
|
||||||
del self.ftpcache[k]
|
del self.ftpcache[k]
|
||||||
v.close()
|
v.close()
|
||||||
try:
|
try:
|
||||||
if not key in self.ftpcache:
|
if key not in self.ftpcache:
|
||||||
self.ftpcache[key] = \
|
self.ftpcache[key] = \
|
||||||
ftpwrapper(user, passwd, host, port, dirs)
|
ftpwrapper(user, passwd, host, port, dirs)
|
||||||
if not file: type = 'D'
|
if not file: type = 'D'
|
||||||
|
|
@ -1954,7 +1953,7 @@ class FancyURLopener(URLopener):
|
||||||
# We are using newer HTTPError with older redirect_internal method
|
# We are using newer HTTPError with older redirect_internal method
|
||||||
# This older method will get deprecated in 3.3
|
# This older method will get deprecated in 3.3
|
||||||
|
|
||||||
if not urlparts.scheme in ('http', 'https', 'ftp'):
|
if urlparts.scheme not in ('http', 'https', 'ftp'):
|
||||||
raise HTTPError(newurl, errcode,
|
raise HTTPError(newurl, errcode,
|
||||||
errmsg +
|
errmsg +
|
||||||
" Redirection to url '%s' is not allowed." % newurl,
|
" Redirection to url '%s' is not allowed." % newurl,
|
||||||
|
|
@ -1981,7 +1980,7 @@ class FancyURLopener(URLopener):
|
||||||
retry=False):
|
retry=False):
|
||||||
"""Error 401 -- authentication required.
|
"""Error 401 -- authentication required.
|
||||||
This function supports Basic authentication only."""
|
This function supports Basic authentication only."""
|
||||||
if not 'www-authenticate' in headers:
|
if 'www-authenticate' not in headers:
|
||||||
URLopener.http_error_default(self, url, fp,
|
URLopener.http_error_default(self, url, fp,
|
||||||
errcode, errmsg, headers)
|
errcode, errmsg, headers)
|
||||||
stuff = headers['www-authenticate']
|
stuff = headers['www-authenticate']
|
||||||
|
|
@ -2007,7 +2006,7 @@ class FancyURLopener(URLopener):
|
||||||
retry=False):
|
retry=False):
|
||||||
"""Error 407 -- proxy authentication required.
|
"""Error 407 -- proxy authentication required.
|
||||||
This function supports Basic authentication only."""
|
This function supports Basic authentication only."""
|
||||||
if not 'proxy-authenticate' in headers:
|
if 'proxy-authenticate' not in headers:
|
||||||
URLopener.http_error_default(self, url, fp,
|
URLopener.http_error_default(self, url, fp,
|
||||||
errcode, errmsg, headers)
|
errcode, errmsg, headers)
|
||||||
stuff = headers['proxy-authenticate']
|
stuff = headers['proxy-authenticate']
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue