diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-10-30 16:38:35 -0700 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-10-30 16:38:35 -0700 |
commit | 84a74d5225e520b3f32ec1d37b7b4a5ed040b66a (patch) | |
tree | a054332610562cedcd9f72862fbb22522844b70f /dbus/gobject_service.py | |
parent | bacb91163539eca0a185298b620db7cf74660411 (diff) | |
download | dbus-python-84a74d5225e520b3f32ec1d37b7b4a5ed040b66a.tar.gz dbus-python-84a74d5225e520b3f32ec1d37b7b4a5ed040b66a.tar.bz2 dbus-python-84a74d5225e520b3f32ec1d37b7b4a5ed040b66a.zip |
Imported Upstream version 1.1.1upstream/1.1.1
Diffstat (limited to 'dbus/gobject_service.py')
-rw-r--r-- | dbus/gobject_service.py | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/dbus/gobject_service.py b/dbus/gobject_service.py index 47a2b5f..1c96546 100644 --- a/dbus/gobject_service.py +++ b/dbus/gobject_service.py @@ -22,20 +22,23 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -__all__ = ['ExportedGObject'] +import sys +from warnings import warn as _warn +_warn(DeprecationWarning("""\ +dbus.gobject_service is deprecated, and is not available under Python 3. -from gi.repository import GObject as gobject -import dbus.service +Porting from gobject (PyGObject 2) to gi.repository.GObject (PyGObject 3), +and using dbus.gi_service instead of dbus.gobject_service, is recommended. +"""), DeprecationWarning, stacklevel=2) -# 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. +if 'gi' in sys.modules: + # this worked in dbus-python 1.0, so preserve the functionality + from gi.repository import GObject as gobject +else: + # this worked in dbus-python < 1.0 + import gobject + +import dbus.service class ExportedGObjectType(gobject.GObjectMeta, dbus.service.InterfaceType): """A metaclass which inherits from both GObjectMeta and @@ -45,39 +48,39 @@ class ExportedGObjectType(gobject.GObjectMeta, dbus.service.InterfaceType): gobject.GObjectMeta.__init__(cls, name, bases, dct) dbus.service.InterfaceType.__init__(cls, name, bases, dct) +class ExportedGObject(gobject.GObject, dbus.service.Object): + """A GObject which is exported on the D-Bus. -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. + 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. + """ + __metaclass__ = ExportedGObjectType - 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) + def __init__(self, conn=None, object_path=None, **kwargs): + """Initialize an exported GObject. - 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) + :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. -ExportedGObject__doc__ = 'A GObject which is exported on the D-Bus.' + 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) -ExportedGObject = ExportedGObjectType( - 'ExportedGObject', - (gobject.GObject, dbus.service.Object), - {'__init__': ExportedGObject__init__, - '__doc__': ExportedGObject__doc__, - }) + 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) |