Mini Shell

Direktori : /lib/python3.6/site-packages/dasbus/server/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/dasbus/server/__pycache__/handler.cpython-36.pyc

3

V]�_YD�@s�ddlZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZmZddlZejd	d
�ddlmZeje�Zdd
dgZGdd�de�ZGdd
�d
ed�ZGdd�de�ZdS)�N)�ABCMeta�abstractmethod)�partial)�ErrorMapper)�Signal)�get_xml)�DBusSpecification�DBusSpecificationError)�get_variant�unwrap_variant�Gioz2.0)r�
GLibServer�AbstractServerObjectHandler�ServerObjectHandlerc@s^eZdZdZeddd��Zeffdd��Zedd��Zed	d
��Zedd��Z	ed
d��Z
dS)r
z0The low-level DBus server library based on GLib.NcCs|j|||||�dS)zEmit a DBus signal.N)�emit_signal)�cls�
connection�object_path�interface_name�signal_name�
parametersZdestination�r�/usr/lib/python3.6/handler.pyr/szGLibServer.emit_signalcCsjtjj|�}t|j||fd�}g}|js0td��x*|jD] }	|j||	|dd�}
|j|
�q8Wt|j	||�S)zRegister an object on DBus.)�	user_dataz$No DBus interfaces for registration.N)
rZDBusNodeInfoZnew_for_xmlr�_object_callbackZ
interfacesr	�register_object�append�_unregister_object)rrrZ
object_xml�callback�
callback_argsZ	node_infoZmethod_call_closure�
registrationsZinterface_info�registration_idrrrr;s*zGLibServer.register_objectcCsx|D]}|j|�qWdS)zUnregister an object from DBus.N)Zunregister_object)rrr r!rrrr]s
zGLibServer._unregister_objectc	Cs |\}	}
|	||||f|
��dS)Nr)rrZsenderrr�method_namer�
invocationrrrrrrrcszGLibServer._object_callbackcCs|j||�dS)z�Set the error of the DBus call.

        :param invocation: an invocation of a DBus call
        :param error_name: a DBus name of the error
        :param error_message: an error message
        N)Zreturn_dbus_error)rr#�
error_nameZ
error_messagerrr�set_call_errorsszGLibServer.set_call_errorcCs&d}|dk	rt||f�}|j|�dS)z�Set the reply of the DBus call.

        :param invocation: an invocation of a DBus call
        :param out_type: a type of the reply
        :param out_value: a value of the reply
        N)r
Zreturn_value)rr#�out_typeZ	out_valueZreply_valuerrr�set_call_reply}szGLibServer.set_call_reply)N)�__name__�
__module__�__qualname__�__doc__�classmethodrrrrr%r'rrrrr
,s
 
c@s�eZdZdZddddgZdd�Zedd	��Zd
d�Ze	dd
��Z
e	dd��Ze	dd��Ze	dd��Z
e	dd��Zdd�Zdd�Zdd�Zdd�Ze	dd��Zd S)!rz+The abstract handler of a published object.�_message_bus�_object_path�_object�_specificationcCs||_||_||_d|_dS)z�Create a new handler.

        :param message_bus: a message bus
        :param object_path: a DBus path of the object
        :param obj: a Python instance of the object
        N)r-r.r/r0)�self�message_busr�objrrr�__init__�sz$AbstractServerObjectHandler.__init__cCs|js|j�|_|jS)zDBus specification.)r0�_get_specification)r1rrr�
specification�s
z)AbstractServerObjectHandler.specificationcCstj|j��S)zKGet the DBus specification.

        :return: a DBus specification
        )rZfrom_xml�_get_xml_specification)r1rrrr5�sz.AbstractServerObjectHandler._get_specificationcCsdS)zIGet the XML specification.

        :return: a XML specification
        �r)r1rrrr7�sz2AbstractServerObjectHandler._get_xml_specificationcCsdS)z�Connect the object to DBus.

        Handle emitted signals of the object with the _emit_signal
        method and handle incoming DBus calls with the _handle_call
        method.
        Nr)r1rrr�connect_object�sz*AbstractServerObjectHandler.connect_objectcCsdS)zdDisconnect the object from DBus.

        Unregister the object and disconnect all signals.
        Nr)r1rrr�disconnect_object�sz-AbstractServerObjectHandler.disconnect_objectcCsdS)z�Connect a DBus signal.

        :param interface_name: a DBus interface name
        :param signal_name: a DBus signal name
        Nr)r1rrrrr�_connect_signal�sz+AbstractServerObjectHandler._connect_signalcGsdS)z�Handle a DBus signal.

        :param interface_name: a DBus interface name
        :param signal_name: a DBus name of the signal
        :param parameters: a signal parameters
        Nr)r1rrrrrr�_emit_signal�sz(AbstractServerObjectHandler._emit_signalcGs|j||�}||�S)z�Handle a DBus call.

        :param interface_name: a name of the interface
        :param method_name: a name of the called method
        :param parameters: parameters of the call
        :return: a result of the DBus call
        )�
_find_handler)r1rr"r�handlerrrr�_handle_call�sz(AbstractServerObjectHandler._handle_callcCs|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
        )r6Z
get_member)r1r�member_namerrr�_find_member_spec�sz-AbstractServerObjectHandler._find_member_speccCs0|j||�p|j||�}|s,tdj||���|S)z�Find a handler of a DBus member.

        :param interface_name: a name of the interface
        :param member_name: a name of the method
        :return: a handler
        z The member {}.{} has no handler.)�_find_object_handler�_find_default_handler�AttributeError�format)r1rr@r>rrrr=�s
z)AbstractServerObjectHandler._find_handlercCst|j|d�S)aeGet an object handler of a DBus call.

        By default, DBus interfaces with members of the same name are
        not supported, so the given interface name is not used to find
        the object handler.

        :param interface_name: a name of the interface.
        :param member_name: a name of the member
        :return: a handler or None
        N)�getattrr/)r1rr@rrrrBsz0AbstractServerObjectHandler._find_object_handlercCsdS)z�Find a default handler of a DBus call.

        :param interface_name: a name of the interface
        :param member_name: a name of the member
        :return: a handler or None
        Nr)r1rr@rrrrCsz1AbstractServerObjectHandler._find_default_handlerN)r(r)r*r+�	__slots__r4�propertyr6r5rr7r9r:r;r<r?rAr=rBrCrrrrr�s$	
	

)�	metaclasscs�eZdZdZddddgZdeef�fdd�	Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zed)d*��Z�ZS)+rz+The handler of an object published on DBus.�_server�_signal_factory�
_error_mapper�_registrationsNcs2t�j|||�||_||_|p$t�|_g|_dS)aACreate a new handler.

        :param message_bus: a message bus
        :param object_path: a DBus path of the object
        :param obj: a Python instance of the object
        :param error_mapper: a DBus error mapper
        :param server: a DBus server library
        :param signal_factory: a signal factory
        N)�superr4rJrKrrLrM)r1r2rr3Zerror_mapperZserverZsignal_factory)�	__class__rrr4*s
zServerObjectHandler.__init__cCs
t|j�S)zIGet the XML specification.

        :return: a XML specification
        )rr/)r1rrrr7;sz*ServerObjectHandler._get_xml_specificationcCs|j�|j�dS)zConnect the object to DBus.N)�_register_object�_connect_signals)r1rrrr9Bsz"ServerObjectHandler.connect_objectcCs x|jr|jj�}|�qWdS)z Disconnect the object from DBus.N)rM�pop)r1rrrrr:Gs
z%ServerObjectHandler.disconnect_objectcCs.|jj|jj|j|j�|j�}|jj|�dS)zLRegister to DBus calls.

        :return: an unregistering callback
        N)	rJrr-rr.r7�_method_callbackrMr)r1Z
unregisterrrrrPMsz$ServerObjectHandler._register_objectcCs4x.|jjD]"}t|tj�sq
|j|j|j�q
WdS)zConnect all DBus signals.N)r6�members�
isinstancerrr;r�name)r1�memberrrrrQ[sz$ServerObjectHandler._connect_signalscCs>|j||�}|j||�}|j|�t|j|�}|jj|�dS)z�Connect a DBus signal.

        :param interface_name: a DBus interface name
        :param signal_name: a DBus signal name
        :return: a disconnecting callback
        N)�
_find_emitterr=Zconnectr�
disconnectrMr)r1rrr�signalrYrrrr;fs

z#ServerObjectHandler._connect_signalcCst|j||�S)z�Find an emitter of a DBus signal.

        :param interface_name: a DBus interface name
        :param signal_name: a DBus signal name
        :return: a callback
        )rr<)r1rrrrrrXtsz!ServerObjectHandler._find_emittercGsH|j||�}|sd}|jdk	r*t|j|�}|jj|jj|j|||�dS)z�Handle a DBus signal.

        :param interface_name: a DBus interface name
        :param signal_name: a DBus signal name
        :param parameters: a signal parameters
        N)rA�typer
rJrr-rr.)r1rrrrWrrrr<}s
z ServerObjectHandler._emit_signalcCsly4|j||�}|j||ft|���}|j|||�Wn2tk
rf}z|j||||�WYdd}~XnXdS)z�The callback for a DBus call.

        :param invocation: an invocation of the DBus call
        :param interface_name: a DBus interface name
        :param method_name: a DBus method name
        :param parameters: a variant of DBus arguments
        N)rAr?r�_handle_method_result�	Exception�_handle_method_error)r1r#rr"rrW�result�errorrrrrS�s$	
z$ServerObjectHandler._method_callbackcCs:tjd||dd�|jjt|��}|jj||t|��dS)aHandle an error of a DBus call.

        :param invocation: an invocation of the DBus call
        :param interface_name: a DBus interface name
        :param method_name: a DBus method name
        :param error: an exception raised during the call
        z,The call %s.%s has failed with an exception:T)�exc_infoN)�logZwarningrLZget_error_namer[rJr%�str)r1r#rr"r`r$rrrr^�s	
z(ServerObjectHandler._handle_method_errorcCs|jj||j|�dS)z�Handle a result of a DBus call.

        :param invocation: an invocation of a DBus call
        :param method_spec: a method specification
        :param method_reply: a method reply
        N)rJr'r&)r1r#Zmethod_specZmethod_replyrrrr\�sz)ServerObjectHandler._handle_method_resultcCsD|dkr@|dkr|jS|dkr$|jS|dkr2|jS|dkr@|jSdS)z�Find a default handler of a DBus call.

        :param interface_name: a name of the interface
        :param member_name: a name of the member
        :return: a handler or None
        zorg.freedesktop.DBus.PropertiesZGet�SetZGetAllZPropertiesChangedN)�
_get_property�
_set_property�_get_all_properties�_properties_changed)r1rr@rrrrC�sz)ServerObjectHandler._find_default_handlercCs:|j||�}|js"tdj||���t|j|�}t|j|�S)z�The default handler of the Get method.

        :param interface_name: an interface name
        :param property_name: a property name
        :return: a variant with a property value
        z#The property {}.{} is not readable.)rA�readablerDrErFr/r
r[)r1r�
property_namerW�valuerrrre�s
z!ServerObjectHandler._get_propertycCs8|j||�}|js"tdj||���t|j|t|��dS)z�The default handler of the Set method.

        :param interface_name: an interface name
        :param property_name: a property name
        :param property_value: a variant with a property value
        z#The property {}.{} is not writable.N)rA�writablerDrE�setattrr/r)r1rrjZproperty_valuerWrrrrf�s

z!ServerObjectHandler._set_propertycs�fdd�|jjD�S)z�Find all properties of the given interface.

        :param interface_name: an interface name
        :return: a list of property names
        cs.g|]&}t|tj�r|j�kr|jr|j�qSr)rUrZPropertyrrirV)�.0rW)rrr�
<listcomp>s
z<ServerObjectHandler._find_all_properties.<locals>.<listcomp>)r6rT)r1rr)rr�_find_all_propertiessz(ServerObjectHandler._find_all_propertiescs��fdd��j��D�S)z�The default handler of the GetAll method.

        :param interface_name: an interface name
        :return: a dictionary of properties
        csi|]}�j�|�|�qSr)re)rnrj)rr1rr�
<dictcomp>sz;ServerObjectHandler._get_all_properties.<locals>.<dictcomp>)rp)r1rr)rr1rrgsz'ServerObjectHandler._get_all_propertiescCs|j�S)zXThe default handler of the PropertiesChanged method.

        :return: a signal
        )rK)r1rrrrh#sz'ServerObjectHandler._properties_changed)r(r)r*r+rGr
rr4r7r9r:rPrQr;rXr<rSr^r\rCrerfrprgrHrh�
__classcell__rr)rOrr s0	 

)Zlogging�abcrr�	functoolsrZdasbus.errorrZ
dasbus.signalrZdasbus.server.interfacerZdasbus.specificationrr	Z
dasbus.typingr
rZgiZrequire_versionZ
gi.repositoryrZ	getLoggerr(rb�__all__�objectr
rrrrrr�<module>s$
a