grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a Êic.2ã@sÌddlZddlmZddlmZddlmZmZmZm Z m Z m Z gd¢Z dZ Gdd„deƒZGd d „d eƒZGd d „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 „ƒZed d „ƒZ d d„Z dd„Z dd„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 œd d „ƒZ ee edœd d„ƒZ dd„Z ‡Z S)r z÷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<)rFZobjectsrrrrA szDBusData.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­sz-generate_string_from_data..z{}({})z, ) rPÚvaluesr,r"ÚpopÚ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 )rKr r<)r%Úotherrrrr ´s  ÿþr )NN)r]ÚabcrÚtypingrZ dasbus.typingrrrrrr Ú__all__rCÚ Exceptionr Úobjectrr/r?r rPrDr r rrrrÚs    O  ]k