o
    Ti                     @   sT  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 zddlmZ W n eyE   ddlmZ Y nw zdd	lmZ W n eyY   d
ZY nw ddlmZ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" g dZ#edZ$edZ%G dd deZ&defddZ'e"e&dedede&fddZ(d
S )z%Preconfigured converters for tomllib.    )	b85decode	b85encode)Set)datedatetime)Enum)
attrgetter)AnyTypeVarUnion)loads)dumpsN   )
is_mappingis_subclass)BaseConverter	Converter)identity)configure_union_passthrough   )validate_datetimewrap)TomllibConverterconfigure_convertermake_converterT_value_c                	   @   sR   e Zd ZdZedurddedededefddZd	ed
ee dedefddZ	dS )r   z-A converter subclass specialized for tomllib.Nobjunstructure_askwargsreturnc                 K   s   t | j||dfi |S )N)r   )r   unstructure)selfr   r   r    r#   J/home/ubuntu/.local/lib/python3.10/site-packages/cattrs/preconf/tomllib.pyr   %   s   zTomllibConverter.dumpsdataclc                 K   s   |  t|fi ||S N)	structurer   )r"   r%   r&   r   r#   r#   r$   r   (   s   zTomllibConverter.loadsr'   )
__name__
__module____qualname____doc__r   r	   strtyper   r   r#   r#   r#   r$   r       s
    "r   	converterc                    s     tdd   tdd   td	dtf fdd} tt   tt  t	t   t	dd  t
tttttf   dS )
a1  
    Configure the converter for use with the tomllib library.

    * bytes are serialized as base85 strings
    * sets are serialized as lists
    * tuples are serializas as lists
    * mapping keys are coerced into strings when unstructuring
    * dates and datetimes are left for tomllib to handle
    c                 S   s   t | S r'   )r   v_r#   r#   r$   <lambda>6   s    z%configure_converter.<locals>.<lambda>c                 S   s   | r	t | dS ddS )N    utf8r   decode)r1   r#   r#   r$   r3   8   s    Nr&   c                    sf   t }t| dd }|r+t|d t rt|d trtnd }nt|d tr+dtfdd} j| ||dS )N__args__r   kc                 S   s   t | dS )Nr5   r6   )r9   r#   r#   r$   key_handlerD   s   zIconfigure_converter.<locals>.gen_unstructure_mapping.<locals>.key_handler)unstructure_tor:   )r-   getattrr   r   _enum_value_getterbytesgen_unstructure_mapping)r&   r;   r:   argsr/   r#   r$   r?   ;   s   z4configure_converter.<locals>.gen_unstructure_mappingc                 S   s   t | tr| S t| S r'   )
isinstancer   fromisoformatr0   r#   r#   r$   r3   O   s    r'   )register_structure_hookr>   register_unstructure_hook!register_unstructure_hook_factoryr   r	   r   r   r   r   r   r   r-   intfloatbool)r/   r?   r#   rA   r$   r   ,   s   
r   r@   r   r    c                  O   s6   t ttti|di |d< t| i |}t| |S )Nunstruct_collection_overrides)r   listtuplegetr   r   )r@   r   resr#   r#   r$   r   T   s   
r   ))r,   base64r   r   collections.abcr   r   r   enumr   operatorr   typingr	   r
   r   tomllibr   ImportErrortomlitomli_wr   _compatr   r   
convertersr   r   fnsr   
strategiesr    r   r   __all__r   r=   r   r   r   r#   r#   r#   r$   <module>   s:    (