Workaround for missing PyGObject support for GStrv
authorAlberto Mardegan <mardy@users.sourceforge.net>
Wed, 21 Dec 2011 07:46:11 +0000 (09:46 +0200)
committerAlberto Mardegan <alberto.mardegan@canonical.com>
Mon, 13 Aug 2012 08:01:33 +0000 (11:01 +0300)
Currently PyGObject doesn't support marshalling of string lists (see
https://bugzilla.gnome.org/show_bug.cgi?id=666636 ), so we need to
workaround this limitation somehow.
This code uses pygobject "hidden" support for GStrv to convert Python
lists to GStrv on the fly.

Makefile.am
autogen.sh
configure.ac
pygobject/Makefile.am [new file with mode: 0644]
pygobject/Signon.py [new file with mode: 0644]

index 7af8337ba7483d5a9b900688b6149a676fa8d289..022de5c90b861da3d9d535ddf18928e673c64742 100644 (file)
@@ -4,6 +4,10 @@ DISTCHECK_CONFIGURE_FLAGS = \
        --enable-introspection=yes
 SUBDIRS = libsignon-glib docs tests
 
+if ENABLE_PYTHON
+SUBDIRS += pygobject
+endif
+
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libsignon-glib.pc
 
index 909607197574aa6dfcfad4fd1e94b2e374b2b09a..fe96569baa96f760fff6c55c6ee0351fd669e459 100755 (executable)
@@ -1,3 +1,4 @@
 gtkdocize
+automake --add-missing
 autoreconf -i --force && ./configure "$@"
 
index 3189448c20a4527dd8ad2a7cf2d1f2255574337c..fbbcac4b4e465511b64ca6df023b9fab8c36fc41 100644 (file)
@@ -55,6 +55,29 @@ if test "x$coverage" = "xyes"; then
     CFLAGS="$CFLAGS -g -fprofile-arcs -ftest-coverage"
 fi
 
+AM_PATH_PYTHON
+
+PYGOBJECT_REQUIRED=2.90
+
+AC_ARG_ENABLE([python],
+              AS_HELP_STRING([--enable-python[=@<:@no/auto/yes@:>@]],[Build with python support]),
+              [enable_python=$enableval],
+              [enable_python="auto"])
+
+if test "x$enable_python" = "xauto"; then
+    PKG_CHECK_EXISTS([pygobject-3.0 >= $PYGOBJECT_REQUIRED],
+                    [enable_python=yes],[enable_python=no])
+fi
+
+if test "x$enable_python" = "xyes"; then
+    PKG_CHECK_MODULES(PYTHON, [pygobject-3.0 >= $PYGOBJECT_REQUIRED])
+
+    pyoverridesdir=`$PYTHON -c "import gi;print gi._overridesdir"`
+    AC_SUBST(pyoverridesdir)
+fi
+
+AM_CONDITIONAL(ENABLE_PYTHON, test x"$enable_python" = "xyes")
+
 AC_OUTPUT([
        Makefile
        libsignon-glib/Makefile
@@ -62,4 +85,5 @@ AC_OUTPUT([
        docs/Makefile
        docs/reference/Makefile
        tests/Makefile
+       pygobject/Makefile
 ])
diff --git a/pygobject/Makefile.am b/pygobject/Makefile.am
new file mode 100644 (file)
index 0000000..405cc1d
--- /dev/null
@@ -0,0 +1,4 @@
+overridesdir = $(pyoverridesdir)
+overrides_PYTHON = \
+       Signon.py
+
diff --git a/pygobject/Signon.py b/pygobject/Signon.py
new file mode 100644 (file)
index 0000000..1a0aaa9
--- /dev/null
@@ -0,0 +1,26 @@
+from ..overrides import override
+from ..importer import modules
+from gi.repository import GObject
+
+Signon = modules['Signon']._introspection_module
+
+__all__ = []
+
+class GStrv(list):
+    __gtype__ = GObject.type_from_name('GStrv')
+
+class AuthSession(Signon.AuthSession):
+
+    # Convert list of strings into a single string
+    def process(self, session_data, mechanism, callback, userdata):
+        cleaned_data = {}
+        for (key, value) in session_data.iteritems():
+            if isinstance(value, list):
+                cleaned_data[key] = GStrv(value)
+            else:
+                cleaned_data[key] = value
+        Signon.AuthSession.process(self, cleaned_data, mechanism, callback, userdata)
+
+AuthSession = override(AuthSession)
+__all__.append('AuthSession')
+