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 )zÕConfigure 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 )zÈChoose 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     



ÿ