@@ -557,12 +557,11 @@ def http_error_302(self, req, fp, code, msg, headers):
557557 # For security reasons we don't allow redirection to anything other
558558 # than http, https or ftp.
559559
560- if not urlparts .scheme in ('http' , 'https' , 'ftp' ):
561- raise HTTPError (newurl , code ,
562- msg +
563- " - Redirection to url '%s' is not allowed" %
564- newurl ,
565- headers , fp )
560+ if urlparts .scheme not in ('http' , 'https' , 'ftp' ):
561+ raise HTTPError (
562+ newurl , code ,
563+ "%s - Redirection to url '%s' is not allowed" % (msg , newurl ),
564+ headers , fp )
566565
567566 if not urlparts .path :
568567 urlparts = list (urlparts )
@@ -727,7 +726,7 @@ def add_password(self, realm, uri, user, passwd):
727726 # uri could be a single URI or a sequence
728727 if isinstance (uri , str ):
729728 uri = [uri ]
730- if not realm in self .passwd :
729+ if realm not in self .passwd :
731730 self .passwd [realm ] = {}
732731 for default_port in True , False :
733732 reduced_uri = tuple (
@@ -831,7 +830,7 @@ def http_error_auth_reqed(self, authreq, host, req, headers):
831830
832831 if authreq :
833832 scheme = authreq .split ()[0 ]
834- if not scheme .lower () = = 'basic' :
833+ if scheme .lower () ! = 'basic' :
835834 raise ValueError ("AbstractBasicAuthHandler does not"
836835 " support the following scheme: '%s'" %
837836 scheme )
@@ -929,7 +928,7 @@ def http_error_auth_reqed(self, auth_header, host, req, headers):
929928 scheme = authreq .split ()[0 ]
930929 if scheme .lower () == 'digest' :
931930 return self .retry_http_digest_auth (req , authreq )
932- elif not scheme .lower () = = 'basic' :
931+ elif scheme .lower () ! = 'basic' :
933932 raise ValueError ("AbstractDigestAuthHandler does not support"
934933 " the following scheme: '%s'" % scheme )
935934
@@ -1839,7 +1838,7 @@ def open_ftp(self, url):
18391838 del self .ftpcache [k ]
18401839 v .close ()
18411840 try :
1842- if not key in self .ftpcache :
1841+ if key not in self .ftpcache :
18431842 self .ftpcache [key ] = \
18441843 ftpwrapper (user , passwd , host , port , dirs )
18451844 if not file : type = 'D'
@@ -1954,7 +1953,7 @@ def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
19541953 # We are using newer HTTPError with older redirect_internal method
19551954 # This older method will get deprecated in 3.3
19561955
1957- if not urlparts .scheme in ('http' , 'https' , 'ftp' ):
1956+ if urlparts .scheme not in ('http' , 'https' , 'ftp' ):
19581957 raise HTTPError (newurl , errcode ,
19591958 errmsg +
19601959 " Redirection to url '%s' is not allowed." % newurl ,
@@ -1981,7 +1980,7 @@ def http_error_401(self, url, fp, errcode, errmsg, headers, data=None,
19811980 retry = False ):
19821981 """Error 401 -- authentication required.
19831982 This function supports Basic authentication only."""
1984- if not 'www-authenticate' in headers :
1983+ if 'www-authenticate' not in headers :
19851984 URLopener .http_error_default (self , url , fp ,
19861985 errcode , errmsg , headers )
19871986 stuff = headers ['www-authenticate' ]
@@ -2007,7 +2006,7 @@ def http_error_407(self, url, fp, errcode, errmsg, headers, data=None,
20072006 retry = False ):
20082007 """Error 407 -- proxy authentication required.
20092008 This function supports Basic authentication only."""
2010- if not 'proxy-authenticate' in headers :
2009+ if 'proxy-authenticate' not in headers :
20112010 URLopener .http_error_default (self , url , fp ,
20122011 errcode , errmsg , headers )
20132012 stuff = headers ['proxy-authenticate' ]
0 commit comments