HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/dasbus/server/__pycache__/handler.cpython-39.pyc
a

װ_YD�@s�ddlZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZmZddlZe�d	d
�ddlmZe�e�Zgd�ZGd
d�de�ZGdd�ded�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��Zeddd��Zedd	��Zed
d��Zedd
��Z	edd��Z
dS)r
z0The 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)rrZsenderrr�method_namer�
invocationrrrrrrrcs��zGLibServer._object_callbackcCs|�||�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}|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)r
Zreturn_value)rr#�out_typeZ	out_valueZreply_valuerrr�set_call_reply}szGLibServer.set_call_reply)N)r)�__name__�
__module__�__qualname__�__doc__�classmethodrrrrr%r'rrrrr
,s��!


	r
c@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
        Nr-)�self�message_busr�objrrr�__init__�sz$AbstractServerObjectHandler.__init__cCs|js|��|_|jS)zDBus specification.)r1�_get_specification�r2rrr�
specification�s
z)AbstractServerObjectHandler.specificationcCst�|���S)zKGet the DBus specification.

        :return: a DBus specification
        )rZfrom_xml�_get_xml_specificationr7rrrr6�s�z.AbstractServerObjectHandler._get_specificationcCsdS)�IGet the XML specification.

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

        Unregister the object and disconnect all signals.
        Nrr7rrr�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�r2rrrrr�_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)r2rrrrrr�_emit_signal�sz(AbstractServerObjectHandler._emit_signalcGs|�||�}||�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)r2rr"r�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
        )r8Z
get_member�r2r�member_namerrr�_find_member_spec�s�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)r2rrErBrrrrA�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)�getattrr0rDrrrrGsz0AbstractServerObjectHandler._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
        NrrDrrrrHsz1AbstractServerObjectHandler._find_default_handlerN)r(r)r*r+�	__slots__r5�propertyr8r6rr9r<r=r?r@rCrFrArGrHrrrrr�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%�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)�superr5rPrQrrRrS)r2r3rr4Zerror_mapperZserverZsignal_factory��	__class__rrr5*s
zServerObjectHandler.__init__cCs
t|j�S)r:)rr0r7rrrr9;sz*ServerObjectHandler._get_xml_specificationcCs|��|��dS)zConnect the object to DBus.N)�_register_object�_connect_signalsr7rrrr<Bsz"ServerObjectHandler.connect_objectcCs|jr|j��}|�qdS)z Disconnect the object from DBus.N)rS�pop)r2rrrrr=Gs
z%ServerObjectHandler.disconnect_objectcCs.|j�|jj|j|��|j�}|j�|�dS)zLRegister to DBus calls.

        :return: an unregistering callback
        N)	rPrr.rr/r9�_method_callbackrSr)r2Z
unregisterrrrrWMs�z$ServerObjectHandler._register_objectcCs0|jjD]"}t|tj�sq|�|j|j�qdS)zConnect all DBus signals.N)r8�members�
isinstancerrr?r�name)r2�memberrrrrX[s�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_emitterrAZconnectr�
disconnectrSr)r2rrr�signalr`rrrr?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@r>rrrr_tsz!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)rF�typer
rPrr.rr/)r2rrrr^rrrr@}s
�z ServerObjectHandler._emit_signalc
Cspz6|�||�}|j||gt|��R�}|�|||�Wn4tyj}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)rFrCr�_handle_method_result�	Exception�_handle_method_error)r2r#rr"rr^�result�errorrrrrZ�s.	�����z$ServerObjectHandler._method_callbackcCs: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)�logZwarningrRZget_error_namerbrPr%�str)r2r#rr"rgr$rrrre�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)rPr'r&)r2r#Zmethod_specZmethod_replyrrrrc�s
�z)ServerObjectHandler._handle_method_resultcCsD|dkr@|dkr|jS|dkr$|jS|dkr2|jS|dkr@|jSdS)rLzorg.freedesktop.DBus.PropertiesZGet�SetZGetAllZPropertiesChangedN)�
_get_property�
_set_property�_get_all_properties�_properties_changedrDrrrrH�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.)rF�readablerIrJrKr0r
rb)r2r�
property_namer^�valuerrrrl�s�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)rF�writablerIrJ�setattrr0r)r2rrqZproperty_valuer^rrrrm�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)r\rZPropertyrrpr])�.0r^�rrr�
<listcomp>s

�z<ServerObjectHandler._find_all_properties.<locals>.<listcomp>)r8r[�r2rrrvr�_find_all_propertiess
�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)rl)rurq�rr2rr�
<dictcomp>s�z;ServerObjectHandler._get_all_properties.<locals>.<dictcomp>)ryrxrrzrrns�z'ServerObjectHandler._get_all_propertiescCs|��S)zXThe default handler of the PropertiesChanged method.

        :return: a signal
        )rQr7rrrro#sz'ServerObjectHandler._properties_changed)r(r)r*r+rMr
rr5r9r<r=rWrXr?r_r@rZrercrHrlrmryrnrNro�
__classcell__rrrUrr s.�	 

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