
    _j3                       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Jr  S SKrSSKJrJrJr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.       S=S j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r-SES jr.SFS jr/SGS jr0SHS jr1SIS jr2SJS  jr3S!S"S#.SKS$ jjr4SLS% jr5SMS& jr6\
" S'5      r7\
" S(5      r8\SNS) j5       r9\SOS* j5       r9\SPS+ j5       r9SQS, jr9SRS- jr:SSS. jr;STS/ jr<SUS0 jr=SVS1 jr>SWS2 jr?SXS3 jr@SYS4 jrASZS5 jrBS[S6 jrCS\S7 jrDS8S9.S]S: jjrES^S; jrFg)_    )annotationsN)	AnyTupleMappingTypeVarCallableIterableSequencecastoverload)Path)datedatetime)	TypeGuardget_args   )OmitNotGiven	FileTypesArrayFormatHeadersLike_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      K/home/rurouni/.local/lib/python3.13/site-packages/parallel/_utils/_utils.pyflattenr%   !   s"     !6WgdDgD666s   brackets)array_formatc               R    / nU H  nUR                  [        XSSUS95        M      U$ )a  Recursively extract files from the given dictionary based on specified paths.

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

``array_format`` controls how ``<array>`` segments contribute to the emitted
field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and
``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``).

Note: this mutates the given dictionary.
r   Nindexflattened_keyr'   )extend_extract_items)querypathsr'   filespaths        r$   extract_filesr2   %   s0    $ *,E^Eq[ghi L    c           
         U S:X  a  gU S:X  a  SU S3$ U S:X  d  U S:X  a  g[        S	U  S
SR                  [        [        5      5       35      e)Nr&   z[]indices[]repeatcomma zUnknown array_format value: z, choose from , )NotImplementedErrorjoinr   r   )r'   array_indexs     r$   _array_suffixr?   =   se    z!y ;-q!!x<7#: 

&|nN499XVaMbCcBde r3   c                    X   nUS-  n[        U 5      (       aM   [        S XS   5       5      (       a  U R                  U5      nOX   n Uc  UnO	USU S3-  n[        UUUUUS9$ [	        U 5      (       aM  US	:w  a  / $ [        [        U 5       VVs/ s H#  u  p[        UUUUb  UOS
[        XH5      -   US9PM%     snn5      $ / $ ! [          a    [        U 5      (       d  / s $ SSKJn  Uc   e[	        U 5      (       aY  / n[        U 5       HD  u  p[        XH5      n
U(       a  X:-   OU
nU" XS9  UR                  U[        [        U	5      45        MF     Us $ U" XS9  U[        [        U 5      4/s $ f = f! [         a    / s $ f = fs  snnf )Nr   )assert_is_file_content)key   c              3  *   #    U  H	  oS :H  v   M     g7f)<array>Nr    ).0ps     r$   	<genexpr>!_extract_items.<locals>.<genexpr>q   s     8<a	><s   r6   r7   r)   rE   r:   )
IndexErroris_given_filesrA   is_list	enumerater?   appendr   r   is_dictallpopKeyErrorr-   r%   )objr1   r*   r+   r'   rB   rA   r0   r>   entrysuffixemitted_keyr#   s                r$   r-   r-   K   s   7k0 
QJEs||	 84<888wws|x  MqQZ'M'%
 	
 
)I *33 *8%K *7*C}]iOww!- *8
 	
  II  7}}I 	4 (((3<<13E&/n"&|A:G}5V&u>k4	5+ABC	 '5
 Ls6Y 4566+7@  	 I		*s;   C *E8 E8 *F

E5%A2E5E54E58FFc                d    [        U [        5      (       + =(       a    [        U [        5      (       + $ r   )
isinstancer   r   rT   s    r$   rK   rK      s!    #x((FC1F-FFr3   c                "    [        U [        5      $ r   rY   tuplerZ   s    r$   is_tupler^          c5!!r3   c                "    [        U [        5      $ r   r\   rZ   s    r$   
is_tuple_tra      r_   r3   c                "    [        U [        5      $ r   rY   r
   rZ   s    r$   is_sequencerd          c8$$r3   c                "    [        U [        5      $ r   rc   rZ   s    r$   is_sequence_trg      re   r3   c                "    [        U [        5      $ r   rY   r   rZ   s    r$   
is_mappingrj          c7##r3   c                "    [        U [        5      $ r   ri   rZ   s    r$   is_mapping_trm      rk   r3   c                "    [        U [        5      $ r   )rY   dictrZ   s    r$   rP   rP          c4  r3   c                "    [        U [        5      $ r   )rY   strrZ   s    r$   is_strrs      s    c3r3   c                "    [        U [        5      $ r   )rY   listrZ   s    r$   rM   rM      rp   r3   c                "    [        U [        5      $ r   )rY   r	   rZ   s    r$   is_iterablerw      re   r3   r;   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   r:   rC   r    )lenr=   )seqry   rz   sizes       r$   
human_joinr      sv    s8Dqyqy1vqya&5'3q6(++::c#2hAeWAc"gY"777r3   c                    SU  S3$ )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r    )strings    r$   quoter      s    vha=r3   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    )rF   paramgiven_paramss     r$   rH   @required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>  s     J'4's   rC   (and)rz   )z,Missing required arguments; Expected either z arguments to be givenr   zMissing required arguments: zMissing required argument: )setrN   addrJ   	TypeError__name__r~   keysrQ   r   r   ru   )argskwargsi_rB   variantmatchesarg
variationsmsgmissingr   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
parametersitemskindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD	functoolswraps)r   paramsnamer   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 Lr3   _K_Vc                    g r   r    rZ   s    r$   strip_not_givenr   5  s    (+r3   c                    g r   r    rZ   s    r$   r   r   9  s    FIr3   c                    g r   r    rZ   s    r$   r   r   =  s    ,/r3   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)rj   r   rY   r   )rT   rB   values      r$   r   r   A  sE    
{c??
),X:3Juh<WJCJXXXs   A	Ac                    [        U SS9$ )N
   )base)intvals    r$   coerce_integerr   L  s    sr3   c                    [        U 5      $ r   )floatr   s    r$   coerce_floatr   P  s    :r3   c                <    U S:H  =(       d    U S:H  =(       d    U S:H  $ )Ntrue1onr    r   s    r$   coerce_booleanr   T  s    &=5C3J5#+5r3   c                     U c  g [        U 5      $ r   )r   r   s    r$   maybe_coerce_integerr   X      
{#r3   c                     U c  g [        U 5      $ r   )r   r   s    r$   maybe_coerce_floatr   ^  s    
{r3   c                     U c  g [        U 5      $ r   )r   r   s    r$   maybe_coerce_booleanr   d  r   r3   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~   )r   prefixs     r$   removeprefixr   j  s+    
   c&km$$Mr3   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~   )r   rV   s     r$   removesuffixr   t  s+    
 vnV%%Mr3   c                x    [        U 5      R                  5       n[        R                  R	                  U 5      nX!4$ r   )r   
read_bytesosr1   basename)r1   contents	file_names      r$   file_from_pathr   ~  s1    Dz$$&H  &I  r3   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       -   $ )NrC   r   )groupupper)pats    r$   <lambda>%get_required_header.<locals>.<lambda>  s#    #))A,STI[I[I]:]r3   zCould not find z header)lowerrm   r   rY   rr   resub
capitalizer   get
ValueError)headersheaderlower_headerkvintercaps_headernormalized_headerr   s           r$   get_required_headerr     s    <<>LGMMODAwwyL(Z3-?-? $
 vvn.]_e_p_p_rs$FLLNDTU-.5L V
 vhg6
77r3   c                 N     [         R                  " 5       $ ! [         a     gf = f)Nfalse)sniffiocurrent_async_library	Exceptionr    r3   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r3   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")`.
)rj   r   	json_saferw   rY   rr   bytes	bytearrayr   r   	isoformat)datarB   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'   r   r   list[tuple[str, FileTypes]])r'   r   r>   r   r   rr   )rT   r   r1   Sequence[str]r*   r   r+   
str | Noner'   r   r   r  )rT   z_T | NotGiven | Omitr   zTypeGuard[_T])rT   r   r   zTypeGuard[tuple[object, ...]])rT   z_TupleT | objectr   zTypeGuard[_TupleT])rT   r   r   zTypeGuard[Sequence[object]])rT   z_SequenceT | objectr   zTypeGuard[_SequenceT])rT   r   r   zTypeGuard[Mapping[str, object]])rT   z_MappingT | objectr   zTypeGuard[_MappingT])rT   r   r   zTypeGuard[dict[object, object]])rT   r   r   zTypeGuard[str])rT   r   r   zTypeGuard[list[object]])rT   r   r   zTypeGuard[Iterable[object]])r   r  ry   rr   rz   rr   r   rr   )r   rr   r   rr   )r   r  r    Callable[[CallableT], CallableT])rT   Noner   r
  )rT   zMapping[_K, _V | NotGiven]r   zdict[_K, _V])rT   r   r   r   )rT   zobject | Noner   r   )r   rr   r   r   )r   rr   r   r   )r   rr   r   bool)r   r  r   
int | None)r   r  r   zfloat | None)r   r  r   zbool | None)r   rr   r   rr   r   rr   )r   rr   rV   rr   r   rr   )r1   rr   r   r   )r   r   r   rr   r   rr   )r   rr   )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   r   _typesr   r   r   r   r   r   r   r   rr   r   r   r   r%   r2   r?   r-   rK   r^   ra   rd   rg   rj   rm   rP   rs   rM   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r    r3   r$   <module>r     s   " 	 	  
 
 
  # 1  H HT]
)5#5
6KwsF{';<	\&)9:
KxS'9:	7 !+  
 #  !0N	N
N 	N
 N N !NbG""%%$$! !%
 48d 8
HV T]T] 
 + 
 + 
 I 
 I 
 / 
 /Y6!8& (+ r3   