Description: Switch sip bindings to Python3
Author: Gianfranco Costamagna <locutusofborg@debian.org>
Forwarded: https://github.com/crayzeewulf/libserial/pull/157/files
Last-Update: 2020-02-17

--- libserial-1.0.0.orig/.ycm_extra_conf.py
+++ libserial-1.0.0/.ycm_extra_conf.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 import ycm_core
 
 def FlagsForFile( filename, **kwargs ):
--- libserial-1.0.0.orig/README.md
+++ libserial-1.0.0/README.md
@@ -19,7 +19,7 @@ An self-contained example project demons
 If you are a developer and would like to make use of the latest code, you will
 need to have a few packages installed to build LibSerial: a recent g++ release
 (anything after gcc-3.2 should work), autotools, cmake, doxygen, sphinx, the
-python sip library, the boost unit test library, pkg-config, and Google Test
+python3 sip library, the boost unit test library, pkg-config, and Google Test
 (gtest). The following commands should install the required packages for
 Debian/Ubuntu users:
 
@@ -27,7 +27,7 @@ Debian/Ubuntu users:
 sudo apt update
 sudo apt install g++ git autogen autoconf build-essential cmake graphviz \
                  libboost-dev libboost-test-dev libgtest-dev libtool \
-                 python-sip-dev doxygen python-sphinx pkg-config
+                 python3-sip-dev doxygen python3-sphinx pkg-config
 ```
 ----
 If you get the source code from github and would like to install the library, there are a few steps you will need to accomplish:
--- libserial-1.0.0.orig/configure.ac
+++ libserial-1.0.0/configure.ac
@@ -43,10 +43,10 @@ dnl Checks for typedefs, structures, and
 AC_C_CONST
 AC_C_INLINE
 
-AC_ARG_WITH([python],
-	AS_HELP_STRING([--without-python], [Disable Python bindings]),
-	[], [with_python=yes])
-AM_CONDITIONAL([PYTHON], [test "${with_python}" != "no"])
+AC_ARG_WITH([python3],
+	AS_HELP_STRING([--without-python3], [Disable Python bindings]),
+	[], [with_python3=yes])
+AM_CONDITIONAL([PYTHON], [test "${with_python3}" != "no"])
 
 AC_ARG_ENABLE([tests],
 	AS_HELP_STRING([--disable-tests], [Disable tests]),
--- libserial-1.0.0.orig/sip/Makefile.am
+++ libserial-1.0.0/sip/Makefile.am
@@ -19,7 +19,7 @@ libserialmod.so: Makefile.sip @top_build
 	make -f Makefile.sip
 
 Makefile.sip: configure.py $(SIPFILES)
-	python ./configure.py
+	python3 ./configure.py
 
 clean-local: Makefile.sip
 	make -f Makefile.sip clean
--- libserial-1.0.0.orig/sip/configure.py.in
+++ libserial-1.0.0/sip/configure.py.in
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 import os
 import sys
 import logging
@@ -7,7 +7,7 @@ import sipconfig
 
 def create_options_parser():
     """Create a parser to extract value from command line options."""
-    parser = optparse.OptionParser( usage = "python %prog [opts]" )
+    parser = optparse.OptionParser( usage = "python3 %prog [opts]" )
     parser.add_option( "-t", "--otdir",
                        action = "store",
                        type   = "string",
--- libserial-1.0.0.orig/sip/recv_test.py
+++ libserial-1.0.0/sip/recv_test.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 from libserial import SerialPort
 import errno
 import sys
@@ -15,8 +15,8 @@ def main():
             sys.stdout.write( serial_port.ReadByte() )
     except IOError, (errorNumber, errorMessage):
         if ( errno.EINTR == errorNumber ):
-            print
-            print "Ignoring EINTR."
+            print()
+            print("Ignoring EINTR.")
             pass
         else:
             raise
--- libserial-1.0.0.orig/sip/send_test.py
+++ libserial-1.0.0/sip/send_test.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 import sys
 import libserial
 
--- libserial-1.0.0.orig/sip/string.sip
+++ libserial-1.0.0/sip/string.sip
@@ -11,7 +11,7 @@
     // Python object and return the result.
     if ( ! sipIsErr )
     {
-        return PyString_Check( sipPy );
+        return PyUnicode_Check(PyObject_Str( sipPy ));
     }
 
     char *str_val = 0 ;
--- libserial-1.0.0.orig/sip/test_control_lines.py
+++ libserial-1.0.0/sip/test_control_lines.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 from libserial import SerialPort
 from time      import sleep
 import optparse
--- libserial-1.0.0.orig/sip/vector.sip
+++ libserial-1.0.0/sip/vector.sip
@@ -205,7 +205,7 @@ template<TYPE>
     for (int i = 0; i < (int)sipCpp -> size(); ++i)
     {
         // Add the wrapper to the list.
-        PyList_SET_ITEM(l, i, PyInt_FromLong(sipCpp -> at(i)));
+        PyList_SET_ITEM(l, i, PyLong_FromLong(sipCpp -> at(i)));
     }
 
     // Return the Python list.
@@ -236,14 +236,14 @@ template<TYPE>
     {
         while ((item = PyIter_Next(iterator)))
         {
-            if (!PyInt_Check(item))
+            if (!PyLong_Check(item))
             {
                 PyErr_Format(PyExc_TypeError, "object in iterable cannot be converted to float");
                 *sipIsErr = 1;
                 break;
             }
 
-            int val = PyInt_AsLong(item);
+            int val = PyLong_AsLong(item);
             V->push_back(val);
 
             Py_DECREF(item);
@@ -286,7 +286,7 @@ template<TYPE>
     for (int i = 0; i < (int)sipCpp -> size(); ++i)
     {
         // Add the wrapper to the list.
-        PyList_SET_ITEM(l, i, PyInt_FromLong(sipCpp -> at(i)));
+        PyList_SET_ITEM(l, i, PyLong_FromLong(sipCpp -> at(i)));
     }
 
     // Return the Python list.
@@ -317,14 +317,14 @@ template<TYPE>
     {
         while ((item = PyIter_Next(iterator)))
         {
-            if (!PyInt_Check(item))
+            if (!PyLong_Check(item))
             {
                 PyErr_Format(PyExc_TypeError, "object in iterable cannot be converted to float");
                 *sipIsErr = 1;
                 break;
             }
 
-            unsigned int val = PyInt_AsLong(item);
+            unsigned int val = PyLong_AsLong(item);
             V->push_back(val);
 
             Py_DECREF(item);
@@ -366,7 +366,7 @@ template<TYPE>
     for (int i = 0; i < (int)sipCpp -> size(); ++i)
     {
         // Add the wrapper to the list.
-        PyList_SET_ITEM(l, i, PyInt_FromLong(sipCpp -> at(i)));
+        PyList_SET_ITEM(l, i, PyLong_FromLong(sipCpp -> at(i)));
     }
 
     // Return the Python list.
@@ -397,14 +397,14 @@ template<TYPE>
     {
         while ((item = PyIter_Next(iterator)))
         {
-            if (!PyInt_Check(item))
+            if (!PyLong_Check(item))
             {
                 PyErr_Format(PyExc_TypeError, "object in iterable cannot be converted to float");
                 *sipIsErr = 1;
                 break;
             }
 
-            unsigned int val = PyInt_AsLong(item);
+            unsigned int val = PyLong_AsLong(item);
             V->push_back(val);
 
             Py_DECREF(item);
