Re: [getdata-devel] Patch for Python 3 Support
Scientific Database Format
Brought to you by:
ketiltrout
|
From: D. V. W. <ge...@ke...> - 2016-04-28 23:07:18
|
On Mon, Apr 04, 2016 at 10:22:05AM -0400, Matthew Petroff wrote: > Attached is a patch to add Python 3 support to the Python bindings. > Most of the changes are wrapped in preprocessor conditionals and are > related to the int/long and str/unicode changes in Python 3 [1]. The > only visible change for Python 2 is allowing Unicode strings to be > accepted; this breaks support for versions <2.6. If desired, I could > add additional preprocessor conditionals to avoid breaking support. > Currently, bindings are only built for one Python version; it would be > nice to automatically build bindings for both Python 2 and 3, but I'm > not particularly familiar with Autotools. The patch has been tested > with Python 2.7 and 3.4 on Linux Mint 17.3 (Ubuntu 14.04 base). > > -Matthew Petroff Thanks for the patch! I finally got around to applying it, and it worked well, but then I realised pygetdata couldn't automatically UTF-8 decode all the strings returned by the C library because Dirfiles are vague about their character encoding. So, that left me with pygetdata reutning PyBytes objects in Python3, which I didn't like either. So I added the capability in pygetdata for the caller to specify what character encoding to use for strings, which I think is the best that can be done. So, you can do something like: import pygetdata pygetdata.character_encoding = 'utf-8' and proceed. If character_encoding is None (the default), the current locale's default character encoding is used to encode Unicode strings passed to the bindings, but no decoding of strings returned from the C library is done. I've committed the final result of this in SVN revision 1063, which adds Python3 and PyUnicode support. It should be released as 0.9.3 at some point. I've tested it a bit in Python2.4, 2.7, 3.2 (the earliest supported Python3 version), and 3.4. Python 2.3 support has been dropped due to bugs in the 2.3 branch we're not interested in working around, but we're still okay with 2.4 and 2.5, so long as Unicode support is enabled in those versions. It still needs a bit of polish. Cheers, -don -- D. V. Wiebe ge...@ke... http://getdata.sourceforge.net/ |