[Python-3000] PEP 3138- String representation in Python 3000
M.-A. Lemburg
mal at egenix.com
Tue May 20 12:19:40 CEST 2008
On 2008-05-19 23:03, Martin v. Löwis wrote:
>> They are convenience methods to the codecs registry
>> with the added benefit of applying type checks which the codecs
>> registry does not guarantee since it only manages codecs.
>
> I argue that things that could be parameters to .transform don't
> belong into the codec registry in the first place.
>
>> Of course, you can write everything directly against the codec
>> registry or some other specialized interface, but that's not
>> really what we're after here.
>
> No need for writing directly against the codec registry.
>
> Using some other specialized interface: yes, Yes, YES!
So you would like to force users to write e.g.
def uu(input,errors='strict',filename='<data>',mode=0666):
from cStringIO import StringIO
from binascii import b2a_uu
# using str() because of cStringIO's Unicode undesired Unicode behavior.
infile = StringIO(str(input))
outfile = StringIO()
read = infile.read
write = outfile.write
# Encode
write('begin %o %s\n' % (mode & 0777, filename))
chunk = read(45)
while chunk:
write(b2a_uu(chunk))
chunk = read(45)
write(' \nend\n')
return outfile.getvalue()
(this is adapted Py2 code taken from the uu codec)
instead of writing
output = input.transform('uu')
Fair enough, I've noted your -1.
Still, I don't think the specialized interfaces are very user-friendly.
They do serve their purpose, but common usage just doesn't really bother
with all those details.
And it doesn't end there...
You have to look up, implement and test a similar standardizing function
for all other specialized interfaces you want to use as well - more or
less reinventing the codec interface for every application you write.
Anyway, even without a .transform() method, you can still do:
import codecs
output = codecs.encode(input, 'uu')
However, you then have to do the type checking yourself.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 20 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-3000
mailing list