관리-도구
편집 파일: interface.cpython-39.opt-1.pyc
a ����װ_�D����������������������@���s����d�dl�Z�d�dlZd�dl�mZ�d�dlmZ�d�dlmZ�d�dlmZ�d�dl m Z mZ�d�dlm Z �d�dlmZ�g�d �Zd ZG�dd��de�Zddd�Zdd��Zdd��ZG�dd��de�ZdS�)�����N)� Parameter)�get_type_hints)� get_dbus_name)�Signal)�DBusSpecificationError�DBusSpecification)� get_dbus_type)�XMLGenerator)� dbus_class�dbus_interface�dbus_signal�get_xmlZ__dbus_xml__c�������������������@���s6���e�Zd�ZdZdefdd�Zdd��Zdd��Zd d ��ZdS�)r���a���DBus signal. Can be used as: .. code-block:: python Signal = dbus_signal() Or as a method decorator: .. code-block:: python @dbus_signal def Signal(x: Int, y: Double): pass Signal is defined by the type hints of a decorated method. This method is accessible as: signal.definition If the signal is not defined by a method, it is expected to have no arguments and signal.definition is equal to None. Nc�����������������C���s���||�_�||�_d|�_dS�)z�Create a signal descriptor. :param definition: a definition of the emit function :param factory: a signal factory N)� definition�factory�name)�selfr���r�����r����;/usr/lib/python3.9/site-packages/dasbus/server/interface.py�__init__F���s����zdbus_signal.__init__c�����������������C���s.���|�j�durdS�d�t|��j���|����|�_�dS�)aV��Set a name of the descriptor The descriptor has been assigned to the specified name. Generate a name of a private attribute that will be set to a signal in the ``__get__`` method. For example: ``__dbus_signal_my_name`` :param owner: the owning class :param name: the descriptor name Nz__{}_{})r����format�type�__name__�lower)r����ownerr���r���r���r����__set_name__P���s���� �zdbus_signal.__set_name__c�����������������C���s<���|du�r|�S�t�||�jd�}|du�r8|����}t||�j|��|S�)a���Get a value of the descriptor. If the descriptor is accessed as a class attribute, return the descriptor. If the descriptor is accessed as an instance attribute, return a signal created by the signal factory. :param instance: an instance of the owning class :param owner: an owning class :return: a value of the attribute N)�getattrr���r����setattr)r����instancer����signalr���r���r����__get__d���s���� zdbus_signal.__get__c�����������������C���s���t�d��dS�)zSet a value of the descriptor.zCan't set DBus signal.N)�AttributeError)r���r����valuer���r���r����__set__|���s����zdbus_signal.__set__) r���� __module__�__qualname__�__doc__r���r���r���r���r"���r���r���r���r���r���/���s ��� r���r���c��������������������s������fdd�}|S�)a��DBus interface. A new DBus interface can be defined as: .. code-block:: python @dbus_interface class Interface(): ... The interface will be generated from the given class cls with a name interface_name and added to the DBus XML specification of the class. The XML specification is accessible as: .. code-block:: python Interface.__dbus_xml__ :param interface_name: a DBus name of the interface :param namespace: a sequence of strings c��������������������s.���t�g������R���}t�|�|�}t|�t|��|�S�)N)r����DBusSpecificationGenerator�generate_specificationr����DBUS_XML_ATTRIBUTE)�clsr����xml��interface_name� namespacer���r���� decorated����s����z!dbus_interface.<locals>.decoratedr���)r,���r-���r.���r���r+���r���r�������s����r���c�����������������C���s���t��|��}t|�t|��|�S�)a���DBus class. A new DBus class can be defined as: .. code-block:: python @dbus_class class Class(Interface): ... DBus class can implement DBus interfaces, but it cannot define a new interface. The DBus XML specification will be generated from implemented interfaces (inherited) and it will be accessible as: .. code-block:: python Class.__dbus_xml__ )r&���r'���r���r(���)r)���r*���r���r���r���r �������s���� r ���c�����������������C���s&���t�|�td�}|du�r"td�t���|S�)z�Return XML specification of an object. :param obj: an object decorated with @dbus_interface or @dbus_class :return: a string with XML specification Nz)XML specification is not defined at '{}'.)r���r(���r���r���)�objZxml_specificationr���r���r���r �������s������r ���c�������������������@���s����e�Zd�ZdZeZe�d�Ze d dd��Z e dd���Ze dd ���Ze d d���Z e dd ���Ze dd���Ze dd���Ze dd���Ze dd���Ze dd���Ze dd���Ze dd���Ze dd���Ze dd���ZdS�)!r&���z,Class for generating DBus XML specification.z[A-Z][A-Za-z0-9]*Nc�����������������C���sN���|���|�}|r6|����}|�|��|��|||�}|||<�|��||�}|�j�|�S�)aE��Generates DBus XML specification for given class. If class defines a new interface, it will be added to the specification. :param interface_cls: class object to decorate :param str interface_name: name of the interface defined by class :return str: DBus specification in XML )�_collect_interfaces�_collect_standard_interfaces�update�_generate_interface�_generate_node� xml_generatorZelement_to_xml)r)���� interface_clsr,���� interfacesZall_interfaces� interface�noder���r���r���r'�������s���� �z1DBusSpecificationGenerator.generate_specificationc�����������������C���s���|�j��tj�}|�j��|�S�)z�Collect standard interfaces. Standard interfaces are implemented by default. :return: a dictionary of standard interfaces )r5����xml_to_elementr���ZSTANDARD_INTERFACES�get_interfaces_from_node)r)���r9���r���r���r���r1�������s�����z7DBusSpecificationGenerator._collect_standard_interfacesc�����������������C���sR���t���}tt�|��D�]8}t|td�}|s*q|�j�|�}|�j�|�}|� |��q|S�)z�Collect interfaces implemented by the class. Returns a dictionary that maps interface names to interface elements. :param interface_cls: a class object :return: a dictionary of implemented interfaces N) �dict�reversed�inspectZgetmror���r(���r5���r:���r;���r2���)r)���r6���r7����memberZ member_xmlr9���Znode_interfacesr���r���r���r0�����s���� z.DBusSpecificationGenerator._collect_interfacesc�����������������C���s����|�j��|�}t�|�D�]�\}}|��|�s*q|��||�r8q|��|�rP|��||�}n>|��|�rh|�� ||�}n&|�� |�r�|��||�}ntd� |���|�j��||��q|S�)ap��Generate interface defined by given class. :param interface_cls: a class object that defines the interface :param interfaces: a dictionary of implemented interfaces :param interface_name: a name of the new interface :return: a new interface element :raises DBusSpecificationError: if a class member cannot be exported z+Unsupported definition of DBus member '{}'.)r5���Zcreate_interfacer>���Z getmembers�_is_exportable�_is_defined� _is_signal�_generate_signal�_is_property�_generate_property� _is_method�_generate_methodr���r���� add_child)r)���r6���r7���r,���r8����member_namer?����elementr���r���r���r3�����s&���� ��z.DBusSpecificationGenerator._generate_interfacec�����������������C���s���t�|�j�|��S�)z�Is the name of a class member exportable? The name is exportable if it follows the DBus specification. Only CamelCase names are allowed. )�bool�NAME_PATTERN� fullmatch)r)���rI���r���r���r���r@���F��s����z)DBusSpecificationGenerator._is_exportablec�����������������C���s@���|����D�]2}|D�](}|�j�|�s"q|�j�||�s2q��dS�qdS�)z�Is the member name defined in given interfaces? :param interfaces: a dictionary of interfaces :param member_name: a name of the class member :return: True if the name is defined, otherwise False TF)�valuesr5���Z is_memberZhas_name)r)���r7���rI���r8���r?���r���r���r���rA���O��s���� z&DBusSpecificationGenerator._is_definedc�����������������C���s ���t�|t�S�)z"Is the class member a DBus signal?)� isinstancer����r)���r?���r���r���r���rB���d��s����z%DBusSpecificationGenerator._is_signalc����������� ������C���st���|�j��|�}|j}|s|S�|��|�D�]J\}}}|tjkrFtd�|���tj}|�j��|t |�|�}|�j�� ||��q$|S�)z�Generate signal defined by a class member. :param member: a dbus_signal object. :param member_name: a name of the signal :return: a signal element raises DBusSpecificationError: if signal has defined return type z(Invalid return type of DBus signal '{}'.)r5���Z create_signalr����_iterate_parametersr���� DIRECTION_OUTr���r����create_parameterr���rH���) r)���r?���rI���rJ����methodr���� type_hint� direction� parameterr���r���r���rC���i��s&���� ���z+DBusSpecificationGenerator._generate_signalc�����������������c���s����t�|�}t�|�}t|j�dd��D�]J}|j|�j}|tjkrFtd��||vr\td� |���|||�t jfV��q$|j|j u�r�dS�|jdu�r�dS�t j|jt jfV��dS�)z�Iterate over method parameters. For every parameter returns its name, a type hint and a direction. :param member: a method object :return: an iterator raises DBusSpecificationError: if parameters are invalid ����Nz1Only positional or keyword arguments are allowed.z!Undefined type of parameter '{}'.)r���r>���� signature�list� parameters�kindr���ZPOSITIONAL_OR_KEYWORDr���r���r���ZDIRECTION_INZreturn_annotation�emptyZRETURN_PARAMETERrR���)r)���r?���Z type_hintsrY���r���r\���r���r���r���rQ������s*���� �� �z.DBusSpecificationGenerator._iterate_parametersc�����������������C���s ���t�|t�S�)z$Is the class member a DBus property?)rO����propertyrP���r���r���r���rD������s����z'DBusSpecificationGenerator._is_propertyc�����������������C���s����d}d}zD|j�r*|��|j��\\}}}tj}|jrJ|��|j�\\}}}tj}W�n �tyl���td�|���Y�n0�|jr�|j�r�tj }|du�r�td�|���|�j �|t|�|�S�)z�Generate DBus property defined by class member. :param member: a property object :param member_name: a property name :return: a property element raises DBusSpecificationError: if the property is invalid Nz%Undefined type of DBus property '{}'.z%DBus property '{}' is not accessible.) �fsetrQ���r���ZACCESS_WRITE�fgetZACCESS_READ� ValueErrorr���r���ZACCESS_READWRITEr5���Zcreate_propertyr���)r)���r?���rI����accessrU����_r���r���r���rE������s0���� � ��z-DBusSpecificationGenerator._generate_propertyc�����������������C���s���t��|�pt��|�S�)a��Is the class member a DBus method? Ignore the difference between instance method and class method. For example: .. code-block:: python class Foo(object): def bar(cls, x): pass inspect.isfunction(Foo.bar) # True inspect.isfunction(Foo().bar) # False inspect.ismethod(Foo.bar) # False inspect.ismethod(Foo().bar) # True _is_method(Foo.bar) # True _is_method(Foo().bar) # True )r>���ZismethodZ isfunctionrP���r���r���r���rF������s����z%DBusSpecificationGenerator._is_methodc�����������������C���sH���|�j��|�}|��|�D�],\}}}|�j��|t|�|�}|�j��||��q|S�)z�Generate method defined by given class member. :param member: a method object :param member_name: a name of the method :return: a method element )r5���Z create_methodrQ���rS���r���rH���)r)���r?���rI���rT���r���rU���rV���rW���r���r���r���rG�����s���� �z+DBusSpecificationGenerator._generate_methodc�����������������C���sH���|�j����}|�j��|d�|j���t|����D�]}|�j��|||���q,|S�)z�Generate node element that specifies the given class. :param interface_cls: a class object :param interfaces: a dictionary of interfaces :return: a node element zSpecifies {})r5���Zcreate_nodeZadd_commentr���r����sorted�keysrH���)r)���r6���r7���r9���r,���r���r���r���r4�����s���� �z)DBusSpecificationGenerator._generate_node)N)r���r#���r$���r%���r ���r5����re�compilerL����classmethodr'���r1���r0���r3���r@���rA���rB���rC���rQ���rD���rE���rF���rG���r4���r���r���r���r���r&�������s>��� ) # / + r&���)r���)r>���rf���r����typingr���Zdasbus.namespacer���Z dasbus.signalr���Zdasbus.specificationr���r���Z dasbus.typingr���Z dasbus.xmlr ����__all__r(����objectr���r���r ���r ���r&���r���r���r���r����<module>���s���R