
    f ja+                       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                   Z  e
de	e!ef                   Z" e
dee                   Z# e
dedef                   Z$dldZ%dmdZ&dnd#Z'dod&Z(dpd(Z)dqd+Z*drd-Z+dsd0Z,dtd2Z-dud5Z.dvd7Z/dwd9Z0dxd;Z1dyd=Z2d>d?d@dzdEZ3d{dGZ4d|dJZ5 e
dK          Z6 e
dL          Z7ed}dN            Z8ed~dQ            Z8eddR            Z8ddTZ8ddVZ9ddXZ:ddZZ;dd\Z<dd^Z=dd`Z>ddbZ?dddZ@ddfZAddjZBddk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	CallableTtIterable[Iterable[_T]]returnlist[_T]c                    d | D             S )Nc                    g | ]	}|D ]}|
S  r#   ).0sublistitems      hC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\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+   r-   filespaths       r'   extract_filesr8   %   sE     *,E O O^E4qMMMNNNNLr)   objobjectr7   Sequence[str]r2   intr3   
str | Nonec               ,   	          }nX# t           $ rK t          | t                    rg cY S ddlm}  ||            J 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   []r1   z<array>c           	     D    g | ]}t          |dz   nd          S )Nz[]r1   )r5   )r$   r&   r3   r2   r7   s     r'   r(   z"_extract_items.<locals>.<listcomp>j   sV         :G"]-$"6"6Y]	    r)   )
IndexError
isinstancer   _filesr?   r   r   is_dictlenpopKeyErrorr5   is_listr*   )r9   r7   r2   r3   r@   r?   r&   s    ```   r'   r5   r5   8   s   75k 7 7 7c8$$ 	III 	433333 	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&    !A#/A#"A#;1B- -B<;B<NotGivenOr[_T]TypeGuard[_T]c                .    t          | t                     S NrF   r   r9   s    r'   is_givenrS   y   s    #x((((r)   TypeGuard[tuple[object, ...]]c                ,    t          | t                    S rP   rF   tuplerR   s    r'   is_tuplerX          c5!!!r)   _TupleT | objectTypeGuard[_TupleT]c                ,    t          | t                    S rP   rV   rR   s    r'   
is_tuple_tr]      rY   r)   TypeGuard[Sequence[object]]c                ,    t          | t                    S rP   rF   r
   rR   s    r'   is_sequencera          c8$$$r)   _SequenceT | objectTypeGuard[_SequenceT]c                ,    t          | t                    S rP   r`   rR   s    r'   is_sequence_trf      rb   r)   TypeGuard[Mapping[str, object]]c                ,    t          | t                    S rP   rF   r   rR   s    r'   
is_mappingrj          c7###r)   _MappingT | objectTypeGuard[_MappingT]c                ,    t          | t                    S rP   ri   rR   s    r'   is_mapping_tro      rk   r)   TypeGuard[dict[object, object]]c                ,    t          | t                    S rP   )rF   dictrR   s    r'   rH   rH          c4   r)   TypeGuard[list[object]]c                ,    t          | t                    S rP   )rF   listrR   s    r'   rL   rL      rs   r)   TypeGuard[Iterable[object]]c                ,    t          | t                    S rP   )rF   r	   rR   s    r'   is_iterablery      rb   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$   entrys     r'   r(   z$deepcopy_minimal.<locals>.<listcomp>   s!    CCCU)%00CCCr)   )rj   r   r   itemsrL   )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    rA   r    )rI   join)r   r   r   sizes       r'   
human_joinr      s    s88Dqy rqy 1vqy ,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 )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:
        ...
    ```
    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>   sJ     
 
 
ez%+

 
 
r)   argsr:   kwargsr   c                   
 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}nmt          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 rP   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)   rA   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addrE   	TypeError__name__rI   keysallr   rv   r   )r   r   i_r@   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$ P!+vvmuvvv" "J lkkkCC #3x{#3#3l#BCCG7||a' P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
 
%||~~
 
 

 
			) 	) 	) 	) 	) 	) 	) 
		)B r)   )r   r   r   r   r#   )r   r   s   ` r'   required_argsr      s)    2. . . . . .` Lr)   _K_VNonec                    d S rP   r#   rR   s    r'   strip_not_givenr         Cr)   Mapping[_K, _V | NotGiven]dict[_K, _V]c                    d S rP   r#   rR   s    r'   r   r   #  r   r)   c                    d S rP   r#   rR   s    r'   r   r   (  r   r)   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#   rQ   )r$   r@   values      r'   r   z#strip_not_given.<locals>.<dictcomp>5  s-    XXX:3Juh<W<WXCXXXr)   )rj   r   rR   s    r'   r   r   -  s>    
 tc?? 
XXXXXXr)   valc                $    t          | d          S )N
   )base)r<   r   s    r'   coerce_integerr   8  s    sr)   floatc                     t          |           S rP   )r   r   s    r'   coerce_floatr   <  s    ::r)   boolc                &    | dk    p| dk    p| dk    S )Ntrue1onr#   r   s    r'   coerce_booleanr   @  s    &=5C3J5#+5r)   
int | Nonec                (    | d S t          |           S rP   )r   r   s    r'   maybe_coerce_integerr   D      
 t#r)   float | Nonec                (    | d S t          |           S rP   )r   r   s    r'   maybe_coerce_floatr   J  s    
 tr)   bool | Nonec                (    | d S t          |           S rP   )r   r   s    r'   maybe_coerce_booleanr   P  r   r)   prefixc                ^    |                      |          r| t          |          d         S | S )zXRemove a prefix from a string.

    Backport of `str.removeprefix` for Python < 3.9
    N)
startswithrI   )r   r   s     r'   removeprefixr   V  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)endswithrI   )r   r   s     r'   removesuffixr   `  s4    
 v &nVn%%Mr)   r   c                    t          |                                           }t          j                            |           }||fS rP   )r   
read_bytesosr7   basename)r7   contents	file_names      r'   file_from_pathr   j  s9    Dzz$$&&H  &&Ix  r)   headersr   headerc                   |                                 }t          | t                    r`t          t          |           } |                                 D ]6\  }}|                                 |k    rt          |t                    r|c S 7	 t          j        dd |	                                          }|||
                                |fD ]}|                     |          }|r|c S t          d| d          )Nz([^\w])(\w)c                |    |                      d          |                      d                                          z   S )NrA   r   )groupupper)pats    r'   <lambda>z%get_required_header.<locals>.<lambda>y  s,    #))A,,STI[I[I]I]:] r)   zCould not find z header)lowerrF   r   r   r   r   r   resub
capitalizer  get
ValueError)r   r   lower_headerr~   r   intercaps_headernormalized_headerr   s           r'   get_required_headerr  p  s	   <<>>L'7## w((MMOO 	 	DAqwwyyL( Z3-?-? P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    
##)r   r   r   r    )r+   r,   r-   r.   r   r/   )
r9   r:   r7   r;   r2   r<   r3   r=   r   r/   )r9   rM   r   rN   )r9   r:   r   rT   )r9   rZ   r   r[   )r9   r:   r   r^   )r9   rc   r   rd   )r9   r:   r   rg   )r9   rl   r   rm   )r9   r:   r   rp   )r9   r:   r   rt   )r9   r:   r   rw   )r&   r   r   r   )r   r;   r   r   r   r   r   r   )r   r   r   r   )r   r;   r   r   )r9   r   r   r   )r9   r   r   r   )r9   r:   r   r:   )r9   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   )r7   r   r   r   )r   r   r   r   r   r   )r   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*   r8   r5   rS   rX   r]   ra   rf   rj   ro   rH   rL   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r#   r)   r'   <module>r     s   " " " " " " 				 				     
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       ' ' ' ' ' '  J J J J J J J J J J J J J J P P P P P P P PWT]]
')5#5
6
6
6GKwsF{';<<<	W\&)9:::
GKxS'9:::	7 7 7 7   &> > > >B) ) ) )" " " "" " " "% % % %% % % %$ $ $ $$ $ $ $! ! ! !! ! ! !% % % %     48d 8 8 8 8 8 8   
I I I IX WT]]WT]] 
   
 
   
 
   
Y Y Y Y      6 6 6 6               ! ! ! !8 8 8 8&     r)   