
    хi.                       S SK Jr  S SKrS SKrS SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJr  S SKJr  S SKJrJr  S SKJr  S SKrSSKJrJrJrJr  SS	KJrJr  \
" S
5      r\
" S\\ S4   S9r!\
" S\	\"\ 4   S9r#\
" S\\    S9r$\
" S\S\4   S9r%S:S jr&      S;S jr'          S<S jr(S=S jr)S>S jr*S?S jr+S@S jr,SAS jr-SBS jr.SCS jr/SDS jr0SES jr1SFS jr2SGS jr3SS S!.SHS" jjr4SIS# jr5SJS$ jr6\
" S%5      r7\
" S&5      r8\SKS' j5       r9\SLS( j5       r9\SMS) j5       r9SNS* jr9SOS+ jr:SPS, jr;SQS- jr<SRS. jr=SSS/ jr>STS0 jr?SUS1 jr@SVS2 jrASWS3 jrBSXS4 jrCSYS5 jrDS6S7.SZS8 jjrES[S9 jrFg)\    )annotationsN)	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	CallableTc                H    U  VVs/ s H  o  H  o"PM     M     snn$ s  snnf N )tsublistitems      N/home/james-whalen/.local/lib/python3.13/site-packages/openai/_utils/_utils.pyflattenr%   "   s"     !6WgdDgD666s   c          
     P    / nU H  nUR                  [        XSSS95        M     U$ )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)querypathsfilespaths       r$   extract_filesr0   &   s-     *,E^EqMN L    c                   X   nUS-  n[        U 5      (       aB   [        U5      U:X  a  U R                  U5      nOX   n Uc  UnO	USU S3-  n[        UUUUS9$ [        U 5      (       a6  US:w  a  / $ [        U  Vs/ s H  n[        UUUUb  US	-   OS	S9PM     sn5      $ / $ ! [          a@    [        U [        5      (       a  / s $ SSKJn  U" XS9  Uc   eU[        [        U 5      4/s $ f = f! [         a    / s $ f = fs  snf )
Nr   )assert_is_file_content)key   []r'   z<array>z[])
IndexError
isinstancer   _filesr3   r   r   is_dictlenpopKeyErrorr+   is_listr%   )objr/   r(   r)   r4   r3   r#   s          r$   r+   r+   9   sY   7k 
QJEs||
	D	e#wws|x  MqQZ'M'	
 	
 
)I    D :G:S-$"6Y]	  

 
	
 Ik  7c8$$I 	4 	s6(((Y 45667*  	 I		(s3   B%  C2 C2 >D%!C/$C/.C/2D Dc                ,    [        U [        5      (       + $ r   )r9   r   r@   s    r$   is_givenrC   z   s    #x(((r1   c                "    [        U [        5      $ r   r9   tuplerB   s    r$   is_tuplerG          c5!!r1   c                "    [        U [        5      $ r   rE   rB   s    r$   
is_tuple_trJ      rH   r1   c                "    [        U [        5      $ r   r9   r
   rB   s    r$   is_sequencerM          c8$$r1   c                "    [        U [        5      $ r   rL   rB   s    r$   is_sequence_trP      rN   r1   c                "    [        U [        5      $ r   r9   r   rB   s    r$   
is_mappingrS          c7##r1   c                "    [        U [        5      $ r   rR   rB   s    r$   is_mapping_trV      rT   r1   c                "    [        U [        5      $ r   )r9   dictrB   s    r$   r;   r;          c4  r1   c                "    [        U [        5      $ r   )r9   listrB   s    r$   r?   r?      rY   r1   c                "    [        U [        5      $ r   )r9   r	   rB   s    r$   is_iterabler]      rN   r1   c                *   [        U 5      (       a=  [        [        U R                  5        VVs0 s H  u  pU[	        U5      _M     snn5      $ [        U 5      (       a*  [        [        U  Vs/ s H  n[	        U5      PM     sn5      $ U $ s  snnf s  snf )zMinimal reimplementation of copy.deepcopy() that will only copy certain object types:

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

This is done for performance reasons.
)rS   r   r   itemsdeepcopy_minimalr?   )r#   kventrys       r$   r`   r`      sw     $BDJJLILDA,Q//LIJJt}}BdCdU)%0dCDDK JCs   B
,B
z, or)delimfinalc                   [        U 5      nUS:X  a  gUS:X  a  U S   $ US:X  a  U S    SU SU S    3$ UR                  U S S 5      SU SU S    3-   $ )Nr    r5   r    )r<   join)seqre   rf   sizes       r$   
human_joinrn      sv    s8Dqyqy1vqya&5'3q6(++::c#2hAeWAc"gY"777r1   c                    SU  S3$ )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r    )strings    r$   quoterr      s    vha=r1   c                    ^  SU 4S jjnU$ )a   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: ...
```
c                8  >^ ^ [         R                  " T 5      R                  nUR                  5        VVs/ s H/  u  p#UR                  UR
                  UR                  1;   d  M-  UPM1     snnm[        R                  " T 5      SU UU4S jj5       nU$ s  snnf )Nc                 n  >^ [        5       m[        U 5       H  u  p# TR                  TU   5        M     UR                  5        H  nTR                  U5        M     T H!  n[        U4S jU 5       5      nU(       d  M!    O   [        T5      S:  aM  [        T VVs/ s H-  nS[        U Vs/ s H  n[        U5      PM     snSS9-   S	-   PM/     snn5      nS
U S3n	Ot[        T5      S:  d   e[        [        TS   5      T-
  5      n
[        U
5      S:  a)  S[        U
 Vs/ s H  n[        U5      PM     sn5       3n	OS[        U
S   5       3n	[	        U	5      eT" U 0 UD6$ ! [         a2    [	        TR
                   S[        T5       S[        U 5       S35      S ef = fs  snf s  snnf s  snf )Nz	() takes z argument(s) but z were givenc              3  ,   >#    U  H	  oT;   v   M     g 7fr   r    ).0paramgiven_paramss     r$   	<genexpr>@required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>   s     J'4's   r5   (and)rf   )z,Missing required arguments; Expected either z arguments to be givenr   zMissing required arguments: zMissing required argument: )set	enumerateaddr8   	TypeError__name__r<   keysallrn   rr   r[   )argskwargsi_r4   variantmatchesarg
variationsmsgmissingry   func
positionalvariantss              @r$   wrapper-required_args.<locals>.inner.<locals>.wrapper   s   %(UL!$  $$Z]3 ( {{}  % % $J'JK7 $
 x=1$!+muvmubiz*I#5:*IQVWWZ]]muv"J ITjkCx=1,,, #3x{#3l#BCG7|a' <Z_fHg_fX[s_fHg=h<ij ;E'!*<M;NOn$(((9 "  #==/3z?2CCTUXY]U^T__jk   +Jv Ihs)   E(F,
.F'F,
%F2
(<F$'F,
)r   objectr   r   returnr   )	inspect	signature
parametersr_   kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD	functoolswraps)r   paramsnamerx   r   r   r   s   `    @r$   innerrequired_args.<locals>.inner   s    ""4(33  &||~
-zz%%++ -

 
	!	) !	) 
!	)F ]
s   ,B'B)r   r   r   r   r    )r   r   s   ` r$   required_argsr      s    ,0d Lr1   _K_Vc                    g r   r    rB   s    r$   strip_not_givenr     s    (+r1   c                    g r   r    rB   s    r$   r   r   "  s    FIr1   c                    g r   r    rB   s    r$   r   r   &  s    ,/r1   c                    U c  g[        U 5      (       d  U $ U R                  5        VVs0 s H  u  p[        U[        5      (       a  M  X_M      snn$ s  snnf )zHRemove all top-level keys where their values are instances of `NotGiven`N)rS   r_   r9   r   )r@   r4   values      r$   r   r   *  sE    
{c??
),X:3Juh<WJCJXXXs   A	Ac                    [        U SS9$ )N
   )base)intvals    r$   coerce_integerr   5  s    sr1   c                    [        U 5      $ r   )floatr   s    r$   coerce_floatr   9  s    :r1   c                <    U S:H  =(       d    U S:H  =(       d    U S:H  $ )Ntrue1onr    r   s    r$   coerce_booleanr   =  s    &=5C3J5#+5r1   c                     U c  g [        U 5      $ r   )r   r   s    r$   maybe_coerce_integerr   A      
{#r1   c                     U c  g [        U 5      $ r   )r   r   s    r$   maybe_coerce_floatr   G  s    
{r1   c                     U c  g [        U 5      $ r   )r   r   s    r$   maybe_coerce_booleanr   M  r   r1   c                N    U R                  U5      (       a  U [        U5      S $ U $ )zPRemove a prefix from a string.

Backport of `str.removeprefix` for Python < 3.9
N)
startswithr<   )rq   prefixs     r$   removeprefixr   S  s+    
   c&km$$Mr1   c                P    U R                  U5      (       a  U S[        U5      *  $ U $ )zPRemove a suffix from a string.

Backport of `str.removesuffix` for Python < 3.9
N)endswithr<   )rq   suffixs     r$   removesuffixr   ]  s+    
 vnV%%Mr1   c                x    [        U 5      R                  5       n[        R                  R	                  U 5      nX!4$ r   )r   
read_bytesosr/   basename)r/   contents	file_names      r$   file_from_pathr   g  s1    Dz$$&H  &I  r1   c                   UR                  5       n[        U 5      (       aH  U R                  5        H4  u  p4UR                  5       U:X  d  M  [        U[        5      (       d  M2  Us  $    [
        R                  " SS UR                  5       5      nXUR                  5       U4 H  nU R                  U5      nU(       d  M  Us  $    [        SU S35      e)Nz([^\w])(\w)c                d    U R                  S5      U R                  S5      R                  5       -   $ )Nr5   r   )groupupper)pats    r$   <lambda>%get_required_header.<locals>.<lambda>v  s#    #))A,STI[I[I]:]r1   zCould not find z header)lowerrV   r_   r9   strresub
capitalizer   get
ValueError)headersheaderlower_headerra   rb   intercaps_headernormalized_headerr   s           r$   get_required_headerr   m  s    <<>LGMMODAwwyL(Z3-?-? $
 vvn.]_e_p_p_rs$FLLNDTU-.5L V
 vhg6
77r1   c                 N     [         R                  " 5       $ ! [         a     gf = f)Nfalse)sniffiocurrent_async_library	Exceptionr    r1   r$   get_async_libraryr     s(    ,,.. s    
$$   maxsizec                J    [         R                  " U S9n[        [        U5      $ )zeA 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     s&     !!G Wr1   c                   [        U 5      (       a8  U R                  5        VVs0 s H  u  p[        U5      [        U5      _M     snn$ [        U 5      (       a<  [	        U [
        [        [        45      (       d  U  Vs/ s H  n[        U5      PM     sn$ [	        U [        [        45      (       a  U R                  5       $ U $ s  snnf s  snf )znTranslates a mapping / sequence recursively in the same fashion
as `pydantic` v2's `model_dump(mode="json")`.
)rS   r_   	json_safer]   r9   r   bytes	bytearrayr   r   	isoformat)datar4   r   r#   s       r$   r   r     s     $CG::<P<ZS	#	% 00<PP4D3y2I!J!J,01DD	$D11$4())~~K Q 2s   !C=C)r!   zIterable[Iterable[_T]]r   zlist[_T])r,   zMapping[str, object]r-   zSequence[Sequence[str]]r   list[tuple[str, FileTypes]])
r@   r   r/   Sequence[str]r(   r   r)   
str | Noner   r   )r@   zNotGivenOr[_T]r   zTypeGuard[_T])r@   r   r   zTypeGuard[tuple[object, ...]])r@   z_TupleT | objectr   zTypeGuard[_TupleT])r@   r   r   zTypeGuard[Sequence[object]])r@   z_SequenceT | objectr   zTypeGuard[_SequenceT])r@   r   r   zTypeGuard[Mapping[str, object]])r@   z_MappingT | objectr   zTypeGuard[_MappingT])r@   r   r   zTypeGuard[dict[object, object]])r@   r   r   zTypeGuard[list[object]])r@   r   r   zTypeGuard[Iterable[object]])r#   r   r   r   )rl   r   re   r   rf   r   r   r   )rq   r   r   r   )r   r   r    Callable[[CallableT], CallableT])r@   Noner   r   )r@   zMapping[_K, _V | NotGiven]r   zdict[_K, _V])r@   r   r   r   )r@   zobject | Noner   r   )r   r   r   r   )r   r   r   r   )r   r   r   bool)r   r   r   
int | None)r   r   r   zfloat | None)r   r   r   zbool | None)rq   r   r   r   r   r   )rq   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   )G
__future__r   r   r   r   r   typingr   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%   r0   r+   rC   rG   rJ   rM   rP   rS   rV   r;   r?   r]   r`   rn   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r1   r$   <module>r     s   " 	 	  
 
 
  # '  A A PT]
)5#5
6KwsF{';<	\&)9:
KxS'9:	7  
 # !&>	>
> 	>
 > !>B)""%%$$!!%  48d 8
HV T]T] 
 + 
 + 
 I 
 I 
 / 
 /Y6!8& (+ r1   