
    i%                     6   d dl Z d dlZd dlZd dlmZ 	 d dlmZ 	 d dlmZm	Z	 d Z	  ej                  dd       d	 Zej                  dk\  rd Znej                  Zej                  dk\  rd dlmZ nd Zd Zd Zd Zi eeeeeeeeeeej4                  eej6                  eej8                  eej:                  eej<                  eej>                  eej@                  eejB                  eejD                  eejF                  eejH                  eejJ                  ee jL                  j>                  ee jL                  j@                  ee jL                  jB                  ee jL                  jH                  ee jL                  j8                  ee jL                  jD                  ee jL                  jF                  eiZ'd Z(d Z)d Z*d Z+y# e$ r
 d dlmZ Y w xY w# e$ r 	 d dlmZm	Z	 n# e$ r dxZ	ZY nw xY wY w xY w# e$ r d
 ZY w xY w)    N)_AnnotatedAlias)get_type_hints)NotRequiredRequiredc                     t        | d      S )NT)include_extras)_get_type_hints)objs    A/root/searxng-venv/lib/python3.12/site-packages/msgspec/_utils.pyr   r      s    3t44    FooT)is_classc                 2    t        j                  | dd      S )NFT)is_argumentr   typing
ForwardRefvalues    r   _forward_refr   &   s      EDIIr   c                 0    t        j                  | d      S )NF)r   r   r   s    r   r   r   !   s      E::r   )      c                 2    t        j                  | ||d      S )N )r   
_eval_type)tglobalnslocalnss      r   r   r   -   s      Hgr::r   )r      )get_annotationsc                 :    | j                   j                  di       S )N__annotations__)__dict__get)clss    r   _get_class_annotationsr'   8   s    || 1266r   c                     t        | t        j                        rj                  | |       S 	 t	        | j
                        }|s| S t	        fd|D              }| |   S # t        $ r | cY S w xY w)Nc              3   B   K   | ]  }j                  ||        y wN)r%   ).0pmappings     r   	<genexpr>z _apply_params.<locals>.<genexpr>K   s     7qQ"7s   )
isinstancer   TypeVarr%   tuple__parameters__	Exception)r
   r-   
parametersargss    `  r   _apply_paramsr6   <   ss    #v~~&{{3$$3--.

 
 7J77Dt9  
s   A! !A/.A/c                     i t        | t              r| }n| j                  }fd | i        |j                  fS )Nc                    t        | t              r| }i }nt        | dd       }|d t        t        j
                  fv s|	v ry |j                  }t        fd| j                  D              }t        |      t        |      k(  sJ t        t        ||            x	|<   }t        |t        j
                        r(t        |d|j                        }|D ]  } ||        y y )N
__origin__c              3   6   K   | ]  }t        |        y wr*   )r6   )r+   ascopes     r   r.   zE_get_class_mro_and_typevar_mappings.<locals>.inner.<locals>.<genexpr>`   s     EQq%0Es   __orig_bases__)r/   typegetattrobjectr   Genericr2   r1   __args__lendictzip
issubclass	__bases__)
cr<   r&   	new_scopeparamsr5   basesbinnerr-   s
    `      r   rM   z2_get_class_mro_and_typevar_mappings.<locals>.innerW   s    aCI!\40CtVV^^44w''FE!**EEDv;#d)+++'+C,='>>GCL9c6>>*C!13==AE $a#$ +r   )r/   r>   r9   __mro__)r
   r&   rM   r-   s     @@r   #_get_class_mro_and_typevar_mappingsrO   O   s?    G#tnn$$ 
#rN;;r   c                    i }t        |       \  }}|D ]  }|t        j                  t        fv r|j	                  |      }t        t        |            }t        t        j                  j	                  |j                  d      di       }t        |      }|j                         D ]R  \  }	}
|	|v rt        |
t              rt        |
      }
t!        |
||      }
|t#        |
|      }
|
t%        d      }
|
||	<   T  |S )a  Get the annotations for a class.

    This is similar to ``typing.get_type_hints``, except:

    - We maintain it
    - It leaves extras like ``Annotated``/``ClassVar`` alone
    - It resolves any parametrized generics in the class mro. The returned
      mapping may still include ``TypeVar`` values, but those should be treated
      as their unparametrized variants (i.e. equal to ``Any`` for the common case).

    Note that this function doesn't check that Generic types are being used
    properly - invalid uses of `Generic` may slip through without complaint.

    The assumption here is that the user is making use of a static analysis
    tool like ``mypy``/``pyright`` already, which would catch misuse of these
    APIs.
    Nr$   )rO   r   rA   r@   r%   rD   varsr?   sysmodules
__module__r'   itemsr/   strr   r   r6   r>   )r
   hintsmrotypevar_mappingsr&   r-   
cls_localscls_globalsannnamer   s              r   get_class_annotationsr^   m   s    $ E?DC	  6>>6**"&&s+$s)_
ckkoocnndCZQST$S)99; 
	 KD%u}%%$U+uj+>E"%eW5}T
E$K
	  ( Lr   c                 V   t        | t              r| }n| j                  }t        |       }t	        |d      rt        |j                        }n"|j                  rt        |      }n
t               }i |j                         D ]o  \  }}t        |dd      }|t        u r$|j                  |       |j                  d   |<   ?|t        u r$|j                  |       |j                  d   |<   k||<   q t        fd|D              st!        d| dj#                                |fS )N__required_keys__r9   Fr   c              3   &   K   | ]  }|v  
 y wr*   r   )r+   krW   s     r   r.   z%get_typeddict_info.<locals>.<genexpr>   s     ,aqEz,s   zRequired set z% contains keys that are no in hints: )r/   r>   r9   r^   hasattrsetr`   	__total__rU   r?   r   addrB   r   discardallRuntimeErrorkeys)r
   r&   	raw_hintsrequiredrb   voriginrW   s          @r   get_typeddict_inforo      s   #tnn%c*Is'(s,,-	y>5 E! 	1L%0XLLOzz!}E!H{"Qzz!}E!HE!H	 ,8,,H:%J5::<.Y
 	
 (?r   c                    t        | t              r| }n| j                  }t        |       }g }g }g }t	        |d      rddlm}m}m} |j                  j                         D ]  }	|	j                  |ur|	j                  |u rt        d      +|	j                  }
||
   }|	j                  |ur0|j                  |	j                         |j                  |
|df       z|	j                   |ur0|j                  |	j                          |j                  |
|df       |j                  |
|df        |j#                  |       d }t%        |dd       }n ddlm}m} g }|j,                  D ]  }	|	j                  }
||
   }|	j                  }||uryt        ||      rG|j.                  rt1        d	      |j                  |j2                         |j                  |
|df       n:|j                  |       |j                  |
|df       n|j                  |
|df       |	j4                  |j                  |	        |j#                  |       t%        |d
d       }t%        |dd       }|rt7        ||      }|t9        |      t9        |      ||fS )N__dataclass_fields__r   )_FIELD_FIELD_INITVARMISSINGz3dataclasses with `InitVar` fields are not supportedFT__post_init__)NOTHINGFactoryzvSupport for default factories with `takes_self=True` is not implemented. File a GitHub issue if you need this feature!__attrs_pre_init____attrs_post_init__)r/   r>   r9   r^   rc   dataclassesrr   rs   rt   rq   values_field_type	TypeErrorr]   defaultappenddefault_factoryextendr?   attrsrv   rw   __attrs_attrs__
takes_selfNotImplementedErrorfactory	validator_wrap_attrs_validatorsr1   )r
   r&   rW   rl   optionaldefaultsrr   rs   rt   fieldr]   typpre_init	post_initrv   rw   fields_with_validatorsr~   s                     r   get_dataclass_infor      se   #tnn!#&EHHHs*+??--446 	4E  .$$6#M  ::D+C}}G+.sE 23&&g5 5 56sD 12sE 23!	4$ 	!C$7	*!#(( 	5E::D+CmmGg%gw/))1, 
 OOGOO4OOT3$56OOG,OOT3$67sE 23*&--e4+	5. 	!3 4d;C!6=	!./EyQIhx(IEEr   c                       fd}|S )Nc           	      x    D ])  }|j                  | |t        | |j                               + 	 |        y y r*   )r   r?   r]   )r
   r   fieldsr   s     r   rM   z%_wrap_attrs_validators.<locals>.inner-  sA     	BEOOCUZZ(@A	B cN !r   r   )r   r   rM   s   `` r   r   r   ,  s     Lr   c                      | di |S )z1Used to unpickle Structs with keyword-only fieldsr   r   )r&   kwargss     r   rebuildr   6  s    ==r   ),collectionsrR   r   r   typing_extensionsr   r	   r3   r   r   r   r   r}   version_infor   annotationlibr!   r'   r6   rO   r^   listr1   rd   	frozensetrD   ListTupleSet	FrozenSetDict
CollectionMutableSequenceSequenceMutableMappingMapping
MutableSetAbstractSetabc_CONCRETE_TYPESro   r   r   r   r   r   r   <module>r      s    
  "9C&75
JFed+J
 w; ""J wG7& <)^$	5  y	
 	$ KK LL% JJ i KK t D OOT 4 NND  s!" #$ OOOO##TOOdOOOOOO""DOOT18'TGFT[	  9889
  &&00 &!%%;&&"  ;;;sW   G G' H G$#G$'H	-G65H	6	H?H	HH	H	HH