On 2008-05-15 13:01, Nick Coghlan wrote:
M.-A. Lemburg wrote:
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)]
Do we need something that flexible? Would a simpler approach with
separate "binary_transform" and "text_transform" flags be enough?
With the latter approach, the encode()/decode() methods could complain
if either of the transform flags was set on the codec, while the
transform()/untransform() methods could complain if the appropriate
transform flag *wasn't* set.
The above is a mechanism for codecs which do have a very
flexible interface in terms of supported types.
The methods on various objects are just convenience helpers
for easier access and in Py3k also provide type-safety.
The .transform() methods would simply check for the corresponding
type combination, ie. str.transform() would check for (str, str).
str.encode() would check for (str, bytes), bytes.decode() for
(bytes, str).
Alternatively, we could just not check the type combinations
at all and only apply the result type check.
Note also that both bytearray and bytes provide decode() methods, and
will presumably provide transform() methods, so actual type annotations
may not be the best way to go about this.
I'm not sure I understand.
--
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
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com