[Python-3000] PEP 3138- String representation in Python 3000

M.-A. Lemburg mal at egenix.com
Thu May 15 12:22:45 CEST 2008


On 2008-05-15 11:12, Stephen J. Turnbull wrote:
> Greg Ewing writes:
> 
>  > What I'm not seeing is a clear rationale on where you
>  > draw the line. Out of all the possible transformations
>  > between a string and some other kind of data, which
>  > ones deserve to be available via this rather strange
>  > and special interface, and why?
> 
> I don't know nuthin about just desserts.
> 
> As I wrote earlier in response to Jim, what I would *expect* to be
> provided by this interface (not necessarily named "encode" and
> "decode", but invoked as a method with a transformation name as
> parameter) are those transformations that are "like codecs":
> stream-oriented and invertible.

str.transform(encoding) will use the standard codecs.encode(encoding),
but additionally check that the output has the type str and raise
an error if it doesn't.

Dito for .untransform(encoding).

For bytes, the methods will check that the output has type bytes and
raise an error if it doesn't.

The methods could also check the meta-data on the found codecs
before actually running the transformation, but that may not
always lead to usable results, e.g. if a codec can handle both
str->str and bytes->bytes by doing the type check itself.

In any case, the above type checks will always happen to not cause
unexpected results.

I'll write up a PEP once we have a better understanding of the
details, e.g. of how the codec type information should be
defined...

Here's a straight-forward approach:

codecinfo.encode_type_combinations = [(bytes, bytes), (str, str)]
codecinfo.decode_type_combinations = [(bytes, bytes), (str, str)]

for most codecs (e.g. utf-8, latin-1, cp850, etc.) this would
then be:

codecinfo.encode_type_combinations = [(str, bytes)]
codecinfo.decode_type_combinations = [(bytes, str)]

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 15 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