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

װ_62�@s�ddlZddlmZddlmZddlmZmZmZm	Z	m
Z
mZgd�ZdZ
Gdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�ded�Zdd�ZGdd�de�Zddd�Zdd�ZdS)�N)�ABCMeta)�get_type_hints)�get_variant�get_type_arguments�unwrap_variant�is_base_type�	Structure�List)�DBusStructureError�DBusData�generate_string_from_data�compare_dataZ__dbus_fields__c@seZdZdZdS)r
z,General exception for DBus structure errors.N)�__name__�
__module__�__qualname__�__doc__�rr�4/usr/lib/python3.9/site-packages/dasbus/structure.pyr
(sr
c@sjeZdZdZddd�Zedd��Zedd��Zed	d
��Zedd��Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�	DBusFieldz+Description of a field in a DBus structure.�cCs||_||_||_dS)z�Create a description of the field.

        :param name: a name of the field
        :param type_hint: a type hint
        :param description: a description
        N)�_name�
_type_hint�_description)�self�name�	type_hint�descriptionrrr�__init__0szDBusField.__init__cCs|jS)z4Name of the field.

        :return: a name
        )r�rrrrr;szDBusField.namecCs|jS)z>Type hint of the field.

        :return: a type hint
        )rrrrrrCszDBusField.type_hintcCs|jS)zBDescription of the field.

        :return: a description
        )rrrrrrKszDBusField.descriptioncCs|j�dd�S)zQReturn name of a data attribute.

        :return: a data attribute name
        �-�_)r�replacerrrr�	data_nameSszDBusField.data_namecCst||j|�dS)zaSet the data attribute.

        :param obj: a data object
        :param value: a value
        N)�setattrr"�r�obj�valuerrr�set_data[szDBusField.set_datacCs|�|t|��dS)ztSet the data attribute from a variant.

        :param obj: a data object
        :param variant: a variant
        N)r'r)rr%�variantrrr�set_data_variantcszDBusField.set_data_variantcCst||j�S)z\Get the data attribute.

        :param obj: a data object
        :return: a value
        )�getattrr"�rr%rrr�get_datakszDBusField.get_datacCst|j|�|��S)zkGet a variant of the data attribute.

        :param obj: a data object
        :return: a variant
        )rrr,r+rrr�get_data_variantsszDBusField.get_data_variantN)r)rrrrr�propertyrrrr"r'r)r,r-rrrrr-s




rcsBeZdZdZd�fdd�	Zedd��Z�fdd�Zd	d
�Z�Z	S)�
DBusDataFieldz0Description of a data field in a DBus structure.rcst��|t|�||_dS�z�Create a description of the field.

        :param name: a name of the field
        :param data_type: a subclass of DBusData
        :param description: a description
        N)�superrr�
_data_type�rr�	data_typer��	__class__rrrszDBusDataField.__init__cCs|jS�zMType of the data structure.

        :return: a subclass of DBusData
        �r2rrrrr4�szDBusDataField.data_typecs|j�|�}t��||�dS�zSet the data attribute.N)r2�from_structurer1r'r$r5rrr'�szDBusDataField.set_datacCs|j�|�|��}t|j|�S�z$Get a variant of the data attribute.)r2�to_structurer,rrr$rrrr-�szDBusDataField.get_data_variant)r�
rrrrrr.r4r'r-�
__classcell__rrr5rr/|s

r/csBeZdZdZd�fdd�	Zedd��Z�fdd�Zd	d
�Z�Z	S)�DBusDataListFieldz5Description of a data list field in a DBus structure.rcst��|tt|�||_dSr0)r1rr	rr2r3r5rrr�szDBusDataListField.__init__cCs|jSr7r8rrrrr4�szDBusDataListField.data_typecs|j�|�}t��||�dSr9)r2�from_structure_listr1r'r$r5rrr'�szDBusDataListField.set_datacCs|j�|�|��}t|j|�Sr;)r2�to_structure_listr,rrr$rrrr-�sz"DBusDataListField.get_data_variant)rr=rrr5rr?�s

r?csxeZdZdZ�fdd�Zeed�dd��Zeed�dd	��Zee	ed
�dd��Z
ee	ed�d
d��Zdd�Z�Z
S)rz�Object representation of data in a DBus structure.

    Classes derived from this class should represent specific types
    of DBus structures. They will support a conversion from a DBus
    structure of this type to a Python object and back.
    cs(t�j|i|��t|tt�|��dS)zCreate a new data class.N)r1�__init_subclass__r#�DBUS_FIELDS_ATTRIBUTE�DBusFieldFactory�generate_fields)�cls�args�kwargsr5rrrB�s�zDBusData.__init_subclass__)�	structurecCslt|t�std�t|�j���|�}t|�}|��D]2\}}|�|d�}|sZt	d�|���|�
||�q4|S)z~Convert a DBus structure to a data object.

        :param structure: a DBus structure
        :return: a data object
        �Invalid type '{}'.NzField '{}' doesn't exist.)�
isinstance�dict�	TypeError�format�typer�
get_fields�items�getr
r))rFrI�data�fieldsrr(�fieldrrrr:�s
��zDBusData.from_structure)�returncCsNt||�std�t|�j���i}t|�}|��D]\}}|�|�||<q2|S)zYConvert this data object to a DBus structure.

        :return: a DBus structure
        rJ)rKrMrNrOrrPrQr-)rFrSrIrTrrUrrrr<�s
�zDBusData.to_structure)�
structurescCs.t|t�std�t|�j���tt|j|��S)z�Convert DBus structures to data objects.

        :param structures: a list of DBus structures
        :return: a list of data objects
        rJ)rK�listrMrNrOr�mapr:)rFrWrrrr@�s

�zDBusData.from_structure_listcCstt|j|��S)z�Convert data objects to DBus structures.

        :param objects: a list of data objects
        :return: a list of DBus structures
        )rXrYr<)rFZobjectsrrrrAszDBusData.to_structure_listcCst|�S)z%Convert this data object to a string.)rrrrr�__repr__szDBusData.__repr__)rrrrrB�classmethodrr:r<r	r@rArZr>rrr5rr�s
r)�	metaclasscCs&t|td�}|dur"td�t���|S)zjReturn DBus fields of a data object.

    :param obj: a data object
    :return: a map of DBus fields
    NzFields are not defined at '{}'.)r*rCr
rN)r%rTrrrrPs�rPc@sLeZdZdZedd��Zedd��Zedd��Zedd	��Zed
d��Z	dS)
rDzA DBus field factory.cCs\i}t�|�D]<\}}|�||�s$q|�|�}|�||�}|�||�||<q|sXtd��|S)a�Generate DBus fields from properties of a class.

        Properties of the class will be used to generate a map of a DBus
        fields. The property should have a getter and a setter, otherwise
        an error is raised. The type hint of the getter is used to define
        the type of the DBus field.

        :param data_class: a data class
        :return: a map of DBus fields

        :raise DBusStructureError: if the DBus fields cannot be generated
        zNo fields found.)�inspectZ
getmembers�	_is_field�_get_field_name�_get_member_hint�
_create_fieldr
)rFZ
data_classrT�member_name�memberrrrrrrE,s
z DBusFieldFactory.generate_fieldscCs |�d�rdSt|t�sdSdS)z�Is the member a representation of a DBus field?

        :param member_name: a name of the class member
        :param member: a class member
        :return: True or False
        r FT)�
startswithrKr.)rFrbrcrrrr^Is
	

zDBusFieldFactory._is_fieldcCs|�dd�S)z�Get the name of the DBus field.

        :param member_name: a name of the class member
        :return: a name of the DBus field
        r r)r!)rFrbrrrr_[sz DBusFieldFactory._get_field_namecCsT|jstd�|���|js(td�|���t|j�}|�dd�}|sPtd�|���|S)z�Get the type hint of the member.

        :param field_name: a name of the DBus field
        :param member: a class member
        :return: a type hint
        zField '{}' cannot be set.zField '{}' cannot be get.rVNzField '{}' has unknown type.)�fsetr
rN�fgetrrR)rF�
field_namercZgetter_type_hintsrrrrr`ds��
�z!DBusFieldFactory._get_member_hintcCsFt|t�rt||�St|t�r<t|�\}t|t�r<t||�St||�S)z�Create a representation of a DBus field.

        :param field_name: a name of the field
        :param member_hint: a type hint of the member
        :return: a new instance of DBus field
        )rrr/r	rr?r)rFrgZmember_hintZarg_hintrrrra�s





zDBusFieldFactory._create_fieldN)
rrrrr[rEr^r_r`rarrrrrD)s



rDcCs�i}t|���D]}|�|�||j<q|p.t�D]}|�|d�q0|pJt�D]}||||<qLtdd�|��D��}d�	|j
jd�|��S)a�Generate a string representation of a data object.

    Set the argument 'skip' to skip attributes with sensitive data.

    Set the argument 'add' to add other values to the string
    representation. The attributes in the string representation
    will be sorted alphabetically.

    :param obj: a data object
    :param skip: a list of names that should be skipped or None
    :param add: a dictionary of attributes to add or None
    :return: a string representation of the data object
    NcSs g|]\}}d�|t|���qS)z{}={})rN�repr)�.0rr&rrr�
<listcomp>�sz-generate_string_from_data.<locals>.<listcomp>z{}({})z, )
rP�valuesr,r"rX�poprL�sortedrQrNr6r�join)r%�skip�addZ
dictionaryrUrZ
attributesrrrr�s�rcCs(t|t�o&t|t�o&|�|�|�|�kS)z�Compare data of the given data objects.

    :param obj: a data object
    :param other: another data object
    :return: True if the data is equal, otherwise False
    )rKrr<)r%�otherrrrr
�s

��r
)NN)r]�abcr�typingrZ
dasbus.typingrrrrrr	�__all__rC�	Exceptionr
�objectrr/r?rrPrDrr
rrrr�<module>s 	O  ]k