2013-10-21 05:00 Mike Frysinger napisaƂ(a):
> On Wednesday 16 October 2013 23:42:26 Arfrever Frehtes Taifersar wrote:
> > - cStringIO module should not be used. io module is a replacement available
> > since Python 2.6.
> 
> unfortunately, that doesn't work as well as it should.  python 2.7's 
> interface 
> is annoyingly different when using other python 2.7 modules.  i'll have the 
> code import the old module and then fallback to using the new io module.

(io.StringIO works only with unicode strings.
When bytes-compatible functions are really needed, then io.BytesIO can be used, 
which works only with bytes.
cStringIO.StringIO is designed to work with bytes, but 
cStringIO.StringIO().write(instance_of_unicode)
implicitly encodes its argument to bytes.)

In your another patch, 
portage.tests.bin.test_prepstrip.PrepStripFull._prepstrip() passes an instance 
of
cStringIO.StringIO class to portage.bin.prepstrip.main(), which passes it to 
portage.bin.prepstrip.Prepstrip(),
which passes it to print(), portage.elog.messages.eqawarn() and 
portage.elog.messages.ewarn().

pym/portage/bin/prepstrip.py should have:
from __future__ import unicode_literals

Then print('...', file=out) calls will work with an instance of io.StringIO 
class.

(portage.elog.messages.eqawarn() and portage.elog.messages.ewarn() internally 
decode message,
so they already work with out=io.StringIO, but not out=io.BytesIO.)

--
Arfrever Frehtes Taifersar Arahesis

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to