[Yum-devel] [PATCH 1/2] add exception2msg, as str(IOError/OSError) may fail

tim.lauridsen at gmail.com tim.lauridsen at gmail.com
Wed Sep 19 14:45:01 UTC 2012


On Wed, Sep 19, 2012 at 1:26 PM, Zdeněk Pavlas <zpavlas at redhat.com> wrote:

> ---
>  urlgrabber/grabber.py |    6 ++++++
>  urlgrabber/mirror.py  |    3 ++-
>  2 files changed, 8 insertions(+), 1 deletions(-)
>
> 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']
> --
> 1.7.4.4
>
> _______________________________________________
> Yum-devel mailing list
> Yum-devel at lists.baseurl.org
> http://lists.baseurl.org/mailman/listinfo/yum-devel
>

ACK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.baseurl.org/pipermail/yum-devel/attachments/20120919/56d6bdca/attachment.html>


More information about the Yum-devel mailing list