o
    "“i  ã                   @   s$  d Z ddl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mZmZ ddlmZmZ d	d
lmZ d	dlmZmZmZ d	dlmZ d	dlmZ d	dlmZ d	dlm Z  ddl!m"Z"m#Z#m$Z$ g d¢Z%edƒZ&G dd„ deƒZ'deddfdd„Z(e$e'ƒdedede'fdd„ƒZ)dS )z$Preconfigured converters for orjson.é    )Ú	b85decodeÚ	b85encode)ÚSet)ÚdateÚdatetime)ÚEnum)Úpartial)ÚAnyÚTypeVarÚUnion)ÚdumpsÚloadsé   )Úis_subclass)Ú
is_mappingÚis_namedtupleÚnamedtuple_unstructure_factory)Ú	Converter)Úidentity)Úis_literal_containing_enums)Úconfigure_union_passthroughé   )Úis_primitive_enumÚ'literals_with_enums_unstructure_factoryÚwrap)ÚOrjsonConverterÚconfigure_converterÚmake_converterÚTc                	   @   sN   e Zd Zddedededefdd„Zdeeeee	f d	e
e defd
d„ZdS )r   NÚobjÚunstructure_asÚkwargsÚreturnc                 K   s   t | j||d�fi |¤ŽS )N)r    )r   Úunstructure)Úselfr   r    r!   © r%   úU/var/www/html/premium_crap/venv/lib/python3.10/site-packages/cattrs/preconf/orjson.pyr      s   zOrjsonConverter.dumpsÚdataÚclc                 C   s   |   t|ƒ|¡S ©N)Ú	structurer   )r$   r'   r(   r%   r%   r&   r      s   zOrjsonConverter.loadsr)   )Ú__name__Ú
__module__Ú__qualname__r	   Úbytesr   r   Ú	bytearrayÚ
memoryviewÚstrÚtyper   r   r%   r%   r%   r&   r      s    *r   Ú	converterr"   Nc                    s´   ˆ   tdd„ ¡ ˆ  tdd„ ¡ ˆ  tdd„ ¡ ˆ  tdd„ ¡ ddtf‡ fdd	„}ˆ j t|d
ft	t
ttd�dfg¡ ˆ  t
td
d�t¡ ˆ  tt¡ ttttttdf ˆ ƒ dS )a„  
    Configure the converter for use with the orjson library.

    * bytes are serialized as base85 strings
    * datetimes and dates are passed through to be serialized as RFC 3339 by orjson
    * typed namedtuples are serialized as lists
    * sets are serialized as lists
    * string enum mapping keys have special handling
    * mapping keys are coerced into strings when unstructuring
    * bare, string and int enums are passed through when unstructuring

    .. versionchanged:: 24.1.0
        Add support for typed namedtuples.
    .. versionchanged:: 24.2.0
        Enums are left to the library to unstructure, speeding them up.
    c                 S   s   | r	t | ƒ d¡S d d¡S )Nó    Úutf8)r   Údecode©Úvr%   r%   r&   Ú<lambda>3   s    z%configure_converter.<locals>.<lambda>c                 S   s   t | ƒS r)   )r   ©r8   Ú_r%   r%   r&   r9   5   s    c                 S   ó
   t  | ¡S r)   )r   Úfromisoformatr:   r%   r%   r&   r9   7   ó   
 c                 S   r<   r)   )r   r=   r:   r%   r%   r&   r9   8   r>   Nr(   c                    sd   t }t| dd ƒ}|r*t|d t ƒrt|d tƒrdd„ }nˆ  |d ¡}|tkr*|}ˆ j| ||d�S )NÚ__args__r   c                 S   s   | j S r)   )Úvaluer7   r%   r%   r&   Úkey_handler@   s   zMconfigure_converter.<locals>.unstructure_mapping_factory.<locals>.key_handler)Úunstructure_torA   )r1   Úgetattrr   r   Úget_unstructure_hookr   Úgen_unstructure_mapping)r(   rB   rA   ÚargsÚkh©r3   r%   r&   Úunstructure_mapping_factory:   s   
ÿz8configure_converter.<locals>.unstructure_mapping_factoryT)rB   Úextended)Úinclude_bare_enumsr)   )Úregister_unstructure_hookr.   Úregister_structure_hookr   r   r	   Ú_unstructure_funcÚregister_func_listr   r   r   r   ÚtupleÚregister_unstructure_hook_funcr   r   Ú!register_unstructure_hook_factoryr   r   r   r   r1   ÚboolÚintÚfloat)r3   rI   r%   rH   r&   r   !   s,   ÿ
ýþÿ
ÿÿr   rF   r!   c                  O   s2   t ti| di ¡¥|d< t| i |¤Ž}t|ƒ |S )NÚunstruct_collection_overrides)r   ÚlistÚgetr   r   )rF   r!   Úresr%   r%   r&   r   c   s   ÿ
þr   )*Ú__doc__Úbase64r   r   Úcollections.abcr   r   r   Úenumr   Ú	functoolsr   Útypingr	   r
   r   Úorjsonr   r   Ú_compatr   Úcolsr   r   r   Ú
convertersr   Úfnsr   Úliteralsr   Ú
strategiesr   Ú r   r   r   Ú__all__r   r   r   r   r%   r%   r%   r&   Ú<module>   s*    B