python: Fix Python 2.6 compatibility
authorLumir Balhar <lbalhar@redhat.com>
Wed, 11 Oct 2017 19:00:29 +0000 (21:00 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 18 Oct 2017 08:20:26 +0000 (10:20 +0200)
PyErr_NewExceptionWithDoc() isn't available in Python 2.6 so it can
be used only in higher versions of Python.

Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/pam_wrapper/python/pypamtest.c

index 585f27d0f110fbbe6c79af356eab3178c209ba7c..a71fd359bff2037613a93b5d079c939f5bd21820 100644 (file)
@@ -1004,12 +1004,14 @@ static struct PyModuleDef pypamtestdef = {
  *** Initialize the module
  **********************************************************/
 
+#if PY_VERSION_HEX >= 0x02070000 /* >= 2.7.0 */
 PyDoc_STRVAR(PamTestError__doc__,
 "pypamtest specific exception\n\n"
 "This exception is raised if the _pamtest() function fails. If _pamtest() "
 "returns PAMTEST_ERR_CASE (a test case returns unexpected error code), then "
 "the exception also details which test case failed."
 );
+#endif
 
 #if IS_PYTHON3
 PyMODINIT_FUNC PyInit_pypamtest(void)
@@ -1034,10 +1036,17 @@ PyMODINIT_FUNC initpypamtest(void)
                          pypamtest_module_methods);
 #endif
 
+#if PY_VERSION_HEX >= 0x02070000 /* >= 2.7.0 */
        PyExc_PamTestError = PyErr_NewExceptionWithDoc(discard_const_p(char, "pypamtest.PamTestError"),
                                                       PamTestError__doc__,
                                                       PyExc_EnvironmentError,
                                                       NULL);
+#else /* < 2.7.0 */
+       PyExc_PamTestError = PyErr_NewException(discard_const_p(char, "pypamtest.PamTestError"),
+                                                      PyExc_EnvironmentError,
+                                                      NULL);
+#endif
+
        if (PyExc_PamTestError == NULL) {
                RETURN_ON_ERROR;
        }