a F `&&@s ddlmZmZmZmZmZddlZeddddlm Z m Z gdZ e Z eZeZeZedeZedeZed eZed eZed eZed eZed eZeZedeZeee fZddZddZddZ ddZ!ddZ"ddZ#ddZ$ddZ%Gdd d e&Z'dS)!)TupleDictListNewTypeIONZGLibz2.0)Variant VariantType)BoolStrDoubleByteIntInt16UInt16Int32UInt32Int64UInt64FileObjPathrrrrr Structure get_native get_variantget_variant_typeunwrap_variant is_base_typeget_type_arguments get_dbus_typer rrrrrrrcCs t|S)zReturn DBus representation of a type hint. :param type_hint: a type hint :return: a string with DBus representation DBusTypeget_dbus_representation type_hintr#1/usr/lib/python3.9/site-packages/dasbus/typing.pyrZsrcCs4t|tkr|}nt|}|dur*tdt||S)a^Return a variant data type. The type of a variant is specified with a type hint. Example: .. code-block:: python v1 = get_variant(Bool, True) v2 = get_variant(List[Int], [1,2,3]) :param type_hint: a type hint or a type string :param value: a value of the variant :return: an instance of Variant NzInvalid DBus value 'None'.)typestrr TypeErrorr)r"value type_stringr#r#r$rcs  rcCs$t|tkr|}nt|}t|S)zReturn a type of a variant data type. :param type_hint: a type hint or a type string :return: an instance of VariantType )r%r&rrnew)r"r)r#r#r$rs rcCsbt|tr|St|tr*ttt|St|trBttt|St|tr^dd|DS|S)zDecompose a DBus value into a native Python object. This function is useful for testing, when the DBus library doesn't decompose arguments and return values of DBus calls. :param value: a DBus value :return: a native Python object cSsi|]\}}|t|qSr#)r).0kvr#r#r$ zget_native..) isinstancerunpacktuplemaprlistdictitems)r(r#r#r$rs    rcs}|dr0tfddtDS|dri}tD]2}|}|d}|d}t|||<qJ|S|drtfddtDS|d r SS) aAUnwrap a variant data type. Unlike the unpack method of the Variant class, this function doesn't recursively unpacks all variants in the data structure. It will unpack only the topmost variant. The implementation is inspired by the unpack method. :param variant: a variant :return: a value (c3s|]}t|VqdSNrget_child_valuer+ivariantr#r$ sz!unwrap_variant..za{rac3s|]}t|VqdSr8r9r;r=r#r$r?sr-) Zget_type_string startswithr2rangeZ n_childrenr:rr1r4r)r>r)resultr<entrykeyr(r#r=r$rs(            rcCs<t|d|}||krdSz t||WSty6Yn0dS)aKIs the given base type a base of the specified type hint? For example, List is a base of the type hint List[Int] and Int is a base of the type hint Int. A class is a base of itself and of every subclass of this class. :param type_hint: a type hint :param base_type: a base type :return: True or False __origin__TF)getattr issubclassr'r"Z base_typer#r#r$rs   rcCs t|ddS)zGet the arguments of the type hint. For example, Str and Int are arguments of the type hint Tuple(Str, Int). :param type_hint: a type hint :return: a type arguments __args__r#)rHr!r#r#r$rsrcCst|dt|S)zkGet the name of the type hint. :param type_hint: a type hint :return: a name of the type hint __name__)rHr&r!r#r#r$ get_type_namesrMc@seZdZdZededededede de de de d e d ed ed ed ediZededediZeddZeddZeddZeddZeddZeddZeddZd S)!rz0Class for transforming type hints to DBus types.bsdr<ynquxthor-z(%s)za%sza{%s}cCs>t|rt|St|r(t|Stdt|dS)zReturn a DBus representation of the given type hint. :param type_hint: a type hint :return str: a DBus representation of the type hint :raises ValueError: for unknown types zInvalid DBus type '{}'.N)r_is_basic_type_get_basic_type_is_container_type_get_container_typer'formatrMr!r#r#r$r !s    z DBusType.get_dbus_representationcCs |tjvS)zIs it a basic type?r_basic_type_mappingr!r#r#r$rY9szDBusType._is_basic_typecCs tj|S)zReturn a basic type.r^r!r#r#r$rZ>szDBusType._get_basic_typecCst|duS)zIs it a container type?N)r_get_container_base_typer!r#r#r$r[CszDBusType._is_container_typecCs"tjD]}t||r|SqdS)zReturn a container base type.N)r_container_type_mappingrrJr#r#r$r`Hs   z!DBusType._get_container_base_typecCsJt|}t|}|tkr$t|tj|}dd|D}|d|S)zReturn a container type.cSsg|]}t|qSr#r)r+argr#r#r$ ar/z0DBusType._get_container_type..)rr`rr_check_if_valid_dictionaryrajoin)r"Zbasetypeargs containerr6r#r#r$r\Ss   zDBusType._get_container_typecCs4t|\}}t|s|tkr0tdt|dS)zVCheck the type of a dictionary. :raises ValueError: for invalid type z)Invalid DBus type of dictionary key: '{}'N)rrr[rr'r]rM)r"rF_r#r#r$reds z#DBusType._check_if_valid_dictionaryN)rL __module__ __qualname____doc__r r r r r rrrrrrrrrr_rrrra staticmethodr rYrZr[r`r\rer#r#r#r$rsD      r)(typingrrrrrZgiZrequire_versionZgi.repository.GLibrr__all__boolr floatr r&r intr r rrrrrrrrrrrrrrrrrMobjectrr#r#r#r$s6           0