%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/dasbus/server/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/dasbus/server/__pycache__/handler.cpython-39.pyc

a

F
�`vK�@s�ddlZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZddl
mZmZddlmZmZddlZe�d	d
�ddlmZe�e�Zgd�ZGd
d�de�ZGdd�ded�ZGdd�de�ZdS)�N)�ABCMeta�abstractmethod)�partial)�ErrorMapper)�Signal)�get_xml�"are_additional_arguments_supported)�DBusSpecification�DBusSpecificationError)�get_variant�unwrap_variant�Gioz2.0)r
)�
GLibServer�AbstractServerObjectHandler�ServerObjectHandlerc@sheZdZdZeddd��Zeddd��Zedd	��Zed
d��Zedd
��Z	edd��Z
edd��ZdS)rz0The low-level DBus server library based on GLib.NcCs|�|||||�dS)zEmit a DBus signal.N)�emit_signal)�cls�
connection�object_path�interface_name�signal_name�
parametersZdestination�r�9/usr/lib/python3.9/site-packages/dasbus/server/handler.pyr/s�zGLibServer.emit_signalrcCsftj�|�}t|j||fd�}g}|js0td��|jD] }	|�||	|dd�}
|�|
�q6t|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;s4���
��zGLibServer.register_objectcCs|D]}|�|�qdS)zUnregister an object from DBus.N)Zunregister_object)rrr!r"rrrr]szGLibServer._unregister_objectc	Cs"|\}	}
|	||||g|
�R�dS)Nr)rr�senderrr�method_namer�
invocationrrr rrrrcs��zGLibServer._object_callbackcCsd|��iS)a9Get information about the DBus call.

        Supported items:

            sender str: The bus name that invoked the method

        There can be more supported items in the future.

        :param invocation: an invocation of a DBus call
        :return: a dictionary of information about the DBus call
        r#)Z
get_sender)rr%rrr�
get_call_infoss�zGLibServer.get_call_infocCs|�||�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_error�szGLibServer.set_call_errorcCs&d}|durt||f�}|�|�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)rZreturn_value)rr%�out_typeZ	out_valueZreply_valuerrr�set_call_reply�szGLibServer.set_call_reply)N)r)�__name__�
__module__�__qualname__�__doc__�classmethodrrrrr&r(r*rrrrr,s"��!



	rc@s�eZdZdZgd�Zdd�Zedd��Zdd�Ze	d	d
��Z
e	dd��Ze	d
d��Ze	dd��Z
e	dd��Zdd�Zdd�Zdd�Zdd�Ze	dd��ZdS)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
        Nr0)�self�message_busr�objrrr�__init__�sz$AbstractServerObjectHandler.__init__cCs|js|��|_|jS)zDBus specification.)r4�_get_specification�r5rrr�
specification�s
z)AbstractServerObjectHandler.specificationcCst�|���S)zKGet the DBus specification.

        :return: a DBus specification
        )r	Zfrom_xml�_get_xml_specificationr:rrrr9�s�z.AbstractServerObjectHandler._get_specificationcCsdS)�IGet the XML specification.

        :return: a XML specification
        �rr:rrrr<�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.
        Nrr:rrr�connect_object�sz*AbstractServerObjectHandler.connect_objectcCsdS)zdDisconnect the object from DBus.

        Unregister the object and disconnect all signals.
        Nrr:rrr�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�r5rrrrr�_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)r5rrrrrr�_emit_signal�sz(AbstractServerObjectHandler._emit_signalcOs&|�||�}t|�si}||i|��S)a*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
        :param additional_args: additional arguments of the call
        :return: a result of the DBus call
        )�
_find_handlerr)r5rr$r�additional_args�handlerrrr�_handle_call�s
z(AbstractServerObjectHandler._handle_callcCs|j�||�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
        )r;Z
get_member�r5r�member_namerrr�_find_member_specs�z-AbstractServerObjectHandler._find_member_speccCs0|�||�p|�||�}|s,td�||���|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)r5rrIrFrrrrDs
��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)�getattrr3rHrrrrK sz0AbstractServerObjectHandler._find_object_handlercCsdS)��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
        NrrHrrrrL-sz1AbstractServerObjectHandler._find_default_handlerN)r+r,r-r.�	__slots__r8�propertyr;r9rr<r?r@rBrCrGrJrDrKrLrrrrr�s,
	

	


	
r)�	metaclasscs�eZdZdZgd�Zdeef�fdd�	Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�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��|||�||_||_|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)�superr8rTrUrrVrW)r5r6rr7Zerror_mapperZserverZsignal_factory��	__class__rrr8Bs
zServerObjectHandler.__init__cCs
t|j�S)r=)rr3r:rrrr<Ssz*ServerObjectHandler._get_xml_specificationcCs|��|��dS)zConnect the object to DBus.N)�_register_object�_connect_signalsr:rrrr?Zsz"ServerObjectHandler.connect_objectcCs|jr|j��}|�qdS)z Disconnect the object from DBus.N)rW�pop)r5rrrrr@_s
z%ServerObjectHandler.disconnect_objectcCs.|j�|jj|j|��|j�}|j�|�dS)zLRegister to DBus calls.

        :return: an unregistering callback
        N)	rTrr1rr2r<�_method_callbackrWr)r5Z
unregisterrrrr[es�z$ServerObjectHandler._register_objectcCs0|jjD]"}t|tj�sq|�|j|j�qdS)zConnect all DBus signals.N)r;�members�
isinstancer	rrBr�name)r5�memberrrrr\ss�z$ServerObjectHandler._connect_signalscCs>|�||�}|�||�}|�|�t|j|�}|j�|�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_emitterrDZconnectr�
disconnectrWr)r5rrr�signalrdrrrrB~s

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
        )rrCrArrrrc�sz!ServerObjectHandler._find_emittercGsH|�||�}|sd}|jdur*t|j|�}|j�|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)rJ�typerrTrr1rr2)r5rrrrbrrrrC�s
�z ServerObjectHandler._emit_signalc	
Cs�zL|�||||�}|�||�}|j||gt|��Ri|��}|�|||�Wn4ty�}z|�||||�WYd}~n
d}~00dS)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)�_get_additional_argumentsrJrGr�_handle_method_result�	Exception�_handle_method_error)	r5r%rr$rrErb�result�errorrrrr^�s>	�������z$ServerObjectHandler._method_callbackcCsd|j�|�iS)aBGet additional arguments of a DBus call.

        Supported items:

            call_info dict: Information about the DBus call

        This method is useful for customizations. It shouldn't be changed
        in this library unless we make sure that the change won't break
        the existing use cases.

        :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
        :return: a dictionary of additional info
        Z	call_info)rTr&)r5r%rr$rrrrrg�s�z-ServerObjectHandler._get_additional_argumentscCs:tjd||dd�|j�t|��}|j�||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)�logZwarningrVZget_error_namerfrTr(�str)r5r%rr$rlr'rrrrj�s	���z(ServerObjectHandler._handle_method_errorcCs|j�||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)rTr*r))r5r%Zmethod_specZmethod_replyrrrrh�s
�z)ServerObjectHandler._handle_method_resultcCsD|dkr@|dkr|jS|dkr$|jS|dkr2|jS|dkr@|jSdS)rPzorg.freedesktop.DBus.PropertiesZGet�SetZGetAllZPropertiesChangedN)�
_get_property�
_set_property�_get_all_properties�_properties_changedrHrrrrLsz)ServerObjectHandler._find_default_handlercCs:|�||�}|js"td�||���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.)rJ�readablerMrNrOr3rrf)r5r�
property_namerb�valuerrrrqs�z!ServerObjectHandler._get_propertycCs8|�||�}|js"td�||���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)rJ�writablerMrN�setattrr3r)r5rrvZproperty_valuerbrrrrr0s�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)r`r	ZPropertyrrura)�.0rb�rrr�
<listcomp>Fs

�z<ServerObjectHandler._find_all_properties.<locals>.<listcomp>)r;r_�r5rrr{r�_find_all_properties@s
�z(ServerObjectHandler._find_all_propertiescs��fdd�����D�S)z�The default handler of the GetAll method.

        :param interface_name: an interface name
        :return: a dictionary of properties
        csi|]}|���|��qSr)rq)rzrv�rr5rr�
<dictcomp>Ss�z;ServerObjectHandler._get_all_properties.<locals>.<dictcomp>)r~r}rrrrsMs�z'ServerObjectHandler._get_all_propertiescCs|��S)zXThe default handler of the PropertiesChanged method.

        :return: a signal
        )rUr:rrrrtXsz'ServerObjectHandler._properties_changed)r+r,r-r.rQrrr8r<r?r@r[r\rBrcrCr^rgrjrhrLrqrrr~rsrRrt�
__classcell__rrrYrr8s0�	'

r)Zlogging�abcrr�	functoolsrZdasbus.errorrZ
dasbus.signalrZdasbus.server.interfacerrZdasbus.specificationr	r
Z
dasbus.typingrrZgiZrequire_versionZ
gi.repositoryr
Z	getLoggerr+rn�__all__�objectrrrrrrr�<module>s 
r

Zerion Mini Shell 1.0