a
    DPÎj2  ã                   @   sê   d dl mZ ddlmZ ddlmZmZ ddlmZ G dd„ dƒZ	e	dƒZ
e	d	ƒZe	d
ƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%S )&é    )Ú	Componenté   )Úvalidate_callback)Úflatten_groupingÚmake_grouping_by_index)Ústringify_idc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú	_Wildcardc                 C   s
   || _ d S ©N©Ú_name)ÚselfÚname© r   úa/mounts/lovelace/software/anaconda3/envs/metadmg/lib/python3.9/site-packages/dash/dependencies.pyÚ__init__	   s    z_Wildcard.__init__c                 C   s   | j S r	   r
   ©r   r   r   r   Ú__str__   s    z_Wildcard.__str__c                 C   s   d| › d�S )Nú<ú>r   r   r   r   r   Ú__repr__   s    z_Wildcard.__repr__c                 C   s   d| j › d�S )Nz["z"]r
   r   r   r   r   Úto_json   s    z_Wildcard.to_jsonN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s   r   ÚMATCHÚALLÚ
ALLSMALLERc                   @   sT   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚDashDependencyc                 C   s,   t |tƒr| ¡ | _n|| _|| _d| _d S )NF)Ú
isinstancer   Z_set_random_idÚcomponent_idÚcomponent_propertyÚallow_duplicate)r   r   r    r   r   r   r      s
    
zDashDependency.__init__c                 C   s   |   ¡ › d| j› �S )NÚ.©Úcomponent_id_strr    r   r   r   r   r   (   s    zDashDependency.__str__c                 C   s   d| j j› d| › d�S )Nr   z `z`>)Ú	__class__r   r   r   r   r   r   +   s    zDashDependency.__repr__c                 C   s
   t | jƒS r	   )r   r   r   r   r   r   r$   .   s    zDashDependency.component_id_strc                 C   s   |   ¡ | jdœS )N)ÚidÚpropertyr#   r   r   r   r   Úto_dict1   s    zDashDependency.to_dictc                 C   s    t |tƒo| j|jko|  |¡S )zÔ
        We use "==" to denote two deps that refer to the same prop on
        the same component. In the case of wildcard deps, this means
        the same prop on *at least one* of the same components.
        )r   r   r    Ú_id_matches)r   Úotherr   r   r   Ú__eq__4   s
    

ÿýzDashDependency.__eq__c                 C   sÒ   | j }|j }t|tƒ}t|tƒ}||kr,dS |rÊt| ¡ ƒt| ¡ ƒkrLdS | ¡ D ]p\}}|| }||krnqTt|tƒ}	t|tƒ}
|	sŠ|
r¾|	rT|
s”qT|tu sT|tu r¦qT|tu s¶|tu rÄ dS qT dS qTdS ||kS )NFT)	r   r   ÚdictÚsetÚkeysÚitemsr   r   r   )r   r*   Zmy_idZother_idZ	self_dictÚ
other_dictÚkÚvZother_vZv_wildZ
other_wildr   r   r   r)   @   s2    



zDashDependency._id_matchesc                 C   s   t t| ƒƒS r	   )ÚhashÚstrr   r   r   r   Ú__hash__`   s    zDashDependency.__hash__c                 C   s0   t | jtƒr,| j ¡ D ]}t |tƒr dS qdS )zS
        Return true if id contains a wildcard (MATCH, ALL, or ALLSMALLER)
        TF)r   r   r,   Úvaluesr   )r   r2   r   r   r   Úhas_wildcardc   s
    
zDashDependency.has_wildcardN)r   r   r   r   r   r   r$   r(   r+   r)   r5   r7   r   r   r   r   r      s   
 r   c                       s*   e Zd ZdZeefZd‡ fdd„	Z‡  ZS )ÚOutputzOutput of a callback.Fc                    s   t ƒ  ||¡ || _d S r	   )Úsuperr   r!   )r   r   r    r!   ©r%   r   r   r   s   s    zOutput.__init__)F)	r   r   r   Ú__doc__r   r   Úallowed_wildcardsr   Ú__classcell__r   r   r:   r   r8   n   s   r8   c                   @   s   e Zd ZdZeeefZdS )ÚInputz8Input of callback: trigger an update when it is updated.N©r   r   r   r;   r   r   r   r<   r   r   r   r   r>   x   s   r>   c                   @   s   e Zd ZdZeeefZdS )ÚStatezAUse the value of a State in a callback but don't trigger updates.Nr?   r   r   r   r   r@   ~   s   r@   c                   @   s   e Zd Zddd„Zdd„ ZdS )ÚClientsideFunctionNc                 C   s:   |  d¡rtdƒ‚|dv r*td|› d�ƒ‚|| _|| _d S )NZ_dashprivate_z-Namespaces cannot start with '_dashprivate_'.)ZPreventUpdateZ	no_updateú"z." is a forbidden namespace in dash_clientside.)Ú
startswithÚ
ValueErrorÚ	namespaceÚfunction_name)r   rE   rF   r   r   r   r   …   s    

ÿzClientsideFunction.__init__c                 C   s   d| j › d| j› d�S )NzClientsideFunction(z, ú))rE   rF   r   r   r   r   r   ’   s    zClientsideFunction.__repr__)NN)r   r   r   r   r   r   r   r   r   rA   „   s   
rA   c                 C   s�   d|v rP|d }t |ttfƒr&t|ƒ}t|ƒD ]}t |tƒs.td|› �ƒ‚q.|S g }| rŒt| d ƒ}tdd„ |D ƒƒrŒ| |  d¡¡ qTqŒqT|S )NÚoutputzGInvalid value provided where an Output dependency object was expected: r   c                 s   s   | ]}t |tƒV  qd S r	   )r   r8   ©Ú.0Údr   r   r   Ú	<genexpr>ª   ó    z7extract_grouped_output_callback_args.<locals>.<genexpr>)	r   ÚlistÚtupler   r8   rD   ÚallÚappendÚpop)ÚargsÚkwargsÚ
parametersÚdepÚ	next_depsr   r   r   Ú$extract_grouped_output_callback_args–   s&    
ÿÿrX   c                 C   sÂ   | d }t |tƒr|g}|  dd ¡}t |tƒr4|g}t |tƒrl|rdt |tƒsTtdƒ‚|}| |¡ n|}|S t |ttfƒr¬t|ƒ}|r¨t |ttfƒsœtdƒ‚|t|ƒ7 }|S tdt|ƒ› �ƒ‚d S )NÚinputsÚstatez€The input argument to app.callback was a dict, but the state argument was not.
input and state arguments must have the same typez€The input argument to app.callback was a list, but the state argument was not.
input and state arguments must have the same typez]The input argument to app.callback may be a dict, list, or tuple,
but received value of type )	r   r   Úgetr,   rD   ÚupdaterN   rO   Útype)rT   Zinput_parametersZstate_parametersrU   r   r   r   Ú5extract_grouped_input_state_callback_args_from_kwargs±   s<    



ÿÿÿÿr^   c                 C   sT   g }| r<t | d ƒ}tdd„ |D ƒƒr<| |  d¡¡ qq<qt|ƒdkrP|d S |S )Nr   c                 s   s   | ]}t |ttfƒV  qd S r	   )r   r>   r@   rI   r   r   r   rL   æ   rM   zFextract_grouped_input_state_callback_args_from_args.<locals>.<genexpr>r   )r   rP   rQ   rR   Úlen)rS   rU   rW   r   r   r   Ú3extract_grouped_input_state_callback_args_from_argsá   s    r`   c                 C   s(   d|v rt |ƒS d|v r tdƒ‚t| ƒS )NrY   rZ   zQThe state keyword argument may not be provided without the input keyword argument)r^   rD   r`   )rS   rT   r   r   r   Ú)extract_grouped_input_state_callback_argsó   s    ÿra   c           
      C   sŠ   t | ƒ}dd„ |D ƒ}dd„ |D ƒ}t|ƒ}d}d}g }|D ]8}t|tƒr^| |¡ |d7 }q<| || ¡ |d7 }q<t| |ƒ}	|||	fS )Nc                 S   s   g | ]}t |tƒr|‘qS r   )r   r>   ©rJ   rV   r   r   r   Ú
<listcomp>  rM   z8compute_input_state_grouping_indices.<locals>.<listcomp>c                 S   s   g | ]}t |tƒr|‘qS r   )r   r@   rb   r   r   r   rc     rM   r   r   )r   r_   r   r>   rQ   r   )
Zinput_state_groupingZ	flat_depsÚflat_inputsÚ
flat_stateZtotal_inputsZinput_countZstate_countZ	flat_indsrV   Zgrouping_indsr   r   r   Ú$compute_input_state_grouping_indices  s    




rf   c                 C   s   |  dd¡}|du r<| r<t| d tƒr<| dd… | d  } }g }| D ] }|t|ttfƒr\|n|g7 }qDt||ƒ}t|ƒ}t|ttfƒrÀt|ƒdkrÀ|  d| r¤| d nd¡}t|ttfƒsÀ|d }t||ƒ}t	|ƒ\}	}
}t
ttf}t||	|
||ƒ ||	|
||fS )ú*Split args into outputs, inputs and statesÚprevent_initial_callNéÿÿÿÿr   rH   r   )r[   r   ÚboolrN   rO   rX   r   r_   ra   rf   r>   r8   r@   r   )rS   rT   rh   Ú	flat_argsÚargÚoutputsZflat_outputsÚout0Zinputs_staterd   re   Zinput_state_indicesÚtypesr   r   r   Úhandle_grouped_callback_args  s&    

ÿ

rp   c                 C   sN   |  |g ¡}|r&t|ttfƒsJ|gS n$| rJt| d |ƒrJ| |  d¡¡ q&|S )z3Extract arguments for callback from a name and typer   )r[   r   rN   rO   rQ   rR   )rS   rT   r   Útype_rU   r   r   r   Úextract_callback_args>  s    rr   c                 C   sô   |  dd¡}|du r<| r<t| d tƒr<| dd… | d  } }g }| D ] }|t|ttfƒr\|n|g7 }qDt||dtƒ}|}t|ƒdkr²|  d| r–| d nd¡}t|ttfƒs²|d }t||dtƒ}t||dt	ƒ}	ttt	f}
t
|||	||
ƒ |||	|fS )	rg   rh   Nri   rH   r   r   rY   rZ   )r[   r   rj   rN   rO   rr   r8   r_   r>   r@   r   )rS   rT   rh   rk   rl   rm   Zvalidate_outputsrn   rY   Zstatesro   r   r   r   Úhandle_callback_argsM  s"    
rs   N)Zdash.development.base_componentr   Ú	_validater   Z	_groupingr   r   Z_utilsr   r   r   r   r   r   r8   r>   r@   rA   rX   r^   r`   ra   rf   rp   rr   rs   r   r   r   r   Ú<module>   s(   Q
0"