diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-04-15 16:19:12 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-04-15 16:19:12 +0200 |
| commit | c876c5095673a2f1c0f2c0eef6eadef2ce200e19 (patch) | |
| tree | f0832dbbdeb688e0176294e9b487f996108555ad /python/generic.h | |
| parent | 97d985d73d12da5578628418aa787d78a33b652d (diff) | |
| download | python-apt-c876c5095673a2f1c0f2c0eef6eadef2ce200e19.tar.gz | |
* Introduce support for Python 3 (Closes: #523645)
This is the first initial port to Python 3. The API is almost completely
identical to the one found in Python 2, except that functions working with
binary data require bytes (md5sum,sha1sum,sha256sum,Base64Encode).
Using setup3.py to install the modules will not work, because the apt package
still has to be converted to Python 3. For the package, we call 2to3-3.1 in
debian/rules to do this automatically.
Diffstat (limited to 'python/generic.h')
| -rw-r--r-- | python/generic.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/python/generic.h b/python/generic.h index ce79a54c..6e66d24c 100644 --- a/python/generic.h +++ b/python/generic.h @@ -35,6 +35,31 @@ typedef int Py_ssize_t; #endif +/* Define compatibility for Python 3. + * + * We will use the names PyString_* to refer to the default string type + * of the current Python version (PyString on 2.X, PyUnicode on 3.X). + * + * When we really need unicode strings, we will use PyUnicode_* directly, as + * long as it exists in Python 2 and Python 3. + * + * When we want bytes in Python 3, we use PyBytes*_ instead of PyString_* and + * define aliases from PyBytes_* to PyString_* for Python 2. + */ + +#if PY_MAJOR_VERSION >= 3 +#define PyString_Check PyUnicode_Check +#define PyString_FromString PyUnicode_FromString +#define PyString_FromStringAndSize PyUnicode_FromStringAndSize +#define PyString_AsString(op) PyBytes_AsString(PyUnicode_AsUTF8String(op)) +#define PyInt_Check PyLong_Check +#define PyInt_AsLong PyLong_AsLong +#else +#define PyBytes_Check PyString_Check +#define PyBytes_AsString PyString_AsString +#define PyBytes_AsStringAndSize PyString_AsStringAndSize +#endif + template <class T> struct CppPyObject : public PyObject { // We are only using CppPyObject and friends as dumb structs only, ie the |
