From c6067649b43bd330ffd585dc03629dfe267ec262 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Wed, 21 Dec 2011 09:46:11 +0200 Subject: [PATCH] Workaround for missing PyGObject support for GStrv 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 | 4 ++++ autogen.sh | 1 + configure.ac | 24 ++++++++++++++++++++++++ pygobject/Makefile.am | 4 ++++ pygobject/Signon.py | 26 ++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 pygobject/Makefile.am create mode 100644 pygobject/Signon.py diff --git a/Makefile.am b/Makefile.am index 7af8337..022de5c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/autogen.sh b/autogen.sh index 9096071..fe96569 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,3 +1,4 @@ gtkdocize +automake --add-missing autoreconf -i --force && ./configure "$@" diff --git a/configure.ac b/configure.ac index 3189448..fbbcac4 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000..405cc1d --- /dev/null +++ b/pygobject/Makefile.am @@ -0,0 +1,4 @@ +overridesdir = $(pyoverridesdir) +overrides_PYTHON = \ + Signon.py + diff --git a/pygobject/Signon.py b/pygobject/Signon.py new file mode 100644 index 0000000..1a0aaa9 --- /dev/null +++ b/pygobject/Signon.py @@ -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') + -- 2.34.1