Python 3 compatibility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

I got a request to help with preparing ecryptfs-utils for Python 3. Because Python code is basically generated by Swig, it was not that hard.

The problem I have right now is testing. Because ecryptfs-utils hasn't any testsuite, it's hard for me to tell whether it works properly or not.

Is there anybody who can help me finish porting of Python part to Python 3 compatible form? I can write tests but I need to know some examples of usage.

Patch attached.

Thank you and have a nice day.

Lumír

>From 82be4f362932c1e4cb94098a1df8e79c8d4962ad Mon Sep 17 00:00:00 2001
From: Lumir Balhar <lbalhar@xxxxxxxxxx>
Date: Mon, 18 Jun 2018 13:16:23 +0200
Subject: [PATCH] Python 3 compatibility

---
 configure                          | 32 ++++++++++++++----------------
 configure.ac                       |  2 +-
 m4/ac_python_devel.m4              | 32 ++++++++++++++----------------
 src/libecryptfs-swig/libecryptfs.i |  4 ++++
 4 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/configure b/configure
index 4995a51..41fabae 100755
--- a/configure
+++ b/configure
@@ -14973,9 +14973,9 @@ fi
         #
         { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a version of Python >= '2.1.0'" >&5
 $as_echo_n "checking for a version of Python >= '2.1.0'... " >&6; }
-        ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                ver = string.split(sys.version)[0]; \
-                print ver >= '2.1.0'"`
+        ac_supports_python_ver=`$PYTHON -c "import sys; \
+                ver = sys.version.split())[0]; \
+                print(ver >= '2.1.0')"`
         if test "$ac_supports_python_ver" != "True"; then
                 if test -z "$PYTHON_NOVERSIONCHECK"; then
                         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -15007,9 +15007,9 @@ $as_echo "yes" >&6; }
         if test -n ""; then
                 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a version of Python " >&5
 $as_echo_n "checking for a version of Python ... " >&6; }
-                ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                        ver = string.split(sys.version)[0]; \
-                        print ver "`
+                ac_supports_python_ver=`$PYTHON -c "import sys; \
+                        ver = sys.version.split()[0]; \
+                        print(ver)"`
                 if test "$ac_supports_python_ver" = "True"; then
                    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
@@ -15050,12 +15050,12 @@ $ac_distutils_result" "$LINENO" 5
 $as_echo_n "checking for Python include path... " >&6; }
         if test -z "$PYTHON_CPPFLAGS"; then
                 python_path=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_inc();"`
+                        print(distutils.sysconfig.get_python_inc());"`
                 if test -n "${python_path}"; then
                         python_path="-I$python_path"
                 fi
                 python_plat_path=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_inc(plat_specific=True);"`
+                        print(distutils.sysconfig.get_python_inc(plat_specific=True));"`
                 if test -n "${python_plat_path}"; then
                         python_plat_path="-I$python_plat_path"
                 fi
@@ -15074,21 +15074,19 @@ $as_echo_n "checking for Python library path... " >&6; }
                 # (makes two attempts to ensure we've got a version number
                 # from the interpreter)
                 py_version=`$PYTHON -c "from distutils.sysconfig import *; \
-                        from string import join; \
-                        print join(get_config_vars('VERSION'))"`
+                        print(''.join(get_config_vars('VERSION')))"`
                 if test "$py_version" == "None"; then
                         if test -n "$PYTHON_VERSION"; then
                                 py_version=$PYTHON_VERSION
                         else
                                 py_version=`$PYTHON -c "import sys; \
-                                        print sys.version[:3]"`
+                                        print(sys.version[:3])"`
                         fi
                 fi
 
                 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
-                        from string import join; \
-                        print '-L' + get_python_lib(0,1), \
-                        '-lpython';"`$py_version
+                        print('-L' + get_python_lib(0,1), \
+                        '-lpython');"`$py_version
         fi
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_LDFLAGS" >&5
 $as_echo "$PYTHON_LDFLAGS" >&6; }
@@ -15101,7 +15099,7 @@ $as_echo "$PYTHON_LDFLAGS" >&6; }
 $as_echo_n "checking for Python site-packages path... " >&6; }
         if test -z "$PYTHON_SITE_PKG"; then
                 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_lib(0,0);"`
+                        print(distutils.sysconfig.get_python_lib(0,0));"`
         fi
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_SITE_PKG" >&5
 $as_echo "$PYTHON_SITE_PKG" >&6; }
@@ -15115,7 +15113,7 @@ $as_echo_n "checking python extra libraries... " >&6; }
         if test -z "$PYTHON_EXTRA_LIBS"; then
            PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
                 conf = distutils.sysconfig.get_config_var; \
-                print conf('LOCALMODLIBS'), conf('LIBS')"`
+                print(conf('LOCALMODLIBS'), conf('LIBS'))"`
         fi
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_EXTRA_LIBS" >&5
 $as_echo "$PYTHON_EXTRA_LIBS" >&6; }
@@ -15129,7 +15127,7 @@ $as_echo_n "checking python extra linking flags... " >&6; }
         if test -z "$PYTHON_EXTRA_LDFLAGS"; then
                 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
                         conf = distutils.sysconfig.get_config_var; \
-                        print conf('LINKFORSHARED')"`
+                        print(conf('LINKFORSHARED'))"`
         fi
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_EXTRA_LDFLAGS" >&5
 $as_echo "$PYTHON_EXTRA_LDFLAGS" >&6; }
diff --git a/configure.ac b/configure.ac
index bbc6ffc..dffe45f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -267,7 +267,7 @@ CFLAGS="${OLD_CFLAGS}"
 
 if test "${enable_pywrap}" != "no" ; then
 	AM_PATH_PYTHON(2.5, [have_python="yes"], [have_python="no"])
-	AC_PROG_SWIG(1.3.31)
+	AC_PROG_SWIG()
 	SWIG_PYTHON
 fi
 
diff --git a/m4/ac_python_devel.m4 b/m4/ac_python_devel.m4
index 084cfc2..966071a 100644
--- a/m4/ac_python_devel.m4
+++ b/m4/ac_python_devel.m4
@@ -17,9 +17,9 @@ AC_DEFUN([AC_PYTHON_DEVEL],[
         # Check for a version of Python >= 2.1.0
         #
         AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
-        ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                ver = string.split(sys.version)[[0]]; \
-                print ver >= '2.1.0'"`
+        ac_supports_python_ver=`$PYTHON -c "import sys; \
+                ver = sys.version.split()[[0]]; \
+                print(ver >= '2.1.0')"`
         if test "$ac_supports_python_ver" != "True"; then
                 if test -z "$PYTHON_NOVERSIONCHECK"; then
                         AC_MSG_RESULT([no])
@@ -44,9 +44,9 @@ to something else than an empty string.
         #
         if test -n "$1"; then
                 AC_MSG_CHECKING([for a version of Python $1])
-                ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                        ver = string.split(sys.version)[[0]]; \
-                        print ver $1"`
+                ac_supports_python_ver=`$PYTHON -c "import sys; \
+                        ver = sys.version.split()[[0]]; \
+                        print(ver $1)"`
                 if test "$ac_supports_python_ver" = "True"; then
                    AC_MSG_RESULT([yes])
                 else
@@ -81,12 +81,12 @@ $ac_distutils_result])
         AC_MSG_CHECKING([for Python include path])
         if test -z "$PYTHON_CPPFLAGS"; then
                 python_path=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_inc();"`
+                        print(distutils.sysconfig.get_python_inc());"`
                 if test -n "${python_path}"; then
                         python_path="-I$python_path"
                 fi
                 python_plat_path=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_inc(plat_specific=True);"`
+                        print(distutils.sysconfig.get_python_inc(plat_specific=True));"`
                 if test -n "${python_plat_path}"; then
                         python_plat_path="-I$python_plat_path"
                 fi
@@ -103,21 +103,19 @@ $ac_distutils_result])
                 # (makes two attempts to ensure we've got a version number
                 # from the interpreter)
                 py_version=`$PYTHON -c "from distutils.sysconfig import *; \
-                        from string import join; \
-                        print join(get_config_vars('VERSION'))"`
+                        print(''.join(get_config_vars('VERSION')))"`
                 if test "$py_version" == "[None]"; then
                         if test -n "$PYTHON_VERSION"; then
                                 py_version=$PYTHON_VERSION
                         else
                                 py_version=`$PYTHON -c "import sys; \
-                                        print sys.version[[:3]]"`
+                                        print(sys.version[[:3]])"`
                         fi
                 fi
 
                 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
-                        from string import join; \
-                        print '-L' + get_python_lib(0,1), \
-                        '-lpython';"`$py_version
+                        print('-L' + get_python_lib(0,1), \
+                        '-lpython');"`$py_version
         fi
         AC_MSG_RESULT([$PYTHON_LDFLAGS])
         AC_SUBST([PYTHON_LDFLAGS])
@@ -128,7 +126,7 @@ $ac_distutils_result])
         AC_MSG_CHECKING([for Python site-packages path])
         if test -z "$PYTHON_SITE_PKG"; then
                 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
-                        print distutils.sysconfig.get_python_lib(0,0);"`
+                        print(distutils.sysconfig.get_python_lib(0,0));"`
         fi
         AC_MSG_RESULT([$PYTHON_SITE_PKG])
         AC_SUBST([PYTHON_SITE_PKG])
@@ -140,7 +138,7 @@ $ac_distutils_result])
         if test -z "$PYTHON_EXTRA_LIBS"; then
            PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
                 conf = distutils.sysconfig.get_config_var; \
-                print conf('LOCALMODLIBS'), conf('LIBS')"`
+                print(conf('LOCALMODLIBS'), conf('LIBS'))"`
         fi
         AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
         AC_SUBST(PYTHON_EXTRA_LIBS)
@@ -152,7 +150,7 @@ $ac_distutils_result])
         if test -z "$PYTHON_EXTRA_LDFLAGS"; then
                 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
                         conf = distutils.sysconfig.get_config_var; \
-                        print conf('LINKFORSHARED')"`
+                        print(conf('LINKFORSHARED'))"`
         fi
         AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
         AC_SUBST(PYTHON_EXTRA_LDFLAGS)
diff --git a/src/libecryptfs-swig/libecryptfs.i b/src/libecryptfs-swig/libecryptfs.i
index e7fd3d3..7b7b93d 100644
--- a/src/libecryptfs-swig/libecryptfs.i
+++ b/src/libecryptfs-swig/libecryptfs.i
@@ -9,7 +9,11 @@ extern int ecryptfs_add_blob_to_keyring(char *blob, char *sig);
 #include "../include/ecryptfs.h"
 
 %typemap(out) binary_data {
+%#if PY_MAJOR_VERSION >= 3
+    $result = PyBytes_FromStringAndSize((char *)($1.data),$1.size);
+%#else
     $result = PyString_FromStringAndSize((char *)($1.data),$1.size);
+%#endif
 }
 
 extern binary_data ecryptfs_passphrase_blob(char *salt, char *passphrase);
-- 
2.17.1


[Index of Archives]     [Linux Crypto]     [Device Mapper Crypto]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux