403Webshell
Server IP : 77.50.203.18  /  Your IP : 192.168.0.10
Web Server : Apache/2.4.62 (CentOS Stream) OpenSSL/3.5.7 mpm-itk/2.4.7-04 PHP/8.4.23
System : Linux web2 5.14.0-722.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jul 6 09:07:51 UTC 2026 x86_64
User : warsnews.ru ( 1001)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3.9/site-packages/dasbus/server/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/dasbus/server/__pycache__/interface.cpython-39.pyc
a

�ic�V�@s�ddlZddlZddlmZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
mZmZmZddlmZgd	�Zd
ZdZdZd
d�Zdd�Zdd�ZGdd�de�Zddd�Zdd�Zdd�ZGdd�de�ZdS)�N)�	Parameter)�get_type_hints)�
get_dbus_name)�Signal)�DBusSpecificationError�DBusSpecification)�
get_dbus_type�is_base_type�get_type_arguments�Tuple)�XMLGenerator)�
dbus_class�dbus_interface�dbus_signal�get_xml�accepts_additional_arguments�"are_additional_arguments_supportedZ__dbus_xml__Z*__dbus_method_returns_multiple_arguments__Z-__dbus_handler_accepts_additional_arguments__cCst|td�|S)a�Decorator for returning multiple arguments from a DBus method.

    The decorator allows to generate multiple output arguments in the
    XML specification of the decorated DBus method. Otherwise, there
    will be only one output argument in the specification.

    Define a DBus method with multiple output arguments:

    .. code-block:: python

        @returns_multiple_arguments
        def Method(self) -> Tuple[Int, Bool]:
            return 0, False

    The generated XML specification of the example:

    .. code-block:: xml

        <method name="Method">
            <arg direction="out" name="return_0" type="i"/>
            <arg direction="out" name="return_1" type="b"/>
        </method>

    If the XML specification is not generated by the dbus_interface
    decorator, the returns_multiple_arguments decorator has no effect.

    :param method: a DBus method
    :return: a DBus method with a flag
    T)�setattr�$RETURNS_MULTIPLE_ARGUMENTS_ATTRIBUTE��method�r�;/usr/lib/python3.9/site-packages/dasbus/server/interface.py�returns_multiple_arguments:srcCst|td�|S)a[Decorator for accepting extra arguments in a DBus method.

    The decorator allows the server object handler to propagate
    additional information about the DBus call into the decorated
    method.

    Use a dictionary of keyword arguments:

    .. code-block:: python

        @accepts_additional_arguments
        def Method(x: Int, y: Str, **info):
            pass

    Or use keyword only parameters:

    .. code-block:: python

        @accepts_additional_arguments
        def Method(x: Int, y: Str, *, call_info):
            pass

    At this moment, the library provides only the call_info argument
    generated by GLibServer.get_call_info, but the additional arguments
    can be customized in the _get_additional_arguments method of the
    server object handler.

    :param method: a DBus method
    :return: a DBus method with a flag
    T)r�&ACCEPTS_ADDITIONAL_ARGUMENTS_ATTRIBUTErrrrr\srcCst|td�S)zyDoes the given DBus method accept additional arguments?

    :param method: a DBus method
    :return: True or False
    F)�getattrrrrrrrsrc@s6eZdZdZdefdd�Zdd�Zdd�Zd	d
�ZdS)ra�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)�selfrrrrr�__init__�szdbus_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__�s
�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)rrrr)r�instancer%�signalrrr�__get__�s
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__rr r&r)r,rrrrr�s

rrcs��fdd�}|S)aeDBus 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__

    It is conventional for member names on DBus to consist
    of capitalized words with no punctuation. The generator
    of the XML specification enforces this convention to
    prevent unintended changes in the specification. You can
    provide the XML specification yourself, or override the
    generator class to work around these constraints.

    :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)r6r7r8rr5rr�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__

    )r0r1rr2)r3r4rrrr
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 '{}'.)rr2rr!)�objZxml_specificationrrrrs��rc@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��Ze	d d!��Ze	d"d#��ZdS)%r0z,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)r3�
interface_clsr6�
interfacesZall_interfaces�	interface�noderrrr18s

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

        Standard interfaces are implemented by default.

        :return: a dictionary of standard interfaces
        )r?�xml_to_elementrZSTANDARD_INTERFACES�get_interfaces_from_node)r3rCrrrr;Us�z7DBusSpecificationGenerator._collect_standard_interfacescCsPi}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)	�reversed�inspectZgetmrorr2r?rDrEr<)r3r@rA�memberZ
member_xmlrCZnode_interfacesrrrr:bs
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 '{}'.)r?Zcreate_interfacerGZ
getmembers�_is_exportable�_is_defined�
_is_signal�_generate_signal�_is_property�_generate_property�
_is_method�_generate_methodrr!�	add_child)r3r@rAr6rB�member_namerH�elementrrrr=|s&



��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)r3rRrrrrI�sz)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)�valuesr?Z	is_memberZhas_name)r3rArRrBrHrrrrJ�s
z&DBusSpecificationGenerator._is_definedcCs
t|t�S)z"Is the class member a DBus signal?)�
isinstancer�r3rHrrrrK�sz%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 '{}'.)r?Z
create_signalr�_iterate_parametersr�
DIRECTION_OUTrr!�create_parameterrrQ)	r3rHrRrSrr�	type_hint�	direction�	parameterrrrrL�s&

���z+DBusSpecificationGenerator._generate_signalccs2t�|�}|�||�EdH|�||�EdHdS)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
        N)rG�	signature�_iterate_in_parameters�_iterate_out_parameters)r3rHr`rrrrZ�s
z.DBusSpecificationGenerator._iterate_parametersccs�tj}t|�}t|j�dd�D]b}|j|j}|tjtjfvrJt	|�rJq |tj
kr\td��||vrrtd�|���||||fVq dS)zIterate over input parameters.�Nz1Only positional or keyword arguments are allowed.z!Undefined type of parameter '{}'.)
rZDIRECTION_INr�list�
parameters�kindrZVAR_KEYWORDZKEYWORD_ONLYrZPOSITIONAL_OR_KEYWORDrr!)r3rHr`r^Z
type_hintsrrfrrrra�s"�
��z1DBusSpecificationGenerator._iterate_in_parametersc	cs�tj}tj}|j}||jur dS|dur,dSt|td�r�t|t�sJt	d��t
|�}t|�dkrft	d��t|�D]\}}d�
||�||fVqndS|||fVdS)zIterate over output parameters.NFz'Expected a tuple of multiple arguments.�z+Expected a tuple of more than one argument.z{}_{})rZRETURN_PARAMETERr[Zreturn_annotation�emptyrrr	rrr
�len�	enumerater!)	r3rHr`rr^r]Z	type_args�iZtype_argrrrrbs*

��z2DBusSpecificationGenerator._iterate_out_parameterscCs
t|t�S)z$Is the class member a DBus property?)rX�propertyrYrrrrMCsz'DBusSpecificationGenerator._is_propertycCs�d}d}zD|jr*|�|j�\\}}}tj}|jrJ|�|j�\\}}}tj}Wn"tyntd�|��d�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.)
�fsetrZrZACCESS_WRITE�fgetZACCESS_READ�
ValueErrorrr!ZACCESS_READWRITEr?Zcreate_propertyr)r3rHrR�accessr]�_rrrrNHs4

����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

        )rGZismethodZ
isfunctionrYrrrrOtsz%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
        )r?Z
create_methodrZr\rrQ)r3rHrRrrr]r^r_rrrrP�s
�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 {})r?Zcreate_nodeZadd_commentr!r#�sorted�keysrQ)r3r@rArCr6rrrr>�s
�z)DBusSpecificationGenerator._generate_node)N)r#r-r.r/rr?�re�compilerU�classmethodr1r;r:r=rIrJrKrLrZrarbrMrNrOrPr>rrrrr0/sF



)



#


'

+

r0)r) rGrtr�typingrZdasbus.namespacerZ
dasbus.signalrZdasbus.specificationrrZ
dasbus.typingrr	r
rZ
dasbus.xmlr�__all__r2rrrrr�objectrrr
rr0rrrr�<module>s,
��"#	R
'

Youez - 2016 - github.com/yon3zu
LinuXploit