
    MfL                         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)dS )    )MutableSequenceN)dedent)	iskeyword   )grouping_lenmap_grouping)	Component)
exceptions)patch_collections_abcstringify_idto_jsoncoerce_to_listclean_property_namec           	      d   |\  }}}|rt          |d         |||f          s8t          j        t          dt	          |d                    d                    t          j        t          d| |z   |z   d         d|d         d                    | ||fD ]}|D ]}	t          |	           d S )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
             M/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash/_validate.pyvalidate_callbackr#      s     E65 
*Q-&%)?@@ 
	3 *Q-((	   	 	 	 / F"U*B/ 
 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          |            d S t          | j	        t                    rt          |            d S 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   3   s   gc#7>>DD 
/<?<R   
 
 	
 s%&& 
2
 
 	
 #"D)) 
	C$c	*	* 

3 />A>N   
 
 	
r$   c           
          | j         }|D ]?}t          |t                    s(t          j        t          d|d|d                    @d S )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.   U   s    F   !S!! 	3 '-     		 r$   c           
          | j         d}fd|D             }|rDt          j        d dd                    |           dd                    |           d          d S )Nz.{c                     g | ]}|v |	S  r5   ).0xr1   s     r"   
<listcomp>z&validate_id_string.<locals>.<listcomp>k   s    ===1fQr$   z
            The element `z` contains `z`, `z%` in its ID.
            Characters `z&` are not allowed in IDs.
            )r,   r
   InvalidComponentIdErrorjoin)r!   invalid_charsinvalid_foundr1   s      @r"   r/   r/   g   s    FM=======M 
0  .4kk-.H.H ]33  
 
 	

 
r$   c           	         t          | t          t          f          s| g|g}} n4t          |           t          |          k    rt	          j        d          t          | |          D ]h\  }}t          |t          t          f          r|n|g}|D ]?} ||d         t          |d                             |k    st	          j        d          @idS )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_specrK   u   s     ftUm,, G%h	VK((	(	(*+EFFF6;// 	 	e(u>>KUUUG
  	 	FF6$<)<VJ=O)P)PQQ  !2?  		 	r$   c                     t          |          t                     k    rt          j        d          t	           fd|          }t          |t                    r5g }|}|D ]-}|                                st          j        | d          .n3t          |t          t          f          rt          |          }i }n|g}i }||fS )Nz'Inputs do not match callback definitionc                     |          S Nr5   )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   rB   r
   rC   r   r   r-   isidentifierrA   r@   )rP   arg_index_groupingargs_grouping	func_argsfunc_kwargskeys   `     r"   validate_and_group_input_argsrX      s    &''3y>>99*+TUUU !;!;!;!;=OPPM$d++ 	# 	 	C##%%  2@@@  	
 
&	6	6 ''	 #O	k!!r$   c                    t          |t          t          f          s(t          j        t          d| d|d                    t          |          t          |           k    r8t          j        d| dt          |            dt          |           d          t          |           D ]\  }}t          |t                    r||         }t          |t          t          f          s.t          j        t          d| d	| d
|d|d	                    t          |          t          |          k    rNt          j        t          d| d| dt          |           dt          |           d|d|d                    d S )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@   rA   r
   InvalidCallbackReturnValuer   rB   	enumerate)outputs_listoutput_valuecallback_idirG   vis         r"   validate_multi_returnrb      s3   lT5M22 	
3)     
 
 	
 <C----31< ,'' /2</@/@  
 
 	
 \**  4dD!! 	aBb4-00 
 ;&1 ;<    '+	   	 	 	 2ww#d))## ;=H PQ "%b'' 14T  '+  (*	   	 	 	! r$   c                   	
 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	          )NFc                 t   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
   r[   )bad_val	outer_valpathindextoplevelbad_typeouter_id
outer_typelocationindex_stringobjrE   s              r"   _raise_invalidz,fail_callback_output.<locals>._raise_invalid   sZ   ==)/6y$/N/NV+),+++++TV)__-
 	 HH %*M55~5~~~~L  * -5     H ,4@##3#)   19 
      
 
 	
r$   c                 $    t          |           S rN   r   )valvalid_childrens    r"   _valid_childz*fail_callback_output.<locals>._valid_child   s    #~...r$   c                 $    t          |           S rN   r|   )r}   valid_propss    r"   _valid_propz)fail_callback_output.<locals>._valid_prop  s    #{+++r$   c                 |     |           s |           sdS 	 t          |            n# t          $ r Y dS w xY wdS )NFT)r   	TypeError)r}   r   r   s    r"   _can_serializez,fail_callback_output.<locals>._can_serialize  sd    S!! 	[[%5%5 	5	CLLLL 	 	 	55	ts   + 
99c           	      T   t          | t                    r`g }|                                 D ]\  } |          s || |            |          sDfd|D             }|r nt          fd|D                       r|                    |f           t          |dd           }t          |t          t          f          s7|r5 |          s* || 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	
           d S d S )N)ro   rp   rq   rr   c                 J    g | ]}                     |d                    | S r   
startswithr6   r`   ps     r"   r8   zAfail_callback_output.<locals>._validate_value.<locals>.<listcomp>  s>     , , ,q||AaD?Q?Q,, , ,r$   c              3   P   K   | ] }|d                                          V  !dS )r   Nr   r   s     r"   	<genexpr>z@fail_callback_output.<locals>._validate_value.<locals>.<genexpr>$  s6      PPaqtq111PPPPPPr$   children
z[*] r   rg   T)ro   rp   rq   rr   rs   )
r   r	   _traverse_with_pathsallappendr(   rA   r   rm   rn   )	r}   rr   unserializable_itemsjchildr   r   rz   r   s	        @r"   _validate_valuez-fail_callback_output.<locals>._validate_value  sm   c9%% 0	#% 0022  1#|A R"N1!5QQQQ%~a(( <, , , ,#7, , ,( ,  PPPP;OPPPPP <,33QF;;;  :t44!%%)ABB  ^^E%:%: &$)&)!"TF!2T%[[5I!I"'	    $ N+A.1 qCauMMMM CT22Eee_%=>>  !4!4 "N %"%!%[[1#	    ~c"" 	Ns)),     	 	r$   )rr   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.
        )NFrN   )r)   intfloatrm   r	   rA   r   r   r@   r\   r
   r[   )r^   rE   r   r`   r}   r   rz   r   r   r~   r   s    `   @@@@@@r"   fail_callback_outputr      s[   3tDzz9=NUDJJGK&
 &
 &
 &
 &
 &
P/ / / / /, , , , ,     ; ; ; ; ; ; ; ;z ,%% &-- 	* 	*FAsOCq)))))	* 	%%% 
/	"(	 	 	  r$   c                 l    | D ]0}|dv rt          j        d| d          t          d| d          d S )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.
                z+Dash() got an unexpected keyword argument '')r
   ObsoleteKwargExceptionr   )kwargsrW   s     r"   check_obsoleter   ^  ss     	N 	N???3     LcLLLMMM	N 	Nr$   c           	          || vr:t          j        d| dt          |                                            d          || |         vrt          j        d| d| d|  d          d S )Nz(
            Error loading dependency. "zQ" is not a registered library.
            Registered libraries are:
            rZ   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   k  s    +++,(4  "''))**  
 
 	
 #3L#AAA, "6  (8  
 
 	
 BAr$   c           	          fd|D             }|rHt          |          dk    rdnd}t          j        d| dd                    |           d|  d	          d S )
Nc                 h    g | ].\  }}t          j        |                                        ,|/S r5   )recompilesearch)r6   checkr`   rr   s      r"   r8   z"validate_index.<locals>.<listcomp>  s:    OOOXUArz%/@/@/G/G/N/NOqOOOr$   r   re   rg   zMissing itemrk   z, z in .)rB   r
   InvalidIndexExceptionr:   )namechecksrr   missingplurals     `  r"   validate_indexr     s    OOOOOOOG 
Gq((b.C6CCDIIg$6$6CCDCCC
 
 	

 
r$   c                 v    t          | t          t          d          f          st          j        d          d S )NCallablezLLayout must be a dash component or a function that returns a dash component.)r   r	   r   r
   NoLayoutException)rl   s    r"   validate_layout_typer     sF    ei)>z)J)JKLL 
*;
 
 	

 
r$   c                 d   | t          j        d          t          t          |dd                     }|r|hnt	                      }|                                D ]S}t          t          |dd                     }|r||v rt          j        d| d          |                    |           Td S )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.
            r>   zF
                Duplicate component id found in the initial layout: `z`
                )r
   r   r   r(   set	_traverseDuplicateIdErroradd)layoutlayout_value	layout_idcomponent_ids	componentr,   s         r"   validate_layoutr     s    ~*
 
 	
 W\4>>??I#,7YKK#%%M!++-- ( (	#GItT$B$BCC 	LM99-FR    
 	,''''( (r$   c                     t          j        d|           }|D ];}|                                rt          |          rt	          d| d|  d          <d S )Nz<(.*?)>`z;` is not a valid Python variable name in `path_template`: "z".)r   findallrR   r   	Exception)templatevariable_namesr   s      r"   validate_templater     s{    Z	844N    "" 	ioo 	aDaaU]aaa  	 r$   c                 :   i }|                                  D ]F}|d         |vr|d         g||d         <   ||d                                      |d                    G|                                 D ](}t          |          dk    rt          d| d          )d S )Nrq   moduler   zmodules z have duplicate paths)valuesr   rB   r   )registrypath_to_modulepagemoduless       r"   check_for_duplicate_pathnamesr     s    N!! @ @<~--,0N+;N4<((4<(//X????!((** G Gw<<!EwEEEFFF G Gr$   c                     |                                  D ]?}d|vrt          j        d|d          d          |d         dk    rt          d          @d S )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     s    !!  4.OXOOO   >Z''   ( r$   c                 V    t          |d          st          j        d|  d          d S )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     sJ    4"" 
*'-  
 
 	

 
r$   c                     |                      dd           st          j        d          t          j                    rt          j        d          d S )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     sg    ::ot,, 
"K
 
 	
  "" 
"
 
 	

 
r$   c                 X    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     s3    fc"" 
"X
 
 	
 Mr$   c                   
 t                      }i }|                                 D ]}t          |d                   }|                    |           |D ]R}|                    |t                                 ||                             t          |d                              Sd |                                 D             D ]}|d         }|                    dg           }|                    dg           }t          |d                   
t          d |D             |z             
fdt          fd	|                                D                       D             }	|	rt          j        d
|	 d          d S )NrE   
raw_inputsc              3   D   K   | ]}|                     d           |V  dS )longN)r   r6   r7   s     r"   r   z*validate_long_callbacks.<locals>.<genexpr>  s1      GG1vGQGGGGGGr$   r   progressrunningc                     g | ]
}|d          S r   r5   r   s     r"   r8   z+validate_long_callbacks.<locals>.<listcomp>  s    ---qt---r$   c                     g | ]}|v |	S r5   r5   )r6   r7   long_inputss     r"   r8   z+validate_long_callbacks.<locals>.<listcomp>  s.     
 
 
K r$   c              3   L   K   | ]\  }}|                               |V  d S rN   )intersection)r6   r2   vr   s      r"   r   z*validate_long_callbacks.<locals>.<genexpr>  s8      XXtq!w@W@WXXXXXXXr$   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   circularr   r   s             @@r"   validate_long_callbacksr     s    %%KM '')) L LXh/003 	L 	LA$$Q...!##N8L3I$J$JKKKK	L HG 3 3 5 5GGG  V$	==R00--	2..$Xl%;<<--W---899
 
 
 
XXXX}':':'<'<XXXXX
 
 
  	.m( m m m  	 r$   c                     dfv rd S fd}t          | t          t          f          r| D ]} ||           d S  ||            d S )Ninitial_duplicatec                 N    | j         rsst          j        d          d S d S d S )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>._valid  s[    
	(
	 0
	
 .[  
	 
	 
	 
	 
	 
	r$   )r   r@   rA   )rE   r  r  r  r   s    ``  r"   validate_duplicate_outputr    s     35PQQQ      &4-((  	 	AF1IIII
F6NNNNNr$   )*collections.abcr   r   textwrapr   keywordr   r   	_groupingr   r   development.base_componentr	   rg   r
   _utilsr   r   r   r   r   r#   r   r.   r/   rK   rX   rb   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r5   r$   r"   <module>r     s"   + + + + + + 				              1 1 1 1 1 1 1 1 1 1 1 1 1 1                   ' ' '@
 
 
D  $
 
 
  ." " "0- - -`G G GT
N 
N 
N
 
 
(
 
 

 
 
( ( (0  
G 
G 
G  
 
 

 
 
    @    r$   