@@ -1419,9 +1419,9 @@ def open_local_file(self, req):
14191419 else :
14201420 origurl = 'file://' + filename
14211421 return addinfourl (open (localfile , 'rb' ), headers , origurl )
1422- except OSError as msg :
1422+ except OSError as exp :
14231423 # users shouldn't expect OSErrors coming from urlopen()
1424- raise URLError (msg )
1424+ raise URLError (exp )
14251425 raise URLError ('file not on local host' )
14261426
14271427def _safe_gethostbyname (host ):
@@ -1480,8 +1480,8 @@ def ftp_open(self, req):
14801480 headers += "Content-length: %d\n " % retrlen
14811481 headers = email .message_from_string (headers )
14821482 return addinfourl (fp , headers , req .full_url )
1483- except ftplib .all_errors as msg :
1484- exc = URLError ('ftp error: %s ' % msg )
1483+ except ftplib .all_errors as exp :
1484+ exc = URLError ('ftp error: %r ' % exp )
14851485 raise exc .with_traceback (sys .exc_info ()[2 ])
14861486
14871487 def connect_ftp (self , user , passwd , host , port , dirs , timeout ):
@@ -1876,7 +1876,7 @@ def open_https(self, url, data=None):
18761876 def open_file (self , url ):
18771877 """Use local file or FTP depending on form of URL."""
18781878 if not isinstance (url , str ):
1879- raise URLError ('file error' , ' proxy support for file protocol currently not implemented' )
1879+ raise URLError ('file error: proxy support for file protocol currently not implemented' )
18801880 if url [:2 ] == '//' and url [2 :3 ] != '/' and url [2 :12 ].lower () != 'localhost/' :
18811881 raise ValueError ("file:// scheme is supported only on localhost" )
18821882 else :
@@ -1912,15 +1912,15 @@ def open_local_file(self, url):
19121912 elif file [:2 ] == './' :
19131913 raise ValueError ("local file url may start with / or file:. Unknown url of type: %s" % url )
19141914 return addinfourl (open (localname , 'rb' ), headers , urlfile )
1915- raise URLError ('local file error' , ' not on local host' )
1915+ raise URLError ('local file error: not on local host' )
19161916
19171917 def open_ftp (self , url ):
19181918 """Use FTP protocol."""
19191919 if not isinstance (url , str ):
1920- raise URLError ('ftp error' , ' proxy support for ftp protocol currently not implemented' )
1920+ raise URLError ('ftp error: proxy support for ftp protocol currently not implemented' )
19211921 import mimetypes
19221922 host , path = splithost (url )
1923- if not host : raise URLError ('ftp error' , ' no host given' )
1923+ if not host : raise URLError ('ftp error: no host given' )
19241924 host , port = splitport (host )
19251925 user , host = splituser (host )
19261926 if user : user , passwd = splitpasswd (user )
@@ -1969,13 +1969,13 @@ def open_ftp(self, url):
19691969 headers += "Content-Length: %d\n " % retrlen
19701970 headers = email .message_from_string (headers )
19711971 return addinfourl (fp , headers , "ftp:" + url )
1972- except ftperrors () as msg :
1973- raise URLError ('ftp error' , msg ).with_traceback (sys .exc_info ()[2 ])
1972+ except ftperrors () as exp :
1973+ raise URLError ('ftp error %r' % exp ).with_traceback (sys .exc_info ()[2 ])
19741974
19751975 def open_data (self , url , data = None ):
19761976 """Use "data" URL."""
19771977 if not isinstance (url , str ):
1978- raise URLError ('data error' , ' proxy support for data protocol currently not implemented' )
1978+ raise URLError ('data error: proxy support for data protocol currently not implemented' )
19791979 # ignore POSTed data
19801980 #
19811981 # syntax of data URLs:
@@ -2304,7 +2304,7 @@ def retrfile(self, file, type):
23042304 conn , retrlen = self .ftp .ntransfercmd (cmd )
23052305 except ftplib .error_perm as reason :
23062306 if str (reason )[:3 ] != '550' :
2307- raise URLError ('ftp error' , reason ).with_traceback (
2307+ raise URLError ('ftp error: %d' % reason ).with_traceback (
23082308 sys .exc_info ()[2 ])
23092309 if not conn :
23102310 # Set transfer mode to ASCII!
@@ -2316,7 +2316,7 @@ def retrfile(self, file, type):
23162316 try :
23172317 self .ftp .cwd (file )
23182318 except ftplib .error_perm as reason :
2319- raise URLError ('ftp error' , reason ) from reason
2319+ raise URLError ('ftp error: %d' % reason ) from reason
23202320 finally :
23212321 self .ftp .cwd (pwd )
23222322 cmd = 'LIST ' + file
0 commit comments