From ba3f3ff253982c9ad3b5a33df5b120e5692c9d29 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 2 May 2012 10:39:29 +0100 Subject: Rename gobject_service (PyGI version) to gi_service Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48904 --- Makefile.am | 2 +- dbus/gi_service.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ dbus/gobject_service.py | 83 ------------------------------------------------- test/test-service.py | 10 +++--- 4 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 dbus/gi_service.py delete mode 100644 dbus/gobject_service.py diff --git a/Makefile.am b/Makefile.am index f3a57de..f244061 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,8 +26,8 @@ nobase_python_PYTHON = \ dbus/decorators.py \ dbus/exceptions.py \ dbus/_expat_introspect_parser.py \ + dbus/gi_service.py \ dbus/glib.py \ - dbus/gobject_service.py \ dbus/__init__.py \ dbus/lowlevel.py \ dbus/mainloop/__init__.py \ diff --git a/dbus/gi_service.py b/dbus/gi_service.py new file mode 100644 index 0000000..924442f --- /dev/null +++ b/dbus/gi_service.py @@ -0,0 +1,83 @@ +"""Support code for implementing D-Bus services via PyGI.""" + +# Copyright (C) 2007 Collabora Ltd. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, copy, +# modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +__all__ = ['ExportedGObject'] + +from gi.repository import GObject +import dbus.service + +# The odd syntax used here is required so that the code is compatible with +# both Python 2 and Python 3. It essentially creates a new class called +# ExportedGObject with a metaclass of ExportGObjectType and an __init__() +# function. +# +# Because GObject and `dbus.service.Object` both have custom metaclasses, the +# naive approach using simple multiple inheritance won't work. This class has +# `ExportedGObjectType` as its metaclass, which is sufficient to make it work +# correctly. + +class ExportedGObjectType(GObject.GObjectMeta, dbus.service.InterfaceType): + """A metaclass which inherits from both GObjectMeta and + `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`. + """ + def __init__(cls, name, bases, dct): + GObject.GObjectMeta.__init__(cls, name, bases, dct) + dbus.service.InterfaceType.__init__(cls, name, bases, dct) + + +def ExportedGObject__init__(self, conn=None, object_path=None, **kwargs): + """Initialize an exported GObject. + + :Parameters: + `conn` : dbus.connection.Connection + The D-Bus connection or bus + `object_path` : str + The object path at which to register this object. + :Keywords: + `bus_name` : dbus.service.BusName + A bus name to be held on behalf of this object, or None. + `gobject_properties` : dict + GObject properties to be set on the constructed object. + + Any unrecognised keyword arguments will also be interpreted + as GObject properties. + """ + bus_name = kwargs.pop('bus_name', None) + gobject_properties = kwargs.pop('gobject_properties', None) + + if gobject_properties is not None: + kwargs.update(gobject_properties) + GObject.GObject.__init__(self, **kwargs) + dbus.service.Object.__init__(self, conn=conn, + object_path=object_path, + bus_name=bus_name) + +ExportedGObject__doc__ = 'A GObject which is exported on the D-Bus.' + +ExportedGObject = ExportedGObjectType( + 'ExportedGObject', + (GObject.GObject, dbus.service.Object), + {'__init__': ExportedGObject__init__, + '__doc__': ExportedGObject__doc__, + }) diff --git a/dbus/gobject_service.py b/dbus/gobject_service.py deleted file mode 100644 index 47a2b5f..0000000 --- a/dbus/gobject_service.py +++ /dev/null @@ -1,83 +0,0 @@ -"""Support code for implementing D-Bus services via GObjects.""" - -# Copyright (C) 2007 Collabora Ltd. -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation -# files (the "Software"), to deal in the Software without -# restriction, including without limitation the rights to use, copy, -# modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. - -__all__ = ['ExportedGObject'] - -from gi.repository import GObject as gobject -import dbus.service - -# The odd syntax used here is required so that the code is compatible with -# both Python 2 and Python 3. It essentially creates a new class called -# ExportedGObject with a metaclass of ExportGObjectType and an __init__() -# function. -# -# Because GObject and `dbus.service.Object` both have custom metaclasses, the -# naive approach using simple multiple inheritance won't work. This class has -# `ExportedGObjectType` as its metaclass, which is sufficient to make it work -# correctly. - -class ExportedGObjectType(gobject.GObjectMeta, dbus.service.InterfaceType): - """A metaclass which inherits from both GObjectMeta and - `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`. - """ - def __init__(cls, name, bases, dct): - gobject.GObjectMeta.__init__(cls, name, bases, dct) - dbus.service.InterfaceType.__init__(cls, name, bases, dct) - - -def ExportedGObject__init__(self, conn=None, object_path=None, **kwargs): - """Initialize an exported GObject. - - :Parameters: - `conn` : dbus.connection.Connection - The D-Bus connection or bus - `object_path` : str - The object path at which to register this object. - :Keywords: - `bus_name` : dbus.service.BusName - A bus name to be held on behalf of this object, or None. - `gobject_properties` : dict - GObject properties to be set on the constructed object. - - Any unrecognised keyword arguments will also be interpreted - as GObject properties. - """ - bus_name = kwargs.pop('bus_name', None) - gobject_properties = kwargs.pop('gobject_properties', None) - - if gobject_properties is not None: - kwargs.update(gobject_properties) - gobject.GObject.__init__(self, **kwargs) - dbus.service.Object.__init__(self, conn=conn, - object_path=object_path, - bus_name=bus_name) - -ExportedGObject__doc__ = 'A GObject which is exported on the D-Bus.' - -ExportedGObject = ExportedGObjectType( - 'ExportedGObject', - (gobject.GObject, dbus.service.Object), - {'__init__': ExportedGObject__init__, - '__doc__': ExportedGObject__doc__, - }) diff --git a/test/test-service.py b/test/test-service.py index a4448f6..a7bf469 100755 --- a/test/test-service.py +++ b/test/test-service.py @@ -39,8 +39,8 @@ import dbus.service import dbus.glib import random -from dbus.gobject_service import ExportedGObject -from gi.repository import GObject as gobject +from dbus.gi_service import ExportedGObject +from gi.repository import GObject from dbus._compat import is_py2, is_py3 @@ -263,7 +263,7 @@ class TestObject(dbus.service.Object, TestInterface): def AsynchronousMethod(self, async, fail, variant, return_cb, error_cb): try: if async: - gobject.timeout_add(500, self.AsynchronousMethod, False, fail, + GObject.timeout_add(500, self.AsynchronousMethod, False, fail, variant, return_cb, error_cb) return else: @@ -310,7 +310,7 @@ class TestObject(dbus.service.Object, TestInterface): def return_from_async_wait(): return_cb() return False - gobject.timeout_add(500, return_from_async_wait) + GObject.timeout_add(500, return_from_async_wait) @dbus.service.method(IFACE, in_signature='', out_signature='') def RaiseValueError(self): @@ -356,7 +356,7 @@ def main(): logger.info('making Fallback') fallback_object = Fallback(session_bus) logger.info('creating mainloop') - loop = gobject.MainLoop() + loop = GObject.MainLoop() logger.info('running') loop.run() logger.info('done') -- cgit v1.2.1