
    hZhj3                     6   d dl mZmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ eeeef   Z G d d      Z ed	      Z ed
      Z ed      Z G d d      Z G d de      Z G d de      Z G d de      Z G d d      Zd Zd Zd Zd Zd Zd Zd Zd Zy)    )UnionSequence   )	Component)validate_callback)flatten_groupingmake_grouping_by_index)stringify_idc                   0    e Zd ZdefdZd Zd ZdefdZy)	_Wildcardnamec                     || _         y N_name)selfr   s     `/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/dash/dependencies.py__init__z_Wildcard.__init__   s	    
    c                     | j                   S r   r   r   s    r   __str__z_Wildcard.__str__   s    zzr   c                     d|  dS )N<> r   s    r   __repr__z_Wildcard.__repr__   s    4&{r   returnc                 "    d| j                    dS )Nz["z"]r   r   s    r   to_jsonz_Wildcard.to_json   s     DJJ<r""r   N)__name__
__module____qualname__strr   r   r   r    r   r   r   r   r      s$    S # #r   r   MATCHALL
ALLSMALLERc                       e Zd ZU eed<   eed<   eed<   ee   ed<   dedefdZ	d Z
d Zdefd	Zdefd
Zd ZdefdZd ZdefdZy)DashDependencycomponent_idallow_duplicatecomponent_propertyallowed_wildcardsc                 z    t        |t              r|j                         | _        n|| _        || _        d| _        y )NF)
isinstancer   _set_random_idr*   r,   r+   )r   r*   r,   s      r   r   zDashDependency.__init__'   s5    lI. , ; ; =D ,D"4$r   c                 @    | j                          d| j                   S )N.component_id_strr,   r   s    r   r   zDashDependency.__str__1   s$    '')*!D,C,C+DEEr   c                 <    d| j                   j                   d|  dS )Nr   z `z`>)	__class__r!   r   s    r   r   zDashDependency.__repr__4   s"    4>>**+2dV266r   r   c                 ,    t        | j                        S r   )r
   r*   r   s    r   r4   zDashDependency.component_id_str7   s    D--..r   c                 <    | j                         | j                  dS )N)idpropertyr3   r   s    r   to_dictzDashDependency.to_dict:   s    ++-4;R;RSSr   c                 ~    t        |t              xr, | j                  |j                  k(  xr | j                  |      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   others     r   __eq__zDashDependency.__eq__=   s?     un- (''5+C+CC(  '	
r   c                    | j                   }|j                   }t        |t              }t        |t              }||k7  ry|rt        |j	                               t        |j	                               k7  ry|j                         D ]^  \  }}||   }||k(  rt        |t              }	t        |t              }
|	s|
r)|	r|
s:|t        u s|t        u rK|t        u s	|t        u s\ y y y||k(  S )NFT)	r*   r/   dictsetkeysitemsr   r&   r%   )r   r>   my_idother_id	self_dict
other_dictkvother_vv_wild
other_wilds              r   r=   zDashDependency._id_matchesI   s    !!%%ud+	$/

"5::< C$88 !1"1+<#Ay1';
Z"z Cx7c> EzW%5$ !    r   c                 *    t        t        |             S r   )hashr$   r   s    r   __hash__zDashDependency.__hash__i   s    CIr   c                     t        | j                  t              r1| j                  j                         D ]  }t        |t              s y y)zS
        Return true if id contains a wildcard (MATCH, ALL, or ALLSMALLER)
        TF)r/   r*   rA   valuesr   )r   rJ   s     r   has_wildcardzDashDependency.has_wildcardl   sD     d''.&&--/  a+  r   N)r!   r"   r#   ComponentIdType__annotations__boolr$   r   r   r   r   r   r4   rA   r;   r?   r=   rP   rS   r   r   r   r)   r)   !   sz    !!	**%_ %# %F7/# /T T

!D !@d r   r)   c                   <     e Zd ZdZeefZ	 ddedede	f fdZ
 xZS )OutputzOutput of a callback.r*   r,   r+   c                 4    t         |   ||       || _        y r   )superr   r+   )r   r*   r,   r+   r6   s       r   r   zOutput.__init__|   s     	'9:.r   )F)r!   r"   r#   __doc__r%   r&   r-   rT   r$   rV   r   __classcell__)r6   s   @r   rX   rX   w   s;     !&	/%/  / 	/ /r   rX   c                       e Zd ZdZeeefZy)Inputz8Input of callback: trigger an update when it is updated.Nr!   r"   r#   r[   r%   r&   r'   r-   r   r   r   r^   r^      s    BZ0r   r^   c                       e Zd ZdZeeefZy)StatezAUse the value of a State in a callback but don't trigger updates.Nr_   r   r   r   ra   ra      s    KZ0r   ra   c                   "    e Zd ZdedefdZd Zy)ClientsideFunction	namespacefunction_namec                 ~    |j                  d      rt        d      |dv rt        d| d      || _        || _        y )N_dashprivate_z-Namespaces cannot start with '_dashprivate_'.)PreventUpdate	no_update"z." is a forbidden namespace in dash_clientside.)
startswith
ValueErrorrd   re   )r   rd   re   s      r   r   zClientsideFunction.__init__   sP    0LMM66I;LM  #*r   c                 <    d| j                    d| j                   dS )NzClientsideFunction(z, ))rd   re   r   s    r   r   zClientsideFunction.__repr__   s#    $T^^$4Bt7I7I6J!LLr   N)r!   r"   r#   r$   r   r   r   r   r   rc   rc      s    +# +c +Mr   rc   c                 P   d|v rV|d   }t        |t        t        f      rt        |      }t        |      D ]   }t        |t              rt        d|        |S g }| rGt        | d         }t        d |D              r!|j                  | j                  d             n	 |S | rG|S )NoutputzGInvalid value provided where an Output dependency object was expected: r   c              3   <   K   | ]  }t        |t                y wr   )r/   rX   .0ds     r   	<genexpr>z7extract_grouped_output_callback_args.<locals>.<genexpr>   s     8z!V$8s   )	r/   listtupler   rX   rl   allappendpop)argskwargs
parametersdep	next_depss        r   $extract_grouped_output_callback_argsr      s    6H%
j4-0j)J $J/ 	Cc6* ,,/52 	 J
$T!W-	8i88dhhqk*  r   c                    | d   }t        |t              r|g}| j                  dd       }t        |t              r|g}t        |t              r6|r0t        |t              st	        d      |}|j                  |       |S |}|S t        |t        t        f      r>t        |      }|r/t        |t        t        f      st	        d      |t        |      z  }|S t	        dt        |             )NinputsstatezThe input argument to app.callback was a dict, but the state argument was not.
input and state arguments must have the same typezThe 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)   getrA   rl   updaterv   rw   type)r|   input_parametersstate_parametersr}   s       r   5extract_grouped_input_state_callback_args_from_kwargsr      s   h'"N3,-zz'40"N3,-"D).5 H  *J./  *J"T5M2*+
.u> H  $/00J
	&&*+;&<%=	? r   c                     g }| rEt        | d         }t        d |D              r!|j                  | j                  d             nn| rEt	        |      dk(  r|d   S |S )Nr   c              3   H   K   | ]  }t        |t        t        f        y wr   )r/   r^   ra   rr   s     r   ru   zFextract_grouped_input_state_callback_args_from_args.<locals>.<genexpr>   s     @z!eU^,@s    "r   )r   rx   ry   rz   len)r{   r}   r   s      r   3extract_grouped_input_state_callback_args_from_argsr      sd    J
$T!W-	@i@@dhhqk*  :!!} r   c                 T    d|v rt        |      S d|v rt        d      t        |       S )Nr   r   zQThe state keyword argument may not be provided without the input keyword argument)r   rl   r   )r{   r|   s     r   )extract_grouped_input_state_callback_argsr     s<    6DVLL&)
 	

 ?tDDr   c                 ~   t        |       }|D cg c]  }t        |t              s| }}|D cg c]  }t        |t              s| }}t	        |      }d}d}g }|D ]B  }t        |t              r|j                  |       |dz  }*|j                  ||z          |dz  }D t        | |      }	|||	fS c c}w c c}w )Nr   r   )r   r/   r^   ra   r   ry   r	   )
input_state_grouping	flat_depsr~   flat_inputs
flat_statetotal_inputsinput_countstate_count	flat_indsgrouping_indss
             r   $compute_input_state_grouping_indicesr     s     !56I #,F3z#u/E3FKF!*E#je.D#EJE {#LKKI c5![)1K\K781K ++?KM
M11' GEs   B5B5B:B:c                    |j                  dd      }|| rt        | d   t              r
| dd | d   }} g }| D ]   }|t        |t        t        f      r|n|gz  }" t        ||      }t        |      }t        |t        t        f      rBt        |      dk(  r4|j                  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_callNr   rp   r   )r   r/   rV   rv   rw   r   r   r   r   r   r^   rX   ra   r   )r{   r|   r   	flat_argsargoutputsflat_outputsout0inputs_stater   r   input_state_indicestypess                r   handle_grouped_callback_argsr   *  s$   !::&<dC#DHd1K%)#2YR" I FJsT5M:SE	F 39fEG#G,L'D%=)c'la.?zz(tDG>$u. ajG<YOL3W40K0 65 ElKYNK-@BVVVr   c                     |j                  |g       }|rt        |t        t        f      s|gS |S | rAt        | d   |      r2|j	                  | j                  d             | rt        | d   |      r2|S )z3Extract arguments for callback from a name and typer   )r   r/   rv   rw   ry   rz   )r{   r|   r   type_r}   s        r   extract_callback_argsr   L  su    D"%J*tUm4 <  z$q'51dhhqk* z$q'51r   c                    |j                  dd      }|| rt        | d   t              r
| dd | d   }} g }| D ]   }|t        |t        t        f      r|n|gz  }" t        ||dt              }|}t        |      dk(  r4|j                  d| r| d   nd      }t        |t        t        f      s|d   }t        ||dt              }t        ||dt              }	t        t        t        f}
t        |||	||
       |||	|fS )	r   r   Nr   rp   r   r   r   r   )r   r/   rV   rv   rw   r   rX   r   r^   ra   r   )r{   r|   r   r   r   r   validate_outputsr   r   statesr   s              r   handle_callback_argsr   [  s   !::&<dC#DHd1K%)#2YR" I FJsT5M:SE	F $IvxHG
7|qzz(tDG>$u. ajG"9fhFF"9fguEF65 E&	5IFF$888r   N) typingr   r   development.base_componentr   	_validater   	_groupingr   r	   _utilsr
   r$   rA   rT   r   r%   r&   r'   r)   rX   r^   ra   rc   r   r   r   r   r   r   r   r   r   r   r   <module>r      s    " 1 ( ?   Y,-# #  	'|$
S Sl/^ /1N 11N 1M M$6-`$E26WD9r   