o
    3˜ŽjÐ  ã                   @   s  d Z ddlZddlmZmZmZ ddlmZmZm	Z	m
Z
mZ ddlmZ ddlmZmZ e
ee	ef Ze
eee f Ze
deeeef eeeef  f Zded	efd
d„ZdeeeeB ef  d	efdd„ZdeeeeB ef  d	efdd„Zdeded	edB fdd„ZdS )zQuery string handling.é    N)ÚIterableÚMappingÚSequence)ÚTYPE_CHECKINGÚAnyÚSupportsIntÚUnionÚcast)Úistré   )ÚQUERY_PART_QUOTERÚQUERY_QUOTERÚvÚreturnc                 C   sŽ   t | ƒ}|tu rt| ƒS t| tƒr| S t| tƒr0t | ¡r!tdƒ‚t | ¡r*tdƒ‚tt| ƒƒS |t	ur?t| t
ƒr?tt| ƒƒS td | |¡ƒ‚)a,  Convert a query variable to a string.

    Note: Objects implementing the ``__int__`` data model method (typed as
    ``SupportsInt``; e.g. ``uuid.UUID``) are converted via ``int()`` first.
    Callers should convert such values to ``str`` explicitly if the string
    representation is desired.
    zfloat('inf') is not supportedzfloat('nan') is not supportedzMInvalid variable type: value should be str, int or float, got {!r} of type {})ÚtypeÚintÚstrÚ
isinstanceÚfloatÚmathÚisinfÚ
ValueErrorÚisnanÚboolr   Ú	TypeErrorÚformat)r   Úcls© r   úH/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/yarl/_query.pyÚ	query_var   s"   



ýr   Úitemsc                    ó    t ‰ ‡ fdd„| D ƒ}d |¡S )z·Return a query string from a sequence of (key, value) pairs.

    value is a single value or a sequence of values for the key

    The sequence of values must be a list or tuple.
    c                    sd   g | ].\}}t |ƒturt|ttfƒr|n|fD ]}ˆ |ƒ› d ˆ t |ƒtu r(|nt|ƒƒ› �‘qqS ©ú=)r   r   r   ÚlistÚtupler   )Ú.0ÚkÚvalr   ©Úquoterr   r   Ú
<listcomp>8   s    "ü(þÿz8get_str_query_from_sequence_iterable.<locals>.<listcomp>ú&©r   Újoin©r    Úpairsr   r)   r   Ú$get_str_query_from_sequence_iterable.   s
   	
þ
r1   c                    r!   )zðReturn a query string from an iterable.

    The iterable must contain (key, value) pairs.

    The values are not allowed to be sequences, only single values are
    allowed. For sequences, use `_get_str_query_from_sequence_iterable`.
    c                    s:   g | ]\}}ˆ |ƒ› d ˆ t |ƒtu r|nt|ƒƒ› �‘qS r"   )r   r   r   )r&   r'   r   r)   r   r   r+   O   s    .ÿz/get_str_query_from_iterable.<locals>.<listcomp>r,   r-   r/   r   r)   r   Úget_str_query_from_iterableB   s
   

ÿ
r2   ÚargsÚkwargsc                  O   sð   |r| r
d}t |ƒ‚|}nt| ƒdkr| d }nt dƒ‚|du r"dS |s&dS t|ƒtu r2t| ¡ ƒS t|ƒtu s=t|tƒrAt|ƒS t|t	ƒrLt| ¡ ƒS t|t
ttfƒrZd}t|ƒ‚t|tƒrttrpttttttf tf  |ƒ}t|ƒS tdƒ‚)z*Return a query string from supported args.z7Either kwargs or single query parameter must be presentr   r   NÚ zAInvalid query type: bytes, bytearray and memoryview are forbiddenzRInvalid query type: only str, mapping or sequence of (key, value) pairs is allowed)r   Úlenr   Údictr1   r    r   r   r   r   ÚbytesÚ	bytearrayÚ
memoryviewr   r   r   r	   r%   r   r
   ÚSimpleQueryr2   )r3   r4   ÚmsgÚqueryr   r   r   Úget_str_queryU   s8   


ÿr>   )Ú__doc__r   Úcollections.abcr   r   r   Útypingr   r   r   r   r	   Ú	multidictr
   Ú_quotersr   r   r   r   r;   ÚQueryVariabler%   ÚQueryr   r1   r2   r>   r   r   r   r   Ú<module>   s.    ÿÿ
þÿ
þ