관리-도구
편집 파일: handler.cpython-39.pyc
a ����װ_YD����������������������@���s����d�dl�Z�d�dlmZmZ�d�dlmZ�d�dlmZ�d�dlm Z �d�dl mZ�d�dlm Z mZ�d�dlmZmZ�d�dlZe�d d ��d�dlmZ�e��e�Zg�d�ZG�d d��de�ZG�dd��ded�ZG�dd��de�ZdS�)�����N)�ABCMeta�abstractmethod)�partial)�ErrorMapper)�Signal)�get_xml)�DBusSpecification�DBusSpecificationError)�get_variant�unwrap_variant�Gioz2.0)r���)� GLibServer�AbstractServerObjectHandler�ServerObjectHandlerc�������������������@���s\���e�Zd�ZdZeddd��Zeddd��Zedd ���Zed d���Zedd ���Z edd���Z dS�)r ���z0The low-level DBus server library based on GLib.Nc�����������������C���s���|��|||||��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_signalr���c�����������������C���sf���t�j�|�}t|�j||fd�}g�}|js0td��|jD�] } |�|| |dd�} |�| ��q6t|�j ||�S�)zRegister an object on DBus.)� user_dataz$No DBus interfaces for registration.N) r���ZDBusNodeInfoZnew_for_xmlr����_object_callbackZ interfacesr ����register_object�append�_unregister_object)r���r���r���Z object_xml�callback� callback_argsZ node_infoZmethod_call_closure� registrationsZinterface_info�registration_idr���r���r���r���;���s4������� ��zGLibServer.register_objectc�����������������C���s���|D�]}|��|��qdS�)zUnregister an object from DBus.N)Zunregister_object)r���r���r ���r!���r���r���r���r���]���s����zGLibServer._unregister_objectc �����������������C���s"���|\} } | ||||g| �R����d�S�)Nr���)r���r���Zsenderr���r����method_namer���� invocationr���r���r���r���r���r���r���c���s������zGLibServer._object_callbackc�����������������C���s���|��||��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)r���r#���� error_nameZ error_messager���r���r����set_call_errors���s����zGLibServer.set_call_errorc�����������������C���s&���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 ���Zreturn_value)r���r#����out_typeZ out_valueZreply_valuer���r���r����set_call_reply}���s����zGLibServer.set_call_reply)N)r���)�__name__� __module__�__qualname__�__doc__�classmethodr���r���r���r���r%���r'���r���r���r���r���r ���,���s�������! r ���c�������������������@���s����e�Zd�ZdZg�d�Zdd��Zedd���Zdd��Ze d d ���Z e dd���Ze d d���Ze dd���Z e dd���Zdd��Zdd��Zdd��Zdd��Ze dd���ZdS�)r���z+The abstract handler of a published object.��_message_bus�_object_path�_object�_specificationc�����������������C���s���||�_�||�_||�_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����objr���r���r����__init__����s����z$AbstractServerObjectHandler.__init__c�����������������C���s���|�j�s|����|�_�|�j�S�)zDBus specification.)r1����_get_specification�r2���r���r���r���� specification����s���� z)AbstractServerObjectHandler.specificationc�����������������C���s���t��|�����S�)zKGet the DBus specification. :return: a DBus specification )r���Zfrom_xml�_get_xml_specificationr7���r���r���r���r6�������s�����z.AbstractServerObjectHandler._get_specificationc�����������������C���s���dS�)�IGet the XML specification. :return: a XML specification ��r���r7���r���r���r���r9�������s����z2AbstractServerObjectHandler._get_xml_specificationc�����������������C���s���dS�)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���r7���r���r���r����connect_object����s����z*AbstractServerObjectHandler.connect_objectc�����������������C���s���dS�)zdDisconnect the object from DBus. Unregister the object and disconnect all signals. Nr���r7���r���r���r����disconnect_object����s����z-AbstractServerObjectHandler.disconnect_objectc�����������������C���s���dS�)z�Connect a DBus signal. :param interface_name: a DBus interface name :param signal_name: a DBus signal name Nr����r2���r���r���r���r���r����_connect_signal����s����z+AbstractServerObjectHandler._connect_signalc�����������������G���s���dS�)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���)r2���r���r���r���r���r���r����_emit_signal����s����z(AbstractServerObjectHandler._emit_signalc�����������������G���s���|���||�}||��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)r2���r���r"���r����handlerr���r���r����_handle_call����s����z(AbstractServerObjectHandler._handle_callc�����������������C���s���|�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 )r8���Z get_member�r2���r����member_namer���r���r����_find_member_spec����s�����z-AbstractServerObjectHandler._find_member_specc�����������������C���s0���|���||�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)r2���r���rE���rB���r���r���r���rA�������s���� ��z)AbstractServerObjectHandler._find_handlerc�����������������C���s���t�|�j|d�S�)ae��Get 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)�getattrr0���rD���r���r���r���rG�����s����z0AbstractServerObjectHandler._find_object_handlerc�����������������C���s���dS�)��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���rD���r���r���r���rH�����s����z1AbstractServerObjectHandler._find_default_handlerN)r(���r)���r*���r+���� __slots__r5����propertyr8���r6���r���r9���r<���r=���r?���r@���rC���rF���rA���rG���rH���r���r���r���r���r�������s,��� r���)� metaclassc�����������������������s����e�Zd�ZdZg�d�Zdeef��fdd� Zdd��Zdd ��Z d d��Z dd ��Zdd��Zdd��Z dd��Zdd��Zdd��Zdd��Zdd��Zdd��Zdd��Zd d!��Zd"d#��Zd$d%��Zed&d'���Z���ZS�)(r���z+The handler of an object published on DBus.)�_server�_signal_factory� _error_mapper�_registrationsNc��������������������s2���t����|||��||�_||�_|p$t��|�_g�|�_dS�)aA��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 :param error_mapper: a DBus error mapper :param server: a DBus server library :param signal_factory: a signal factory N)�superr5���rP���rQ���r���rR���rS���)r2���r3���r���r4���Zerror_mapperZserverZsignal_factory�� __class__r���r���r5���*��s ����zServerObjectHandler.__init__c�����������������C���s ���t�|�j�S�)r:���)r���r0���r7���r���r���r���r9���;��s����z*ServerObjectHandler._get_xml_specificationc�����������������C���s���|������|�����dS�)zConnect the object to DBus.N)�_register_object�_connect_signalsr7���r���r���r���r<���B��s����z"ServerObjectHandler.connect_objectc�����������������C���s���|�j�r|�j����}|���q�dS�)z Disconnect the object from DBus.N)rS����pop)r2���r���r���r���r���r=���G��s���� z%ServerObjectHandler.disconnect_objectc�����������������C���s.���|�j��|�jj|�j|����|�j�}|�j�|��dS�)zLRegister to DBus calls. :return: an unregistering callback N) rP���r���r.���r���r/���r9����_method_callbackrS���r���)r2���Z unregisterr���r���r���rW���M��s�����z$ServerObjectHandler._register_objectc�����������������C���s0���|�j�jD�]"}t|tj�sq|��|j|j��qdS�)zConnect all DBus signals.N)r8����members� isinstancer���r���r?���r����name)r2����memberr���r���r���rX���[��s�����z$ServerObjectHandler._connect_signalsc�����������������C���s>���|���||�}|��||�}|�|��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_emitterrA���Zconnectr���� disconnectrS���r���)r2���r���r���r����signalr`���r���r���r���r?���f��s ���� z#ServerObjectHandler._connect_signalc�����������������C���s���t�|�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 )r���r@���r>���r���r���r���r_���t��s����z!ServerObjectHandler._find_emitterc�����������������G���sH���|���||�}|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 ���rP���r���r.���r���r/���)r2���r���r���r���r^���r���r���r���r@���}��s���� �z ServerObjectHandler._emit_signalc�������������� ���C���sp���z6|���||�}|�j||gt|��R���}|��|||��W�n4�tyj�}�z|��||||��W�Y�d}~n d}~0�0�dS�)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)rF���rC���r����_handle_method_result� Exception�_handle_method_error)r2���r#���r���r"���r���r^����result�errorr���r���r���rZ������s.���� �����z$ServerObjectHandler._method_callbackc�����������������C���s:���t�jd||dd��|�j�t|��}|�j�||t|���dS�)a��Handle 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)�logZwarningrR���Zget_error_namerb���rP���r%����str)r2���r#���r���r"���rg���r$���r���r���r���re������s���� ���z(ServerObjectHandler._handle_method_errorc�����������������C���s���|�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)rP���r'���r&���)r2���r#���Zmethod_specZmethod_replyr���r���r���rc������s �����z)ServerObjectHandler._handle_method_resultc�����������������C���sD���|dkr@|dkr|�j�S�|dkr$|�jS�|dkr2|�jS�|dkr@|�jS�dS�)rL���zorg.freedesktop.DBus.PropertiesZGet�SetZGetAllZPropertiesChangedN)� _get_property� _set_property�_get_all_properties�_properties_changedrD���r���r���r���rH������s����z)ServerObjectHandler._find_default_handlerc�����������������C���s:���|���||�}|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����readablerI���rJ���rK���r0���r ���rb���)r2���r���� property_namer^����valuer���r���r���rl������s�����z!ServerObjectHandler._get_propertyc�����������������C���s8���|���||�}|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����writablerI���rJ����setattrr0���r���)r2���r���rq���Zproperty_valuer^���r���r���r���rm������s�����z!ServerObjectHandler._set_propertyc��������������������s�����fdd�|�j�jD��S�)z�Find all properties of the given interface. :param interface_name: an interface name :return: a list of property names c��������������������s.���g�|�]&}t�|tj�r|j��kr|jr|j�qS�r���)r\���r���ZPropertyr���rp���r]���)�.0r^����r���r���r���� <listcomp>��s ��� �z<ServerObjectHandler._find_all_properties.<locals>.<listcomp>)r8���r[����r2���r���r���rv���r����_find_all_properties��s���� �z(ServerObjectHandler._find_all_propertiesc��������������������s������fdd�������D��S�)z�The default handler of the GetAll method. :param interface_name: an interface name :return: a dictionary of properties c��������������������s���i�|�]}|�����|��qS�r���)rl���)ru���rq����r���r2���r���r���� <dictcomp>��s����z;ServerObjectHandler._get_all_properties.<locals>.<dictcomp>)ry���rx���r���rz���r���rn�����s�����z'ServerObjectHandler._get_all_propertiesc�����������������C���s���|�����S�)zXThe default handler of the PropertiesChanged method. :return: a signal )rQ���r7���r���r���r���ro���#��s����z'ServerObjectHandler._properties_changed)r(���r)���r*���r+���rM���r ���r���r5���r9���r<���r=���rW���rX���r?���r_���r@���rZ���re���rc���rH���rl���rm���ry���rn���rN���ro���� __classcell__r���r���rU���r���r��� ��s.���� r���)Zlogging�abcr���r���� functoolsr���Zdasbus.errorr���Z dasbus.signalr���Zdasbus.server.interfacer���Zdasbus.specificationr���r ���Z dasbus.typingr ���r���ZgiZrequire_versionZ gi.repositoryr���Z getLoggerr(���ri����__all__�objectr ���r���r���r���r���r���r����<module>���s ��� a�