[Yum-devel] [PATCH] Stop the python encoding madness, with a big hammer of fire.

Toshio Kuratomi a.badger at gmail.com
Mon Mar 7 18:03:20 UTC 2011


On Mon, Mar 07, 2011 at 10:56:07AM -0500, seth vidal wrote:
> On Mon, 2011-03-07 at 10:52 -0500, James Antill wrote:
> > ---
> >  yum/misc.py |    7 ++++++-
> >  1 files changed, 6 insertions(+), 1 deletions(-)
> > 
> > diff --git a/yum/misc.py b/yum/misc.py
> > index 8e81c34..305d4aa 100644
> > --- a/yum/misc.py
> > +++ b/yum/misc.py
> > @@ -977,7 +977,8 @@ def getloginuid():
> >  # ---------- i18n ----------
> >  import locale
> >  import sys
> > -def setup_locale(override_codecs=True, override_time=False):
> > +def setup_locale(override_codecs=True, override_time=False,
> > +                 override_encoding=True):
> >      # This test needs to be before locale.getpreferredencoding() as that
> >      # does setlocale(LC_CTYPE, "")
> >      try:
> > @@ -995,6 +996,10 @@ def setup_locale(override_codecs=True, override_time=False):
> >          import codecs
> >          sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
> >          sys.stdout.errors = 'replace'
> > +    if override_encoding:
> > +        # Dear python, please let your 'ascii' default die in a fire. kthxbye
> > +        reload(sys)
> > +        sys.setdefaultencoding('utf-8')
> >  
> > 
> >  def get_my_lang_code():
> 
> 
> So, you're just interested in seeing what ways this breaks things?
> 
> How about we apply this to rawhide yum first, just for s&g and see what
> goes KABOOM before applying upstream?
> 
Although getting rid of sys.setdefaultencoding() is probably a good thing
(upstream python claims that using it will break certain aspects of text
handling in python's internals), I agree that there's a lot of potential to
break stuff by making this change.  Test and fix will be in order when this
is applied.

Also, you might want to look at how kitchen.text.converters.getwriter()
is implemented instead of using codecs.getwriter().  It won't save you from
mangled text but it will save you from some tracebacks.

https://fedorahosted.org/releases/k/i/kitchen/docs/unicode-frustrations.html#frustration-4-now-it-doesn-t-take-byte-strings
https://fedorahosted.org/releases/k/i/kitchen/docs/api-text-converters.html#kitchen.text.converters.getwriter
http://bzr.fedorahosted.org/bzr/kitchen/devel/revision/263

-Toshio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.baseurl.org/pipermail/yum-devel/attachments/20110307/fd979ea3/attachment.asc>


More information about the Yum-devel mailing list