Package: python-pam
Version: 0.4.2-13
Severity: wishlist
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu quantal ubuntu-patch

Hi Dima,

In Ubuntu, we've patched the python-pam package to support Python 3.  Please
consider applying the attached patch for Python3 support to Debian as well.

Here's a changelog summary of the patch:

  * Port to python3; dead project upstream so not forwarding anywhere.
    - replace 'staticforward' with 'static'.
    - replace ob_type with Py_TYPE(ob).
    - drop tp_getattr function, we just need to set tp_methods instead.
    - fix PyTypeObject definition.
    - use PyUnicode_FromString, not PyString_FromString
    - use PyLong_FromLong when building for python3.
    - use PyModule_Create instead of Py_InitModule for python3
    - LP: #1015320
  * Modernize packaging to dh and debhelper 9.

Normally I wouldn't propose such extensive changes to debian/rules, but in
this case updating debhelper is a significant aid in packaging of python
modules, and particularly for python3 modules.

Thanks for considering the patch.
-- 
Steve Langasek                   Give me a lever long enough and a Free OS
Debian Developer                   to set it on, and I can move the world.
Ubuntu Developer                                    http://www.debian.org/
slanga...@ubuntu.com                                     vor...@debian.org
=== modified file 'PAMmodule.c'
--- PAMmodule.c	2012-03-06 21:48:38 +0000
+++ PAMmodule.c	2012-07-03 23:10:57 +0000
@@ -24,7 +24,7 @@
     PyObject            *userData;
 } PyPAMObject;
 
-staticforward PyTypeObject PyPAMObject_Type;
+static PyTypeObject PyPAMObject_Type;
 
 static void PyPAM_Err(PyPAMObject *self, int result)
 {
@@ -107,7 +107,7 @@
     PyPAMObject         *p;
     struct pam_conv     *spc;
 
-    PyPAMObject_Type.ob_type = &PyType_Type;
+    Py_TYPE(&PyPAMObject_Type) = &PyType_Type;
     p = (PyPAMObject *) PyObject_NEW(PyPAMObject, &PyPAMObject_Type);
 
     if ((spc = (struct pam_conv *) malloc(sizeof(struct pam_conv))) == NULL) {
@@ -490,35 +490,33 @@
     PyObject_FREE(self);
 }
 
-static PyObject * PyPAM_getattr(PyPAMObject *self, char *name)
-{
-    return Py_FindMethod(PyPAMObject_Methods, (PyObject *) self, name);
-}
-
 static PyObject * PyPAM_repr(PyPAMObject *self)
 {
     char                buf[1024];
     
     snprintf(buf, 1024, "<pam object, service=\"%s\", user=\"%s\", conv=%p, pamh=%p>",
         self->service, self->user, self->conv, self->pamh);
-    return PyString_FromString(buf);
+    return PyUnicode_FromString(buf);
 }
 
 static PyTypeObject PyPAMObject_Type = {
-    PyObject_HEAD_INIT(0)   /* Must fill in type value later */
-    0,
+    PyVarObject_HEAD_INIT(&PyType_Type, 0)   /* Must fill in type value later */
     "pam",
     sizeof(PyPAMObject),
     0,
     (destructor)PyPAM_dealloc,      /*tp_dealloc*/
     0,      /*tp_print*/
-    (getattrfunc)PyPAM_getattr,     /*tp_getattr*/
+    0,      /*tp_getattr*/
     0,      /*tp_setattr*/
     0,      /*tp_compare*/
     (reprfunc)PyPAM_repr,           /*tp_repr*/
     0,      /*tp_as_number*/
     0,      /*tp_as_sequence*/
     0,      /*tp_as_mapping*/
+    0,      /*hash*/
+    0,      /*ternary*/
+    0,      /*another repr*/
+    (getattrofunc)PyObject_GenericGetAttr,
 };
 
 static PyMethodDef PyPAM_Methods[] = {
@@ -526,6 +524,16 @@
     {NULL, NULL, 0, NULL}
 };
 
+#if PY_MAJOR_VERSION > 2
+static struct PyModuleDef PyPAM_Module = {
+    PyModuleDef_HEAD_INIT,
+    "PAM",    /* name of module */
+    NULL,     /* module documentation */
+    -1,       /* size of per-interpreter state */
+    PyPAM_Methods
+};
+#endif
+
 static char PyPAMObject_doc[] = "";
 
 /* Convenience routine to export an integer value.
@@ -535,7 +543,11 @@
  */
 static void insint(PyObject *d, char *name, int value)
 {
+#if PY_MAJOR_VERSION > 2
+    PyObject            *v = PyLong_FromLong((long) value);
+#else
     PyObject            *v = PyInt_FromLong((long) value);
+#endif
 
     if (!v || PyDict_SetItemString(d, name, v))
         PyErr_Clear();
@@ -543,20 +555,32 @@
     Py_XDECREF(v);
 }
 
+#if PY_MAJOR_VERSION > 2
+PyMODINIT_FUNC PyInit_PAM(void)
+#else
 void initPAM(void)
+#endif
 {
     PyObject            *m, *d;
 
+#if PY_MAJOR_VERSION > 2
+    m = PyModule_Create(&PyPAM_Module);
+#else
     m = Py_InitModule("PAM", PyPAM_Methods);
+#endif
     d = PyModule_GetDict(m);
     
     PyPAM_Error = PyErr_NewException("PAM.error", NULL, NULL);
     if (PyPAM_Error == NULL)
-        return;
+#if PY_MAJOR_VERSION > 2
+		return m;
+#else
+		return;
+#endif
     PyDict_SetItemString(d, "error", PyPAM_Error);
 
-    PyPAMObject_Type.ob_type = &PyType_Type;
     PyPAMObject_Type.tp_doc = PyPAMObject_doc;
+    PyPAMObject_Type.tp_methods = PyPAMObject_Methods,
     Py_INCREF(&PyPAMObject_Type);
 
     insint(d, "PAM_SUCCESS", PAM_SUCCESS);
@@ -620,4 +644,7 @@
     insint(d, "PAM_BINARY_PROMPT", PAM_BINARY_PROMPT);
 #endif
 
+#if PY_MAJOR_VERSION > 2
+    return m;
+#endif
 }

=== modified file 'debian/changelog'

=== modified file 'debian/compat'
--- debian/compat	2012-03-06 21:48:38 +0000
+++ debian/compat	2012-07-03 23:11:03 +0000
@@ -1 +1 @@
-5
+9

=== modified file 'debian/control'
--- debian/control	2012-03-06 21:48:38 +0000
+++ debian/control	2012-07-03 23:13:39 +0000
@@ -1,10 +1,11 @@
 Source: python-pam
 Section: python
 Priority: optional
-Build-Depends: debhelper (>= 5.0.37.2), python-all-dev (>= 2.3.5-11), libpam0g-dev, python-support
+Build-Depends: debhelper (>= 9), python-all-dev (>= 2.3.5-11), python3-all-dev, libpam0g-dev
 Maintainer: Dima Barsky <d...@debian.org>
+X-Python-Version: >= 2.6
+X-Python3-Version: >= 3.2
 Standards-Version: 3.9.3
-X-Python-Version: 2.6, 2.7
 
 Package: python-pam
 Architecture: any
@@ -12,7 +13,19 @@
 Conflicts: python2.3-pam, python2.4-pam
 Replaces: python2.3-pam, python2.4-pam
 Provides: ${python:Provides}
+XB-Python-Version: ${python:Versions}
 Description: Python interface to the PAM library
  This module makes the PAM (Pluggable Authentication Modules) functions
  available in Python. With this module you can write Python applications
  that implement authentication services using PAM.
+
+Package: python3-pam
+Architecture: any
+Depends: ${python3:Depends}, ${shlibs:Depends}, ${misc:Depends}
+Provides: ${python3:Provides}
+Suggests: python3-pam-dbg
+XB-Python-Version: ${python3:Versions}
+Description: Python interface to the PAM library
+ This module makes the PAM (Pluggable Authentication Modules) functions
+ available in Python 3. With this module you can write Python 3 applications
+ that implement authentication services using PAM.

=== added file 'debian/python-pam.examples'
--- debian/python-pam.examples	1970-01-01 00:00:00 +0000
+++ debian/python-pam.examples	2012-07-03 23:09:33 +0000
@@ -0,0 +1 @@
+examples/*

=== added file 'debian/python-pam.install'
--- debian/python-pam.install	1970-01-01 00:00:00 +0000
+++ debian/python-pam.install	2012-07-03 23:09:33 +0000
@@ -0,0 +1,2 @@
+usr/lib/python2*/dist-packages/*[!_][!_].so
+usr/lib/python2*/dist-packages/*.egg-info

=== added file 'debian/python3-pam.examples'
--- debian/python3-pam.examples	1970-01-01 00:00:00 +0000
+++ debian/python3-pam.examples	2012-07-03 23:09:33 +0000
@@ -0,0 +1 @@
+examples/*

=== added file 'debian/python3-pam.install'
--- debian/python3-pam.install	1970-01-01 00:00:00 +0000
+++ debian/python3-pam.install	2012-07-03 23:09:33 +0000
@@ -0,0 +1,2 @@
+usr/lib/python3/dist-packages/*-[0-9][0-9][!d]*.so
+usr/lib/python3/dist-packages/*.egg-info

=== modified file 'debian/rules'
--- debian/rules	2012-03-06 21:48:38 +0000
+++ debian/rules	2012-07-03 23:11:44 +0000
@@ -2,61 +2,37 @@
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-# This is the debhelper compatibility version to use.
-#export DH_COMPAT=5
-
-PYVERS=$(shell pyversions -r)
-
--include /usr/share/python/python.mk
-
-build: build-arch build-indep
-build-arch: build-stamp
-build-indep: build-stamp
-
-build-stamp:
-	dh_testdir
-	for python in $(PYVERS); \
-		do $$python setup.py build; \
-	done
-	touch build-stamp
-
-clean:
-	dh_testdir
-	for python in $(PYVERS); \
-		do $$python setup.py clean; \
-	done
-	rm -rf build-stamp build
-	dh_clean
-
-install: build
-	dh_testdir
-	dh_testroot
-	dh_clean -k
-	dh_installdirs
-
-	for python in $(PYVERS); \
-		do $$python setup.py install --root=debian/python-pam --prefix=/usr $(py_setup_install_args); \
-	done
-
-# Build architecture-independent files here.
-binary-indep: build install
-
-# Build architecture-dependent files here.
-binary-arch: build install
-	dh_testdir
-	dh_testroot
-	dh_installdocs -a -A AUTHORS README
-	dh_installexamples -a -A examples/*
-	dh_installchangelogs -a ChangeLog
-	dh_strip -a
-	dh_compress -a
-	dh_fixperms -a
-	dh_python2 -a
-	dh_installdeb -a
-	dh_shlibdeps -a
-	dh_gencontrol -a
-	dh_md5sums -a
-	dh_builddeb -a
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary
+PYTHON2=$(shell pyversions -vr)
+PYTHON3=$(shell py3versions -vr)
+
+%:
+	dh $@ --with python2,python3
+
+build-python%:
+	python$* setup.py build
+
+override_dh_auto_build: $(PYTHON3:%=build-python%)
+	dh_auto_build
+
+install-python%:
+	python$* setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb
+
+override_dh_auto_install: $(PYTHON3:%=install-python%)
+	dh_auto_install
+
+override_dh_auto_clean:
+	dh_auto_clean
+	rm -rf build
+	rm -rf *.egg-info
+
+override_dh_installdocs:
+	dh_installdocs AUTHORS README
+
+override_dh_installchangelogs:
+	dh_installchangelogs ChangeLog

Reply via email to