]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
pybind: Add Python 3 support for rados and rbd modules
authorDavid Coles <dcoles@gaikai.com>
Thu, 15 Oct 2015 21:58:53 +0000 (14:58 -0700)
committerDavid Coles <dcoles@gaikai.com>
Mon, 19 Oct 2015 22:06:52 +0000 (15:06 -0700)
commitab6b92398071a5e364514afe2bdb57a634c04ceb
treef310a591abdd2c0902b031503f5da06e988c7ffd
parentc55f8d4300019bf2da1fe52edb0c2151cc8e3d2e
pybind: Add Python 3 support for rados and rbd modules

Python 3 explicitly distinguishes between strings (which can contain any Unicode
character) and 8-bit byte strings. This means that we must explicitly encode and
decode strings that use C-style char* string APIs.

Functions that take a true-strings now have their values encoded to UTF-8 before
being passed to the C API, while functions that accept binary data only accept
the bytes type. To help with this the `cstr` helper function has been introduced
as a way of easily a string into a C-string compatible form.

There is also a number of general Python 3 compatibility fixes:

    - dict.iteritems() is replaced with just dict.items()
    - xrange() is replaced with just range
    - Iterators now use the __next__ magic method
    - zip() and map() now return iterators, rather than lists
    - print() is now a function
    - contextlib.nexted() is replaced with multiple manager with-statement (from Python 2.7)

This also required updating of the unit-tests for these modules, mostly due to
explicitly distinguishing between strings and byte strings.

Signed-off-by: David Coles <dcoles@gaikai.com>
src/pybind/rados.py
src/pybind/rbd.py
src/test/pybind/test_rados.py
src/test/pybind/test_rbd.py