o
    "iR                     @  s  d Z ddlmZ ddlmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 edZ7g dZ8G dd de)Z9d9d d!Z:e6e9d:d%d&Z;d9d'd(Z<d;d*d+Z=d<d-d.Z>	/d=d>d3d4Z?d?d6d7Z@d8S )@z%Preconfigured converters for msgspec.    )annotations	b64decode)is_dataclass)datedatetime)Enum)partial)AnyCallableTypeVarUnionget_type_hints)has)resolve_types)Structconvertto_builtins)Encoderdecode   )fieldsget_args
get_originis_bare
is_mappingis_sequence)is_namedtuple)BaseConverter	Converter)UnstructureHook)identity) make_hetero_tuple_unstructure_fn)is_literal_containing_enums)configure_union_passthrough   )'literals_with_enums_unstructure_factorywrapT)MsgspecJsonConverterconfigure_convertermake_converterc                   @  sJ   e Zd ZU dZe Zded< ddddZdddZdddZ	dddZ
dS )r)   z2A converter specialized for the _msgspec_ library.r   encoderNobjr
   unstructure_askwargsreturnbytesc                 K  s   | j j| j||dfi |S )z-Unstructure and encode `obj` into JSON bytes.)r.   )r,   encodeunstructure)selfr-   r.   r/    r5   V/var/www/html/premium_crap/venv/lib/python3.10/site-packages/cattrs/preconf/msgspec.pydumps&   s
   zMsgspecJsonConverter.dumpsCallable[[Any], bytes]c                 K  s$   |  |}|ttfv r| jjS | jS )z*Produce a `dumps` hook for the given type.)get_unstructure_hookr!   r   r,   r2   r7   )r4   r.   r/   unstruct_hookr5   r5   r6   get_dumps_hook,   s   
z#MsgspecJsonConverter.get_dumps_hookdatacltype[T]r(   c                 K  s   |  t|fi ||S )z7Decode and structure `cl` from the provided JSON bytes.)	structurer   )r4   r<   r=   r/   r5   r5   r6   loads5   s   zMsgspecJsonConverter.loadsCallable[[bytes], T]c                 C  s   t | j|dS )z*Produce a `loads` hook for the given type.)r=   )r	   r@   )r4   r=   r5   r5   r6   get_loads_hook9   s   z#MsgspecJsonConverter.get_loads_hookN)r-   r
   r.   r
   r/   r
   r0   r1   )r.   r
   r/   r
   r0   r8   )r<   r1   r=   r>   r/   r
   r0   r(   )r=   r>   r0   rA   )__name__
__module____qualname____doc__r   r,   __annotations__r7   r;   r@   rB   r5   r5   r5   r6   r)       s   
 

	r)   	converterr   r0   Nonec                 C  s   t |  | tt | tt | tt | tdd  | t	dd  | t
dd  | tt ttttttdf |  dS )a  Configure the converter for the msgspec library.

    * bytes are serialized as base64 strings, directly by msgspec
    * datetimes and dates are passed through to be serialized as RFC 3339 directly
    * enums are passed through to msgspec directly
    * union passthrough configured for str, bool, int, float and None
    * bare, string and int enums are passed through when unstructuring

    .. versionchanged:: 24.2.0
        Enums are left to the library to unstructure, speeding them up.
    c                 S  s   t | S rC   r   v_r5   r5   r6   <lambda>P   s    z%configure_converter.<locals>.<lambda>c                 S  s
   t | tS rC   )r   r   rK   r5   r5   r6   rN   Q      
 c                 S  s
   t | S rC   )r   fromisoformatrK   r5   r5   r6   rN   R   rO   N)configure_passthroughsregister_unstructure_hookr   r   r   r!   register_structure_hookr   r1   r   r   !register_unstructure_hook_factoryr#   r&   r$   r   strboolintfloatrI   r5   r5   r6   r*   >   s   r*   argsr
   r/   c                  O  s   t | i |}t| |S rC   )r)   r*   )rZ   r/   resr5   r5   r6   r+   Y   s   r+   c                 C  sT   |  tt | tt | tt | tt	 | t
tt	dd | tt dS )zConfigure optimizing passthroughs.

    A passthrough is when we let msgspec handle something automatically.

    .. versionchanged:: 25.1.0
        Dataclasses with private attributes are now passed through.
    F)msgspec_skips_privateN)rR   r1   r   rT   r   mapping_unstructure_factoryr   seq_unstructure_factory	attrs_has!msgspec_attrs_unstructure_factoryr   r	   r   namedtuple_unstructure_factoryrY   r5   r5   r6   rQ   `   s   
rQ   r    c                 C  sF   t | rt}nt| }|d }|j|dd}|ttfv r|S || S )z3The msgspec unstructure hook factory for sequences.r   Fcache_result)r   r
   r   r9   r!   r   gen_unstructure_iterable)typerI   type_argrZ   handlerr5   r5   r6   r^   w   s   
r^   r   c                 C  s   t | rt}t}|j|dd}|j|dd}n"t| }t|dkr&|\}}n|t}}|j|dd}|j|dd}|ttfv rG|ttfv rGtS || S )z2The msgspec unstructure hook factory for mappings.Frb   r   )r   r
   r9   r   lenr!   r   gen_unstructure_mapping)re   rI   key_argval_argkey_handlervalue_handlerrZ   r5   r5   r6   r]      s"   


r]   Tre   r\   rV   c                   sj   t | }t|p| }t| r!tdd |D r!t|  t|p| }|r3t fdd|D r3 | S tS )zChoose whether to use msgspec handling or our own.

    Args:
        msgspec_skips_private: Whether the msgspec library skips unstructuring
            private attributes, making us do the work.
    c                 s  s    | ]	}t |jtV  qd S rC   )
isinstancere   rU   ).0ar5   r5   r6   	<genexpr>   s    z4msgspec_attrs_unstructure_factory.<locals>.<genexpr>c                 3  s4    | ]}|j d p j|jddttfvV  qdS )rM   Frb   N)name
startswithr9   re   r!   r   )ro   attrrY   r5   r6   rq      s    
)r   r   r_   anyr   gen_unstructure_attrs_fromdictr   )re   rI   r\   originattribsr5   rY   r6   r`      s   	
r`   type[tuple]c                   s>   t  fddt|  D rtS t|  ttt|  dS )zCA hook factory for unstructuring namedtuples, modified for msgspec.c                 3  s"    | ]}  |ttfv V  qd S rC   )r9   r!   r   )ro   trY   r5   r6   rq      s
    
z1namedtuple_unstructure_factory.<locals>.<genexpr>)unstructure_to	type_args)allr   valuesr!   r"   tuple)re   rI   r5   rY   r6   ra      s   
ra   N)rI   r   r0   rJ   )rZ   r
   r/   r
   r0   r)   )rI   r   r0   r    )rI   r   r0   r    )T)re   r
   rI   r   r\   rV   r0   r    )re   ry   rI   r   r0   r    )ArG   
__future__r   base64r   dataclassesr   r   r   enumr   	functoolsr	   typingr
   r   r   r   r   attrsr   r_   r   msgspecr   r   r   msgspec.jsonr   r   _compatr   r   r   r   r   r   colsr   
convertersr   r   dispatchr    fnsr!   genr"   literalsr#   
strategiesr$    r&   r'   r(   __all__r)   r*   r+   rQ   r^   r]   r`   ra   r5   r5   r5   r6   <module>   sB     



