a
    _g0                     @  s  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mZ d dlmZ d dlmZmZ d dlmZ d dlZddl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&erddl'm(Z(m)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d0d&d1d2Z0d3d4d&d5d6Z1dd7d&d8d9Z2d:d;d&d<d=Z3dd>d&d?d@Z4ddAd&dBdCZ5ddDd&dEdFZ6d
d
dGdHdIZ7dJdKdLddMdMdMdNdOdPZ8dMdMdQdRdSZ9ddTdUdVdWZ:edXZ;edYZ<edZdZd&d[d\Z=ed]d^d&d_d\Z=eddd&d`d\Z=dadd&dbd\Z=dMddcdddeZ>dMdfdcdgdhZ?dMdidcdjdkZ@d dldcdmdnZAd dodcdpdqZBd drdcdsdtZCdMdMdMdudvdwZDdMdMdMdxdydzZEdMd{d|d}d~ZFddMdMdddZGdMdddZHdddldTdddZIdddddZJdddddZKdddddZLdS )    )annotationsN)
TYPE_CHECKINGAnyTupleMappingTypeVarCallableIterableSequencecastoverload)Path)datedatetime)	TypeGuard   )NotGiven	FileTypes
NotGivenOrHeadersLike)
parse_dateparse_datetime_T_TupleT.)bound	_MappingT
_SequenceT	CallableT)AzureOpenAIAsyncAzureOpenAIz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"   b/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/openai/_utils/_utils.py
<listcomp>'       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    r2   objectzSequence[str]intz
str | None)objr1   r,   r-   r!   c                  s  z }W nX t yd   t| tr,g  Y S ddlm} ||  d  d usPJ  tt| fg Y S 0 d7 t| rz$tkr| 	|}n| | }W n t
y   g  Y S 0  d u 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 ur  d nddqS )Nz[]r+   )r/   r#   r$   r-   r,   r1   r"   r%   r&   o   s   z"_extract_items.<locals>.<listcomp>)
IndexError
isinstancer   _filesr6   r   r   is_dictlenpopKeyErrorr/   is_listr(   )r5   r1   r,   r-   r7   r6   r$   r"   r<   r%   r/   =   sF    



r/   zNotGivenOr[_T]zTypeGuard[_T])r5   r!   c                 C  s   t | t S Nr>   r   r5   r"   r"   r%   is_given~   s    rH   zTypeGuard[tuple[object, ...]]c                 C  s
   t | tS rE   r>   tuplerG   r"   r"   r%   is_tuple   s    rK   z_TupleT | objectzTypeGuard[_TupleT]c                 C  s
   t | tS rE   rI   rG   r"   r"   r%   
is_tuple_t   s    rL   zTypeGuard[Sequence[object]]c                 C  s
   t | tS rE   r>   r
   rG   r"   r"   r%   is_sequence   s    rN   z_SequenceT | objectzTypeGuard[_SequenceT]c                 C  s
   t | tS rE   rM   rG   r"   r"   r%   is_sequence_t   s    rO   zTypeGuard[Mapping[str, object]]c                 C  s
   t | tS rE   r>   r   rG   r"   r"   r%   
is_mapping   s    rQ   z_MappingT | objectzTypeGuard[_MappingT]c                 C  s
   t | tS rE   rP   rG   r"   r"   r%   is_mapping_t   s    rR   zTypeGuard[dict[object, object]]c                 C  s
   t | tS rE   )r>   dictrG   r"   r"   r%   r@      s    r@   zTypeGuard[list[object]]c                 C  s
   t | tS rE   )r>   listrG   r"   r"   r%   rD      s    rD   zTypeGuard[Iterable[object]]c                 C  s
   t | tS rE   )r>   r	   rG   r"   r"   r%   is_iterable   s    rU   )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>   r'   z$deepcopy_minimal.<locals>.<dictcomp>c                 S  s   g | ]}t |qS r"   rV   )r#   entryr"   r"   r%   r&      r'   z$deepcopy_minimal.<locals>.<listcomp>)rQ   r   r   itemsrD   )r$   r"   r"   r%   rW      s
    rW   z, or)delimfinalstr)seqr^   r_   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    r8   r    )rA   join)ra   r^   r_   sizer"   r"   r%   
human_join   s    rg   )stringr!   c                 C  s   d|  dS )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r"   )rh   r"   r"   r%   quote   s    rj   z Callable[[CallableT], CallableT])variantsr!   c                    s   ddd fdd}|S )a4  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v r|qS r"   )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)r#   nameparamr"   r"   r%   r&      s   z0required_args.<locals>.inner.<locals>.<listcomp>r3   )argskwargsr!   c            
        sF  t   t| D ]T\}}z |  W q ty`   tj dt dt|  dd Y q0 q| D ]} | qlD ]$}t fdd|D }|r q8qtdkrt	dd D }d	| d
}n^tdksJ t
t d   }	t|	dkrdt	dd |	D  }ndt|	d  }t|| i |S )Nz	() takes z argument(s) but z were givenc                 3  s   | ]}| v V  qd S rE   r"   )r#   rq   Zgiven_paramsr"   r%   	<genexpr>  r'   z@required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>r8   c                 S  s*   g | ]"}d t dd |D dd d qS )(c                 S  s   g | ]}t |qS r"   rj   r#   argr"   r"   r%   r&   
  r'   zLrequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>.<listcomp>and)r_   ))rg   )r#   variantr"   r"   r%   r&   
  r'   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"   rw   rx   r"   r"   r%   r&     r'   zMissing required argument: )set	enumerateaddr=   	TypeError__name__rA   keysallrg   rT   rj   )
rr   rs   i_r7   r|   matchesZ
variationsmsgmissing)rl   
positionalrk   rt   r%   wrapper   s8    
z-required_args.<locals>.inner.<locals>.wrapper)inspect	signature
parametersr\   	functoolswraps)rl   paramsr   rk   )rl   r   r%   inner   s    
#zrequired_args.<locals>.innerr"   )rk   r   r"   r   r%   required_args   s    2r   _K_VNonec                 C  s   d S rE   r"   rG   r"   r"   r%   strip_not_given"  s    r   zMapping[_K, _V | NotGiven]zdict[_K, _V]c                 C  s   d S rE   r"   rG   r"   r"   r%   r   &  s    c                 C  s   d S rE   r"   rG   r"   r"   r%   r   *  s    zobject | Nonec                 C  s*   | du 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"   rF   r#   r7   valuer"   r"   r%   rZ   6  r'   z#strip_not_given.<locals>.<dictcomp>)rQ   r\   rG   r"   r"   r%   r   .  s
    )valr!   c                 C  s   t | ddS )N
   )base)r4   r   r"   r"   r%   coerce_integer9  s    r   floatc                 C  s   t | S rE   )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_booleanA  s    r   z
int | Nonec                 C  s   | d u rd S t | S rE   )r   r   r"   r"   r%   maybe_coerce_integerE  s    r   zfloat | Nonec                 C  s   | d u rd S t | S rE   )r   r   r"   r"   r%   maybe_coerce_floatK  s    r   zbool | Nonec                 C  s   | d u rd S t | S rE   )r   r   r"   r"   r%   maybe_coerce_booleanQ  s    r   )rh   prefixr!   c                 C  s   |  |r| t|d S | S )zXRemove a prefix from a string.

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

    Backport of `str.removesuffix` for Python < 3.9
    N)endswithrA   )rh   r   r"   r"   r%   removesuffixa  s    
r   r   )r1   r!   c                 C  s    t |  }tj| }||fS rE   )r   
read_bytesosr1   basename)r1   contents	file_namer"   r"   r%   file_from_pathk  s    r   r   )headersheaderr!   c                 C  s   |  }t| r@|  D ]&\}}|  |krt|tr|  S qtddd | }||| |fD ]}| 	|}|rf|  S qft
d| dd S )Nz([^\w])(\w)c                 S  s   |  d|  d  S )Nr8   r   )groupupper)patr"   r"   r%   <lambda>z  r'   z%get_required_header.<locals>.<lambda>zCould not find z header)lowerrR   r\   r>   r`   resub
capitalizer   get
ValueError)r   r   Zlower_headerrX   rY   Zintercaps_headerZnormalized_headerr   r"   r"   r%   get_required_headerq  s    


r   )r!   c                   C  s$   z
t  W S  ty   Y dS 0 d S )Nfalse)sniffioZcurrent_async_library	Exceptionr"   r"   r"   r%   get_async_library  s    
r      maxsize)r   r!   c                 C  s   t j| d}tt|S )zmA version of functools.lru_cache that retains the type signature
    for the wrapped function arguments.
    r   )r   	lru_cacher   r   )r   r   r"   r"   r%   r     s    r   )datar!   c                 C  sZ   t | rdd |  D S t| r@t| tttfs@dd | D S t| ttfrV| 	 S | S )zvTranslates a mapping / sequence recursively in the same fashion
    as `pydantic` v2's `model_dump(mode="json")`.
    c                 S  s   i | ]\}}t |t |qS r"   	json_safer   r"   r"   r%   rZ     r'   zjson_safe.<locals>.<dictcomp>c                 S  s   g | ]}t |qS r"   r   r;   r"   r"   r%   r&     r'   zjson_safe.<locals>.<listcomp>)
rQ   r\   rU   r>   r`   bytes	bytearrayr   r   	isoformat)r   r"   r"   r%   r     s    r   zTypeGuard[AzureOpenAI])clientr!   c                 C  s   ddl m} t| |S )Nr   )r   )	lib.azurer   r>   )r   r   r"   r"   r%   is_azure_client  s    r   zTypeGuard[AsyncAzureOpenAI]c                 C  s   ddl m} t| |S )Nr   )r   )r   r   r>   )r   r   r"   r"   r%   is_async_azure_client  s    r   )M
__future__r   r   r   r   r   typingr   r   r   r   r   r   r	   r
   r   r   pathlibr   r   r   Ztyping_extensionsr   r   _typesr   r   r   r   Z_compatr   r   r   r3   r   r`   r   r   r   r   r   r   r(   r2   r/   rH   rK   rL   rN   rO   rQ   rR   r@   rD   rU   rW   rg   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r"   r"   r%   <module>   sv   0AK


