%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/dasbus/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/dasbus/__pycache__/typing.cpython-39.pyc

a

F
�`&&�@sddlmZmZmZmZmZddlZe�dd�ddlm	Z	m
Z
gd�ZeZ
eZeZeZede�Zede�Zed	e�Zed
e�Zede�Zede�Zed
e�ZeZede�Zeee	fZdd�Zdd�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%Gdd �d e&�Z'dS)!�)�Tuple�Dict�List�NewType�IONZGLibz2.0)�Variant�VariantType)�Bool�Str�Double�Byte�Int�Int16�UInt16�Int32�UInt32�Int64�UInt64�File�ObjPathrrrrr�	Structure�
get_native�get_variant�get_variant_type�unwrap_variant�is_base_type�get_type_arguments�
get_dbus_typerrrrrrrrcCs
t�|�S)z�Return DBus representation of a type hint.

    :param type_hint: a type hint
    :return: a string with DBus representation
    ��DBusType�get_dbus_representation��	type_hint�r#�1/usr/lib/python3.9/site-packages/dasbus/typing.pyrZsrcCs4t|�tkr|}nt|�}|dur*td��t||�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'.)�type�strr�	TypeErrorr)r"�value�type_stringr#r#r$rcsrcCs$t|�tkr|}nt|�}t�|�S)z�Return a type of a variant data type.

    :param type_hint: a type hint or a type string
    :return: an instance of VariantType
    )r%r&rr�new)r"r)r#r#r$rsrcCsbt|t�r|��St|t�r*ttt|��St|t�rBttt|��St|t�r^dd�|��D�S|S)z�Decompose 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)�.0�k�vr#r#r$�
<dictcomp>��zget_native.<locals>.<dictcomp>)	�
isinstancer�unpack�tuple�mapr�list�dict�items)r(r#r#r$r�s	



rcs����}|�d�r0t�fdd�t����D��S|�d�r�i}t����D]2}��|�}|�d�}|�d�}t|�||��<qJ|S|�d�r�t�fdd�t����D��S|�d	�r���	�S���S)
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��|��VqdS�N�r�get_child_value�r+�i��variantr#r$�	<genexpr>�s�z!unwrap_variant.<locals>.<genexpr>za{r��ac3s|]}t��|��VqdSr8r9r;r=r#r$r?�s�r-)
Zget_type_string�
startswithr2�rangeZ
n_childrenr:rr1r4r)r>r)�resultr<�entry�keyr(r#r=r$r�s(

�





�
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$r�srcCst|dd�S)z�Get 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$r�srcCst|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_name�srMc@s�eZdZdZededededede	de
deded	e
d
ededed
ediZededediZedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zedd��Zd S)!rz0Class for transforming type hints to DBus types.�b�s�dr<�y�n�q�u�x�t�h�or-z(%s)za%sza{%s}cCs>t�|�rt�|�St�|�r(t�|�Std�t|����dS)z�Return 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$�
<listcomp>ar/z0DBusType._get_container_type.<locals>.<listcomp>�)rr`rr�_check_if_valid_dictionaryra�join)r"Zbasetype�args�	containerr6r#r#r$r\Ss


zDBusType._get_container_typecCs4t|�\}}t�|�s|tkr0td�t|����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
rr
rrrrrrrrrrr_rrrra�staticmethodr rYrZr[r`r\rer#r#r#r$rsD��






r)(�typingrrrrrZgiZrequire_versionZgi.repository.GLibrr�__all__�boolr	�floatrr&r
�intr
rrrrrrrrrrrrrrrrrrM�objectrr#r#r#r$�<module>s6







	0	

Zerion Mini Shell 1.0