From: Zac Medico Date: Tue, 21 Sep 2010 15:41:54 +0000 (-0700) Subject: Bug #338190 - Handle more exceptions inside getbinpkg.dir_get_metadata(). X-Git-Tag: v2.2_rc86~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bf5877484cbca0b59c1b9d3688d338465083bcf9;p=portage.git Bug #338190 - Handle more exceptions inside getbinpkg.dir_get_metadata(). The ftplib.all_errors attribute is a useful collection of exceptions to handle here. Thanks to Christian Kauhaus for the suggestion. --- diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 56167c504..c8a0edc4d 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -16,6 +16,8 @@ import time import tempfile import base64 +_all_errors = [ValueError, socket.error] + try: from html.parser import HTMLParser as html_parser_HTMLParser except ImportError: @@ -35,6 +37,8 @@ try: import ftplib except ImportError as e: sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT FTPLIB: ")+str(e)+"\n") +else: + _all_errors.extend(ftplib.all_errors) try: try: @@ -42,13 +46,19 @@ try: from http.client import HTTPSConnection as http_client_HTTPSConnection from http.client import BadStatusLine as http_client_BadStatusLine from http.client import ResponseNotReady as http_client_ResponseNotReady + from http.client import error as http_client_error except ImportError: from httplib import HTTPConnection as http_client_HTTPConnection from httplib import HTTPSConnection as http_client_HTTPSConnection from httplib import BadStatusLine as http_client_BadStatusLine from httplib import ResponseNotReady as http_client_ResponseNotReady + from httplib import error as http_client_error except ImportError as e: sys.stderr.write(colorize("BAD","!!! CANNOT IMPORT HTTP.CLIENT: ")+str(e)+"\n") +else: + _all_errors.append(http_client_error) + +_all_errors = tuple(_all_errors) if sys.hexversion >= 0x3000000: long = int @@ -500,7 +510,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= try: conn, protocol, address, params, headers = create_conn(baseurl, conn) - except socket.error as e: + except _all_errors as e: # ftplib.FTP(host) can raise errors like this: # socket.error: (111, 'Connection refused') sys.stderr.write("!!! %s\n" % (e,))