
    MiM                        % S r SSKrSSKrSSKJrJrJr  SSKJr  SSKJ	r
  \R                  S:  a  SrSrO SSKJr  SS	KJr   SSKJr  SS	KJr   " S
 S5      r " S S5      r " S S5      r " S S5      rS'SS.S jjr " S S\5      r " S S5      r " S S5      rS(S jrS rS r S r!S(S jr"0 r#\$\%S'   S  r&S! r'S" r(S# r)S$ r*S% r+S& r,g! \\4 a    SrSr Nf = f! \\4 a    SrSr Nf = f))zLightweight type validation system replacing Pydantic.

Provides Schema base class, dynamic schema creation, and type validation
for config values against function signatures.
    N)AnyOptionalget_type_hints   )Ctx)
check_type)      )	BaseModel)ValidationErrorc                       \ rS rSrSrSrg)
StrictBool.   z.Only accepts actual bool values (not int 0/1). N__name__
__module____qualname____firstlineno____doc____static_attributes__r       o/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/confection/validation.pyr   r   .   s    8r   r   c                       \ rS rSrSrSrg)PositiveInt4   z/Only accepts positive integers (> 0, not bool).r   Nr   r   r   r   r   r   4   s    9r   r   c                       \ rS rSrSrSrg)StrictFloat:   z+Only accepts actual float values (not int).r   Nr   r   r   r   r   r   :   s    5r   r   c                   4    \ rS rSrSrSrS	SS.S jjrS rSrg)
	FieldInfoC   z!Information about a schema field.defaultalias
annotationNr%   c                *    Xl         X l        S U l        g Nr#   )selfr$   r%   s      r   __init__FieldInfo.__init__H   s    
#r   c                     U R                   SL $ )N.r$   r*   s    r   is_requiredFieldInfo.is_requiredM   s    ||s""r   )r%   r&   r$   .)	r   r   r   r   r   	__slots__r+   r0   r   r   r   r   r!   r!   C   s    +2I$T $
#r   r!   r'   c                    [        XS9$ )zCreate a field definition.r$   r%   )r!   r5   s     r   Fieldr6   Q   s    W22r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r   Y   z$Raised when schema validation fails.c                 `   > Xl         SR                  S U 5       5      n[        TU ]  U5        g )Nz; c              3   D   #    U  H  oR                  S S5      v   M     g7f)msg N)get).0es     r   	<genexpr>+ValidationError.__init__.<locals>.<genexpr>^   s     >:aub)):s    )_errorsjoinsuperr+   )r*   
error_listmsgs	__class__s      r   r+   ValidationError.__init__\   s)    !yy>:>>r   c                     U R                   $ r)   rB   r/   s    r   errorsValidationError.errorsa   s    ||r   rJ   )	r   r   r   r   r   r+   rK   r   __classcell__rG   s   @r   r   r   Y   s    .
 r   r   c                       \ rS rSrSrS rSrg)_ValidatedResulth   z0Attribute-accessible result from model_validate.c                 :    U R                   R                  U5        g r)   )__dict__update)r*   datas     r   r+   _ValidatedResult.__init__k   s    T"r   r   N)r   r   r   r   r   r+   r   r   r   r   rP   rP   h   s
    :#r   rP   c                      ^  \ rS rSr% SrSSS.r\\S'   0 r\\S'   U 4S jr	S	 r
\S
 5       r\SS.S j5       rS rSrU =r$ )Schemao   zFBase class for config validation schemas. Replaces pydantic.BaseModel.allowTextraarbitrary_types_allowedmodel_configmodel_fieldsc           	      z  > [         TU ]  " S0 UD6  0 n0 n[        U R                  5       H!  n[	        US0 5      nUR                  U5        M#     UR                  5        H  u  pgUS;   d  UR                  S5      (       a  M#  SnS n	U R                   H  n
XjR                  ;   d  M  U
R                  U   n[        U[        5      (       a  UR                  nUR                  n	O7[        U[        [        [        [         45      (       d  [#        U5      (       d  Un  O   [        XS9nX|l        XU'   M     X l        g )N__annotations__)r^   r_   _.r5   r   )rD   __init_subclass__reversed__mro__getattrrT   items
startswithrS   
isinstancer!   r$   r%   typeclassmethodstaticmethodpropertycallabler&   r_   )clskwargsfields	all_hintsbasebase_annotationsnamer&   r$   r%   klassvalfieldrG   s                r   rc   Schema.__init_subclass__u   s   !+F+	S[[)D&t->C-. * !* 1D774??3;O;OGE>>)...C!#y11"%++ #		'dKxH   (}}&)G % g;E) 4L' !2* "r   c                     U R                   R                  R                  5        HG  u  p#X!;   a  [        XX   5        M  UR	                  5       (       a  M1  [        XUR
                  5        MI     g r)   )rG   r_   rg   setattrr0   r$   )r*   rp   ru   rx   s       r   r+   Schema.__init__   sO    >>66<<>KD~FL1&&((EMM2	 ?r   c                    U R                   R                  S5      n[        XR                  U R                   U5      nU(       a  [	        U5      e[        U5      nU R                  R                  5        H\  u  pVUnUR                  b  UR                  nOU(       a  U" U5      nXt;  d  M7  UR                  5       (       a  MN  UR                  XG'   M^     [        U5      $ )z$Validate a dict against this schema.alias_generator)r^   r=   _validate_schemar_   r   dictrg   r%   r0   r$   rP   )ro   rU   	alias_genrK   result_dataru   rx   data_keys           r   model_validateSchema.model_validate   s     $$(():;	!$(8(8#:J:JIV!&))4j++113KDH{{& ;;$T?*53D3D3F3F(-% 4  ,,r   N)configc                    SSK Jn  Uc  SSS.n[        U5      n0 n[        R                  " U5      R
                  R                  5        H  nUR                  UR                  UR                  5      nU[        R                  R                  L a  [        nUR                  [        R                  R                  L a  SnOUR                  nUR                  [        R                  R                  :X  a  X7   nUR                  [        R                  R                   :X  a  M  [#        US9n	Xyl	        XUR                  '   M     [%        UR&                  4SU0UR)                  5        V
Vs0 s H  u  pXR                  U4_M     snn
D6$ s  snn
f )	a  Build a Schema subclass from a function's signature.

Each parameter becomes a field.  The annotation is used as the type
(defaulting to ``Any`` when missing) and the default value is
preserved (parameters without defaults become required fields).

``*args`` parameters are wrapped in ``Sequence[annotation]`` and
stored under the ``VARIABLE_POSITIONAL_ARGS`` field name.

Forward-reference annotations are resolved via
``typing.get_type_hints`` against the function's module namespace.
r   )SequenceforbidTr[   .r.   
__config__)typingr   resolve_type_hintsinspect	signature
parametersvaluesr=   ru   r&   	Parameteremptyr   r$   kindVAR_POSITIONALVAR_KEYWORDr!   create_schemar   rg   )ro   funcr   _Seqresolvedrq   paramr&   r$   rx   ru   fs               r   from_functionSchema.from_function   sK   & 	,>'DIF%d+&&t,77>>@E!ejj%2B2BCJW..444 
}} 1 1 7 77--zzW..===!-
zzW..:::g.E)!&5:: A  MM

 7=llnEn74tllA&&nE
 	
 Fs   *F
c                     0 nU R                   R                   HM  n[        X5      (       d  M  [        X5      n[	        U[
        5      (       a  UR                  5       X'   MI  X1U'   MO     U$ )zConvert instance to dict.)rG   r_   hasattrrf   ri   rX   
model_dump)r*   resultru   rw   s       r   r   Schema.model_dump   sY    NN//Dt""d)c6**#&>>#3FL#&4L 0 r   r   )r   r   r   r   r   r^   r   ra   r_   rc   r+   rk   r   r   r   r   rM   rN   s   @r   rX   rX   o   sa    P#*tLL$LL$">3 - -$ 
 	-
 -
^
 
r   rX   c                    Uc  SS0n0 n0 n0 nUR                  5        H  u  pg[        U[        5      (       a2  [        U5      S:X  a#  Uu  p[        U	[        5      (       d	  [	        U	S9n	O[        SU S35      eXl        XU'   XU'   U	R                  5       (       a  M  U	R                  XV'   M     UUS.n
U
R                  U5        [        U [        4U
5      nU(       a  UR                  S	5      OSnU(       aE  [        U5      (       a5  UR                  5        H!  u  pmUR                  b  M  U" U5      Ul        M#     X;l        U$ )
zcDynamically create a Schema subclass.

Each field value should be a (annotation, FieldInfo) tuple.
Nr\   rZ      r.   zField z& must be (annotation, FieldInfo) tuple)ra   r^   r~   )rg   ri   tuplelenr!   
ValueErrorr&   r0   r$   rT   rj   rX   r=   rn   r%   r_   )__namer   rq   	processedannotationsdefaultsru   	field_defr&   
field_info	namespacero   r   rx   s                 r   r   r      s7   
 w'
IKH!<<>i''C	Na,?%."Jj)44&z:
vdV+QRSS *$$&D%%'''//HN * '"I X
vy)
,C5?
01TIXi(($??,KD{{"'o - !Jr   c                      [        U SS5      nU(       a  [        R                  R                  U5      OSnU(       a  [	        U5      OSn[        XS9$ ! [        [        [        [        4 a    0 s $ f = f)ztResolve type hints for a function, handling forward references.

Falls back to raw annotations if resolution fails.
r   N)globalns)
rf   sysmodulesr=   varsr   	NameErrorAttributeError	TypeErrorRecursionError)r   mod_namemoduler   s       r   r   r     sb    

4t4.6*D#)4<td66~y.A 
 	s   AA A32A3c                     U [         L d	  U [        L a  gU [        L a  gU [        L d	  U [        L a  gU [
        L d	  U [        L a  gg)z+Get an error type string for an annotation.int_parsingstring_typefloat_parsing	bool_typevalue_error)intr   strfloatr   boolr   )r&   s    r   _error_type_forr   /  sF    SJ+5	s		u	
k 9	t	zZ7r   c                     [        5       n[        XUS9(       a  gUR                  (       a  [        UR                  S   5      $ U < SU 3$ )ziValidate value against a type annotation.

Returns None if valid, or an error message string if invalid.
)ctxNr   z does not match )r   _tc2_check_typerK   r   )valuer&   r   s      r   validate_typer   <  sD    
 %Cuc2
zz3::a=!!Y&zl33r   c                    / nUR                  SS5      n0 n[        5       nUR                  5        HG  u  pU	R                  b  U	R                  n
OU(       a	  U" U5      n
OUn
UR	                  U
5        X4Xj'   MI     US:X  a&  U  H   nX;  d  M
  UR                  U4SSS.5        M"     UR                  5        H  u  n
u  pX;   aM  X
   n[        XR                  5      nU(       a+  UR                  U
4U[        U	R                  5      S.5        MX  MZ  U	R                  5       (       d  Mq  UR                  U
4SSS.5        M     U$ )	z[Validate a data dict against schema fields.

Returns list of error dicts (empty if valid).
r\   rZ   r   zExtra inputs are not permittedextra_forbidden)locr;   rj   zField requiredmissing)
r=   setrg   r%   addappendr   r&   r   r0   )rU   rq   r   r~   rK   
extra_modekey_to_field
known_keysru   rx   r   keyr   errs                 r   r   r   L  sF   
 FGW-J LJ||~;;"{{H&t,HHx "& & XC$ #v? 1  $0#5#5#7-4NE'7'78C ({" /0@0@ A    MM$;+% $8* Mr   _pydantic_cachec                      / n [         b  U R                  [         5        [        b  U R                  [        5        U (       a  [        U 5      $ [        4$ )zReturn the pydantic ValidationError class(es) to catch.

Tries both pydantic.v1 and pydantic so we catch the right exception
regardless of which API the caller's model was built with.
)_PydanticV1ValidationErrorr   _PydanticV2ValidationErrorr   	Exception)rK   s    r   _get_pydantic_validation_errorr     sF     F!-01!-01V} <r   c                     [        U [        5      (       d  g[        U [        5      (       a  g[        b  [        U [        5      (       a  g[
        b  [        U [
        5      (       a  gg)zCheck if cls is a pydantic BaseModel class (v1 or v2) without hard-depending
on pydantic. Returns False if pydantic is not installed.FT)ri   rj   
issubclassrX   _PydanticV1BaseModel_PydanticV2BaseModelro   s    r   _is_pydantic_modelr     sS     c4  #v'Js<P,Q,Q'Js<P,Q,Qr   c                     [        U S5      (       a  U R                  5       $ [        U S5      (       a  U R                  5       $ U $ )z,Convert a pydantic model instance to a dict.r   r   )r   r   r   )objs    r   _pydantic_instance_to_dictr     s:    sL!!~~sFxxzJr   c                    0 n[        U S5      (       a  U R                  R                  5        H  u  p#UR                  nUR	                  5       (       a  SnOUR
                  nUR                  n[        U[        5      (       a  [        U5      (       a  [        U5      nUSLa  [        US5      (       a  [        U5      n[        XVS9nXGl        XqU'   M     U$ [        U S5      (       a  U R                  R                  5        H  u  p#UR                  n[        USS5      (       a	  [         U   nUR"                  (       a  SnOUR
                  nUR                  U:w  a  UR                  OSn[        U[        5      (       a  [        U5      (       a  [        U5      nUSLa  [        US5      (       a  [        U5      n[        XVS9nXGl        XqU'   M     U$ )	zEExtract field definitions from a pydantic BaseModel class (v1 or v2).r_   .r   r5   
__fields__
allow_noneFN)r   r_   rg   r&   r0   r$   r%   ri   rj   r   ensure_schemar   r!   r   outer_type_rf   r   required)pydantic_clsrq   ru   	pyd_fieldr&   r$   r%   rx   s           r   _extract_pydantic_fieldsr     s   F|^,,  ,88>>@OD"--J$$&&#++OOE*d++0B:0N0N*:6
c!gg|&D&D4W=g;E) 4L  AT M3 
|	,	,+66<<>OD"..J y,66%j1
!!#++'0$'>IOODE *d++0B:0N0N*:6
c!gg|&D&D4W=g;E) 4L+  ?. Mr   c                    SS0n[        U S5      (       a}  U R                  n[        USS5      n[        US5      (       a  UR                  n[	        U[
        5      (       a  UO
[        U5      US'   [        US5      (       a  UR                  US'   U$ [        U S5      (       a4  [	        U R                  [        5      (       a  [        U R                  5      nU$ )z@Extract model config from a pydantic BaseModel class (v1 or v2).r\   rZ   r   r   r]   r^   )	r   r   rf   r   ri   r   r]   r^   r   )r   r   cfgr\   s       r   _extract_pydantic_configr     s    wF|\**%%Wg.5'""KKE#-eS#9#9%s5zw3122030K0KF,- M 
~	.	.:!!44 4 l//0Mr   c                 d  ^ [        U [        5      (       a  [        U [        5      (       a  U $ [	        U 5      (       d  U $ U [
        ;   a	  [
        U    $ [        U 5      n[        U 5      nU m[        [        U 5      [        40 5      nXl	        X#l
        [        U4S j5       nXCl        U[
        U '   U$ )uB  Ensure *schema_cls* satisfies the Schema interface.

If it already is a Schema subclass, return it unchanged.
If it is a pydantic BaseModel (v1 or v2), build a thin Schema wrapper
that exposes the same ``model_fields`` / ``model_config`` and delegates
``model_validate`` to the original pydantic class so that pydantic
validators, strict types, constrained types etc. keep working.

This allows downstream libraries (spaCy, thinc, …) to keep passing
pydantic schemas to ``registry.resolve()`` / ``registry.fill()`` even
though confection itself no longer depends on pydantic.
c                   > [        5       n [        TS5      (       a  TR                  U5        O,[        TS5      (       a  TR                  U5        O	T" S0 UD6   [        U5      nU R                  R                  5        HL  u  pVUR                  b  UR                  OUnXt;  d  M'  UR                  5       (       a  M>  UR                  XG'   MN     [        U5      $ ! U a  n[	        UR                  5       5      S eS nAff = f)Nr   	parse_objr   )r   r   r   r   r   rK   r   r_   rg   r%   r0   r$   rP   )	ro   rU   pyd_validation_errr?   r   ru   rx   r   pyd_clss	           r   _pydantic_model_validate/ensure_schema.<locals>._pydantic_model_validate$  s     <=
	w 011&&t,+..!!$'$ 4j++113KD&+kk&=u{{4H*53D3D3F3F(-% 4  ,, " 	!
	s"   "C "C C D"C<<D)ri   rj   r   rX   r   r   r   r   pydantic_cls_namer_   r^   rk   r   )
schema_clsrq   r   wrapperr   r   s        @r   r   r     s     *d##
:v(F(Fj)) _$z**%j1F%j1F G$Z06)R@G!! - -0 6")OJNr   c                     [        U SS5      $ )Nr   PydanticSchema)rf   r   s    r   r   r   C  s    3
$455r   r2   r)   )-r   r   r   r   r   r   r   typecheckerr   r   r   version_infor   r   pydantic.v1r   r   ImportErrorModuleNotFoundErrorpydanticr   r   r   r   r   r!   r6   r   rP   rX   r   r   r   r   r   r   r   ra   r   r   r   r   r   r   r   r   r   r   <module>r     sA    
 0 0  6
 w!%	*	
	
	&	 		 		 	# #3 3	i 	# #y yx)^*

4 9|  &1h.>B6O ,- *#%)"* 	() &!%&s#   C C# C C #C21C2