a
    _g(                     @   s
  d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
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 e
eef Ze
eef ZG dd de jZG d	d
 d
eZee ZG dd deZG dd deZG dd deZG dd deZ dS )    N)Fieldfields)AnyCallableDictOptionalTupleUnionTypeget_type_hints)Enum)ValidationError)CatchAllVarc                   @   s   e Zd Zeejeeef eeef dddZ	eeeef eeef dddZ
eeeef dddZeedd	d
Zeeeeef dddZdS )_UndefinedParameterActionkvsreturnc                 C   s   dS )zE
        Return the parameters to initialize the class with.
        N clsr   r   r   h/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/dataclasses_json/undefined.pyhandle_from_dict   s    z*_UndefinedParameterAction.handle_from_dictc                 C   s   |S )zO
        Return the parameters that will be written to the output dict
        r   )objr   r   r   r   handle_to_dict   s    z(_UndefinedParameterAction.handle_to_dictr   c                 C   s   i S )zN
        Return the parameters that will be added to the schema dump.
        r   r   r   r   r   handle_dump"   s    z%_UndefinedParameterAction.handle_dumpc                 C   s   | j S N)__init__r   r   r   r   create_init)   s    z%_UndefinedParameterAction.create_initc                    sJ   t | }dd |D   fdd| D } fdd| D }||fS )zL
        Returns a 2 dictionaries: defined and undefined parameters
        c                 S   s   g | ]
}|j qS r   )name).0fieldr   r   r   
<listcomp>4       zM_UndefinedParameterAction._separate_defined_undefined_kvs.<locals>.<listcomp>c                    s   i | ]\}}| vr||qS r   r   r!   kvfield_namesr   r   
<dictcomp>5   s   zM_UndefinedParameterAction._separate_defined_undefined_kvs.<locals>.<dictcomp>c                    s   i | ]\}}| v r||qS r   r   r%   r(   r   r   r*   7   s   )r   items)r   r   Zclass_fieldsZunknown_given_parametersknown_given_parametersr   r(   r   _separate_defined_undefined_kvs-   s
    z9_UndefinedParameterAction._separate_defined_undefined_kvsN)__name__
__module____qualname__staticmethodabcabstractmethodr   r   strr   r   r   r   r   r   KnownParametersUnknownParametersr-   r   r   r   r   r      s   $"
r   c                   @   s,   e Zd ZdZeeeeef dddZdS )_RaiseUndefinedParameterszw
    This action raises UndefinedParameterError if it encounters an undefined
    parameter during initialization.
    r   c                 C   s0   t j| |d\}}t|dkr,td| |S )Nr   r   z,Received undefined initialization arguments )r   r-   lenUndefinedParameterError)r   r   knownunknownr   r   r   r   B   s    z*_RaiseUndefinedParameters.handle_from_dictN)	r.   r/   r0   __doc__r1   r   r4   r   r   r   r   r   r   r7   <   s   r7   c                   @   s>   e Zd ZdZeeeeef dddZee	dddZ
dS )	_IgnoreUndefinedParametersz
    This action does nothing when it encounters undefined parameters.
    The undefined parameters can not be retrieved after the class has been
    created.
    r   c                 C   s   t j| |d\}}|S )Nr   )r   r-   )r   r   r,   _r   r   r   r   W   s
    z+_IgnoreUndefinedParameters.handle_from_dictr   c                    s0   j t tj  fdd}|S )Nc           
         s   t |\}}t jd }|t| }|d | } j| g|R i |}|  |j}|dd  t	|}	| fi |	 d S )N   self)
_CatchAllUndefinedParametersr-   r8   
parametersbind_partialapply_defaults	argumentspopr=   r   )
r@   argskwargsknown_kwargsr>   num_params_takeablenum_args_takeablebound_parametersrE   final_parametersZinit_signaturer   Zoriginal_initr   r   _ignore_initc   s(    
z<_IgnoreUndefinedParameters.create_init.<locals>._ignore_initr   inspect	signature	functoolswraps)r   rO   r   rN   r   r   ^   s
    

z&_IgnoreUndefinedParameters.create_initN)r.   r/   r0   r<   r1   r   r4   r   r   r   r   r   r   r   r   r=   P   s
   r=   c                   @   s   e Zd ZdZG dd dZeeeeef dddZ	ee
eddd	Zeeeef eeef dd
dZeeeef dddZeedddZee
dddZdS )rA   a  
    This class allows to add a field of type utils.CatchAll which acts as a
    dictionary into which all
    undefined parameters will be written.
    These parameters are not affected by LetterCase.
    If no undefined parameters are given, this dictionary will be empty.
    c                   @   s   e Zd ZdS )z/_CatchAllUndefinedParameters._SentinelNoDefaultN)r.   r/   r0   r   r   r   r   _SentinelNoDefault   s   rU   r   c           
      C   s   t j| |d\}}tj| d}|j|v rt||j t}tj|d}|||j k}|rht|dkrh|}q|r~t|dkr~|}q|r||j }t|dkr|	| qd|j d||j  d}	t
|	n|}|||j< |S )Nr   r   )catch_all_fieldr   z9Received input field with same name as catch-all field: 'z': '')r   r-   rA   _get_catch_all_fieldr    
isinstancedict_get_defaultr8   updater9   )
r   r   r:   r;   rW   Zalready_parseddefault_valueZreceived_defaultZvalue_to_writeerror_messager   r   r   r      s:    




z-_CatchAllUndefinedParameters.handle_from_dict)rW   r   c                 C   sB   t | jtj }t | jtj }tj}|r2| j}n|r>|  }|S r   )rZ   defaultdataclasses_MISSING_TYPEdefault_factoryrA   rU   )rW   Zhas_defaultZhas_default_factoryr^   r   r   r   r\      s    z)_CatchAllUndefinedParameters._get_defaultc                 C   s0   t | j}||j}t|tr,|| |S r   )rA   rY   	__class__rF   r    rZ   r[   r]   )r   r   rW   Zundefined_parametersr   r   r   r      s    

z+_CatchAllUndefinedParameters.handle_to_dictr   c                 C   s   t j| d}t| |jS )NrV   )rA   rY   getattrr    )r   rW   r   r   r   r      s    z(_CatchAllUndefinedParameters.handle_dumpc                    s0   j t tj  fdd}|S )Nc                    s   t |\}}t jd }t j|vr6|d8 }|t| }|d | ||d   }} j| g|R i |}dd t|D }|j}	|		| |		| |	
dd  t |	}
| fi |
 d S )Nr?   c                 S   s   i | ]\}}d | |qS )_UNKNOWNr   )r!   ir'   r   r   r   r*      r$   zU_CatchAllUndefinedParameters.create_init.<locals>._catch_all_init.<locals>.<dictcomp>r@   )rA   r-   r8   rB   rY   r    rC   	enumeraterE   r]   rF   r   )r@   rG   rH   rI   Zunknown_kwargsrJ   rK   Zunknown_argsrL   rE   rM   rN   r   r   _catch_all_init   sB    

zA_CatchAllUndefinedParameters.create_init.<locals>._catch_all_initrP   )r   ri   r   rN   r   r      s
    

z(_CatchAllUndefinedParameters.create_initc                    sv   t tj| j }t| |d tt fddt| }t|}|dkrPt	dn"|dkrjt	d| dn|d S d S )	N)globalnsc                    s    | j  tt kS r   )r    r   r   )ftypesr   r   <lambda>   r$   zC_CatchAllUndefinedParameters._get_catch_all_field.<locals>.<lambda>r   z2No field of type dataclasses_json.CatchAll definedr?   z$Multiple catch-all fields supplied: .)
varssysmodulesr/   r   listfilterr   r8   r9   )r   Zcls_globalsZcatch_all_fieldsZnumber_of_catch_all_fieldsr   rl   r   rY      s"    z1_CatchAllUndefinedParameters._get_catch_all_fieldN)r.   r/   r0   r<   rU   r1   r   r4   r   r   r   r\   r   r   r   r   rY   r   r   r   r   rA   z   s   #"	!rA   c                   @   s   e Zd ZdZeZeZeZ	dS )	Undefinedzv
    Choose the behavior what happens when an undefined parameter is encountered
    during class initialization.
    N)
r.   r/   r0   r<   rA   ZINCLUDEr7   ZRAISEr=   ZEXCLUDEr   r   r   r   ru   
  s   ru   c                   @   s   e Zd ZdZdS )r9   zM
    Raised when something has gone wrong handling undefined parameters.
    N)r.   r/   r0   r<   r   r   r   r   r9     s   r9   )!r2   ra   rS   rQ   rq   r   r   typingr   r   r   r   r   r	   r
   r   enumr   Zmarshmallow.exceptionsr   Zdataclasses_json.utilsr   r4   r5   r6   ABCr   r7   ZCatchAllr=   rA   ru   r9   r   r   r   r   <module>   s&   (** 
