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__/interface.cpython-39.opt-1.pyc
a

װ_�D�@s�ddlZddlZddlmZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
ddlmZgd	�Zd
ZGdd�de�Zddd�Zdd�Zdd�ZGdd�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@s6eZdZdZdefdd�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.
    NcCs||_||_d|_dS)z�Create a signal descriptor.

        :param definition: a definition of the emit function
        :param factory: a signal factory
        N)�
definition�factory�name)�selfrr�r�;/usr/lib/python3.9/site-packages/dasbus/server/interface.py�__init__Fszdbus_signal.__init__cCs.|jdurdSd�t|�j��|���|_dS)aVSet 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�ownerrrrr�__set_name__Ps
�zdbus_signal.__set_name__cCs<|dur|St||jd�}|dur8|��}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)�getattrrr�setattr)r�instancer�signalrrr�__get__ds
zdbus_signal.__get__cCstd��dS)zSet a value of the descriptor.zCan't set DBus signal.N)�AttributeError)rr�valuerrr�__set__|szdbus_signal.__set__)	r�
__module__�__qualname__�__doc__rrrrr"rrrrr/s

rrcs��fdd�}|S)aDBus 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
    cs.tg����R�}t�||�}t|t|�|S)N)r�DBusSpecificationGenerator�generate_specificationr�DBUS_XML_ATTRIBUTE)�clsr�xml��interface_name�	namespacerr�	decorated�sz!dbus_interface.<locals>.decoratedr)r,r-r.rr+rr�srcCst�|�}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'rr()r)r*rrrr
�s
r
cCs&t|td�}|dur"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 '{}'.)rr(rr)�objZxml_specificationrrrr
�s��r
c@s�eZdZdZeZe�d�Ze	d dd��Z
e	dd��Ze	dd	��Ze	d
d��Z
e	dd
��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]*NcCsN|�|�}|r6|��}|�|�|�|||�}|||<|�||�}|j�|�S)aEGenerates 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�noderrrr'�s

�z1DBusSpecificationGenerator.generate_specificationcCs|j�tj�}|j�|�S)z�Collect standard interfaces.

        Standard interfaces are implemented by default.

        :return: a dictionary of standard interfaces
        )r5�xml_to_elementrZSTANDARD_INTERFACES�get_interfaces_from_node)r)r9rrrr1�s�z7DBusSpecificationGenerator._collect_standard_interfacescCsRt�}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�inspectZgetmrorr(r5r:r;r2)r)r6r7�memberZ
member_xmlr9Znode_interfacesrrrr0s
z.DBusSpecificationGenerator._collect_interfacescCs�|j�|�}t�|�D]�\}}|�|�s*q|�||�r8q|�|�rP|�||�}n>|�|�rh|�	||�}n&|�
|�r�|�||�}ntd�
|���|j�||�q|S)apGenerate 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 '{}'.)r5Zcreate_interfacer>Z
getmembers�_is_exportable�_is_defined�
_is_signal�_generate_signal�_is_property�_generate_property�
_is_method�_generate_methodrr�	add_child)r)r6r7r,r8�member_namer?�elementrrrr3s&



��z.DBusSpecificationGenerator._generate_interfacecCst|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)rIrrrr@Fsz)DBusSpecificationGenerator._is_exportablecCs@|��D]2}|D](}|j�|�s"q|j�||�s2qdSqdS)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)�valuesr5Z	is_memberZhas_name)r)r7rIr8r?rrrrAOs
z&DBusSpecificationGenerator._is_definedcCs
t|t�S)z"Is the class member a DBus signal?)�
isinstancer�r)r?rrrrBdsz%DBusSpecificationGenerator._is_signalc	Cst|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 '{}'.)r5Z
create_signalr�_iterate_parametersr�
DIRECTION_OUTrr�create_parameterrrH)	r)r?rIrJ�methodr�	type_hint�	direction�	parameterrrrrCis&

���z+DBusSpecificationGenerator._generate_signalccs�t|�}t�|�}t|j�dd�D]J}|j|j}|tjkrFtd��||vr\td�	|���|||t
jfVq$|j|j
ur�dS|jdur�dSt
j|jt
jfVdS)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 '{}'.)rr>�	signature�list�
parameters�kindrZPOSITIONAL_OR_KEYWORDrrrZDIRECTION_INZreturn_annotation�emptyZRETURN_PARAMETERrR)r)r?Z
type_hintsrYrr\rrrrQ�s*

��
�z.DBusSpecificationGenerator._iterate_parameterscCs
t|t�S)z$Is the class member a DBus property?)rO�propertyrPrrrrD�sz'DBusSpecificationGenerator._is_propertycCs�d}d}zD|jr*|�|j�\\}}}tj}|jrJ|�|j�\\}}}tj}Wn tyltd�|���Yn0|jr�|jr�tj	}|dur�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.)
�fsetrQrZACCESS_WRITE�fgetZACCESS_READ�
ValueErrorrrZACCESS_READWRITEr5Zcreate_propertyr)r)r?rI�accessrU�_rrrrE�s0

�
��z-DBusSpecificationGenerator._generate_propertycCst�|�pt�|�S)aIs 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
isfunctionrPrrrrF�sz%DBusSpecificationGenerator._is_methodcCsH|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
        )r5Z
create_methodrQrSrrH)r)r?rIrTrrUrVrWrrrrGs
�z+DBusSpecificationGenerator._generate_methodcCsH|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
        zSpecifies {})r5Zcreate_nodeZadd_commentrr�sorted�keysrH)r)r6r7r9r,rrrr4s
�z)DBusSpecificationGenerator._generate_node)N)rr#r$r%r	r5�re�compilerL�classmethodr'r1r0r3r@rArBrCrQrDrErFrGr4rrrrr&�s>



)



#
/

+

r&)r)r>rfr�typingrZdasbus.namespacerZ
dasbus.signalrZdasbus.specificationrrZ
dasbus.typingrZ
dasbus.xmlr	�__all__r(�objectrrr
r
r&rrrr�<module>sR