Blame dbus/gobject_service.py

Packit 130fc8
"""Support code for implementing D-Bus services via GObjects."""
Packit 130fc8
Packit 130fc8
# Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
Packit 130fc8
#
Packit 130fc8
# Permission is hereby granted, free of charge, to any person
Packit 130fc8
# obtaining a copy of this software and associated documentation
Packit 130fc8
# files (the "Software"), to deal in the Software without
Packit 130fc8
# restriction, including without limitation the rights to use, copy,
Packit 130fc8
# modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 130fc8
# of the Software, and to permit persons to whom the Software is
Packit 130fc8
# furnished to do so, subject to the following conditions:
Packit 130fc8
#
Packit 130fc8
# The above copyright notice and this permission notice shall be
Packit 130fc8
# included in all copies or substantial portions of the Software.
Packit 130fc8
#
Packit 130fc8
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 130fc8
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 130fc8
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 130fc8
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 130fc8
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Packit 130fc8
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit 130fc8
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit 130fc8
# DEALINGS IN THE SOFTWARE.
Packit 130fc8
Packit 130fc8
import sys
Packit 130fc8
from warnings import warn as _warn
Packit 130fc8
_warn(DeprecationWarning("""\
Packit 130fc8
dbus.gobject_service is deprecated, and is not available under Python 3.
Packit 130fc8
Packit 130fc8
Porting from gobject (PyGObject 2) to gi.repository.GObject (PyGObject 3),
Packit 130fc8
and using dbus.gi_service instead of dbus.gobject_service, is recommended.
Packit 130fc8
"""), DeprecationWarning, stacklevel=2)
Packit 130fc8
Packit 130fc8
if 'gi' in sys.modules:
Packit 130fc8
    # this worked in dbus-python 1.0, so preserve the functionality
Packit 130fc8
    from gi.repository import GObject as gobject
Packit 130fc8
else:
Packit 130fc8
    # this worked in dbus-python < 1.0
Packit 130fc8
    import gobject
Packit 130fc8
Packit 130fc8
import dbus.service
Packit 130fc8
Packit 130fc8
class ExportedGObjectType(gobject.GObject.__class__, dbus.service.InterfaceType):
Packit 130fc8
    """A metaclass which inherits from both GObjectMeta and
Packit 130fc8
    `dbus.service.InterfaceType`. Used as the metaclass for `ExportedGObject`.
Packit 130fc8
    """
Packit 130fc8
    def __init__(cls, name, bases, dct):
Packit 130fc8
        gobject.GObject.__class__.__init__(cls, name, bases, dct)
Packit 130fc8
        dbus.service.InterfaceType.__init__(cls, name, bases, dct)
Packit 130fc8
Packit 130fc8
class ExportedGObject(gobject.GObject, dbus.service.Object):
Packit 130fc8
    """A GObject which is exported on the D-Bus.
Packit 130fc8
Packit 130fc8
    Because GObject and `dbus.service.Object` both have custom metaclasses,
Packit 130fc8
    the naive approach using simple multiple inheritance won't work. This
Packit 130fc8
    class has `ExportedGObjectType` as its metaclass, which is sufficient
Packit 130fc8
    to make it work correctly.
Packit 130fc8
    """
Packit 130fc8
    __metaclass__ = ExportedGObjectType
Packit 130fc8
Packit 130fc8
    def __init__(self, conn=None, object_path=None, **kwargs):
Packit 130fc8
        """Initialize an exported GObject.
Packit 130fc8
Packit 130fc8
        :Parameters:
Packit 130fc8
            `conn` : dbus.connection.Connection
Packit 130fc8
                The D-Bus connection or bus
Packit 130fc8
            `object_path` : str
Packit 130fc8
                The object path at which to register this object.
Packit 130fc8
        :Keywords:
Packit 130fc8
            `bus_name` : dbus.service.BusName
Packit 130fc8
                A bus name to be held on behalf of this object, or None.
Packit 130fc8
            `gobject_properties` : dict
Packit 130fc8
                GObject properties to be set on the constructed object.
Packit 130fc8
Packit 130fc8
                Any unrecognised keyword arguments will also be interpreted
Packit 130fc8
                as GObject properties.
Packit 130fc8
            """
Packit 130fc8
        bus_name = kwargs.pop('bus_name', None)
Packit 130fc8
        gobject_properties = kwargs.pop('gobject_properties', None)
Packit 130fc8
Packit 130fc8
        if gobject_properties is not None:
Packit 130fc8
            kwargs.update(gobject_properties)
Packit 130fc8
        gobject.GObject.__init__(self, **kwargs)
Packit 130fc8
        dbus.service.Object.__init__(self, conn=conn,
Packit 130fc8
                                     object_path=object_path,
Packit 130fc8
                                     bus_name=bus_name)