U
    	fa+                     @  s0  d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZ d dlmZ d dlmZ d dlZddlmZmZmZmZmZ ddlmZmZ e
d	Ze
d
eedf dZ e
de	e!ef dZ"e
dee dZ#e
dedef dZ$dddddZ%ddddddZ&ddddddd d!Z'd"d#d$d%d&Z(dd'd$d(d)Z)d*d+d$d,d-Z*dd.d$d/d0Z+d1d2d$d3d4Z,dd5d$d6d7Z-d8d9d$d:d;Z.dd<d$d=d>Z/dd?d$d@dAZ0ddBd$dCdDZ1d	d	dEdFdGZ2dHdIdJddKdKdKdLdMdNZ3dKdKdOdPdQZ4ddRdSdTdUZ5e
dVZ6e
dWZ7edXdXd$dYdZZ8ed[d\d$d]dZZ8eddd$d^dZZ8d_dd$d`dZZ8dKddadbdcZ9dKdddadedfZ:dKdgdadhdiZ;ddjdadkdlZ<ddmdadndoZ=ddpdadqdrZ>dKdKdKdsdtduZ?dKdKdKdvdwdxZ@dKdydzd{d|ZAd}dKdKd~ddZBdKdddZCdS )    )annotationsN)	AnyTupleMappingTypeVarCallableIterableSequencecastoverload)Path)	TypeGuard   )HeadersNotGiven	FileTypes
NotGivenOrHeadersLike)
parse_dateparse_datetime_T_TupleT.)bound	_MappingT
_SequenceT	CallableTzIterable[Iterable[_T]]zlist[_T])treturnc                 C  s   dd | D S )Nc                 S  s   g | ]}|D ]}|qqS  r   ).0Zsublistitemr   r   U/var/www/html/apigroqsegura/apigroq/lib/python3.8/site-packages/groq/_utils/_utils.py
<listcomp>"   s       zflatten.<locals>.<listcomp>r   )r   r   r   r!   flatten!   s    r#   zMapping[str, object]zSequence[Sequence[str]]zlist[tuple[str, FileTypes]])querypathsr   c             	   C  s(   g }|D ]}| t| |ddd q|S )zRecursively extract files from the given dictionary based on specified paths.

    A path may look like this ['foo', 'files', '<array>', 'data'].

    Note: this mutates the given dictionary.
    r   Nindexflattened_key)extend_extract_items)r$   r%   filespathr   r   r!   extract_files%   s    r-   objectzSequence[str]intz
str | None)objr,   r'   r(   r   c                  s  z }W nZ t k
rf   t| tr.g  Y S ddlm} ||  d  d k	sRt tt| fg Y S X d7 t| rz$t	kr| 
|}n| | }W n tk
r   g  Y S X  d kr| n d| d7  t| dS t| r|dk rg S t fd	d
| D S g S )Nr   )assert_is_file_content)key   []r&   z<array>c                   s,   g | ]$}t | d k	r  d nddqS )Nz[]r&   )r*   )r   r    r(   r'   r,   r   r!   r"   j   s   z"_extract_items.<locals>.<listcomp>)
IndexError
isinstancer   _filesr1   AssertionErrorr
   r   is_dictlenpopKeyErrorr*   is_listr#   )r0   r,   r'   r(   r2   r1   r    r   r6   r!   r*   8   sF    



r*   zNotGivenOr[_T]zTypeGuard[_T])r0   r   c                 C  s   t | t S Nr8   r   r0   r   r   r!   is_giveny   s    rC   zTypeGuard[tuple[object, ...]]c                 C  s
   t | tS r@   r8   tuplerB   r   r   r!   is_tuple   s    rF   z_TupleT | objectzTypeGuard[_TupleT]c                 C  s
   t | tS r@   rD   rB   r   r   r!   
is_tuple_t   s    rG   zTypeGuard[Sequence[object]]c                 C  s
   t | tS r@   r8   r	   rB   r   r   r!   is_sequence   s    rI   z_SequenceT | objectzTypeGuard[_SequenceT]c                 C  s
   t | tS r@   rH   rB   r   r   r!   is_sequence_t   s    rJ   zTypeGuard[Mapping[str, object]]c                 C  s
   t | tS r@   r8   r   rB   r   r   r!   
is_mapping   s    rL   z_MappingT | objectzTypeGuard[_MappingT]c                 C  s
   t | tS r@   rK   rB   r   r   r!   is_mapping_t   s    rM   zTypeGuard[dict[object, object]]c                 C  s
   t | tS r@   )r8   dictrB   r   r   r!   r;      s    r;   zTypeGuard[list[object]]c                 C  s
   t | tS r@   )r8   listrB   r   r   r!   r?      s    r?   zTypeGuard[Iterable[object]]c                 C  s
   t | tS r@   )r8   r   rB   r   r   r!   is_iterable   s    rP   )r    r   c                 C  s@   t | r ttdd |  D S t| r<ttdd | D S | S )zMinimal reimplementation of copy.deepcopy() that will only copy certain object types:

    - mappings, e.g. `dict`
    - list

    This is done for performance reasons.
    c                 S  s   i | ]\}}|t |qS r   deepcopy_minimal)r   kvr   r   r!   
<dictcomp>   s      z$deepcopy_minimal.<locals>.<dictcomp>c                 S  s   g | ]}t |qS r   rQ   )r   entryr   r   r!   r"      s     z$deepcopy_minimal.<locals>.<listcomp>)rL   r
   r   itemsr?   )r    r   r   r!   rR      s
    rR   z, or)delimfinalstr)seqrY   rZ   r   c                C  sn   t | }|dkrdS |dkr$| d S |dkrH| d  d| d| d  S || d d d| d| d   S )Nr    r3   r    )r<   join)r\   rY   rZ   sizer   r   r!   
human_join   s    rb   )stringr   c                 C  s   d|  dS )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r   )rc   r   r   r!   quote   s    re   z Callable[[CallableT], CallableT])variantsr   c                    s   ddd fdd}|S )aL  Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function.

    Useful for enforcing runtime validation of overloaded functions.

    Example usage:
    ```py
    @overload
    def foo(*, a: str) -> str:
        ...


    @overload
    def foo(*, b: bool) -> str:
        ...


    # This enforces the same constraints that a static type checker would
    # i.e. that either a or b must be passed to the function
    @required_args(["a"], ["b"])
    def foo(*, a: str | None = None, b: bool | None = None) -> str:
        ...
    ```
    r   )funcr   c                   sF   t  j}dd | D t dddd fdd}|S )Nc                 S  s&   g | ]\}}|j |j|jhkr|qS r   )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)r   nameparamr   r   r!   r"      s   z0required_args.<locals>.inner.<locals>.<listcomp>r.   )argskwargsr   c            
        s4  t   t| D ]V\}}z |  W q tk
rb   tj dt dt|  dd Y qX q| D ]} | qnD ]$}t fdd|D }|r q*qtdkrt	dd D }d	| d
}nNt
t d   }	t|	dkrdt	dd |	D  }ndt|	d  }t|| |S )Nz	() takes z argument(s) but z were givenc                 3  s   | ]}| kV  qd S r@   r   )r   rl   Zgiven_paramsr   r!   	<genexpr>  s     z@required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>r3   c                 S  s*   g | ]"}d t dd |D dd d qS )(c                 S  s   g | ]}t |qS r   re   r   argr   r   r!   r"     s     zLrequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>.<listcomp>and)rZ   ))rb   )r   variantr   r   r!   r"     s     zArequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>z,Missing required arguments; Expected either z arguments to be givenr   zMissing required arguments: c                 S  s   g | ]}t |qS r   rr   rs   r   r   r!   r"     s     zMissing required argument: )set	enumerateaddr7   	TypeError__name__r<   keysallrb   rO   re   )
rm   rn   i_r2   rw   matchesZ
variationsmsgmissing)rg   
positionalrf   ro   r!   wrapper   s6    
z-required_args.<locals>.inner.<locals>.wrapper)inspect	signature
parametersrW   	functoolswraps)rg   paramsr   rf   )rg   r   r!   inner   s    
!zrequired_args.<locals>.innerr   )rf   r   r   r   r!   required_args   s    0r   _K_VNonec                 C  s   d S r@   r   rB   r   r   r!   strip_not_given  s    r   zMapping[_K, _V | NotGiven]zdict[_K, _V]c                 C  s   d S r@   r   rB   r   r   r!   r   #  s    c                 C  s   d S r@   r   rB   r   r   r!   r   (  s    zobject | Nonec                 C  s*   | dkrdS t | s| S dd |  D S )zHRemove all top-level keys where their values are instances of `NotGiven`Nc                 S  s    i | ]\}}t |ts||qS r   rA   )r   r2   valuer   r   r!   rU   5  s     
  z#strip_not_given.<locals>.<dictcomp>)rL   rW   rB   r   r   r!   r   -  s
    )valr   c                 C  s   t | ddS )N
   )base)r/   r   r   r   r!   coerce_integer8  s    r   floatc                 C  s   t | S r@   )r   r   r   r   r!   coerce_float<  s    r   boolc                 C  s   | dkp| dkp| dkS )Ntrue1onr   r   r   r   r!   coerce_boolean@  s    r   z
int | Nonec                 C  s   | d krd S t | S r@   )r   r   r   r   r!   maybe_coerce_integerD  s    r   zfloat | Nonec                 C  s   | d krd S t | S r@   )r   r   r   r   r!   maybe_coerce_floatJ  s    r   zbool | Nonec                 C  s   | d krd S t | S r@   )r   r   r   r   r!   maybe_coerce_booleanP  s    r   )rc   prefixr   c                 C  s   |  |r| t|d S | S )zXRemove a prefix from a string.

    Backport of `str.removeprefix` for Python < 3.9
    N)
startswithr<   )rc   r   r   r   r!   removeprefixV  s    
r   )rc   suffixr   c                 C  s    |  |r| dt|  S | S )zXRemove a suffix from a string.

    Backport of `str.removesuffix` for Python < 3.9
    N)endswithr<   )rc   r   r   r   r!   removesuffix`  s    
r   r   )r,   r   c                 C  s    t |  }tj| }||fS r@   )r   
read_bytesosr,   basename)r,   contents	file_namer   r   r!   file_from_pathj  s    r   r   )headersheaderr   c                 C  s   |  }t| trLtt| } |  D ]&\}}|  |kr$t|tr$|  S q$tddd |	 }|||
 |fD ]}| |}|rr|  S qrtd| dd S )Nz([^\w])(\w)c                 S  s   |  d|  d  S )Nr3   r   )groupupper)patr   r   r!   <lambda>y      z%get_required_header.<locals>.<lambda>zCould not find z header)lowerr8   r   r
   r   rW   r[   resub
capitalizer   get
ValueError)r   r   Zlower_headerrS   rT   Zintercaps_headerZnormalized_headerr   r   r   r!   get_required_headerp  s    




r   )r   c                   C  s&   z
t  W S  tk
r    Y dS X d S )Nfalse)sniffiocurrent_async_library	Exceptionr   r   r   r!   get_async_library  s    
r   )D
__future__r   r   r   r   r   typingr   r   r   r   r   r   r	   r
   r   pathlibr   typing_extensionsr   r   _typesr   r   r   r   r   _compatr   r   r   r.   r   r[   r   r   r   r#   r-   r*   rC   rF   rG   rI   rJ   rL   rM   r;   r?   rP   rR   rb   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   <module>   sh   ,AL

