On Wed, Jan 12, 2011 at 11:22:56AM -0500, seth vidal wrote: > On Wed, 2011-01-12 at 09:58 -0500, James Antill wrote: > > --- > > utils.py | 23 +---------------------- > > yum/i18n.py | 22 +++++++++++++++++++++- > > 2 files changed, 22 insertions(+), 23 deletions(-) > > > > diff --git a/utils.py b/utils.py > > index ced6ba0..8891ddf 100644 > > --- a/utils.py > > +++ b/utils.py > > @@ -21,7 +21,7 @@ import yum > > from cli import * > > from yum import Errors > > from yum import _ > > -from yum.i18n import utf8_width > > +from yum.i18n import utf8_width, exception2msg > > from yum import logginglevels > > from optparse import OptionGroup > > > > @@ -129,27 +129,6 @@ def show_lock_owner(pid, logger): > > return ps > > > > > > -def exception2msg(e): > > - """ DIE python DIE! Which one works: > > - to_unicode(e.value); unicode(e); str(e); > > - Call this so you don't have to care. """ > > - try: > > - return to_unicode(e.value) > > - except: > > - pass > > - > > - try: > > - return unicode(e) > > - except: > > - pass > > - > > - try: > > - return str(e) > > - except: > > - pass > > - return "<exception failed to convert to text>" > > - > > - > > class YumUtilBase(YumBaseCli): > > def __init__(self,name,ver,usage): > > YumBaseCli.__init__(self) > > diff --git a/yum/i18n.py b/yum/i18n.py > > index 9889bf6..2df81bb 100755 > > --- a/yum/i18n.py > > +++ b/yum/i18n.py > > @@ -461,7 +461,27 @@ def str_eq(a, b): > > return True > > > > return False > > - > > + > > +def exception2msg(e): > > + """ DIE python DIE! Which one works: > > + to_unicode(e.value); unicode(e); str(e); > > + Call this so you don't have to care. """ > > + try: > > + return to_unicode(e.value) > > + except: > > + pass > > + > > + try: > > + return unicode(e) > > + except: > > + pass > > + > > + try: > > + return str(e) > > + except: > > + pass > > + return "<exception failed to convert to text>" > > + > > try: > > ''' > > Setup the yum translation domain and make _() and P_() translation > > wrappers > > > If the longer-term goal is to dump i18n for kitchen - should we think > about either: > > 1. putting exception2msg in kitchen > or > Using kitchen-0.2.3, the code in yum would look like this:
from kitchen.text.converters import (EXCEPTION_CONVERTERS, exception_to_unicode) def exception2msg(e): c = [lambda e: to_unicode(e.value)] c.extend(EXCEPTION_CONVERTERS) return converters.exception_to_unicode(e, converters=c) The kitchen code is a bit more generic than the yum method, it's looking for e.args[0], convert to unicode, or convert to str. From there it creates a unicode string to return. Since yum uses e.value in its exceptions, we have this little shim to add that as a way to convert. -Toshio
pgp1K86L6ICLs.pgp
Description: PGP signature
_______________________________________________ Yum-devel mailing list Yum-devel@lists.baseurl.org http://lists.baseurl.org/mailman/listinfo/yum-devel