
    $gP                        d dl Z d dlmZ d dlZd dlmZ d dlmZ d dl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mZmZ d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*y)    N)MutableSequence)dedent)	iskeyword   )grouping_lenmap_grouping)	Component)
exceptions)patch_collections_abcstringify_idto_jsoncoerce_to_listclean_property_namec           	      .   |\  }}}|rqt        |d   |||f      s.t        j                  t        dt	        |d          d            t        j                  t        d| |z   |z   d   d|d   d            | ||fD ]  }|D ]  }	t        |	         y )Nr   z
                    Callback arguments must be `Output`, `Input`, or `State` objects,
                    optionally wrapped in a list or tuple. We found (possibly after
                    unwrapping a list or tuple):
                    
                    z
                In a callback definition, you must provide all Outputs first,
                then all Inputs, then all States. After this item:
                z:
                we found this item next:
                
                )
isinstancer
   IncorrectTypeExceptionr   reprvalidate_callback_arg)
outputsinputsstate
extra_argstypesInputOutputStateargsargs
             K/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/dash/_validate.pyvalidate_callbackr#      s     E65*Q-&%)?@33 *Q-() *		 	 // F"U*B/2 3A! "

 
	
 &%( ' 	'C!#&	''    c                    t        t        | dd       t              s,t        j                  t        d| j                  d            t        | d      rt        j                  d      t        | j                  t              rt        |        y t        | j                  t              rt        |        y t        j                  t        d| j                  d            )Ncomponent_propertyz<
                component_property must be a string, found r   component_eventzd
            Events have been removed.
            Use the associated property instead.
            z>
                component_id must be a string or dict, found )r   getattrstrr
   r   r   r&   hasattrNonExistentEventExceptioncomponent_iddictvalidate_id_dictvalidate_id_string)r!   s    r"   r   r   4   s    gc#7>D//<<?<R<R;U V
 	
 s%&22
 	
 #""D)	C$$c	*3 //>>A>N>N=Q R
 	
r$   c           
          | j                   }|D ]7  }t        |t              rt        j                  t        d|d|d             y )Nz[
                    Wildcard ID keys must be non-empty strings,
                    found z in id r   )r,   r   r)   r
   r   r   )r!   arg_idks      r"   r.   r.   V   s]    F  !S!33%wvj 1 r$   c           
          | j                   }d}|D cg c]	  }||v s| }}|r=t        j                  d| ddj                  |       ddj                  |       d      y c c}w )Nz.{z
            The element `z` contains `z`, `z%` in its ID.
            Characters `z&` are not allowed in IDs.
            )r,   r
   InvalidComponentIdErrorjoin)r!   r1   invalid_charsxinvalid_founds        r"   r/   r/   h   s    FM -=1fQ=M=00 fkk-.H-I J]34 5
 	
  >s
   	A#A#c           	      b   t        | t        t        f      s| g|g}} n,t        |       t        |      k7  rt	        j
                  d      t        | |      D ]W  \  }}t        |t        t        f      r|n|g}|D ]2  } ||d   t        |d               |k(  rt	        j
                  d       Y y)z
    This validation is for security and internal debugging, not for users,
    so the messages are not intended to be clear.
    `output` comes from the callback definition, `output_spec` from the request.
    zWrong length output_specidpropertyz)Output does not match callback definitionN)r   listtuplelenr
   CallbackExceptionzipr   )outputoutput_specr   outispeci
speci_listspecijs          r"   validate_output_specrG   v   s     ftUm,%h	VK(	(**+EFF6;/ 	e(u>UUG
  	F6$<)<VJ=O)PQ !22? 		r$   c                 h    t        |      t               k7  rt        j                  d      t	         fd|      }t        |t              r7g }|}|D ]*  }|j                         rt        j                  | d       ||fS t        |t        t        f      rt        |      }i }||fS |g}i }||fS )Nz'Inputs do not match callback definitionc                     |    S N )ind	flat_argss    r"   <lambda>z/validate_and_group_input_args.<locals>.<lambda>   s    Ys^ r$   z$ is not a valid Python variable name)
r   r>   r
   r?   r   r   r-   isidentifierr=   r<   )rM   arg_index_groupingargs_grouping	func_argsfunc_kwargskeys   `     r"   validate_and_group_input_argsrU      s    &'3y>9**+TUU !;=OPM$d+	# 	C##% 22e?@ 	 k!! 
&	6'	 k!! #O	k!!r$   c                    t        |t        t        f      s%t        j                  t        d| d|d            t        |      t        |       k7  r1t        j                  d| dt        |        dt        |       d      t        |       D ]  \  }}t        |t              s||   }t        |t        t        f      s+t        j                  t        d| d	| d
|d|d	            t        |      t        |      k7  sut        j                  t        d| d| dt        |       dt        |       d|d|d             y )Nz
                The callback zl is a multi-output.
                Expected the output type to be a list or tuple but got:
                z.
                z1
            Invalid number of output values for z.
            Expected z, got 
            z&
                        The callback z output z is a wildcard multi-output.
                        Expected the output type to be a list or tuple but got:
                        z'.
                        output spec: z
                        z=
                        Invalid number of output values for z item z#.
                        Expected z&
                        output spec: z'
                        output value: )r   r<   r=   r
   InvalidCallbackReturnValuer   r>   	enumerate)output_listsoutput_valuescallback_idirB   output_values         r"   validate_multi_returnr_      s   mdE]333)] +! "
 	
 =S..3311< >,'(s=/A.B C
 	
 $L1 ;k4((+LlT5M: ;;&&1](1# >%( )&&1_ 5		 	 < C$44 ;;==HMPQs S""%k"2!36#l:K9L M&&1_ 5''3&6 7		 	!r$   c                 t  	
 t         t        t        t        d       t        f	t         t        t        t        d       t
        t        f
d	fd		fd
fdfdd
fd	}t        | t              rt        |       D ]  \  }} |||        n ||        t        j                  dd      )Nc                 d   t        |       j                  }t        |dd      rd|j                  ddnd}t        |      j                  }|rt	        d      }n#|dnd	|d
d}	t	        d|	 d| d| d| d	      }|sdnd}
t        j                  t	        dd|
dd| d| d|  d            )Nr:   Fz(id=s) z
                The value in question is either the only value returned,
                or is in the top level of the returned list,
                z[*][d]zE
                The value in question is located at
                 r   z,
                ztree with one valuevaluez#
                The callback for `z`
                returned a z having type `zC`
                which is not JSON serializable.

                z@
                and has string representation
                `z`

                In general, Dash properties can only be
                dash components, strings, dictionaries, numbers, None,
                or lists of those.
                )type__name__r(   r:   r   r
   rX   )bad_val	outer_valpathindextoplevelbad_typeouter_id
outer_typelocationindex_stringobjrA   s              r"   _raise_invalidz,fail_callback_output.<locals>._raise_invalid   s   =))/6y$/NT),,q)+TV)_--
H %*M55)1~La
|1XJ 7 H ,4#33##)* -7.
 ; 
  
 	
r$   c                     t        |       S rJ   r   )valvalid_childrens    r"   _valid_childz*fail_callback_output.<locals>._valid_child  s    #~..r$   c                     t        |       S rJ   ry   )rz   valid_propss    r"   _valid_propz)fail_callback_output.<locals>._valid_prop  s    #{++r$   c                 ^     |       s	 |       sy	 t        |        y# t        $ r Y yw xY w)NFT)r   	TypeError)rz   r|   r   s    r"   _can_serializez,fail_callback_output.<locals>._can_serialize  s:    S![%5	CL   		s     	,,c           	         t        | t              r?g }| j                         D ]  \  } 	|      s || |        |      sO|D cg c]  }j                  |d         r| }}|r nt	        fd|D              r|j                  |f       t        |dd       }t        |t        t        f      r|s |      r || dz   dz   t        |      j                  z   |        |r|d   \  } || |       t        | dd       }t        |t        t        f      s)|r' |       s || t        |      j                  |        |       s! | t        |       j                  d|d	       y y c c}w )
N)rl   rm   rn   ro   r   c              3   H   K   | ]  }|d    j                           yw)r   N)
startswith).0r]   ps     r"   	<genexpr>z@fail_callback_output.<locals>._validate_value.<locals>.<genexpr>%  s!     Paqtq11Ps   "children
z[*] rd   T)rl   rm   rn   ro   rp   )r   r	   _traverse_with_pathsr   allappendr(   r=   r   rj   rk   )
rz   ro   unserializable_itemsjr]   childr   r   rw   r|   s
         @r"   _validate_valuez-fail_callback_output.<locals>._validate_value  s   c9%#% 002 1#A"1!5Q%a(
 $8,q||AaD?Q,( , , P;OPP,33QF;  :t4!%%)AB^E%:&$)&)!"TF!2T%[5I5I!I"'	1< $+A.1 qCauM CT2Eee_%=>!4" %"%!%[11#	 c"s),, #M,s   E=&E=)ro   z"
        The callback for output `z`
        returned a value which is not JSON serializable.

        In general, Dash properties can only be dash components, strings,
        dictionaries, numbers, None, or lists of those.
        )NFrJ   )r)   intfloatrj   r	   r=   r   r   r<   rY   r
   rX   )r^   rA   r   r]   rz   r   rw   r|   r   r{   r~   s    `   @@@@@@r"   fail_callback_outputr      s    3tDz9=NUDJGK&
P/,;z ,%- 	*FAsCq)	* 	% 
/
/""( ,		 r$   c                     | D ]P  }|dv rt        j                  d| d      |dv rt        | dt        j                         Ct        d| d       y )	N)components_cache_max_agestatic_folderr   z is no longer a valid keyword argument in Dash since v1.0.
                See https://dash.plotly.com for details.
                )dynamic_loadingpreloaded_librarieszA has been removed and no longer a valid keyword argument in Dash.)filez+Dash() got an unexpected keyword argument '')r
   ObsoleteKwargExceptionprintsysstderrr   )kwargsrT   s     r"   check_obsoleter   _  s     N??33   <<%XYZZ EcU!LMM!Nr$   c           	          || vr3t        j                  d| dt        | j                                d      || |   vrt        j                  d| d| d|  d      y )Nz(
            Error loading dependency. "zQ" is not a registered library.
            Registered libraries are:
            rW   z
            "zV" is registered but the path requested is not valid.
            The path requested: "z("
            List of registered paths: )r
   DependencyExceptionr<   keys)registered_pathspackage_namepath_in_package_dists      r"   validate_js_pathr   s  s    ++,,((4~ 6"'')*+ ,
 	
 #3L#AA,,^ ""6!7 8''7&8 9
 	
 Br$   c           	         |D cg c],  \  }}t        j                  |      j                  |      r+|. }}}|r@t        |      dkD  rdnd}t	        j
                  d| ddj                  |       d|  d      y c c}}w )	Nr   rb   rd   zMissing itemrh   z, z in .)recompilesearchr>   r
   InvalidIndexExceptionr5   )namechecksro   checkr]   missingplurals          r"   validate_indexr     s    !'OXUArzz%/@/G/G/NqOGOGq(b..6(!DIIg$6#7tD6C
 	
  Ps
   ,A=A=c                 x    t        | t        t        d      t        t        f      st        j                  d      y )NCallablez
            Layout must be a single dash component, a list of dash components,
            or a function that returns a dash component.
            )r   r	   r   r<   r=   r
   NoLayoutException)ri   s    r"   validate_layout_typer     s=    	0<dEJ **
 	
r$   c                    | t        j                  d      t               fd}t        |t        t
        f      rH|D ]B  }t        |t        f      rt        |t        f      r	 ||       /t        j                  d       y  ||       y )Nz
            The layout was `None` at the time that `run_server` was called.
            Make sure to set the `layout` attribute of your application
            before running the server.
            c                 Z    fd} ||        | j                         D ]
  } ||        y )Nc                     t        t        | dd             }|r|v rt        j                  d| d      j	                  |       y )Nr:   zJ
                    Duplicate component id found in the initial layout: `z`
                    )r   r(   r
   DuplicateIdErroradd)compr,   component_idss     r"   _validate_idz8validate_layout.<locals>._validate.<locals>._validate_id  sY    'dD(ABL = 11JJV X 
 l+r$   )	_traverse)ri   r   	componentr   s      r"   	_validatez"validate_layout.<locals>._validate  s0    	, 	U* 	$I#	$r$   z9Only strings and components are allowed in a list layout.)r
   r   setr   r<   r=   r)   r	   )layoutlayout_valuer   r   r   s       @r"   validate_layoutr     s    ~**
 	
 EM$  ,u.% 	I)cV,)i\2)$ 22O 	 	,r$   c                     t        j                  d|       }|D ]/  }|j                         rt        |      st	        d| d|  d       y )Nz<(.*?)>`z;` is not a valid Python variable name in `path_template`: "z".)r   findallrO   r   	Exception)templatevariable_namesr   s      r"   validate_templater     sV    ZZ	84N   "ioD6TU]T^^`a r$   c                     i }| j                         D ]0  }|d   |vr|d   g||d   <   ||d      j                  |d          2 |j                         D ]  }t        |      dkD  st        d| d       y )Nrn   moduler   zmodules z have duplicate paths)valuesr   r>   r   )registrypath_to_modulepagemoduless       r"   check_for_duplicate_pathnamesr     s    N! @<~-,0N+;N4<(4<(//X?	@ "((* Gw<!hwi/DEFFGr$   c                     | j                         D ]5  }d|vrt        j                  d|d    d      |d   dk(  s,t        d       y )Nr   zNo layout in module `r   z` in dash.page_registry__main__z
                When registering pages from app.py, `__name__` is not a valid module name.  Use a string instead.
                For example, `dash.register_page("my_module_name")`, rather than `dash.register_page(__name__)`
                )r   r
   r   r   )r   r   s     r"   validate_registryr     se    ! 4..'X'77NO  >Z' r$   c                 N    t        |d      st        j                  d|  d      y )Nr   z'
            No layout found in module zN
            A variable or a function named "layout" is required.
            )r*   r
   r   )r   r   s     r"   validate_pages_layoutr     s8    4"**''-h /
 	
 #r$   c                     | j                  dd       st        j                  d      t        j                         rt        j                  d      y )Nassets_folderz=`dash.register_page()` must be called after app instantiationu  
            dash.register_page() can’t be called within a callback as it updates dash.page_registry, which is a global variable.
             For more details, see https://dash.plotly.com/sharing-data-between-callbacks#why-global-variables-will-break-your-app
            )getr
   	PageErrorflaskhas_request_context)configs    r"   validate_use_pagesr     sQ    ::ot,""K
 	
   """
 	
 #r$   c                 P    t        | t              st        j                  d      | S )NzJThe first attribute of dash.register_page() must be a string or '__name__')r   r)   r
   r   )r   s    r"   validate_module_namer     s)    fc"""X
 	
 Mr$   c                    t               }i }| j                         D ]b  }t        |d         }|j                  |       |D ]<  }|j	                  |t                      ||   j                  t        |d                > d d | j                         D        D ]  }|d   }|j                  dg       }|j                  dg       }t        |d         }	t        |D 
cg c]  }
|
d   	 c}
|z         t        fd|j                         D              D 
cg c]  }
|
|	v r|

 }}
|st        j                  d	| d
       y c c}
w c c}
w )NrA   
raw_inputsc              3   D   K   | ]  }|j                  d       s|  yw)longN)r   )r   r7   s     r"   r   z*validate_long_callbacks.<locals>.<genexpr>  s     G1vQGs     r   progressrunningr   c              3   L   K   | ]  \  }}|j                        s|  y wrJ   )intersection)r   r2   vr   s      r"   r   z*validate_long_callbacks.<locals>.<genexpr>"  s      Xtq!w@WXs   $$zLong callback circular error!
z~ is used as input for a long callback but also used as output from an input that is updated with progress or running argument.)	r   r   r   update
setdefaultr   itemsr
   LongCallbackError)callback_mapall_outputsinput_indexedcallbackouto	long_infor   r   long_inputsr7   circularr   s               @r"   validate_long_callbacksr     so    %KM '') LXh/03 	LA$$Q.!##N8L3I$JK	LL H 3 3 5G V$	==R0--	2.$Xl%;<W-qt-89 X}':':'<XX
K 
 
 ..1( <l m  .
s   E
E	c                 ~    dfv ry fd}t        | t        t        f      r| D ]
  } ||        y  ||        y )Ninitial_duplicatec                 T    | j                   rsst        j                  d      y y y )Na*  allow_duplicate requires prevent_initial_call to be True. The order of the call is not guaranteed to be the same on every page load. To enable duplicate callback with initial call, set prevent_initial_call='initial_duplicate'  or globally in the config prevent_initial_callbacks='initial_duplicate')allow_duplicater
   DuplicateCallback)r   config_prevent_initial_callprevent_initial_calls    r"   _validz)validate_duplicate_output.<locals>._valid3  s:    (/..[  0 )  r$   )r   r<   r=   )rA   r  r  r  r   s    ``  r"   validate_duplicate_outputr  -  sN     35PQQ &4-( 	A1I	 	
6Nr$   )+r   collections.abcr   r   textwrapr   keywordr   r   	_groupingr   r   development.base_componentr	   rd   r
   _utilsr   r   r   r   r   r#   r   r.   r/   rG   rU   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rK   r$   r"   <module>r     s    
 + 	    1 1  '@
D$
."0-`GTN(
(
	
' T
G

@r$   