Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34d38dc

Browse files
committed
urllib.request - syntax changes enhancing readability. By Éric Araujo
1 parent 202a3c4 commit 34d38dc

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

Lib/urllib/request.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,11 @@ def http_error_302(self, req, fp, code, msg, headers):
552552
# For security reasons we don't allow redirection to anything other
553553
# than http, https or ftp.
554554

555-
if not urlparts.scheme in ('http', 'https', 'ftp'):
556-
raise HTTPError(newurl, code,
557-
msg +
558-
" - Redirection to url '%s' is not allowed" %
559-
newurl,
560-
headers, fp)
555+
if urlparts.scheme not in ('http', 'https', 'ftp'):
556+
raise HTTPError(
557+
newurl, code,
558+
"%s - Redirection to url '%s' is not allowed" % (msg, newurl),
559+
headers, fp)
561560

562561
if not urlparts.path:
563562
urlparts = list(urlparts)
@@ -722,7 +721,7 @@ def add_password(self, realm, uri, user, passwd):
722721
# uri could be a single URI or a sequence
723722
if isinstance(uri, str):
724723
uri = [uri]
725-
if not realm in self.passwd:
724+
if realm not in self.passwd:
726725
self.passwd[realm] = {}
727726
for default_port in True, False:
728727
reduced_uri = tuple(
@@ -1823,7 +1822,7 @@ def open_ftp(self, url):
18231822
del self.ftpcache[k]
18241823
v.close()
18251824
try:
1826-
if not key in self.ftpcache:
1825+
if key not in self.ftpcache:
18271826
self.ftpcache[key] = \
18281827
ftpwrapper(user, passwd, host, port, dirs)
18291828
if not file: type = 'D'
@@ -1938,7 +1937,7 @@ def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
19381937
# We are using newer HTTPError with older redirect_internal method
19391938
# This older method will get deprecated in 3.3
19401939

1941-
if not urlparts.scheme in ('http', 'https', 'ftp'):
1940+
if urlparts.scheme not in ('http', 'https', 'ftp'):
19421941
raise HTTPError(newurl, errcode,
19431942
errmsg +
19441943
" Redirection to url '%s' is not allowed." % newurl,
@@ -1965,7 +1964,7 @@ def http_error_401(self, url, fp, errcode, errmsg, headers, data=None,
19651964
retry=False):
19661965
"""Error 401 -- authentication required.
19671966
This function supports Basic authentication only."""
1968-
if not 'www-authenticate' in headers:
1967+
if 'www-authenticate' not in headers:
19691968
URLopener.http_error_default(self, url, fp,
19701969
errcode, errmsg, headers)
19711970
stuff = headers['www-authenticate']
@@ -1991,7 +1990,7 @@ def http_error_407(self, url, fp, errcode, errmsg, headers, data=None,
19911990
retry=False):
19921991
"""Error 407 -- proxy authentication required.
19931992
This function supports Basic authentication only."""
1994-
if not 'proxy-authenticate' in headers:
1993+
if 'proxy-authenticate' not in headers:
19951994
URLopener.http_error_default(self, url, fp,
19961995
errcode, errmsg, headers)
19971996
stuff = headers['proxy-authenticate']

0 commit comments

Comments
 (0)