[Python-Dev] why doesn't print pass unicode strings on to the file object?

M.-A. Lemburg mal@lemburg.com
Tue, 18 Sep 2001 19:35:45 +0200


Martin von Loewis wrote:
> 
> > > What user code exactly would break? Would that be a serious problem?
> >
> > All code which assumes a tuple as return value. It's hard to
> > say how much code makes such an assumption. Most Python
> > code probably only uses the sequence interface, but the C interface
> > was deliberately designed to return tuples so that C programmers
> > can easily access the data.
> 
> I believe that code would continue to work if you got a instance of a
> tuple subtype.

It might work at Python level, maybe even at C level, but I really
don't see the point in trying to hack up a new type just for this
purpose.
 
Here's an implementation which pretty much solves the "problem":

--

### Helpers for codec lookup

def getencoder(encoding):

    """ Lookup up the codec for the given encoding and return
        its encoder function.

        Raises a LookupError in case the encoding cannot be found.

    """
    return lookup(encoding)[0]

def getdecoder(encoding):

    """ Lookup up the codec for the given encoding and return
        its decoder function.

        Raises a LookupError in case the encoding cannot be found.

    """
    return lookup(encoding)[1]

def getreader(encoding):

    """ Lookup up the codec for the given encoding and return
        its StreamReader class or factory function.

        Raises a LookupError in case the encoding cannot be found.

    """
    return lookup(encoding)[2]

def getwriter(encoding):

    """ Lookup up the codec for the given encoding and return
        its StreamWriter class or factory function.

        Raises a LookupError in case the encoding cannot be found.

    """
    return lookup(encoding)[3]

--

If noone objects, I'll check these into CVS along with some docs
for libcodecs.tex.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/