[Python-Dev] Allowing u.encode() to return non-strings
mal at egenix.com
Wed Jun 16 05:55:00 EDT 2004
As you may know, the method u"abc".encode(encoding) currently
guarantees that the return value will always be an 8-bit string
Now that more and more codecs become available and the scope
of those codecs goes far beyond only encoding from Unicode to
strings and back, I am tempted to open up that restriction,
thereby opening up u.encode() for applications that wish to
use other codecs that return e.g. Unicode objects as well.
There are several applications for this, such as character
escaping, remapping characters (much like you would use
string.translate() on 8-bit strings), compression, etc. etc.
Note that codecs are not restricted in what they can return
for their .encode() or .decode() method, so any object
type is acceptable, including subclasses of str or
unicode, buffers, mmapped files, etc.
The needed code change is a one-liner.
What do you think ?
Professional Python Services directly from the Source (#1, Jun 16 2004)
>>> 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,FreeBSD for free ! ::::
More information about the Python-Dev