TransRead: handle the urllib2.URLError exception
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 13 Sep 2013 09:26:56 +0000 (12:26 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Fri, 13 Sep 2013 10:37:30 +0000 (13:37 +0300)
When opening an URL with urllib2, handle the URLError exceptions too.

This patch adds a new "except" statement instead of adding the exception object
to the existing array. The reason is that in the next commit we will need to
handle the urllib2.URLError exceptions a bit differently.

This patch also refactors the code a tiny bit as a preparation to the next
commit.

Change-Id: I69856aa8698b495c5a2450979db9384aad1b713a
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptools/TransRead.py

index a16d0c8d12eac75b004e1134d55e8173c0a98543..45c243d6ba73ace54450bddda6d04ffec8ed54e3 100644 (file)
@@ -466,14 +466,18 @@ class TransRead:
         urllib2.install_opener(opener)
 
         try:
-            self._f_objs.append(opener.open(url))
-            self.is_url = True
+            f_obj = opener.open(url)
+        except urllib2.URLError as err:
+            raise Error("cannot open URL '%s': %s" % (url, err))
         except (IOError, ValueError, httplib.InvalidURL) as err:
             raise Error("cannot open URL '%s': %s" % (url, err))
         except httplib.BadStatusLine:
             raise Error("cannot open URL '%s': server responds with an HTTP "
                         "status code that we don't understand" % url)
 
+        self.is_url = True
+        self._f_objs.append(f_obj)
+
     def _create_local_copy(self):
         """Create a local copy of a remote or compressed file."""
         import tempfile