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__/handler.cpython-36.opt-1.pyc

3

V]�_�=�@s�ddlmZmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZmZmZdd	lZejd
d�ejdd�dd
lmZmZdddgZGdd�de�ZGdd�ded�ZGdd�de�Zd	S)�)�ABCMeta�abstractmethod)�partial)�
PropertyProxy)�ErrorMapper)�Signal)�DBUS_FLAG_NONE)�DBusSpecification)�get_variant�get_variant_type�unwrap_variantN�Gioz2.0�GLib)r
r�
GLibClient�AbstractClientObjectHandler�ClientObjectHandlerc@s�eZdZdZejZeeefdd��Z	efeefdd��Z
edd��Zefefdd	��Zed
d��Z
edd
��Zedd��Zedd��Zedd��ZdS)rz0The low-level DBus client library based on GLib.c


Cs|j||||||||	d�	S)zVSynchronously call a DBus method.

        :return: a result of the DBus call
        N)Z	call_sync)
�cls�
connection�service_name�object_path�interface_name�method_name�
parameters�
reply_type�flags�timeout�r�/usr/lib/python3.6/handler.py�	sync_call1szGLibClient.sync_callcCs(|j|||||||
||j||	fd�
dS)z"Asynchronously call a DBus method.)�callback�	user_dataN)�call�_async_call_finish)rrrrrrrrr�
callback_argsrrrrr�
async_callEszGLibClient.async_callcs$|\}}|��fdd�f|��dS)z(Finish an asynchronous DBus method call.cs
�j��S)N)Zcall_finishr)�
result_object�
source_objectrr�<lambda>`sz/GLibClient._async_call_finish.<locals>.<lambda>Nr)rr&r%r rr#r)r%r&rr"XszGLibClient._async_call_finishc	

Cs.|j||||d||j||fd�}	t|j||	�S)zKSubscribe to a signal.

        :return: a callback to unsubscribe
        N)rr )Zsignal_subscribe�_signal_callbackr�_unsubscribe_signal)
rrrrr�signal_namerr#r�subscription_idrrr�subscribe_signaldszGLibClient.subscribe_signalc
Cs|\}}	||f|	��dS)z8A callback that is called when a DBus signal is emitted.Nr)
rrZsender_namerrr*rr rr#rrrr(}szGLibClient._signal_callbackcCs|j|�dS)zUnsubscribe from a signal.N)Zsignal_unsubscribe)rrr+rrrr)�szGLibClient._unsubscribe_signalcCst|tj�otjj|�S)zIs it a remote DBus error?)�
isinstancer�Errorr
�	DBusError�is_remote_error)r�errorrrrr0�szGLibClient.is_remote_errorcCstjj|�S)z)Get a DBus name of the remote DBus error.)r
r/Zget_remote_error)rr1rrr�get_remote_error_name�sz GLibClient.get_remote_error_namecCs:|j|�}|j}djd|�}|j|�r6|t|�d�S|S)z'Get a message of the remote DBus error.z{}:{}: zGDBus.ErrorN)r2�message�format�
startswith�len)rr1�namer3�prefixrrr�get_remote_error_message�s

z#GLibClient.get_remote_error_messageN)�__name__�
__module__�__qualname__�__doc__rZMAXINTZDBUS_TIMEOUT_NONE�classmethodrrr$r"r,r(r)r0r2r9rrrrr+s 
c@s�eZdZdZddddgZdd�Zedd	��Zed
d��Zedd
��Z	e
dd��Zdd�Zdd�Z
dd�Ze
dd��Ze
dd��Ze
dd��Ze
dd��ZdS)rz-The abstract handler of a remote DBus object.�_message_bus�
_service_name�_object_path�_specificationcCs||_||_||_d|_dS)z�Create a new handler.

        :param message_bus: a message bus
        :param service_name: a DBus name of the service
        :param object_path: a DBus path the object
        N)r?r@rArB)�self�message_busrrrrr�__init__�sz$AbstractClientObjectHandler.__init__cCs|jS)z9DBus service name.

        :return: a DBus name
        )r@)rCrrrr�sz(AbstractClientObjectHandler.service_namecCs|jS)z8DBus object path.

        :return: a DBus path
        )rA)rCrrrr�sz'AbstractClientObjectHandler.object_pathcCs|js|j�|_|jS)zDBus specification.)rB�_get_specification)rCrrr�
specification�s
z)AbstractClientObjectHandler.specificationcCst�S)zKIntrospect the DBus object.

        :return: a DBus specification
        )r	)rCrrrrF�sz.AbstractClientObjectHandler._get_specificationcCs"|j||�}|jt|��}||�S)z�Create a member of the DBus object.

        :param interface_name: a name of the interface
        :param member_name: a name of the member
        :return: a signal, a method or a property
        )�_find_member_spec�
_find_handler�type)rCr�member_name�specZhandlerrrr�
create_member�sz)AbstractClientObjectHandler.create_membercCs|jj||�S)z�Find a specification of the DBus member.

        :param interface_name: a name of the interface
        :param member_name: a name of the member
        :return: a specification of the member
        )rGZ
get_member)rCrrKrrrrH�sz-AbstractClientObjectHandler._find_member_speccCsD|tjkr|jS|tjkr |jS|tjkr0|jStdj|j	���dS)z�Find a handler for the given member type.

        :param member_type: a type of the member
        :return: a callback
        zUnsupported type: {}N)
r	ZProperty�
_get_propertyZMethod�_get_methodr�_get_signal�	TypeErrorr4r:)rC�member_typerrrrI�s


z)AbstractClientObjectHandler._find_handlercCsdS)z�Get a proxy of the DBus property.

        :param property_spec: a property_specification
        :return: a property object
        Nr)rC�
property_specrrrrNsz)AbstractClientObjectHandler._get_propertycCsdS)zGet a proxy of the DBus method.

        :param method_spec: a method specification
        :return: a callable object
        Nr)rC�method_specrrrrOsz'AbstractClientObjectHandler._get_methodcCsdS)z}Get a proxy of the DBus signal.

        :param signal_spec: a signal specification
        :return: a signal object
        Nr)rC�signal_specrrrrPsz'AbstractClientObjectHandler._get_signalcCsdS)z�Disconnect members of the DBus object.

        Unsubscribe from DBus signals and disconnect all
        registered callbacks of the proxy signals.
        Nr)rCrrr�disconnect_memberssz.AbstractClientObjectHandler.disconnect_membersN)r:r;r<r=�	__slots__rE�propertyrrrGrrFrMrHrIrNrOrPrVrrrrr�s"			)�	metaclasscs�eZdZdZddddgZdeef�fdd�	Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Z�ZS)#rz$The client handler of a DBus object.�_client�_signal_factory�
_error_mapper�_subscriptionsNcs2t�j|||�||_||_|p$t�|_g|_dS)aBCreate a new handler.

        :param message_bus: a message bus
        :param service_name: a DBus name of the service
        :param object_path: a DBus path the object
        :param error_mapper: a DBus error mapper
        :param client: a DBus client library
        :param signal_factory: a signal factory
        N)�superrErZr[rr\r])rCrDrrZerror_mapperZclientZsignal_factory)�	__class__rrrE2s
zClientObjectHandler.__init__cCs|jdddd�}tj|�S)zIntrospect the DBus object.z#org.freedesktop.DBus.IntrospectableZ
IntrospectNz(s))�_call_methodr	Zfrom_xml)rCZxmlrrrrFDsz&ClientObjectHandler._get_specificationc	CsR|j�}|jj|jj|j|j|j|j|j	|j
fd�}|jj|�|jj|j
�|S)zGet a proxy of the DBus signal.)rr#)r[rZr,r?rr@rArr7r(�emitr]�appendZ
disconnect)rCrU�signalZunsubscriberrrrPOszClientObjectHandler._get_signalcCs|t|��dS)z8A callback that is called when a DBus signal is emitted.N)r)rCrrrrrr(esz$ClientObjectHandler._signal_callbackcCs6d}d}|jrt|j|�}|jr,t|j|�}t||�S)z!Get a proxy of the DBus property.N)�readabler�_get_property_value�writable�_set_property_valuer)rCrS�getter�setterrrrrNisz!ClientObjectHandler._get_propertycCs |jdddd|j|j�}t|�S)z!Get a value of the DBus property.zorg.freedesktop.DBus.PropertiesZGetz(ss)z(v))r`rr7r)rCrSZvariantrrrrevsz'ClientObjectHandler._get_property_valuec
Cs"|jdddd|j|jt|j|��S)z!Set a value of the DBus property.zorg.freedesktop.DBus.Properties�Setz(ssv)N)r`rr7r
rJ)rCrSZproperty_valuerrrrg�sz'ClientObjectHandler._set_property_valuecCst|j|j|j|j|j�S)z(Get a callable proxy of the DBus method.)rr`rr7�in_type�out_type)rCrTrrrrO�szClientObjectHandler._get_methodcOs�|sd}|dk	rt||�}d}|dk	r.t|�}|jj|j|j||||f}|jdd�}	|jdt��}
|	s||j|j	j
f|�|�S|j	j|||j|	|
fd���SdS)zKCall a DBus method.

        :return: a result of the call or None
        Nrr#)rr#)
r
rr?rr@rA�pop�tuple�_get_method_replyrZrr$�_method_callback)rCrrrkrlr�kwargsr�argsrr#rrrr`�s4
z ClientObjectHandler._call_methodcs|��fdd�f|��dS)z/A callback of an asynchronous DBus method call.cs
�j��S)N)ror)rhrCrrr'�sz6ClientObjectHandler._method_callback.<locals>.<lambda>Nr)rCrhrr#r)rhrCrrp�sz$ClientObjectHandler._method_callbackcOs@y|||�}|j|�Stk
r:}z
|j|�Sd}~XnXdS)aGet a result of a DBus call.

        :param call: a callback
        :param args: arguments of the callback
        :param kwargs: keyword arguments of the callback
        :return: a result of the callback
        :raise: an exception raised by the callback
        N)�_handle_method_result�	Exception�_handle_method_error)rCr!rrrq�resultr1rrrro�s
	

z%ClientObjectHandler._get_method_replycCsL|jj|�s|�|jj|�}|jj|�}|jj|�}||�}||_|d�dS)zcHandle an error of a DBus call.

        :param error: an exception raised during the call
        N)rZr0r2r\Zget_exception_typer9Z	dbus_name)rCr1r7rr3Z	exceptionrrrru�sz(ClientObjectHandler._handle_method_errorcCs(t|�}|sdSt|�dkr$|dS|S)zPHandle a result of a DBus call.

        :param result: a variant tuple
        N�r)rr6)rCrv�valuesrrrrs�sz)ClientObjectHandler._handle_method_resultcCs x|jr|jj�}|�qWdS)z&Disconnect members of the DBus object.N)r]rm)rCrrrrrVs
z&ClientObjectHandler.disconnect_members)r:r;r<r=rWrrrErFrPr(rNrergrOr`rprorursrV�
__classcell__rr)r_rr(s(

1)�abcrr�	functoolsrZdasbus.client.propertyrZdasbus.errorrZ
dasbus.signalrZdasbus.constantsrZdasbus.specificationr	Z
dasbus.typingr
rrZgiZrequire_versionZ
gi.repositoryr
r�__all__�objectrrrrrrr�<module>s$y