
    9iFW                     ^   S SK r S SKJrJrJrJrJrJr  S SKJ	r	J
r
  S SKJrJrJrJrJrJrJrJrJrJrJrJr   S SKJrJr  S	S
KJrJrJ r   \\/S4   r!\" S5      r"\" S\#\$\4   S9r%\&" 5       r'\S\\"   S\\"   4S j5       r(\SS.S\)S\\\"   /\\"   4   4S jj5       r( S:SS.S\\\"      S\)S\\\"   \\\"   /\\"   4   4   4S jjjr(S\\%   S\#SS4S jr*\	S\\%   S\4S j5       r+S\\%   S\#\$\4   4S jr,\\SSSSS4S\\-\!   \!4   S\\\4   S\\/ \4   \4   S\)S \)S!\\)   S"\)S#\\#   S$\S\4S% jjr.S\!4S& jr/S'\$S(\S)\SS4S* jr0S'\$S(\S+\1\S,4   SS4S- jr2S'\$S(\S+\1\S,4   SS4S. jr3S'\$S(\S+\1\S,4   SS4S/ jr4S'\$S(\S+\1\S,4   SS4S0 jr5S'\$S(\S+\1\S,4   SS4S1 jr6S'\$S(\S+\1\S,4   SS4S2 jr7S'\$S(\S)\SS4S3 jr8S4\S\!4S5 jr9S\S\)4S6 jr:S7\S\)4S8 jr;\\2\\3\-\4\#\5\1\6\<\70r=/ S9Qr>g! \ a/     S SKJrJr   GN! \ a    \" SS0 5      r\" SS0 5      r  GNf = ff = f);    N)_MISSING_TYPEMISSINGFieldfieldfieldsmake_dataclass)	lru_cachewraps)	AnnotatedAnyCallable
ForwardRefLiteralOptionalTypeTypeVarUnionget_args
get_originoverload)NotRequiredRequiredr    r      )#StrictDataclassClassValidationErrorStrictDataclassDefinitionError#StrictDataclassFieldValidationErrorTTypedDictType)boundclsreturnc                     g Nr   )r!   s    [/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/huggingface_hub/dataclasses.pystrictr&   /   s    %(    Faccept_kwargsr)   c                     g r$   r   r(   s    r%   r&   r&   3   s    LOr'   c                b   ^ S[         [           S[         [           4U4S jjnU b  U" U 5      $ U$ )a  
Decorator to add strict validation to a dataclass.

This decorator must be used on top of `@dataclass` to ensure IDEs and static typing tools
recognize the class as a dataclass.

Can be used with or without arguments:
- `@strict`
- `@strict(accept_kwargs=True)`

Args:
    cls:
        The class to convert to a strict dataclass.
    accept_kwargs (`bool`, *optional*):
        If True, allows arbitrary keyword arguments in `__init__`. Defaults to False.

Returns:
    The enhanced dataclass with strict validation on field assignment.

Example:
```py
>>> from dataclasses import dataclass
>>> from huggingface_hub.dataclasses import as_validated_field, strict, validated_field

>>> @as_validated_field
>>> def positive_int(value: int):
...     if not value >= 0:
...         raise ValueError(f"Value must be positive, got {value}")

>>> @strict(accept_kwargs=True)
... @dataclass
... class User:
...     name: str
...     age: int = positive_int(default=10)

# Initialize
>>> User(name="John")
User(name='John', age=10)

# Extra kwargs are accepted
>>> User(name="John", age=30, lastname="Doe")
User(name='John', age=30, *lastname='Doe')

# Invalid type => raises
>>> User(name="John", age="30")
huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'age':
    TypeError: Field 'age' expected int, got str (value: '30')

# Invalid value => raises
>>> User(name="John", age=-1)
huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'age':
    ValueError: Value must be positive, got -1
```
r!   r"   c           	        >^ ^^^^ [        T S5      (       d  [        ST R                   S35      e0 n[        T 5       H  n/ nUR	                  [        U5      5        UR                  R                  S5      nUb^  [        U[        5      (       d  U/nU H/  n[        U5      (       a  M  [        SUR                   SU S35      e   UR                  U5        X1UR                  '   M     UT l        T R                  mS[        S	[         S
[        SS 4U4S jjnUT l        T(       ab  T R"                  m[%        T5      S[        SS 4U U4S jj5       nUT l        T R&                  m[%        T5      S[         4U U4S jj5       nUT l        / n	[)        T 5       H  n
U
R+                  S5      (       d  M  [-        T U
5      n[/        U5      (       d  M9  [1        [2        R4                  " U5      R6                  5      S:w  a  [        ST R                   SU
 S35      eU	R	                  U5        M     U	T l        S[:        SS 4U 4S jjnSUl        [        T S5      (       a5  [-        T R>                  SS5      (       d  [        ST R                   S35      eUT l        T R"                  m[%        T5      SU U4S jj5       n[A        T SU5        T $ )N__dataclass_fields__zClass 'z.' must be a dataclass before applying @strict.	validatorzInvalid validator for field '': z.. Must be a callable taking a single argument.selfnamevaluer"   c                    > U R                   R                  U/ 5       H  n U" U5        M     T" XU5        g! [        [        4 a  n[	        XS9UeSnAff = f)z1Custom __setattr__ method for strict dataclasses.)r   causeN)__validators__get
ValueError	TypeErrorr   )r0   r1   r2   r.   eoriginal_setattrs        r%   __strict_setattr__0strict.<locals>.wrap.<locals>.__strict_setattr__   sc     "0044T2>	Ze$ ? T/	 #I. Z=DRXYYZs   8A
AAkwargsc                 .  > [        T	5       Vs1 s H  o"R                  iM     nnUR                  5        VVs0 s H  u  pEXC;   d  M  XE_M     nnnT
" U 40 UD6  UR                  5        H  u  pxXs;  d  M  U R                  Xx5        M     g s  snf s  snnf r$   )r   r1   items__setattr__)r0   r=   fdataclass_fieldskvstandard_kwargsr1   r2   r!   original_inits            r%   __init__&strict.<locals>.wrap.<locals>.__init__   s     5;3K#@KqFFK #@4:LLN"\NDAaF[414N"\ d6o6 $*<<>KD3((5 $2 $A"\s   BBBc                    > T" U 5      nU R                   R                  5        VVs/ s H   u  p#UTR                  ;  d  M  SU SU< 3PM"     nnnSR                  U5      nU(       a  US S  SU S3$ U$ s  snnf )N*=z, ))__dict__r?   r-   join)r0   standard_reprrC   rD   additional_kwargsadditional_reprr!   original_reprs         r%   __repr__&strict.<locals>.wrap.<locals>.__repr__   s     !.d 3 !% 3 3 5% !6 8 88 "as!A5M 5 " % #')),="> GX-,-R/@Bj]jj%s   A6A6	validate_r   z' has a class validator 'z' that takes more than one argument. Class validators must take only 'self' as an argument. Methods starting with 'validate_' are considered to be class validators.c                    > TR                    H  n U" U 5        M     g! [        [        4 a  n[        UR                  US9UeSnAff = f)z%Run class validators on the instance.)r.   r4   N)__class_validators__r7   r8   r   __name__)r0   r.   r9   r!   s      r%   validate&strict.<locals>.wrap.<locals>.validate   sP     55	ldO 6 #I. l=	HZHZbcdjkkls   A	AA	TrZ   "__is_defined_by_strict_decorator__Fz' already implements a method called 'validate'. This method name is reserved when using the @strict decorator on a dataclass. If you want to keep your own method, please rename it.c                 @   > T" U /UQ70 UD6  TR                  U 5        g)z*Run class validators after initialization.N)rZ   )r0   argsr=   r!   initial_inits      r%   init_with_validate0strict.<locals>.wrap.<locals>.init_with_validate   s#     ///LLr'   rG   )r"   N)!hasattrr   rY   r   append_create_type_validatormetadatar6   
isinstancelist_is_validatorr1   extendr5   r@   r   strrG   r
   rT   dir
startswithgetattrcallableleninspect	signature
parametersrX   r   r\   rZ   setattr)r!   field_validatorsrA   
validatorscustom_validatorr.   r;   rG   rT   class_validatorsr1   methodrZ   r`   r_   rF   rS   r:   r)   s   `             @@@@r%   wrapstrict.<locals>.wrapq   s   s2330#,,'UV 
 :<AJ4Q78 zz~~k:+!"2D99(8'9$!1I(33<;AFF83ykQ  A  "2
 !!"23'1QVV$  . ??
	0S 
	0 
	0C 
	0D 
	0 -LLM=!6 6 6 "6 $CL  LLM=!k# k "k  $CL HD??;//S$'FF##7$$V,778A=4cll^+DTF K> > 
 ##F+  $4 	l1 	l 	l 7;33
##3<<)MuUU4cll^ ,N N    ||	|		 
	
 	Z!34
r'   )r   r   )r!   r)   ry   s    ` r%   r&   r&   7   s8    tH$q' Hd1g HV 491T1r'   schemadatac                 *    [        U 5      nU" S0 UD6  g)an  
Validate that a dictionary conforms to the types defined in a TypedDict class.

Under the hood, the typed dict is converted to a strict dataclass and validated using the `@strict` decorator.

Args:
    schema (`type[TypedDictType]`):
        The TypedDict class defining the expected structure and types.
    data (`dict`):
        The dictionary to validate.

Raises:
    `StrictDataclassFieldValidationError`:
        If any field in the dictionary does not conform to the expected type.

Example:
```py
>>> from typing import Annotated, TypedDict
>>> from huggingface_hub.dataclasses import validate_typed_dict

>>> def positive_int(value: int):
...     if not value >= 0:
...         raise ValueError(f"Value must be positive, got {value}")

>>> class User(TypedDict):
...     name: str
...     age: Annotated[int, positive_int]

>>> # Valid data
>>> validate_typed_dict(User, {"name": "John", "age": 30})

>>> # Invalid type for age
>>> validate_typed_dict(User, {"name": "John", "age": "30"})
huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'age':
    TypeError: Field 'age' expected int, got str (value: '30')

>>> # Invalid value for age
>>> validate_typed_dict(User, {"name": "John", "age": -1})
huggingface_hub.errors.StrictDataclassFieldValidationError: Validation error for field 'age':
    ValueError: Value must be positive, got -1
```
Nr   )!_build_strict_cls_from_typed_dict)r{   r|   
strict_clss      r%   validate_typed_dictr      s    X 36:J r'   c                    [        U 5      n[        U SS5      (       d  UR                  5        H~  u  p#[        U5      nU[        L aH  [        U5      tpV[        U5      (       d	  [        U   n[        [        U/[        U5      -   5         X'   Ma  [        U5      (       a  Ms  [        U   X'   M     / nUR                  5        Hi  u  p#[        U5      [        L a3  [        U5      tpVUR                  " X%[        [        SUS   0S945        MJ  UR                  " X#[        [        S945        Mk     [        [        U R                  U5      5      $ )N	__total__Tr.   r   )defaultre   )r   )_get_typed_dict_annotationsrm   r?   r   r   r   _is_required_or_notrequiredr   tuplerg   rc   r   _TYPED_DICT_DEFAULT_VALUEr&   r   rY   )r{   
type_hintskeyr2   originbasemetar   s           r%   r~   r~   1  s"    -V4J 6;--$**,JC&F"&uo2488&t,D"+E4&4:2E,F"G
077"-e"4
 - F &&(
e	)"5/KDMM3e4MYdfjklfmXn&opqMM3u5N'OPQ ) .&9::r'   c           	           SSK nUR                  U 5      $ ! [         aW    U R                  R	                  S0 5      R                  5        VVs0 s H  u  p#X#b  UO
[        S5      _M     Os  snnf snns $ f = f)z0Extract type annotations from a TypedDict class.r   N__annotations__)annotationlibget_annotationsImportErrorrN   r6   r?   type)r{   r   r1   r2   s       r%   r   r   P  sz    
,,V44 

  &223DbIOOQ	
  R ,%$t*<Q	
 	

s    7A8A+*A87A8Tr.   r   default_factoryinitreprhashcomparere   r=   c                 j    [        U [        5      (       d  U /n Uc  0 nXS'   [        SUUUUUUUS.UD6$ )a  
Create a dataclass field with a custom validator.

Useful to apply several checks to a field. If only applying one rule, check out the [`as_validated_field`] decorator.

Args:
    validator (`Callable` or `list[Callable]`):
        A method that takes a value as input and raises ValueError/TypeError if the value is invalid.
        Can be a list of validators to apply multiple checks.
    **kwargs:
        Additional arguments to pass to `dataclasses.field()`.

Returns:
    A field with the validator attached in metadata
r.   r   r   r   r   r   r   re   r   )rf   rg   r   )	r.   r   r   r   r   r   r   re   r=   s	            r%   validated_fieldr   `  s\    4 i&&K	%[ 	'	 	 	r'   c                    ^  [         [         SSSSS4S[        [        [        4   S[        [        / [        4   [        4   S[
        S[
        S[        [
           S[
        S	[        [           S
[        4U 4S jjjnU$ )z
Decorates a validator function as a [`validated_field`] (i.e. a dataclass field with a custom validator).

Args:
    validator (`Callable`):
        A method that takes a value as input and raises ValueError/TypeError if the value is invalid.
TNr   r   r   r   r   r   re   r=   c                 ,   > [        T4U UUUUUUS.UD6$ )Nr   )r   )	r   r   r   r   r   r   re   r=   r.   s	           r%   _inner"as_validated_field.<locals>._inner  s9     

+

 

 
	
r'   )r   r   r   r   r   boolr   dict)r.   r   s   ` r%   as_validated_fieldr     s     .5CJ##'
sM)*
xC0-?@
 
 	

 tn
 
 4.
 
 
, Mr'   r1   r2   expected_typec                    [        U5      n[        U5      nU[        L a  g[        R	                  U5      =n(       a
  U" XU5        g[        U[        5      (       a  [        XU5        g[        U[        5      (       d  [        U[        5      (       a  gU[        L a(  U[        L a  [        SU  S35      e[        XUS   5        gU[        L a  U[        L a  g[        XUS   5        g[        SU  SU 35      e)z.Validate that 'value' matches 'expected_type'.NField 'z' is required but missing.r   zUnsupported type for field 'r/   )r   r   r   _BASIC_TYPE_VALIDATORSr6   rf   r   _validate_simple_typer   rj   r   r   r8   type_validatorr   )r1   r2   r   r   r^   r.   s         r%   r   r     s    &FM"D,008	8	8$t$	M4	(	(d=9	M:	.	.*]C2P2P	8	--gdV+EFGGtDG,	;	--tDG,6tfCOPPr'   r^   .c                     / nU H  n [        XU5          g   [        SU  S[	        U5       SU SSR                  U5       35      e! [         a%  nUR                  [        U5      5         SnAMm  SnAff = f)z8Validate that value matches one of the types in a Union.Nr   z' with value z doesn't match any type in z
. Errors: z; )r   r8   rc   rj   r   rO   )r1   r2   r^   errorstr9   s         r%   _validate_unionr     s    F	"4*  
$}T%[M1LTFR\]a]f]fgm]n\op   	"MM#a&!!	"s   A
A7A22A7c                 6    X;  a  [        SU  SU SU 35      eg)zValidate Literal type.r   z' expected one of , got N)r8   )r1   r2   r^   s      r%   _validate_literalr     s,    '$'9$veWMNN r'   c           	         [        U[        5      (       d$  [        SU  S[        U5      R                   35      eUS   n[        U5       H  u  pE [        U  SU S3XS5        M     g	! [         a  n[        SU SU  S35      UeS	nAff = f)
zValidate list[T] type.r   z' expected a list, got r   []Invalid item at index z
 in list ''N)rf   rg   r8   r   rY   	enumerater   r1   r2   r^   	item_typeiitemr9   s          r%   _validate_listr     s    eT""'$'>tE{?S?S>TUVV QIU#	RdV1QCq>4; $  	R4QCz$qIJPQQ	Rs   A''
B	1BB	c                 :   [        U[        5      (       d$  [        SU  S[        U5      R                   35      eUu  p4UR                  5        H(  u  pV [        U  S3XS5        [        U  SU< S3Xd5        M*     g! [         a  n[        SU  S35      UeSnAff = f)	zValidate dict[K, V] type.r   z' expected a dict, got z.keyr   r   zInvalid key or value in dict 'r   N)rf   r   r8   r   rY   r?   r   )r1   r2   r^   key_type
value_typerC   rD   r9   s           r%   _validate_dictr     s    eT""'$'>tE{?S?S>TUVV  H	MdV4=!6dV1QE+Q;   	M<TF!DE1L	Ms   "A;;
BBBc           
      x   [        U[        5      (       d$  [        SU  S[        U5      R                   35      e[        U5      S:X  a7  US   [        L a+  [        U5       H  u  p4 [        U  SU S3XBS   5        M     g[        U5      [        U5      :w  a&  [        SU  S[        U5       S[        U5       35      e[        [        X5      5       H  u  nu  pF [        U  SU S3XF5        M     g! [         a  n[        SU S	U  S
35      UeSnAff = f! [         a  n[        SU S	U  S
35      UeSnAff = f)zValidate Tuple type.r   z' expected a tuple, got    r   r   r   r   r   z in tuple 'r   Nz' expected a tuple of length r   )
rf   r   r8   r   rY   ro   Ellipsisr   r   zip)r1   r2   r^   r   r   r9   expecteds          r%   _validate_tupler     sT   eU##'$'?U@T@T?UVWW 4yA~$q'X- 'GAW$q1~t!W= ( 
Tc%j	 '$'DSYKvVYZ_V`Uabcc#,S-=#>AW$q1~t> $?  W"8;tfA NOUVVW  W"8;tfA NOUVVWs0   &C2D2
D<DD
D9!D44D9c                    [        U[        5      (       d$  [        SU  S[        U5      R                   35      eUS   n[        U5       H  u  pE [        U  S3XS5        M     g! [         a  n[        SU  S35      UeSnAff = f)zValidate set[T] type.r   z' expected a set, got r   z itemzInvalid item in set 'r   N)rf   setr8   r   rY   r   r   r   s          r%   _validate_setr     s    eS!!'$'=d5k>R>R=STUU QIU#	DdV5>4; $  	D3D6;<!C	Ds   A$$
B.A>>Bc                     [        X5      (       d>  [        SU  SUR                   S[        U5      R                   S[	        U5       S3	5      eg)z&Validate simple type (int, str, etc.).r   z' expected r   z	 (value: rM   N)rf   r8   rY   r   r   )r1   r2   r   s      r%   r   r     sY    e++dV;}'='=&>fT%[EYEYDZZcdhindocppqr
 	
 ,r'   r   c                 (   ^  S[         SS4U 4S jjnU$ )z-Create a type validator function for a field.r2   r"   Nc                 H   > [        TR                  U TR                  5        g r$   )r   r1   r   )r2   r   s    r%   r.   )_create_type_validator.<locals>.validator)  s    uzz5%**5r'   )r   )r   r.   s   ` r%   rd   rd   %  s    6 6 6 r'   c                    [        U 5      (       d  g[        R                  " U 5      n[        UR                  R                  5       5      n[        U5      S:X  a  gUS   R                  [        R                  R                  [        R                  R                  [        R                  R                  4;  a  gUSS  H-  nUR                  [        R                  R                  :X  d  M-    g   g)zCheck if a function is a validator.

A validator is a Callable that can be called with a single positional argument.
The validator can have more arguments with default values.

Basically, returns True if `validator(value)` is possible.
Fr   r   NT)rn   rp   rq   rg   rr   valuesro   kind	ParameterPOSITIONAL_OR_KEYWORDPOSITIONAL_ONLYVAR_POSITIONALr   empty)r.   rq   rr   	parameters       r%   rh   rh   /  s     I!!),Ii**1134J
:!!}//))((" 
 ^	 1 1 7 77 $ r'   	type_hintc                 ^    U [         [        4;   =(       d    [        U 5      [         [        4;   $ )z2Helper to check if a type is Required/NotRequired.)r   r   r   )r   s    r%   r   r   J  s'    ;//eJy4IhXcMd4der'   )r&   r   r   Validator_Tr   r   r   r$   )?rp   dataclassesr   r   r   r   r   r   	functoolsr	   r
   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   r   r   r   r   rj   r   objectr   r&   r   r   r~   r   rg   r   r   r   r   r   r   r   r   r   r   r   rd   rh   r   r   r   __all__r   r'   r%   <module>r      sK    T T &    
2,  ud{#CLtCH~>"H  
 (Q (DG ( 
 ( 
$) OT OhQy$q'7I.J O 
 O "E2<AE2	$q'	E259E2
47Hd1gYQ/001E2P/] 3 /4 /D /d ;d=.A ;d ; ;<
](; 
S#X 
$ *1?F#(T+&34(3%&( 8BG,m;<( 	(
 ( 4.( ( tn( ( 	(V+ DQ QS Q Q Q2# c sCx T OC O O5c? Ot OR RS Rc3h RD RM MS Mc3h MD MW# Wc WsCx WT W.D DC DuS#X D4 D
 
C 
 
 
% K S T 6f3 f4 f 
?..	? E  22;; 2
B+="b12	2s)   G7 7H,>H		H(#H,'H((H,