[I18n-sig] Transparent Encoding
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Sat, 19 May 2001 08:59:10 +0200
> > An EncodedFile is not suitable since it has byte strings on both ends,
> > and Unicode strings only inside.
>
> EncodedFile seems to work as I ask if I pass it the encoding name as
> "unicode-internal".
What do you mean, "seems to work". The encoding "unicode-internal"
still produces byte strings, e.g.
>>> s=u"Hallo"
>>> s.encode("unicode-internal")
'H\x00a\x00l\x00l\x00o\x00'
>>> s
u'Hallo'
A unicode-internal encoded byte string is *not* the same thing as a
Unicode string.
> Furthermore, code that does that is much simpler
> than code that looks up the codec manually. I'm not a big fan of those
> codec tuples.
>
> Current:
>
> writer = codecs.lookup("utf-8")[3]
> stream = writer(fileobj)
>
> Proposed:
>
> codecs.EncodedFile(fileobj, None, "utf-8")
-0.
Regards,
Martin