enable python3 supoort and drop python2 21/288421/4 sandbox/wangbiao/py3_version
authorwb0716 <biao716.wang@samsung.com>
Thu, 16 Feb 2023 09:23:32 +0000 (17:23 +0800)
committerwb0716 <biao716.wang@samsung.com>
Thu, 16 Feb 2023 09:46:21 +0000 (17:46 +0800)
Change-Id: I36106f1095b5b27ea9b837a07b7e93c66ee5c0af
Signed-off-by: wb0716 <biao716.wang@samsung.com>
24 files changed:
CMakeLists.txt
README.md
debian/createrepo-c-devel.install
packaging/createrepo_c.spec
src/python/CMakeLists.txt
src/python/compression_wrapper-py.c
src/python/contentstat-py.c
src/python/createrepo_cmodule.c
src/python/exception-py.c
src/python/package-py.c
src/python/repomd-py.c
src/python/repomdrecord-py.c
src/python/sqlite-py.c
src/python/typeconversion.c
src/python/typeconversion.h
src/python/updatecollection-py.c
src/python/updatecollectionpackage-py.c
src/python/updateinfo-py.c
src/python/updaterecord-py.c
src/python/updatereference-py.c
src/python/xml_file-py.c
utils/gen_rst.py
utils/get_version.py
utils/single_test.py

index a89a1fce778431596113798a31cafa7f5cb0d083..475db2852b2d59194c216abe69634d9a2cacd2d8 100644 (file)
@@ -99,7 +99,7 @@ IF (ENABLE_DRPM)
 ENDIF (ENABLE_DRPM)
 
 # option to enable/disable python support
-OPTION (ENABLE_PYTHON "Enable python support?" OFF)
+OPTION (ENABLE_PYTHON "Enable python support?" ON)
 
 # Threaded XZ Compression
 # Note: This option is disabled by default, because Createrepo_c
@@ -119,11 +119,6 @@ SET (VERSION "${CR_MAJOR}.${CR_MINOR}.${CR_PATCH}")
 message("Package version: ${VERSION}")
 
 
-# Default python version
-if (NOT PYTHON_DESIRED)
-    set (PYTHON_DESIRED "2")
-endif()
-
 # Other files
 
 pkg_check_modules(BASHCOMP bash-completion)
index 11f781891375f2e4e269a1dc87d383e0b19192fe..3ef6bd87edbcc9bee802a0abeb5bdcbbb3416f72 100644 (file)
--- a/README.md
+++ b/README.md
@@ -24,9 +24,9 @@ Package build requires - Pkg name in Fedora/Ubuntu:
 * xz (http://tukaani.org/xz/) - xz-devel/liblzma-dev
 * zlib (http://www.zlib.net/) - zlib-devel/zlib1g-dev
 * *Documentation:* doxygen (http://doxygen.org/) - doxygen/doxygen
-* *Documentation:* sphinx (http://sphinx-doc.org/) - python-sphinx/
+* *Documentation:* sphinx (http://sphinx-doc.org/) - python3-sphinx/
 * **Test requires:** check (http://check.sourceforge.net/) - check-devel/check
-* **Test requires:** python-nose (https://nose.readthedocs.org/) - python-nose/python-nose
+* **Test requires:** python3-nose (https://nose.readthedocs.org/) - python3-nose/python3-nose
 * **Experimental support:** drpm (https://git.fedorahosted.org/git/drpm.git)
 
 From your checkout dir:
@@ -71,12 +71,6 @@ where the path is path to your build of drpm library.
 
     cmake -DDRPM_PATH="/home/tmlcoch/git/drpm" .. && make
 
-## Building for a different Python version
-
-By default, cmake should set up things to build for Python 2, but you can do a build for Python 3 like this::
-
-    cmake -DPYTHON_DESIRED=3 .
-
 ## Other build options
 
 ### ``-DENABLE_LEGACY_WEAKDEPS=ON``
@@ -129,10 +123,6 @@ Note: The C tests have to be builded by ``make tests``)!
 
     PYTHONPATH=`readlink -f ./build/src/python/` nosetests -s tests/python/tests/
 
-Or, for an alternative python version, specify the appropriate nosetests executable:
-
-    PYTHONPATH=`readlink -f ./build/src/python/` nosetests-3.4 -s tests/python/tests/
-
 ### Links
 
 [Bugzilla](https://bugzilla.redhat.com/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=MODIFIED&bug_status=VERIFIED&component=createrepo_c&query_format=advanced)
index 40bb3aefaa5f74e5abd53ddc8d674aeed168446c..95c6a59435e21b1e2a7bf0ce02ef50ef08bbf097 100644 (file)
@@ -1,4 +1,5 @@
 usr/include/createrepo_c /usr/include/
 usr/lib/libcreaterepo_c.so /usr/lib/
 usr/lib/pkgconfig/createrepo_c.pc /usr/lib/pkgconfig/
+usr/lib/python3/dist-packages/createrepo_c /usr/lib/python3/dist-packages/
 
index 26b7d10b8eea8ae0e487536168bbac45ec33d677..0d6fe18c1b256a82e247c71ac278a1fb17226491 100644 (file)
@@ -72,7 +72,7 @@ done
 %{_libdir}/libcreaterepo_c.so
 %{_libdir}/pkgconfig/createrepo_c.pc
 %{_includedir}/createrepo_c
-#%{python3_sitearch}/createrepo_c
+%{python3_sitearch}/createrepo_c
 
 %files -n libcreaterepo_c0
 %defattr(-, root, root,-)
index 9f1ac6420981e651902d6e34592a860464ee7d06..71eef97472079497182d0edbb7045b4294839b93 100644 (file)
@@ -1,23 +1,17 @@
-if (${PYTHON_DESIRED} STREQUAL "2")
+MACRO(PYTHON_UNSET)
     unset(PYTHON_LIBRARY)
     unset(PYTHON_INCLUDE_DIR)
     unset(PYTHON_EXECUTABLE)
     unset(PYTHON_LIBRARY CACHE)
     unset(PYTHON_INCLUDE_DIR CACHE)
     unset(PYTHON_EXECUTABLE CACHE)
-    FIND_PACKAGE(PythonLibs 2)
-    FIND_PACKAGE(PythonInterp 2 REQUIRED)
-else()
-    SET(Python_ADDITIONAL_VERSIONS 3.0)
-    unset(PYTHON_LIBRARY)
-    unset(PYTHON_INCLUDE_DIR)
-    unset(PYTHON_EXECUTABLE)
-    unset(PYTHON_LIBRARY CACHE)
-    unset(PYTHON_INCLUDE_DIR CACHE)
-    unset(PYTHON_EXECUTABLE CACHE)
-    FIND_PACKAGE(PythonLibs 3.0)
-    FIND_PACKAGE(PythonInterp 3.0 REQUIRED)
-endif()
+ENDMACRO(PYTHON_UNSET)
+
+PYTHON_UNSET()
+SET(Python_ADDITIONAL_VERSIONS 3.0 CACHE INTERNAL "")
+FIND_PACKAGE(PythonLibs 3 EXACT)
+FIND_PACKAGE(PythonInterp 3 EXACT REQUIRED)
+
 
 EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(True))" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
 INCLUDE_DIRECTORIES (${PYTHON_INCLUDE_PATH})
index eb586ab39dad34b770695d94b8b13d1822c37544..e67d4352194f361c8723e3b3309434d31c1deab8 100644 (file)
@@ -17,6 +17,7 @@
  * USA.
  */
 
+#define PY_SSIZE_T_CLEAN
 #include <Python.h>
 #include <assert.h>
 #include <stddef.h>
@@ -205,7 +206,7 @@ static PyObject *
 py_write(_CrFileObject *self, PyObject *args)
 {
     char *str;
-    int len;
+    Py_ssize_t len;
     GError *tmp_err = NULL;
 
     if (!PyArg_ParseTuple(args, "s#:set_num_of_pkgs", &str, &len))
index 4c537ad9803d0f9eac50165736df2feac6088297..b45d346e53a925192ec9a8e9d98f1853d3ca32c7 100644 (file)
@@ -155,10 +155,6 @@ set_num(_ContentStatObject *self, PyObject *value, void *member_offset)
         val = (gint64) PyLong_AsLong(value);
     } else if (PyFloat_Check(value)) {
         val = (gint64) PyFloat_AS_DOUBLE(value);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(value)) {
-        val = (gint64) PyInt_AS_LONG(value);
-#endif
     } else {
         PyErr_SetString(PyExc_TypeError, "Number expected!");
         return -1;
@@ -178,10 +174,6 @@ set_int(_ContentStatObject *self, PyObject *value, void *member_offset)
         val = PyLong_AsLong(value);
     } else if (PyFloat_Check(value)) {
         val = (gint64) PyFloat_AS_DOUBLE(value);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(value)) {
-        val = (gint64) PyInt_AS_LONG(value);
-#endif
     } else {
         PyErr_SetString(PyExc_TypeError, "Number expected!");
         return -1;
@@ -201,7 +193,9 @@ set_str(_ContentStatObject *self, PyObject *value, void *member_offset)
         return -1;
     }
     cr_ContentStat *rec = self->stat;
-    char *str = g_strdup(PyObject_ToStrOrNull(value));
+    PyObject *pybytes = PyObject_ToPyBytesOrNull(value);
+    char *str = g_strdup(PyBytes_AsString(pybytes));
+    Py_XDECREF(pybytes);
     *((char **) ((size_t) rec + (size_t) member_offset)) = str;
     return 0;
 }
index fe4d2adfcabb680b45aba39885378687f272eada..6b0e1294d5e5537634230400afb57ab47ad088c7 100644 (file)
@@ -86,10 +86,9 @@ static struct PyMethodDef createrepo_c_methods[] = {
         METH_VARARGS, detect_compression__doc__},
     {"compression_type",        (PyCFunction)py_compression_type,
         METH_VARARGS, compression_type__doc__},
-    { NULL }
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
-#if PY_MAJOR_VERSION >= 3
 static struct PyModuleDef createrepo_c_module_def = {
         PyModuleDef_HEAD_INIT,
         "_createrepo_c",
@@ -106,113 +105,101 @@ static struct PyModuleDef createrepo_c_module_def = {
 
 PyObject *
 PyInit__createrepo_c(void)
-
-#else
-
-#define FAILURE
-
-PyMODINIT_FUNC
-init_createrepo_c(void)
-#endif
 {
-#if PY_MAJOR_VERSION >= 3
     PyObject *m = PyModule_Create(&createrepo_c_module_def);
-#else
-    PyObject *m = Py_InitModule("_createrepo_c", createrepo_c_methods);
-#endif
     if (!m)
-        return FAILURE;
+        return NULL;
 
     /* Exceptions */
     if (!init_exceptions())
-        return FAILURE;
+        return NULL;
     PyModule_AddObject(m, "CreaterepoCError", CrErr_Exception);
 
     /* Objects */
 
     /* _createrepo_c.ContentStat */
     if (PyType_Ready(&ContentStat_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&ContentStat_Type);
     PyModule_AddObject(m, "ContentStat", (PyObject *)&ContentStat_Type);
 
     /* _createrepo_c.CrFile */
     if (PyType_Ready(&CrFile_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&CrFile_Type);
     PyModule_AddObject(m, "CrFile", (PyObject *)&CrFile_Type);
 
     /* _createrepo_c.Package */
     if (PyType_Ready(&Package_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&Package_Type);
     PyModule_AddObject(m, "Package", (PyObject *)&Package_Type);
 
     /* _createrepo_c.Metadata */
     if (PyType_Ready(&Metadata_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&Metadata_Type);
     PyModule_AddObject(m, "Metadata", (PyObject *)&Metadata_Type);
 
     /* _createrepo_c.MetadataLocation */
     if (PyType_Ready(&MetadataLocation_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&MetadataLocation_Type);
     PyModule_AddObject(m, "MetadataLocation", (PyObject *)&MetadataLocation_Type);
 
     /* _createrepo_c.Repomd */
     if (PyType_Ready(&Repomd_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&Repomd_Type);
     PyModule_AddObject(m, "Repomd", (PyObject *)&Repomd_Type);
 
     /* _createrepo_c.RepomdRecord */
     if (PyType_Ready(&RepomdRecord_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&RepomdRecord_Type);
     PyModule_AddObject(m, "RepomdRecord", (PyObject *)&RepomdRecord_Type);
 
     /* _createrepo_c.Sqlite */
     if (PyType_Ready(&Sqlite_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&Sqlite_Type);
     PyModule_AddObject(m, "Sqlite", (PyObject *)&Sqlite_Type);
 
     /* _createrepo_c.UpdateCollection */
     if (PyType_Ready(&UpdateCollection_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&UpdateCollection_Type);
     PyModule_AddObject(m, "UpdateCollection",
                        (PyObject *)&UpdateCollection_Type);
 
     /* _createrepo_c.UpdateCollectionPackage */
     if (PyType_Ready(&UpdateCollectionPackage_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&UpdateCollectionPackage_Type);
     PyModule_AddObject(m, "UpdateCollectionPackage",
                        (PyObject *)&UpdateCollectionPackage_Type);
 
     /* _createrepo_c.UpdateInfo */
     if (PyType_Ready(&UpdateInfo_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&UpdateInfo_Type);
     PyModule_AddObject(m, "UpdateInfo", (PyObject *)&UpdateInfo_Type);
 
     /* _createrepo_c.UpdateRecord */
     if (PyType_Ready(&UpdateRecord_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&UpdateRecord_Type);
     PyModule_AddObject(m, "UpdateRecord", (PyObject *)&UpdateRecord_Type);
 
     /* _createrepo_c.UpdateReference */
     if (PyType_Ready(&UpdateReference_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&UpdateReference_Type);
     PyModule_AddObject(m, "UpdateReference", (PyObject *)&UpdateReference_Type);
 
     /* _createrepo_c.XmlFile */
     if (PyType_Ready(&XmlFile_Type) < 0)
-        return FAILURE;
+        return NULL;
     Py_INCREF(&XmlFile_Type);
     PyModule_AddObject(m, "XmlFile", (PyObject *)&XmlFile_Type);
 
@@ -285,9 +272,5 @@ init_createrepo_c(void)
     PyModule_AddIntConstant(m, "XML_WARNING_UNKNOWNVAL", CR_XML_WARNING_UNKNOWNVAL);
     PyModule_AddIntConstant(m, "XML_WARNING_BADATTRVAL", CR_XML_WARNING_BADATTRVAL);
 
-#if PY_MAJOR_VERSION >= 3
     return m;
-#else
-    return;
-#endif
 }
index 56c48e6a4c79aeafb9ee463c3c49eacf927ea0bb..01039f77a08799ece2aa72eed2d78e83f42e697e 100644 (file)
@@ -27,12 +27,8 @@ PyObject *CrErr_Exception = NULL;
 int
 init_exceptions()
 {
-#if (PY_MAJOR_VERSION == 2) && (PY_MINOR_VERSION < 7)
-    CrErr_Exception = PyErr_NewException("createrepo_c.CreaterepoCError", NULL, NULL);
-#else
     CrErr_Exception = PyErr_NewExceptionWithDoc("createrepo_c.CreaterepoCError",
                             "Createrepo_c library exception", NULL, NULL);
-#endif
 
     if (!CrErr_Exception)
         return 0;
index 1827757e07e59fa4978cf3b6a5f483406702eadb..f95bb33dc57ec92497ddc5dadeb7699a99a99133 100644 (file)
@@ -237,7 +237,7 @@ static struct PyMethodDef package_methods[] = {
     {"copy", (PyCFunction)copy_pkg, METH_NOARGS, copy__doc__},
     {"__copy__", (PyCFunction)copy_pkg, METH_NOARGS, copy__doc__},
     {"__deepcopy__", (PyCFunction)deepcopy_pkg, METH_VARARGS, copy__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* Getters */
@@ -377,10 +377,6 @@ set_num(_PackageObject *self, PyObject *value, void *member_offset)
         val = (gint64) PyLong_AsLong(value);
     } else if (PyFloat_Check(value)) {
         val = (gint64) PyFloat_AS_DOUBLE(value);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(value)) {
-        val = (gint64) PyInt_AS_LONG(value);
-#endif
     } else {
         PyErr_SetString(PyExc_TypeError, "Number expected!");
         return -1;
index 015546c95e134b46cb80746d3475b3257035f983..4b3b2ce1118b0c492415b56a07f998f0fd84a5aa 100644 (file)
@@ -275,7 +275,7 @@ static struct PyMethodDef repomd_methods[] = {
         sort_records__doc__},
     {"xml_dump", (PyCFunction)xml_dump, METH_NOARGS,
         xml_dump__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* Convertors for getsetters */
@@ -402,8 +402,7 @@ set_str(_RepomdObject *self, PyObject *value, void *member_offset)
     }
     cr_Repomd *repomd = self->repomd;
 
-    char *str = cr_safe_string_chunk_insert(repomd->chunk,
-                                            PyObject_ToStrOrNull(value));
+    char *str = PyObject_ToChunkedString(value, repomd->chunk);
     *((char **) ((size_t) repomd + (size_t) member_offset)) = str;
     return 0;
 }
index c5e3ccb5eac74fba46d19da79dec9994fd6ed078..7c8fe44d9bfe0f5c24cbdb8c921906b87c4c09d0 100644 (file)
@@ -260,7 +260,7 @@ static struct PyMethodDef repomdrecord_methods[] = {
         rename_file__doc__},
     {"load_contentstat", (PyCFunction)load_contentstat, METH_VARARGS,
         load_contentstat__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* getsetters */
@@ -309,10 +309,6 @@ set_num(_RepomdRecordObject *self, PyObject *value, void *member_offset)
         val = (gint64) PyLong_AsLong(value);
     } else if (PyFloat_Check(value)) {
         val = (gint64) PyFloat_AS_DOUBLE(value);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(value)) {
-        val = (gint64) PyInt_AS_LONG(value);
-#endif
     } else {
         PyErr_SetString(PyExc_TypeError, "Number expected!");
         return -1;
@@ -332,10 +328,6 @@ set_int(_RepomdRecordObject *self, PyObject *value, void *member_offset)
         val = PyLong_AsLong(value);
     } else if (PyFloat_Check(value)) {
         val = (long long) PyFloat_AS_DOUBLE(value);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(value)) {
-        val = PyInt_AS_LONG(value);
-#endif
     } else {
         PyErr_SetString(PyExc_TypeError, "Number expected!");
         return -1;
@@ -355,8 +347,7 @@ set_str(_RepomdRecordObject *self, PyObject *value, void *member_offset)
         return -1;
     }
     cr_RepomdRecord *rec = self->record;
-    char *str = cr_safe_string_chunk_insert(rec->chunk,
-                                            PyObject_ToStrOrNull(value));
+    char *str = PyObject_ToChunkedString(value, rec->chunk);
     *((char **) ((size_t) rec + (size_t) member_offset)) = str;
     return 0;
 }
index 5f8d92e30118e87d93208a0dfd55e510fb2bb7d6..95146ff5bad4abccddee696bd5c07a6a27a87405 100644 (file)
@@ -202,7 +202,7 @@ static struct PyMethodDef sqlite_methods[] = {
         dbinfo_update__doc__},
     {"close", (PyCFunction)close_db, METH_NOARGS,
         close__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 PyTypeObject Sqlite_Type = {
index 761ba91daa36e974f27d987352dc0487d2fbde26..2cd02f7e368b88bc382b6d50f9bd22ab42801b12 100644 (file)
@@ -50,7 +50,16 @@ PyErr_ToGError(GError **err)
                     "Error while error handling");
     } else {
         if (PyUnicode_Check(pystr)) {
-            pystr = PyUnicode_AsUTF8String(pystr);
+            PyObject *pybytes = PyUnicode_AsUTF8String(pystr);
+            Py_DECREF(pystr);
+
+            if (!pybytes) {
+                PyErr_Clear();
+                g_set_error(err, ERR_DOMAIN, CRE_XMLPARSER,
+                            "Error while error handling");
+                return;
+            }
+            pystr = pybytes;
         }
         g_set_error(err, ERR_DOMAIN, CRE_XMLPARSER,
                     "%s", PyBytes_AsString(pystr));
@@ -67,26 +76,35 @@ PyUnicodeOrNone_FromString(const char *str)
     return PyUnicode_FromString(str);
 }
 
-char *
-PyObject_ToStrOrNull(PyObject *pyobj)
+PyObject *
+PyObject_ToPyBytesOrNull(PyObject *pyobj)
 {
-    // String returned by this function shoud not be freed or modified
     if (PyUnicode_Check(pyobj)) {
         pyobj = PyUnicode_AsUTF8String(pyobj);
+        if (!pyobj) {
+            return NULL;
+        }
+    } else {
+        Py_XINCREF(pyobj);
     }
 
     if (PyBytes_Check(pyobj)) {
-        return PyBytes_AsString(pyobj);
+        return pyobj;
     }
 
-    // TODO: ? Add support for pyobj like: ("xxx",) and ["xxx"]
     return NULL;
 }
 
 char *
 PyObject_ToChunkedString(PyObject *pyobj, GStringChunk *chunk)
 {
-    return cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    char *ret = NULL;
+    PyObject *pybytes = PyObject_ToPyBytesOrNull(pyobj);
+    if (pybytes) {
+        ret = cr_safe_string_chunk_insert(chunk, PyBytes_AsString(pybytes));
+        Py_DECREF(pybytes);
+    }
+    return ret;
 }
 
 long long
@@ -97,10 +115,6 @@ PyObject_ToLongLongOrZero(PyObject *pyobj)
         num = (long long) PyLong_AsLongLong(pyobj);
     } else if (PyFloat_Check(pyobj)) {
         num = (long long) PyFloat_AS_DOUBLE(pyobj);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(pyobj)) {
-        num = (long long) PyInt_AS_LONG(pyobj);
-#endif
     }
     return num;
 }
@@ -130,19 +144,19 @@ PyObject_ToDependency(PyObject *tuple, GStringChunk *chunk)
     cr_Dependency *dep = cr_dependency_new();
 
     pyobj = PyTuple_GetItem(tuple, 0);
-    dep->name = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    dep->name = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 1);
-    dep->flags = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    dep->flags = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 2);
-    dep->epoch = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    dep->epoch = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 3);
-    dep->version = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    dep->version = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 4);
-    dep->release = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    dep->release = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 5);
     dep->pre = (PyObject_IsTrue(pyobj)) ? TRUE : FALSE;
@@ -172,13 +186,13 @@ PyObject_ToPackageFile(PyObject *tuple, GStringChunk *chunk)
     cr_PackageFile *file = cr_package_file_new();
 
     pyobj = PyTuple_GetItem(tuple, 0);
-    file->type = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    file->type = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 1);
-    file->path = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    file->path = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 2);
-    file->name = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    file->name = PyObject_ToChunkedString(pyobj, chunk);
 
     return file;
 }
@@ -205,13 +219,13 @@ PyObject_ToChangelogEntry(PyObject *tuple, GStringChunk *chunk)
     cr_ChangelogEntry *log = cr_changelog_entry_new();
 
     pyobj = PyTuple_GetItem(tuple, 0);
-    log->author = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    log->author = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 1);
     log->date = PyObject_ToLongLongOrZero(pyobj);
 
     pyobj = PyTuple_GetItem(tuple, 2);
-    log->changelog = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    log->changelog = PyObject_ToChunkedString(pyobj, chunk);
 
     return log;
 }
@@ -237,10 +251,10 @@ PyObject_ToDistroTag(PyObject *tuple, GStringChunk *chunk)
     cr_DistroTag *tag = cr_distrotag_new();
 
     pyobj = PyTuple_GetItem(tuple, 0);
-    tag->cpeid = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    tag->cpeid = PyObject_ToChunkedString(pyobj, chunk);
 
     pyobj = PyTuple_GetItem(tuple, 2);
-    tag->val = cr_safe_string_chunk_insert(chunk, PyObject_ToStrOrNull(pyobj));
+    tag->val = PyObject_ToChunkedString(pyobj, chunk);
 
     return tag;
 }
index 99147b45962fbdf3e26154ad60a1da3fd595cf6c..4aedc2be5501d6788141363045568d2538c6328b 100644 (file)
@@ -27,7 +27,7 @@
 void PyErr_ToGError(GError **err);
 
 PyObject *PyUnicodeOrNone_FromString(const char *str);
-char *PyObject_ToStrOrNull(PyObject *pyobj);
+PyObject *PyObject_ToPyBytesOrNull(PyObject *pyobj);
 char *PyObject_ToChunkedString(PyObject *pyobj, GStringChunk *chunk);
 
 PyObject *PyObject_FromDependency(cr_Dependency *dep);
index 3a791be61142aa090bdfd2d4812813345adae2c6..7a954070197f5654298812ae139889e0a32b811a 100644 (file)
@@ -164,7 +164,7 @@ static struct PyMethodDef updatecollection_methods[] = {
         append__doc__},
     {"copy", (PyCFunction)copy_updatecollection, METH_NOARGS,
         copy__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* Convertors for getsetters */
@@ -259,8 +259,7 @@ set_str(_UpdateCollectionObject *self, PyObject *value, void *member_offset)
         return -1;
     }
     cr_UpdateCollection *rec = self->collection;
-    char *str = cr_safe_string_chunk_insert(rec->chunk,
-                                            PyObject_ToStrOrNull(value));
+    char *str = PyObject_ToChunkedString(value, rec->chunk);
     *((char **) ((size_t) rec + (size_t) member_offset)) = str;
     return 0;
 }
index b36e5b44ab0ff2ef01fe45ea4e736e4e5d450304..175f324030769db0ff2339c84193b7f433431f6d 100644 (file)
@@ -138,7 +138,7 @@ copy_updatecollectionpackage(_UpdateCollectionPackageObject *self,
 static struct PyMethodDef updatecollectionpackage_methods[] = {
     {"copy", (PyCFunction)copy_updatecollectionpackage, METH_NOARGS,
         copy__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* getsetters */
@@ -177,10 +177,6 @@ set_int(_UpdateCollectionPackageObject *self, PyObject *value, void *member_offs
         val = PyLong_AsLong(value);
     } else if (PyFloat_Check(value)) {
         val = (long long) PyFloat_AS_DOUBLE(value);
-#if PY_MAJOR_VERSION < 3
-    } else if (PyInt_Check(value)) {
-        val = PyInt_AS_LONG(value);
-#endif
     } else {
         PyErr_SetString(PyExc_TypeError, "Number expected!");
         return -1;
@@ -200,8 +196,7 @@ set_str(_UpdateCollectionPackageObject *self, PyObject *value, void *member_offs
         return -1;
     }
     cr_UpdateCollectionPackage *pkg = self->pkg;
-    char *str = cr_safe_string_chunk_insert(pkg->chunk,
-                                            PyObject_ToStrOrNull(value));
+    char *str = PyObject_ToChunkedString(value, pkg->chunk);
     *((char **) ((size_t) pkg + (size_t) member_offset)) = str;
     return 0;
 }
index 9c0d691b34e3af42ae99510df356f1e28d4bbb80..0a47b1b196b234a655620cfcf23f721f69ce2b46 100644 (file)
@@ -151,7 +151,7 @@ static struct PyMethodDef updateinfo_methods[] = {
         append__doc__},
     {"xml_dump", (PyCFunction)xml_dump, METH_NOARGS,
         xml_dump__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* Convertors for getsetters */
index 4ea4094739fb9f346f0f0a4407e52b52a18678ef..a145072601538238690837cb6d5db888c5ce797f 100644 (file)
@@ -190,7 +190,7 @@ static struct PyMethodDef updaterecord_methods[] = {
         append_collection__doc__},
     {"copy", (PyCFunction)copy_updaterecord, METH_NOARGS,
         copy__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* Convertors for getsetters */
@@ -321,8 +321,7 @@ set_str(_UpdateRecordObject *self, PyObject *value, void *member_offset)
         return -1;
     }
     cr_UpdateRecord *rec = self->record;
-    char *str = cr_safe_string_chunk_insert(rec->chunk,
-                                            PyObject_ToStrOrNull(value));
+    char *str = PyObject_ToChunkedString(value, rec->chunk);
     *((char **) ((size_t) rec + (size_t) member_offset)) = str;
     return 0;
 }
index a8b8903b8daefff521eee62fe2f213302ef1ca12..e19da50de37283ccae32b39cd1f99b48d57e2935 100644 (file)
@@ -141,7 +141,7 @@ copy_updatereference(_UpdateReferenceObject *self, G_GNUC_UNUSED void *nothing)
 static struct PyMethodDef updatereference_methods[] = {
     {"copy", (PyCFunction)copy_updatereference, METH_NOARGS,
         copy__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 /* getsetters */
@@ -170,14 +170,8 @@ set_str(_UpdateReferenceObject *self, PyObject *value, void *member_offset)
         return -1;
     }
 
-    if (PyUnicode_Check(value)) {
-        value = PyUnicode_AsUTF8String(value);
-    }
-
     cr_UpdateReference *ref = self->reference;
-    char *str = cr_safe_string_chunk_insert(ref->chunk,
-                                            PyObject_ToStrOrNull(value));
-
+    char *str = PyObject_ToChunkedString(value, ref->chunk);
     *((char **) ((size_t) ref + (size_t) member_offset)) = str;
     return 0;
 }
index 6bfef0dcebc07d59b926d3a866404d12d451b05c..1a253a6907e804511a4be153d04f6434638b3545 100644 (file)
@@ -269,7 +269,7 @@ static struct PyMethodDef xmlfile_methods[] = {
         add_chunk__doc__},
     {"close", (PyCFunction)xmlfile_close, METH_NOARGS,
         close__doc__},
-    {NULL} /* sentinel */
+    {NULL, NULL, 0, NULL} /* sentinel */
 };
 
 PyTypeObject XmlFile_Type = {
index 848edd8f6a5c31c9d89739e6ec4819b3d48f87fc..ac1b4838e8de11b61f5f1fbd8eb9b2b73c8f6cfc 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
 import sys
 import re
index 2e4aeaac87e3420a9abf56793d99e0c5f359a35b..6ccd3c17fddd798c89c31b2fe7ae1e9da70bff58 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
 import re
 import sys
@@ -11,14 +11,14 @@ VERSION_FILE_PATH = "VERSION.cmake"
 def parse(root_dir):
     path = os.path.join(root_dir, VERSION_FILE_PATH)
     if not os.path.exists(path):
-        print(("File %s doesn't exists" % path))
+        print("File {path} doesn't exist".format(path=path))
         return None
 
     content = open(path, "r").read()
     ver = {}
-    ver['major'] = re.search('SET\s*\(CR_MAJOR\s+"(\d+)"', content).group(1)
-    ver['minor'] = re.search('SET\s*\(CR_MINOR\s+"(\d+)"', content).group(1)
-    ver['patch'] = re.search('SET\s*\(CR_PATCH\s+"(\d+)"', content).group(1)
+    ver['major'] = re.search(r'SET\s*\(CR_MAJOR\s+"(\d+)"', content).group(1)
+    ver['minor'] = re.search(r'SET\s*\(CR_MINOR\s+"(\d+)"', content).group(1)
+    ver['patch'] = re.search(r'SET\s*\(CR_PATCH\s+"(\d+)"', content).group(1)
     return ver
 
 
@@ -35,19 +35,19 @@ if __name__ == "__main__":
     path = args[0]
 
     if not os.path.isdir(path):
-        parser.error("Directory %s doesn't exists" % path)
+        parser.error("Directory {path} doesn't exist".format(path=path))
 
     ver = parse(path)
     if ver is None:
         sys.exit(1)
 
     if options.major:
-        print((ver['major']))
+        print(ver['major'])
     elif options.minor:
-        print(( ver['minor']))
+        print(ver['minor'])
     elif options.patch:
-        print(( ver['patch']))
+        print(ver['patch'])
     else:
-        print(( "%(major)s.%(minor)s.%(patch)s" % ver))
+        print("{major}.{minor}.{patch}".format(**ver))
 
     sys.exit(0)
index be01dd321e044575599cf8ef98f5e454fbe04580..028359d3e00aa3c67769ae2e79438681aae7008e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 """
 Convert a single line from test output to run single test command.
 
@@ -14,7 +14,7 @@ import sys
 import argparse
 
 LIBPATH = "./build/src/python/"
-COMMAND = "PYTHONPATH=`readlink -f {libpath}` nosetests{nosever} -s -v {testpath}"
+COMMAND = "PYTHONPATH=`readlink -f {libpath}` nosetests -s -v {testpath}"
 TEST_PATH_PREFIX = "tests/python"
 
 if __name__ == "__main__":
@@ -25,7 +25,6 @@ if __name__ == "__main__":
     parser.add_argument('test_out_line', metavar='TESTOUTPUTLINE',
                         type=str,
                         help='A single line from python unittesttest output')
-    parser.add_argument('--python3', action='store_true', help='Python3 version')
     args = parser.parse_args()
 
     test_out_line = args.test_out_line
@@ -59,18 +58,10 @@ if __name__ == "__main__":
 
     full_path = os.path.join(TEST_PATH_PREFIX, test_path)
 
-    nosever = ""
-    pythonversion = 2
-
-    if (args.python3):
-        nosever = "-3.3"
-        pythonversion = 3
-
     testpath = "{0}:{1}.{2}".format(full_path, test_case, test_name)
-    libpath = LIBPATH.format(pythonversion=pythonversion)
-
+    libpath = LIBPATH
 
-    command = COMMAND.format(libpath=libpath, nosever=nosever, testpath=testpath)
+    command = COMMAND.format(libpath=libpath, testpath=testpath)
 
     print(command)