diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2020-04-04 20:01:17 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2020-04-09 16:43:34 +0200 |
commit | c4fa6efa67775a6b333a4a5aa873b5cc24a4f7bc (patch) | |
tree | d8977f4c2c97287865a2407b25c0327c49bbe17c /pyuno | |
parent | 2d64651e889e55f63c90ded24e63e17eaf52102f (diff) |
pyuno,*: kill Python 2 support with fire
Python 2 support was retained for use with --enable-python=system
on RHEL7 and SLES. The time has arrived to remove it.
Some .py files that were imported from third parties are not changed to
enable easier replacement with updated versions if necessary.
solenv/gdb should continue to support Python 2.
bin/get-bugzilla-attachments-by-mimetype requires Python 2 to access
Launchpad.
Change-Id: I26414ae8e9f8402c90336af82020135685694217
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91697
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'pyuno')
-rw-r--r-- | pyuno/inc/pyuno.hxx | 7 | ||||
-rw-r--r-- | pyuno/qa/pytests/testcollections_misc2.py | 22 | ||||
-rw-r--r-- | pyuno/source/loader/pythonloader.py | 5 | ||||
-rw-r--r-- | pyuno/source/loader/pyuno_loader.cxx | 9 | ||||
-rw-r--r-- | pyuno/source/module/pyuno.cxx | 26 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_dlopenwrapper.c | 10 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_impl.hxx | 45 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_module.cxx | 10 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_runtime.cxx | 36 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_type.cxx | 4 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_util.cxx | 10 | ||||
-rw-r--r-- | pyuno/source/module/uno.py | 22 |
12 files changed, 14 insertions, 192 deletions
diff --git a/pyuno/inc/pyuno.hxx b/pyuno/inc/pyuno.hxx index c190cfc348c2..f7cab36c7327 100644 --- a/pyuno/inc/pyuno.hxx +++ b/pyuno/inc/pyuno.hxx @@ -53,12 +53,7 @@ namespace com::sun::star::uno { template <typename > class Reference; } the global interpreter lock is held */ -extern "C" LO_DLLPUBLIC_PYUNO -#if PY_MAJOR_VERSION >= 3 - PyObject* PyInit_pyuno(); -#else - void initpyuno(); -#endif +extern "C" LO_DLLPUBLIC_PYUNO PyObject* PyInit_pyuno(); namespace pyuno { diff --git a/pyuno/qa/pytests/testcollections_misc2.py b/pyuno/qa/pytests/testcollections_misc2.py index 8566d2838e81..b696e050a53d 100644 --- a/pyuno/qa/pytests/testcollections_misc2.py +++ b/pyuno/qa/pytests/testcollections_misc2.py @@ -35,28 +35,18 @@ class Test124953(unittest.TestCase): self.assertEqual(LONG_TYPE, long_type) def test_Char(self): - if sys.version_info[0] == 3: - char_a = uno.Char("a") - char_a2 = uno.Char("a") - char_b = uno.Char("b") - else: - char_a = uno.Char(u"a") - char_a2 = uno.Char(u"a") - char_b = uno.Char(u"b") + char_a = uno.Char("a") + char_a2 = uno.Char("a") + char_b = uno.Char("b") self.assertEqual(char_a, char_a) self.assertEqual(char_a, char_a2) self.assertFalse((char_a != char_a2)) self.assertNotEqual(char_a, char_b) def test_ByteSequence(self): - if sys.version_info[0] == 3: - b1 = uno.ByteSequence(bytes("abcdefg", encoding="utf8")) - b2 = uno.ByteSequence(bytes("abcdefg", encoding="utf8")) - b3 = uno.ByteSequence(bytes("1234567", encoding="utf8")) - else: - b1 = uno.ByteSequence("abcdefg") - b2 = uno.ByteSequence("abcdefg") - b3 = uno.ByteSequence("1234567") + b1 = uno.ByteSequence(bytes("abcdefg", encoding="utf8")) + b2 = uno.ByteSequence(bytes("abcdefg", encoding="utf8")) + b3 = uno.ByteSequence(bytes("1234567", encoding="utf8")) self.assertEqual(b1, b1) self.assertEqual(b1, b2) self.assertFalse(b1 != b2) diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py index 5ce69f62ea7e..4233c0e7ca6e 100644 --- a/pyuno/source/loader/pythonloader.py +++ b/pyuno/source/loader/pythonloader.py @@ -90,10 +90,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ): # read the file filename = unohelper.fileUrlToSystemPath( url ) - if sys.version_info >= (3,0): - fileHandle = open( filename, encoding='utf_8' ) - else: - fileHandle = open( filename ) + fileHandle = open( filename, encoding='utf_8' ) src = fileHandle.read().replace("\r","") if not src.endswith( "\n" ): src = src + "\n" diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index c7b7b7289b86..8556dfdde11f 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -121,7 +121,6 @@ static void setPythonHome ( const OUString & pythonHome ) OUString systemPythonHome; osl_getSystemPathFromFileURL( pythonHome.pData, &(systemPythonHome.pData) ); OString o = OUStringToOString( systemPythonHome, osl_getThreadTextEncoding() ); -#if PY_MAJOR_VERSION >= 3 // static because Py_SetPythonHome just copies the "wide" pointer static wchar_t wide[PATH_MAX + 1]; size_t len = mbstowcs(wide, o.pData->buffer, PATH_MAX + 1); @@ -136,10 +135,6 @@ static void setPythonHome ( const OUString & pythonHome ) return; } Py_SetPythonHome(wide); -#else - rtl_string_acquire(o.pData); // increase reference count - Py_SetPythonHome(o.pData->buffer); -#endif } static void prependPythonPath( const OUString & pythonPathBootstrap ) @@ -216,11 +211,7 @@ PythonInit() { osl_setEnvironment(sEnvName.pData, sPath.pData); #endif -#if PY_MAJOR_VERSION >= 3 PyImport_AppendInittab( "pyuno", PyInit_pyuno ); -#else - PyImport_AppendInittab( (char*)"pyuno", initpyuno ); -#endif #if HAVE_FEATURE_READONLY_INSTALLSET Py_DontWriteBytecodeFlag = 1; diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx index bf6e5c667b7c..1b76a3fb6a9d 100644 --- a/pyuno/source/module/pyuno.cxx +++ b/pyuno/source/module/pyuno.cxx @@ -317,14 +317,9 @@ static sal_Int32 lcl_PyNumber_AsSal_Int32( PyObject *pObj ) // Convert Python number to platform long, then check actual value against // bounds of sal_Int32 -#if PY_VERSION_HEX >= 0x03020000 int nOverflow; long nResult = PyLong_AsLongAndOverflow( pObj, &nOverflow ); if ( nOverflow || nResult > SAL_MAX_INT32 || nResult < SAL_MIN_INT32) { -#else - long nResult = PyLong_AsLong( pObj ); - if ( nResult > SAL_MAX_INT32 || nResult < SAL_MIN_INT32) { -#endif PyErr_SetString( PyExc_IndexError, "Python int too large to convert to UNO long" ); return -1; } @@ -336,14 +331,8 @@ static int lcl_PySlice_GetIndicesEx( PyObject *pObject, sal_Int32 nLen, sal_Int3 { Py_ssize_t nStart_ssize, nStop_ssize, nStep_ssize, nSliceLength_ssize; - int nResult = -#if PY_VERSION_HEX >= 0x030200f0 - PySlice_GetIndicesEx(pObject, + int nResult = PySlice_GetIndicesEx(pObject, nLen, &nStart_ssize, &nStop_ssize, &nStep_ssize, &nSliceLength_ssize ); -#else - PySlice_GetIndicesEx(reinterpret_cast<PySliceObject*>(pObject), - nLen, &nStart_ssize, &nStop_ssize, &nStep_ssize, &nSliceLength_ssize ); -#endif if (nResult == -1) return -1; @@ -1554,9 +1543,6 @@ static PyNumberMethods PyUNONumberMethods[] = nullptr, /* nb_add */ nullptr, /* nb_subtract */ nullptr, /* nb_multiply */ -#if PY_MAJOR_VERSION < 3 - nullptr, /* nb_divide */ -#endif nullptr, /* nb_remainder */ nullptr, /* nb_divmod */ nullptr, /* nb_power */ @@ -1570,22 +1556,12 @@ static PyNumberMethods PyUNONumberMethods[] = nullptr, /* nb_and */ nullptr, /* nb_xor */ nullptr, /* nb_or */ -#if PY_MAJOR_VERSION < 3 - nullptr, /* nb_coerce */ -#endif nullptr, /* nb_int */ nullptr, /* nb_reserved */ nullptr, /* nb_float */ -#if PY_MAJOR_VERSION < 3 - nullptr, /* nb_oct */ - nullptr, /* nb_hex */ -#endif nullptr, /* nb_inplace_add */ nullptr, /* nb_inplace_subtract */ nullptr, /* nb_inplace_multiply */ -#if PY_MAJOR_VERSION < 3 - nullptr, /* nb_inplace_divide */ -#endif nullptr, /* nb_inplace_remainder */ nullptr, /* nb_inplace_power */ nullptr, /* nb_inplace_lshift */ diff --git a/pyuno/source/module/pyuno_dlopenwrapper.c b/pyuno/source/module/pyuno_dlopenwrapper.c index 44e711653e35..78e6982e8945 100644 --- a/pyuno/source/module/pyuno_dlopenwrapper.c +++ b/pyuno/source/module/pyuno_dlopenwrapper.c @@ -76,19 +76,9 @@ static void * load(void const * address, char const * symbol) { return func; } -#if PY_MAJOR_VERSION >= 3 - SAL_DLLPUBLIC_EXPORT PyObject * PyInit_pyuno(void) { return ((PyObject * (*)(void)) load((void *) &PyInit_pyuno, "PyInit_pyuno"))(); } -#else - -SAL_DLLPUBLIC_EXPORT void initpyuno(void) { - ((void (*)(void)) load((void *) &initpyuno, "initpyuno"))(); -} - -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/pyuno/source/module/pyuno_impl.hxx b/pyuno/source/module/pyuno_impl.hxx index a1ac6fbf92fd..44d6bb8985a6 100644 --- a/pyuno/source/module/pyuno_impl.hxx +++ b/pyuno/source/module/pyuno_impl.hxx @@ -26,15 +26,6 @@ #include <Python.h> -#if PY_VERSION_HEX < 0x03020000 -typedef long Py_hash_t; -#endif - -//Must define PyVarObject_HEAD_INIT for Python 2.5 or older -#ifndef PyVarObject_HEAD_INIT -#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, -#endif - //Python 3.0 and newer don't have these flags #ifndef Py_TPFLAGS_HAVE_ITER # define Py_TPFLAGS_HAVE_ITER 0 @@ -71,7 +62,6 @@ namespace com::sun::star::script { class XTypeConverter; } // In Python 3, the PyString_* functions have been replaced by PyBytes_* // and PyUnicode_* functions. -#if PY_MAJOR_VERSION >= 3 // compatibility wrappers for Python "str" type (PyUnicode in 3, PyString in 2) inline PyObject* PyStr_FromString(const char *string) @@ -110,41 +100,6 @@ inline PyObject* PyStrBytes_FromStringAndSize(const char *string, Py_ssize_t len { return PyBytes_FromStringAndSize(string, len); } -#else -inline char * PyStr_AsString(PyObject *object) -{ - return PyString_AsString(object); -} - -inline PyObject* PyStr_FromString(const char *string) -{ - return PyString_FromString(string); -} - -inline bool PyStr_Check(PyObject *object) -{ - return PyString_Check(object); -} -inline bool PyStrBytes_Check(PyObject *object) -{ - return PyString_Check(object); -} - -inline char* PyStrBytes_AsString(PyObject *object) -{ - return PyString_AsString(object); -} - -inline Py_ssize_t PyStrBytes_Size(PyObject *object) -{ - return PyString_Size(object); -} - -inline PyObject* PyStrBytes_FromStringAndSize(const char *string, Py_ssize_t len) -{ - return PyString_FromStringAndSize(string, len); -} -#endif /* PY_MAJOR_VERSION >= 3 */ namespace pyuno { diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx index 4abe28b84539..df7874467503 100644 --- a/pyuno/source/module/pyuno_module.cxx +++ b/pyuno/source/module/pyuno_module.cxx @@ -877,7 +877,6 @@ struct PyMethodDef PyUNOModule_methods [] = } extern "C" -#if PY_MAJOR_VERSION >= 3 PyObject* PyInit_pyuno() { PyUNO_initType(); @@ -898,14 +897,5 @@ PyObject* PyInit_pyuno() }; return PyModule_Create(&moduledef); } -#else -void initpyuno() -{ - PyUNO_initType(); - PyUNOStruct_initType(); - PyEval_InitThreads(); - Py_InitModule ("pyuno", PyUNOModule_methods); -} -#endif /* PY_MAJOR_VERSION >= 3 */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 9b6eb22d4e06..ba0f5adefa98 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -642,41 +642,8 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con { } - // In Python 3, there is no PyInt type. -#if PY_MAJOR_VERSION < 3 - else if (PyInt_Check (o)) - { - if( o == Py_True ) - { - a <<= true; - } - else if ( o == Py_False ) - { - a <<= false; - } - else - { - sal_Int32 l = (sal_Int32) PyLong_AsLong( o ); - if( l < 128 && l >= -128 ) - { - sal_Int8 b = (sal_Int8 ) l; - a <<= b; - } - else if( l <= 0x7fff && l >= -0x8000 ) - { - sal_Int16 s = (sal_Int16) l; - a <<= s; - } - else - { - a <<= l; - } - } - } -#endif /* PY_MAJOR_VERSION < 3 */ else if (PyLong_Check (o)) { -#if PY_MAJOR_VERSION >= 3 // Convert the Python 3 booleans that are actually of type PyLong. if(o == Py_True) { @@ -688,7 +655,6 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con } else { -#endif /* PY_MAJOR_VERSION >= 3 */ sal_Int64 l = static_cast<sal_Int64>(PyLong_AsLong (o)); if( l < 128 && l >= -128 ) { @@ -710,9 +676,7 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con { a <<= l; } -#if PY_MAJOR_VERSION >= 3 } -#endif } else if (PyFloat_Check (o)) { diff --git a/pyuno/source/module/pyuno_type.cxx b/pyuno/source/module/pyuno_type.cxx index de4a212e22bb..19de9430a360 100644 --- a/pyuno/source/module/pyuno_type.cxx +++ b/pyuno/source/module/pyuno_type.cxx @@ -134,11 +134,7 @@ sal_Unicode PyChar2Unicode( PyObject *obj ) "attribute value of uno.Char is not a unicode string" ); } -#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 3 if( PyUnicode_GetLength( value.get() ) < 1 ) -#else - if( PyUnicode_GetSize( value.get() ) < 1 ) -#endif { throw RuntimeException( "uno.Char contains an empty unicode string"); diff --git a/pyuno/source/module/pyuno_util.cxx b/pyuno/source/module/pyuno_util.cxx index f1eebff90345..3d4f452103a3 100644 --- a/pyuno/source/module/pyuno_util.cxx +++ b/pyuno/source/module/pyuno_util.cxx @@ -63,24 +63,14 @@ OUString pyString2ustring( PyObject *pystr ) ret = OUString( reinterpret_cast<sal_Unicode const *>(PyUnicode_AS_UNICODE( pystr )) ); #else -#if PY_MAJOR_VERSION >= 3 Py_ssize_t size(0); char const *pUtf8(PyUnicode_AsUTF8AndSize(pystr, &size)); ret = OUString(pUtf8, size, RTL_TEXTENCODING_UTF8); -#else - PyObject* pUtf8 = PyUnicode_AsUTF8String(pystr); - ret = OUString(PyStr_AsString(pUtf8), PyString_Size(pUtf8), RTL_TEXTENCODING_UTF8); - Py_DECREF(pUtf8); -#endif #endif } else { -#if PY_MAJOR_VERSION >= 3 char *name = PyBytes_AsString(pystr); // hmmm... is this a good idea? -#else - char *name = PyString_AsString(pystr); -#endif ret = OUString( name, strlen(name), osl_getThreadTextEncoding() ); } return ret; diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index bd894a0eea4e..c4ca808feaa0 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -24,14 +24,6 @@ import warnings # since on Windows sal3.dll no longer calls WSAStartup import socket -# Some Python 2/3 compatibility code copied from the six library -PY2 = sys.version_info[0] == 2 - -if PY2: - six_string_types = basestring, -else: - six_string_types = str, - # All functions and variables starting with a underscore (_) must be # considered private and can be changed at any time. Don't use them. _component_context = pyuno.getComponentContext() @@ -216,10 +208,10 @@ class Bool(object): message = "The Bool class is deprecated. Use Python's True and False directly instead." warnings.warn(message, DeprecationWarning) - if isinstance(value, six_string_types) and value == "true": + if isinstance(value, str) and value == "true": return True - if isinstance(value, six_string_types) and value == "false": + if isinstance(value, str) and value == "false": return False if value: @@ -241,10 +233,7 @@ class Char: """ def __init__(self, value): - if PY2: - assert isinstance(value, unicode), "Expected unicode object, got %s instead." % type(value) - else: - assert isinstance(value, str), "Expected str object, got %s instead." % type(value) + assert isinstance(value, str), "Expected str object, got %s instead." % type(value) assert len(value) == 1, "Char value must have length of 1." @@ -254,7 +243,7 @@ class Char: return "<Char instance %s>" % (self.value,) def __eq__(self, that): - if isinstance(that, six_string_types): + if isinstance(that, str): if len(that) > 1: return False @@ -427,8 +416,7 @@ def _uno_import(name, *optargs, **kwargs): uno_import_exc = ImportError("%s (or '%s.%s' is unknown)" % (py_import_exc, name, class_name)) - if sys.version_info[0] >= 3: - uno_import_exc = uno_import_exc.with_traceback(py_import_exc.__traceback__) + uno_import_exc = uno_import_exc.with_traceback(py_import_exc.__traceback__) uno_import_exc._uno_import_failed = True raise uno_import_exc |