
    U th1                       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                   Z" ede
e#e!f                   Z$ edee!                   Z% ededef                   Z&erddl'm(Z(m)Z) dydZ*dzdZ+d{d%Z,d|d(Z-d}d*Z.d~d-Z/dd/Z0dd2Z1dd4Z2dd7Z3dd9Z4dd;Z5dd=Z6dd?Z7d@dAdBddGZ8ddIZ9ddLZ: edM          Z; edN          Z<eddP            Z=eddS            Z=eddT            Z=ddVZ=ddXZ>ddZZ?dd\Z@dd^ZAdd`ZBddbZCdddZDddfZEddhZFddlZGddmZHdndoddqZIddsZJddvZKddx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AsyncAzureOpenAItIterable[Iterable[_T]]returnlist[_T]c                    d | D             S )Nc                    g | ]	}|D ]}|
S  r'   ).0sublistitems      h/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/openai/_utils/_utils.py
<listcomp>zflatten.<locals>.<listcomp>'   s%    666Wg66dD6666    r'   )r!   s    r+   flattenr.   &   s    666666r-   queryMapping[str, object]pathsSequence[Sequence[str]]list[tuple[str, FileTypes]]c          	     `    g }|D ](}|                     t          | |dd                     )|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/   r1   filespaths       r+   extract_filesr<   *   sE     *,E O O^E4qMMMNNNNLr-   objobjectr;   Sequence[str]r6   intr7   
str | Nonec          	        	          }n# t           $ r t          | t                    rg cY S ddlm} J t          |           rLg }| D ]C} ||rdz   nd           |                    dz   t          t          |          f           D|cY S  ||            t          t          |           fgcY S w xY wdz  t          |           rf	 t                    k    r|                     |          }n| |         }n# t          $ r g cY S w xY w|n	d| dz  t          |	          S t          |           r%|d
k    rg S t          fd| D                       S g S )Nr   )assert_is_file_content[] )key   []r5   z<array>c           	     D    g | ]}t          |dz   nd          S )NrD   r5   )r9   )r(   r*   r7   r6   r;   s     r+   r,   z"_extract_items.<locals>.<listcomp>w   sV         :G:S-$"6"6Y]	    r-   )
IndexError
isinstancer   _filesrC   is_listappendr   r   is_dictlenpopKeyErrorr9   r.   )	r=   r;   r6   r7   rF   rC   r:   entryr*   s	    ```     r+   r9   r9   =   s<   75k 7 7 7c8$$ 	III 	433333 (((3<< 	13E M M&&u-2_-$2F2F]_````md2DE4J4JKLLLLLLLs6666Y 4 456666'7* 
QJEs|| $

	D		e##wws||3x 	 	 	 III		
  MMZZZZ'M'	
 
 
 	
 
 
)I         

 

 
	
 Is-    !B>A#B>%B>=B>1D DDNotGivenOr[_T]TypeGuard[_T]c                .    t          | t                     S NrL   r   r=   s    r+   is_givenr[      s    #x((((r-   TypeGuard[tuple[object, ...]]c                ,    t          | t                    S rX   rL   tuplerZ   s    r+   is_tupler`          c5!!!r-   _TupleT | objectTypeGuard[_TupleT]c                ,    t          | t                    S rX   r^   rZ   s    r+   
is_tuple_tre      ra   r-   TypeGuard[Sequence[object]]c                ,    t          | t                    S rX   rL   r   rZ   s    r+   is_sequenceri          c8$$$r-   _SequenceT | objectTypeGuard[_SequenceT]c                ,    t          | t                    S rX   rh   rZ   s    r+   is_sequence_trn      rj   r-   TypeGuard[Mapping[str, object]]c                ,    t          | t                    S rX   rL   r   rZ   s    r+   
is_mappingrr          c7###r-   _MappingT | objectTypeGuard[_MappingT]c                ,    t          | t                    S rX   rq   rZ   s    r+   is_mapping_trw      rs   r-   TypeGuard[dict[object, object]]c                ,    t          | t                    S rX   )rL   dictrZ   s    r+   rP   rP          c4   r-   TypeGuard[list[object]]c                ,    t          | t                    S rX   )rL   listrZ   s    r+   rN   rN      r{   r-   TypeGuard[Iterable[object]]c                ,    t          | t                    S rX   )rL   r
   rZ   s    r+   is_iterabler      rj   r-   r*   c                    t          |           r1t          t          d |                                 D                       S t	          |           rt          t          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                4    i | ]\  }}|t          |          S r'   deepcopy_minimal)r(   kvs      r+   
<dictcomp>z$deepcopy_minimal.<locals>.<dictcomp>   s'    IIIDAq,Q//IIIr-   c                ,    g | ]}t          |          S r'   r   )r(   rT   s     r+   r,   z$deepcopy_minimal.<locals>.<listcomp>   s!    CCCU)%00CCCr-   )rr   r   r   itemsrN   )r*   s    r+   r   r      so     $ KBIIDJJLLIIIJJJt}} EBCCdCCCDDDKr-   z, or)delimfinalseqr   strr   c                   t          |           }|dk    rdS |dk    r| d         S |dk    r| d          d| d| d          S |                    | d d                   d| d| d          z   S )Nr   rE   rG   r    )rQ   join)r   r   r   sizes       r+   
human_joinr      s    s88Dqyyrqyy1vqyya&++5++3q6+++::c#2#h"7e"7"7c"g"7"777r-   stringc                    d|  dS )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r'   )r   s    r+   quoter      s    v===r-   variants Callable[[CallableT], CallableT]c                      d f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: ...
    ```
    funcr   r#   c                     t          j                   j        }d |                                D             t	          j                   d fd            }|S )Nc                B    g | ]\  }}|j         |j        |j        hv |S r'   )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)r(   nameparams      r+   r,   z0required_args.<locals>.inner.<locals>.<listcomp>   sL     
 
 
ez%+    r-   argsr>   kwargsr#   c                 H  
 t                      
t          |           D ]g\  }}	 
                    |                    "# t          $ r9 t	          j         dt                     dt          |            d          d w xY w|                                D ]}
                    |           D ]!}t          
fd|D                       }|r nŌ"t                    dk    r t          d D                       }d| d}nt                    d	k    sJ t          t          d	                   
z
            }	t          |	          dk    rd
t          d |	D                        }ndt          |	d	                    }t	          |           | i |S )Nz	() takes z argument(s) but z were givenc              3      K   | ]}|v V  	d S rX   r'   )r(   r   given_paramss     r+   	<genexpr>z@required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>  s(      JJu4JJJJJJr-   rG   c                P    g | ]#}d t          d |D             d          z   dz   $S )(c                ,    g | ]}t          |          S r'   r   r(   args     r+   r,   zLrequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>.<listcomp>  s    *I*I*I#5::*I*I*Ir-   and)r   ))r   )r(   variants     r+   r,   zArequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>  sA    vvvbiz*I*I*I*I*IQVWWWWZ]]vvvr-   z,Missing required arguments; Expected either z arguments to be givenr   zMissing required arguments: c                ,    g | ]}t          |          S r'   r   r   s     r+   r,   zArequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>  s    HgHgHgX[sHgHgHgr-   zMissing required argument: )set	enumerateaddrK   	TypeError__name__rQ   keysallr   r~   r   )r   r   i_rF   r   matches
variationsmsgmissingr   r   
positionalr   s             @r+   wrapperz-required_args.<locals>.inner.<locals>.wrapper   s	   %(UUL!$    1  $$Z]3333!      #=kk3z??kkUXY]U^U^kkk   
 {{}} & &  %%%%# % %JJJJ'JJJKK E x==1$$!+vvmuvvv" "J lkkkCCx==1,,,, #3x{#3#3l#BCCG7||a''jZHgHg_fHgHgHg=h=hjjOE'!*<M<MOOnn$4((((s   AAB)r   r>   r   r>   r#   r>   )inspect	signature
parametersr   	functoolswraps)r   paramsr   r   r   s   `  @r+   innerzrequired_args.<locals>.inner   s    "4((3
 
%||~~
 
 

 
		!	) !	) !	) !	) !	) !	) !	) 
	!	)F r-   )r   r   r#   r   r'   )r   r   s   ` r+   required_argsr      s)    ,0 0 0 0 0 0d Lr-   _K_VNonec                    d S rX   r'   rZ   s    r+   strip_not_givenr   *  s    (+r-   Mapping[_K, _V | NotGiven]dict[_K, _V]c                    d S rX   r'   rZ   s    r+   r   r   .  s    FIcr-   c                    d S rX   r'   rZ   s    r+   r   r   2  s    ,/Cr-   object | Nonec                h    | dS t          |           s| S d |                                 D             S )zHRemove all top-level keys where their values are instances of `NotGiven`Nc                D    i | ]\  }}t          |t                    ||S r'   rY   r(   rF   values      r+   r   z#strip_not_given.<locals>.<dictcomp>>  s-    XXX:3Juh<W<WXCXXXr-   )rr   r   rZ   s    r+   r   r   6  s;    
{tc?? 
XXXXXXr-   valc                $    t          | d          S )N
   )base)r@   r   s    r+   coerce_integerr   A  s    sr-   floatc                     t          |           S rX   )r   r   s    r+   coerce_floatr   E  s    ::r-   boolc                &    | dk    p| dk    p| dk    S )Ntrue1onr'   r   s    r+   coerce_booleanr   I  s    &=5C3J5#+5r-   
int | Nonec                (    | d S t          |           S rX   )r   r   s    r+   maybe_coerce_integerr   M      
{t#r-   float | Nonec                (    | d S t          |           S rX   )r   r   s    r+   maybe_coerce_floatr   S  s    
{tr-   bool | Nonec                (    | d S t          |           S rX   )r   r   s    r+   maybe_coerce_booleanr   Y  r   r-   prefixc                ^    |                      |          r| t          |          d         S | S )zXRemove a prefix from a string.

    Backport of `str.removeprefix` for Python < 3.9
    N)
startswithrQ   )r   r   s     r+   removeprefixr   _  s4    
    %c&kkmm$$Mr-   suffixc                `    |                      |          r| dt          |                    S | S )zXRemove a suffix from a string.

    Backport of `str.removesuffix` for Python < 3.9
    N)endswithrQ   )r   r   s     r+   removesuffixr   i  s4    
 v &nVn%%Mr-   r   c                    t          |                                           }t          j                            |           }||fS rX   )r   
read_bytesosr;   basename)r;   contents	file_names      r+   file_from_pathr  s  s9    Dzz$$&&H  &&Ix  r-   headersr   headerc                   |                                 }t          |           rK|                                 D ]6\  }}|                                 |k    rt          |t                    r|c S 7t          j        dd |                                          }|||                                |fD ]}| 	                    |          }|r|c S t          d| d          )Nz([^\w])(\w)c                |    |                      d          |                      d                                          z   S )NrG   r   )groupupper)pats    r+   <lambda>z%get_required_header.<locals>.<lambda>  s,    #))A,,STI[I[I]I]:] r-   zCould not find z header)lowerrw   r   rL   r   resub
capitalizer  get
ValueError)r  r  lower_headerr   r   intercaps_headernormalized_headerr   s           r+   get_required_headerr  y  s    <<>>LG MMOO 	 	DAqwwyyL((Z3-?-?( vn.].]_e_p_p_r_rss$lFLLNNDTU  -.. 	LLL	 6v666
7
77r-   c                 L    	 t          j                    S # t          $ r Y dS w xY w)Nfalse)sniffiocurrent_async_library	Exceptionr'   r-   r+   get_async_libraryr    s8    ,...   wws    
##   maxsizer  c                V    t          j        |           }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   s     r+   r  r    s0     !  G Wr-   datac                :   t          |           rd |                                 D             S t          |           r.t          | t          t
          t          f          sd | D             S t          | t          t          f          r| 	                                S | S )zvTranslates a mapping / sequence recursively in the same fashion
    as `pydantic` v2's `model_dump(mode="json")`.
    c                N    i | ]"\  }}t          |          t          |          #S r'   	json_safer   s      r+   r   zjson_safe.<locals>.<dictcomp>  s,    PPPZS%	#	% 0 0PPPr-   c                ,    g | ]}t          |          S r'   r"  )r(   r*   s     r+   r,   zjson_safe.<locals>.<listcomp>  s    111D	$111r-   )
rr   r   r   rL   r   bytes	bytearrayr   r   	isoformat)r  s    r+   r#  r#    s     $ QPP4::<<PPPP4 2D3y2I!J!J 211D1111$4())  ~~Kr-   clientTypeGuard[AzureOpenAI]c                .    ddl m} t          | |          S )Nr   )r   )	lib.azurer   rL   )r(  r   s     r+   is_azure_clientr,    s$    ''''''fk***r-   TypeGuard[AsyncAzureOpenAI]c                .    ddl m} t          | |          S )Nr   )r    )r+  r    rL   )r(  r    s     r+   is_async_azure_clientr/    s%    ,,,,,,f.///r-   )r!   r"   r#   r$   )r/   r0   r1   r2   r#   r3   )
r=   r>   r;   r?   r6   r@   r7   rA   r#   r3   )r=   rU   r#   rV   )r=   r>   r#   r\   )r=   rb   r#   rc   )r=   r>   r#   rf   )r=   rk   r#   rl   )r=   r>   r#   ro   )r=   rt   r#   ru   )r=   r>   r#   rx   )r=   r>   r#   r|   )r=   r>   r#   r   )r*   r   r#   r   )r   r?   r   r   r   r   r#   r   )r   r   r#   r   )r   r?   r#   r   )r=   r   r#   r   )r=   r   r#   r   )r=   r>   r#   r>   )r=   r   r#   r>   )r   r   r#   r@   )r   r   r#   r   )r   r   r#   r   )r   rA   r#   r   )r   rA   r#   r   )r   rA   r#   r   )r   r   r   r   r#   r   )r   r   r   r   r#   r   )r;   r   r#   r   )r  r   r  r   r#   r   )r#   r   )r  r   r#   r   )r  r>   r#   r>   )r(  r>   r#   r)  )r(  r>   r#   r-  )M
__future__r   r   r  r   r   typingr   r   r   r   r   r	   r
   r   r   r   pathlibr   r   r   typing_extensionsr   r  _typesr   r   r   r   _compatr   r   r   r>   r   r   r   r   r   r+  r   r    r.   r<   r9   r[   r`   re   ri   rn   rr   rw   rP   rN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r#  r,  r/  r'   r-   r+   <module>r6     s   " " " " " " 				 				                                   # # # # # # # # ' ' ' ' ' '  A A A A A A A A A A A A P P P P P P P PWT]]
')5#5
6
6
6GKwsF{';<<<	W\&)9:::
GKxS'9:::	 :999999997 7 7 7   &F F F FR) ) ) )" " " "" " " "% % % %% % % %$ $ $ $$ $ $ $! ! ! !! ! ! !% % % %     48d 8 8 8 8 8 8   
H H H HV WT]]WT]] 
 + + + 
 + 
 I I I 
 I 
 / / / 
 /Y Y Y Y      6 6 6 6               ! ! ! !8 8 8 8&    (+          + + + +0 0 0 0 0 0r-   