[Python-3000] Bytes and unicode conversion in C extensions
mal at egenix.com
Wed Jul 30 15:55:39 CEST 2008
On 2008-07-30 07:17, Andrew McNamara wrote:
>>> What about a new keyword argument to the constructor, "encoding". If
>>> specified, *only* accept unicode (and do the conversion internally).
>> Would that apply to keys, values, or both?
> I admit that I deliberately glossed over that. 8-)
> One option is to say "both", just to keep it simple: if you're doing
> something funky, use the "bytes" mode and do your own encoding.
> Another option would be have "key_encoding" and "value_encoding" as well,
> and let them default to "encoding". I'm not so keen on this.
> I think the important point is to throw an exception if the module gets
> input of the wrong type, rather than trying to coerce the input. Which
> implies it needs to know what mode it's in.
Since bsddb is about storing arbitrary data, I think just accepting
bytes for both keys and values is more intuitive.
The question of encoding is application and database specific, so
not something you'd want to put into a low-level interface.
BTW: If you make the database object subclassable, an application
could easily implement whatever strategy is needed on top of the
Professional Python Services directly from the Source (#1, Jul 30 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