Mini Shell

Direktori : /usr/lib/python3.6/site-packages/dasbus/client/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/dasbus/client/__pycache__/observer.cpython-36.pyc

3

��^[�@s�ddlZddlmZddlmZddlmZddlZejdd�ddl	m
Z
eje�Z
dd	d
gZGdd�de�ZGdd
�d
e�ZGd
d	�d	e�ZdS)�N)�partial)�DBUS_FLAG_NONE)�Signal�Gioz2.0)r�DBusObserverError�DBusObserver�GLibMonitoringc@seZdZdZdS)rz'Exception class for the DBus observers.N)�__name__�
__module__�__qualname__�__doc__�r
r
�/usr/lib/python3.6/observer.pyr(sc@sHeZdZdZeeddfdd��Zedd��Zedd��Zed	d
��Z	dS)rz4The low-level DBus monitoring library based on GLib.Nc	CsTd}d}|rt|j|ffd�}|r4t|j|ffd�}tj|||||�}t|j||�S)z,Watch a service name on the DBus connection.N)�	user_data)r�_name_appeared_callback�_name_vanished_callbackrZbus_watch_name_on_connection�
_unwatch_name)	�cls�
connection�name�flagsZ
name_appearedZ
name_vanishedZname_appeared_closureZname_vanished_closure�registration_idr
r
r�
watch_name0s(zGLibMonitoring.watch_namecCs|\}}||f|��dS)zCallback for watch_name..Nr
)rrrZ
name_ownerr�callback�
callback_argsr
r
rrQsz&GLibMonitoring._name_appeared_callbackcCs|\}}||�dS)zCallback for watch_name.Nr
)rrrrrrr
r
rrZsz&GLibMonitoring._name_vanished_callbackcCstj|�dS)z5Stops watching a service name on the DBus connection.N)rZbus_unwatch_name)rrrr
r
rrcszGLibMonitoring._unwatch_name)
r	r
rr�classmethodrrrrrr
r
r
rr-s		c@s�eZdZdZefdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd S)!ra4Base class for DBus observers.

    This class is recommended to use only to watch the availability
    of a service on DBus. It doesn't provide any support for accessing
    objects provided by the service.

    Usage:

    .. code-block:: python

        # Create the observer and connect to its signals.
        observer = DBusObserver(SystemBus, "org.freedesktop.NetworkManager")

        def callback1(observer):
            print("Service is available!")

        def callback2(observer):
            print("Service is unavailable!")

        observer.service_available.connect(callback1)
        observer.service_unavailable.connect(callback2)

        # Connect to the service once it is available.
        observer.connect_once_available()

        # Disconnect the observer.
        observer.disconnect()

    cCs2||_||_d|_t�|_t�|_||_g|_dS)z�Creates a DBus service observer.

        :param message_bus: a message bus
        :param service_name: a DBus name of a service
        FN)�_message_bus�
_service_name�_is_service_availabler�_service_available�_service_unavailable�_monitoring�_subscriptions)�selfZmessage_bus�service_nameZ
monitoringr
r
r�__init__�szDBusObserver.__init__cCs|jS)zReturns a DBus name.)r)r#r
r
rr$�szDBusObserver.service_namecCs|jS)zThe proxy can be accessed.)r)r#r
r
r�is_service_available�sz!DBusObserver.is_service_availablecCs|jS)z�Signal that emits when the service is available.

        Signal emits this class as an argument. You have to
        call the watch method to activate the signals.
        )r)r#r
r
r�service_available�szDBusObserver.service_availablecCs|jS)z�Signal that emits when the service is unavailable.

        Signal emits this class as an argument. You have to
        call the watch method to activate the signals.
        )r )r#r
r
r�service_unavailable�sz DBusObserver.service_unavailablecCs|j�dS)z�Connect to the service once it is available.

        The observer is not connected to the service until it
        emits the service_available signal.
        N)�_watch)r#r
r
r�connect_once_available�sz#DBusObserver.connect_once_availablecCs|j�|jr|j�dS)z�Disconnect from the service.

        Disconnect from the service if it is connected and stop
        watching its availability.
        N)�_unwatchr&�_disable_service)r#r
r
r�
disconnect�szDBusObserver.disconnectcCs.|jj|jj|jt|j|j�}|jj	|�dS)zWatch the service name on DBus.N)
r!rrrr$r�_service_name_appeared_callback�_service_name_vanished_callbackr"�append)r#Zsubscriptionr
r
rr)�szDBusObserver._watchcCs x|jr|jj�}|�qWdS)z'Stop to watch the service name on DBus.N)r"�pop)r#rr
r
rr+�s
zDBusObserver._unwatchcCsd|_|jj|�dS)zEnable the service.TN)rr�emit)r#r
r
r�_enable_service�szDBusObserver._enable_servicecCsd|_|jj|�dS)zDisable the service.FN)rr r2)r#r
r
rr,�szDBusObserver._disable_servicecGs|js|j�dS)zCallback for the watch method.N)r&r3)r#�argsr
r
rr.�sz,DBusObserver._service_name_appeared_callbackcGs|jr|j�dS)zCallback for the watch method.N)r&r,)r#r4r
r
rr/�sz,DBusObserver._service_name_vanished_callbackcCs|jS)z(Returns a string version of this object.)r)r#r
r
r�__str__�szDBusObserver.__str__cCsdj|jj|j�S)z Returns a string representation.z{}({}))�format�	__class__r	r)r#r
r
r�__repr__�szDBusObserver.__repr__N)r	r
rrrr%�propertyr$r&r'r(r*r-r)r+r3r,r.r/r5r8r
r
r
rris 		)Zlogging�	functoolsrZdasbus.constantsrZ
dasbus.signalrZgiZrequire_versionZ
gi.repositoryrZ	getLoggerr	�log�__all__�	Exceptionr�objectrrr
r
r
r�<module>s
<