o
    dM                     @   s$  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
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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'd0d1 Z(d2d3 Z)dS )4    )MutableSequenceN)dedent)	iskeyword   )grouping_lenmap_grouping)	Component)
exceptions)patch_collections_abcstringify_idto_jsoncoerce_to_listclean_property_namec           
      C   s   |\}}}|r6t |d |||fs ttdt|d  dttd| | | d d|d d| ||fD ]}|D ]}	t|	 q?q;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arg r    S/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/dash/_validate.pyvalidate_callback   s0   


r"   c                 C   s   t t| dd tsttd| jdt| drtdt | j	t
r+t|  d S t | j	tr7t|  d S t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   r    r    r!   r   3   s.   
r   c              	   C   s:   | j }|D ]}t|tsttd|d|dq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kr    r    r!   r+   U   s   
r+   c              
      sN   | j  d} fdd|D }|r%td  dd| dd| dd S )	Nz.{c                       g | ]}| v r|qS r    r    .0xr-   r    r!   
<listcomp>k   s    z&validate_id_string.<locals>.<listcomp>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_foundr    r3   r!   r,   g   s   r,   c                 C   s   t | ttfs| g|g} }nt| t|krtdt| |D ]'\}}t |ttfr.|n|g}|D ]}||d t|d |ksGtdq3q!d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specijr    r    r!   validate_output_specu   s"   
rF   c                    s   t |t krtdt fdd|}t|tr4g }|}|D ]}| s/t| dq!||fS t|tt	frEt	|}i }||fS |g}i }||fS )Nz'Inputs do not match callback definitionc                    s    |  S Nr    )ind	flat_argsr    r!   <lambda>   s    z/validate_and_group_input_args.<locals>.<lambda>z$ is not a valid Python variable name)
r   r=   r	   r>   r   r   r*   isidentifierr<   r;   )rJ   arg_index_groupingargs_grouping	func_argsfunc_kwargskeyr    rI   r!   validate_and_group_input_args   s(   

rR   c                 C   s
  t |ttfsttd| d|dt|t| kr0td| dt|  dt| dt| D ]N\}}t |tr|| }t |ttfs\ttd| d	| d
|d|d	t|t|krttd| d| dt| dt| d|d|dq4d 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;   r<   r	   InvalidCallbackReturnValuer   r=   	enumerate)output_listsoutput_valuescallback_idirA   output_valuer    r    r!   validate_multi_return   sr   

r[   c                    s   t tttd tft tttd ttfdfdd	fddfddfdd	 d fd
d	}t| trKt	| D ]
\}}|||d q?n||  t
dd)NFc                    s   t | j}t|ddrd|jddnd}t |j}|r!td}n|d u r'dnd	|d
d}	td|	 d| d| d| d	}|sCdnd}
ttd d|
dd| d| d|  d)Nr9   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%   r9   r   r	   rT   )bad_val	outer_valpathindextoplevelbad_typeouter_id
outer_typelocationindex_stringobj)r@   r    r!   _raise_invalid   sF   
 
z,fail_callback_output.<locals>._raise_invalidc                    
   t |  S rG   r   val)valid_childrenr    r!   _valid_child      
z*fail_callback_output.<locals>._valid_childc                    rr   rG   rs   rt   )valid_propsr    r!   _valid_prop  rx   z)fail_callback_output.<locals>._valid_propc                    s8    | s
| s
dS zt |  W dS  ty   Y dS w )NFT)r   	TypeErrorrt   )rw   rz   r    r!   _can_serialize  s   
z,fail_callback_output.<locals>._can_serializec                    sJ  t | trg }|  D ]W\ }|s||  |d |s> fdd|D }|r, n7t fdd|D r>| |f t|dd }t |ttfsb|rb|sb||  d d t|j	 |d q|rs|d	 \ }||  |d t| dd }t |ttfs|r| s|| t|j	|d | s| t| j	d
|dd d S d S )N)rf   rg   rh   ri   c                    s   g | ]}  |d  s|qS r   
startswithr1   rY   pr    r!   r4     s
    zAfail_callback_output.<locals>._validate_value.<locals>.<listcomp>c                 3   s     | ]}|d     V  qdS )r   Nr~   r   r   r    r!   	<genexpr>$  s    z@fail_callback_output.<locals>._validate_value.<locals>.<genexpr>children
z[*] r   r^   T)rf   rg   rh   ri   rj   )
r   r   _traverse_with_pathsallappendr%   r<   r   rd   re   )ru   ri   unserializable_itemsjchild)r|   rq   rw   r   r!   _validate_value  sX   


z-fail_callback_output.<locals>._validate_valueri   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.
        )NFrG   )r&   intfloatrd   r   r<   r   r   r;   rU   r	   rT   )rZ   r@   r   rY   ru   r    )r|   rq   rw   rz   r@   rv   ry   r!   fail_callback_output   s"   (	
=r   c                 C   s6   | D ]}|dv rt 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{   )kwargsrQ   r    r    r!   check_obsolete^  s   r   c              	   C   sV   || vrt d| dt|   d|| | vr)t d| d| d|  dd S )Nz(
            Error loading dependency. "zQ" is not a registered library.
            Registered libraries are:
            rS   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_distr    r    r!   validate_js_pathk  s&   
r   c              	      sR    fdd|D }|r't |dkrdnd}td| dd| d	|  d
d S )Nc                    s$   g | ]\}}t | s|qS r    )recompilesearch)r1   checkrY   r   r    r!   r4     s   $ z"validate_index.<locals>.<listcomp>r   r\   r^   zMissing itemrb   z, z in .)r=   r	   InvalidIndexExceptionr6   )namechecksri   missingpluralr    r   r!   validate_index  s   r   c                 C   s    t | ttdfstdd S )NCallablezLLayout must be a dash component or a function that returns a dash component.)r   r   r
   r	   NoLayoutException)rc   r    r    r!   validate_layout_type  s
   r   c                 C   s|   | d u r	t dtt|dd }|r|hnt }| D ]}tt|dd }|r6||v r6t d| d|| qd 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.
            r9   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)   r    r    r!   validate_layout  s    r   c                 C   s@   t d| }|D ]}| rt|rtd| d|  dqd S )Nz<(.*?)>`z;` is not a valid Python variable name in `path_template`: "z".)r   findallrL   r   	Exception)templatevariable_namesr   r    r    r!   validate_template  s   r   c                 C   sv   i }|   D ]}|d |vr|d g||d < q||d  |d  q|  D ]}t|dkr8td| dq(d S )Nrh   moduler   zmodules z have duplicate paths)valuesr   r=   r   )registrypath_to_modulepagemodulesr    r    r!   check_for_duplicate_pathnames  s   r   c                 C   sD   |   D ]}d|vrtd|d  d|d dkrtdq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   r    r    r!   validate_registry  s   r   c                 C   s    t |dst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   r    r    r!   validate_pages_layout  s   
r   c                 C   s,   |  dd stdt rt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)configr    r    r!   validate_use_pages  s   r   c                 C   s   t | ts
td| S )NzJThe first attribute of dash.register_page() must be a string or '__name__')r   r&   r	   r   )r   r    r    r!   validate_module_name  s
   
r   c           
         s   t  }i }|  D ]$}t|d }|| |D ]}||t   || t|d  qq	dd |  D D ]B}|d }|dg }|dg }t|d  t dd	 |D |  fd
d	t fdd| D D }	|	rytd|	 dq7d S )Nr@   
raw_inputsc                 s   s    | ]
}| d r|V  qdS )longN)r   r0   r    r    r!   r     s    z*validate_long_callbacks.<locals>.<genexpr>r   progressrunningc                 S   s   g | ]}|d  qS r}   r    r0   r    r    r!   r4     s    z+validate_long_callbacks.<locals>.<listcomp>c                    r/   r    r    r0   )long_inputsr    r!   r4     s    c                 3   s"    | ]\}}|  r|V  qd S rG   )intersection)r1   r.   v)r   r    r!   r     s     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   r   r!   validate_long_callbacks  s0   


r   c                    sN   d fv rd S  fdd}t | ttfr!| D ]}|| qd S ||  d S )Ninitial_duplicatec                    s$   | j rs st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_callr    r!   _valid  s   z)validate_duplicate_output.<locals>._valid)r   r;   r<   )r@   r   r   r   r   r    r   r!   validate_duplicate_output  s   
r   )*collections.abcr   r   textwrapr   keywordr   r   	_groupingr   r   development.base_componentr   r^   r	   _utilsr
   r   r   r   r   r"   r   r+   r,   rF   rR   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r    r    r!   <module>   s>    	 "0 	

 