From 2966b322055158184eebc72bb892ef2ccc42f0d2 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 6 Jun 1997 17:44:07 +0000 Subject: Catch *all* errors that ftplib can raise (ftplib.all_errors) rather than just the four. Also folded some long lines. --- Lib/urllib.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Lib/urllib.py b/Lib/urllib.py index 390dd63..173f83b 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -288,12 +288,16 @@ class URLopener: def open_local_file(self, url): host, file = splithost(url) if not host: - return addinfourl(open(url2pathname(file), 'rb'), noheaders(), 'file:'+file) + return addinfourl( + open(url2pathname(file), 'rb'), + noheaders(), 'file:'+file) host, port = splitport(host) if not port and socket.gethostbyname(host) in ( localhost(), thishost()): file = unquote(file) - return addinfourl(open(url2pathname(file), 'rb'), noheaders(), 'file:'+file) + return addinfourl( + open(url2pathname(file), 'rb'), + noheaders(), 'file:'+file) raise IOError, ('local file error', 'not on local host') # Use FTP protocol @@ -325,8 +329,9 @@ class URLopener: if string.lower(attr) == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = string.upper(value) - return addinfourl(self.ftpcache[key].retrfile(file, type), - noheaders(), self.openedurl) + return addinfourl( + self.ftpcache[key].retrfile(file, type), + noheaders(), self.openedurl) except ftperrors(), msg: raise IOError, ('ftp error', msg), sys.exc_traceback @@ -443,10 +448,7 @@ def ftperrors(): global _ftperrors if not _ftperrors: import ftplib - _ftperrors = (ftplib.error_reply, - ftplib.error_temp, - ftplib.error_perm, - ftplib.error_proto) + _ftperrors = ftplib.all_errors return _ftperrors # Return an empty mimetools.Message object -- cgit v0.12