Użytkownik Paul McNett napisał:
> Modified: trunk/dabo/lib/utils.py
> ===================================================================
> --- trunk/dabo/lib/utils.py   2010-10-21 17:09:46 UTC (rev 6121)
> +++ trunk/dabo/lib/utils.py   2010-10-21 22:12:34 UTC (rev 6122)
> @@ -149,21 +149,31 @@
>
>
>   def ustr(value):
> -     """When converting to a string, do not use the str() function, which
> +     """Convert the passed value to a python unicode object.
> +
> +     When converting to a string, do not use the str() function, which
>       can create encoding errors with non-ASCII text.
>       """
>       if isinstance(value, unicode):
> +             # Don't change the encoding of an object that is already 
> unicode.
>               return value
>       if isinstance(value, Exception):
>               return exceptionToUnicode(value)
>       try:
> +             ## Faster for all-ascii strings and converting from 
> non-basestring types::
>               return unicode(value)
> -     except:
> +     except UnicodeDecodeError:
> +             # Most likely there were bytes whose integer ordinal were>  127 
> and so the
> +             # default ASCII codec used by unicode() couldn't decode them.
>               pass
> +     except UnicodeEncodeError:
> +             # Most likely there were bytes whose integer ordinal were>  127 
> and so the
> +             # default ASCII codec used by unicode() couldn't encode them.
> +             pass
>       for ln in getEncodings():
>               try:
>                       return unicode(value, ln)
> -             except:
> +             except UnicodeError:
>                       pass
>       raise UnicodeError("Unable to convert '%r'." % value)
>
> @@ -172,14 +182,15 @@
>       # Handle DBQueryException first.
>       if hasattr(e, "err_desc"):
>               return ustr(e.err_desc)
> +     if hasattr(e, "args"):
> +             return "\n".join((ustr(a) for a in e.args))
>       if hasattr(e, "message"):
> +             # message is deprecated in python 2.6
>               return ustr(e.message)
> -     if hasattr(e, "args"):
> -             return "\n".join((ustr(a) for a in e.args))
>       try:
>               return ustr(e)
>       except:
> -             return u"Unknow message."
> +             return u"Unknown message."
>
>
>   def relativePathList(toLoc, fromLoc=None):
>
>    

Hi.

I see you reordered 'message' and 'args' conditions accordingly to my 
suggestion.
But I was wrong, because Python 2.5 has 'args' attribute too, but it's 
empty tuple,
thus it leads to empty message string as result.
In python 3.0 there is no 'message' attribute, so there will be no 
warning and no problem here.
In summary, revert code order to handle 'message' attribute first, please.

-- 
Regards
Jacek Kałucki


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[email protected]

Reply via email to