[yum-commits] 2 commits - urlgrabber/grabber.py urlgrabber/mirror.py

zpavlas at osuosl.org zpavlas at osuosl.org
Wed Sep 19 14:59:15 UTC 2012


 urlgrabber/grabber.py |   19 ++++++++++++-------
 urlgrabber/mirror.py  |    3 ++-
 2 files changed, 14 insertions(+), 8 deletions(-)

New commits:
commit 23d46d772b0454f8d5e4c041da41e1cbe461a332
Author: Zdeněk Pavlas <zpavlas at redhat.com>
Date:   Wed Sep 19 12:50:32 2012 +0200

    failed write: raise URLGrabError(16) instead of KeyboardInterrupt
    
    Should help BZ 786640.

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 0e20cee..09ef978 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -1265,7 +1265,11 @@ class PyCurlFileObject(object):
                     self.opts.progress_obj.update(self._amount_read)
 
             self._amount_read += len(buf)
-            self.fo.write(buf)
+            try:
+                self.fo.write(buf)
+            except IOError, e:
+                self._cb_error = URLGrabError(16, exception2msg(e))
+                return -1
             return len(buf)
         except KeyboardInterrupt:
             return -1
@@ -1453,16 +1457,13 @@ class PyCurlFileObject(object):
                 errcode = self._error[0]
                 
             if errcode == 23 and code >= 200 and code < 299:
-                err = URLGrabError(15, _('User (or something) called abort %s: %s') % (errurl, e))
-                err.url = errurl
-                
                 # this is probably wrong but ultimately this is what happens
                 # we have a legit http code and a pycurl 'writer failed' code
                 # which almost always means something aborted it from outside
                 # since we cannot know what it is -I'm banking on it being
                 # a ctrl-c. XXXX - if there's a way of going back two raises to 
                 # figure out what aborted the pycurl process FIXME
-                raise KeyboardInterrupt
+                raise getattr(self, '_cb_error', KeyboardInterrupt)
             
             elif errcode == 28:
                 err = URLGrabError(12, _('Timeout on %s: %s') % (errurl, e))
@@ -1480,8 +1481,6 @@ class PyCurlFileObject(object):
                 raise err
                 
             elif errcode == 42:
-                err = URLGrabError(15, _('User (or something) called abort %s: %s') % (errurl, e))
-                err.url = errurl
                 # this is probably wrong but ultimately this is what happens
                 # we have a legit http code and a pycurl 'writer failed' code
                 # which almost always means something aborted it from outside
commit 3e81729afe7fc558be98816fb4f64ea263a2d9e7
Author: Zdeněk Pavlas <zpavlas at redhat.com>
Date:   Wed Sep 19 10:54:35 2012 +0200

    add exception2msg, as str(IOError/OSError) may fail

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 01218b0..0e20cee 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -621,6 +621,12 @@ def _to_utf8(obj, errors='replace'):
         obj = obj.encode('utf-8', errors)
     return obj
 
+def exception2msg(e):
+    try:
+        return str(e)
+    except UnicodeEncodeError:
+        return unicode(e)
+
 ########################################################################
 #                 END UTILITY FUNCTIONS
 ########################################################################
diff --git a/urlgrabber/mirror.py b/urlgrabber/mirror.py
index b17be17..eeeb5d0 100644
--- a/urlgrabber/mirror.py
+++ b/urlgrabber/mirror.py
@@ -96,6 +96,7 @@ import thread  # needed for locking to make this threadsafe
 
 from grabber import URLGrabError, CallbackObject, DEBUG, _to_utf8
 from grabber import _run_callback, _do_raise
+from grabber import exception2msg
 
 def _(st): 
     return st
@@ -411,7 +412,7 @@ class MirrorGroup:
                 return func_ref( *(fullurl,), opts=opts, **kw )
             except URLGrabError, e:
                 if DEBUG: DEBUG.info('MIRROR: failed')
-                gr.errors.append((fullurl, str(e)))
+                gr.errors.append((fullurl, exception2msg(e)))
                 obj = CallbackObject()
                 obj.exception = e
                 obj.mirror = mirrorchoice['mirror']


More information about the Yum-commits mailing list