o
    dX                     @   s  d dl mZ d dl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 ddlmZmZ dd	lmZ 		d+d
dZ		d+ddZdd Zdd Z	d,ddZdd Zd,ddZdd Zdd Zdd Zdd Zd d! Z	"d-d#d$Zd%d& Zd'd( Z d.d)d*Z!dS )/    )OrderedDictN)filldedent)_explicitize_argsNonExistentEventException   )python_keywords)collect_nodesfilter_base_nodes)	Componentc                    s  d}|dur
| |v s|durd|v rt  ntt  }tt }tttt| }	t| |||d	dd}
t
|}d|v }dd	 |D }t  t  }d v rfd|	v rf|d d
}d}d}nd}d}d}t|dkrud}nd| d}|r|d7 } fdd	|D }|r|d v rdnd }t||kr|d| }|
d7 }
|d|dg 7 }tdd   D }t|j| ||||	|
|||||t|dg dS )a;  Dynamically generate class strings to have nicely formatted docstrings,
    keyword arguments, and repr.
    Inspired by http://jameso.be/2013/08/06/namedtuple.html
    Parameters
    ----------
    typename
    props
    description
    namespace
    prop_reorder_exceptions
    Returns
    -------
    string
    a  class {typename}(Component):
    """{docstring}"""
    _children_props = {children_props}
    _base_nodes = {base_nodes}
    _namespace = '{namespace}'
    _type = '{typename}'
    @_explicitize_args
    def __init__(self, {default_argtext}):
        self._prop_names = {list_of_valid_keys}
        self._valid_wildcard_attributes =            {list_of_valid_wildcard_attr_prefixes}
        self.available_properties = {list_of_valid_keys}
        self.available_wildcard_properties =            {list_of_valid_wildcard_attr_prefixes}
        _explicit_args = kwargs.pop('_explicit_args')
        _locals = locals()
        _locals.update(kwargs)  # For wildcard attrs and excess named props
        args = {args}
        {required_validation}
        super({typename}, self).__init__({argtext})
NALL)component_namepropsdescriptionprop_reorder_exceptionsz

childrenc                 S   s   g | ]}|d kr|qS r    ).0argr   r   o/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/dash/development/_py_components_generation.py
<listcomp>Y   s    z)generate_class_string.<locals>.<listcomp>zchildren=None, z:{k: _locals[k] for k in _explicit_args if k != 'children'}zchildren=children, **args z'{k: _locals[k] for k in _explicit_args}z**argsr   z
        for k in z:
            if k not in args:
                raise TypeError(
                    'Required argument `' + k + '` was not specified.')
        z
        if 'children' not in _explicit_args:
            raise TypeError('Required argument children was not specified.')
        c                    sJ   g | ]!}| d s|tvr|dkr | d r|ddn|ddqS )z-*setPropsrequiredsz=Component.REQUIREDz=Component.UNDEFINED)endswithr	   )r   pr   r   r   r   y   s    

r   z

Note: due to the large number of props for this component,
not all of them appear in the constructor signature, but
they may still be used as keyword arguments., z**kwargsc                 S   s   i | ]\}}|d kr||qS r   r   )r   kvr   r   r   
<dictcomp>   s    z)generate_class_string.<locals>.<dictcomp>)typename	namespacefiltered_props$list_of_valid_wildcard_attr_prefixeslist_of_valid_keys	docstringdefault_argtextargsargtextrequired_validationchildren_props
base_nodes)filter_propsreorder_propsreprparse_wildcardslistmapstrkeyscreate_docstringreplacerequired_propsprohibit_eventsremovelenjoinr
   itemsr   formatr   )r%   r   r   r&   r   	max_propscr'   wildcard_prefixesr)   r*   required_argsis_children_required	prop_keysr+   r,   r-   r.   default_arglistfinal_max_propsnodesr   r    r   generate_class_string   s   %




rK   c                 C   s   d}t | |||||}| dd}tj||}	t|	ddd}
|
| |
| W d   n1 s4w   Y  td|  dS )	zGenerate a Python class file (.py) given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    prop_reorder_exceptions
    Returns
    -------
    zp# AUTO GENERATED FILE - DO NOT EDIT

from dash.development.base_component import Component, _explicitize_args


r   z.pywutf-8encodingNz
Generated )rK   ospathr?   openwriteprint)r%   r   r   r&   r   rB   import_stringclass_string	file_name	file_pathfr   r   r   generate_class_file   s   
rZ   c                 C   s   t tj| dddd*}ddd |D }dd	d |D }| d
| d}|| W d    d S 1 s9w   Y  d S )Nz_imports_.pyrL   rM   rN   r   c                 s   s     | ]}d | d| V  qdS )zfrom .z import Nr   r   xr   r   r   	<genexpr>   s    z#generate_imports.<locals>.<genexpr>z,
c                 s   s    | ]	}d | dV  qdS )z    ""Nr   r[   r   r   r   r]          z

__all__ = [
z
])rR   rP   rQ   r?   rS   )project_shortname
componentsrY   component_importsall_listimports_stringr   r   r   generate_imports   s   "re   c                 G   s\   g }|  D ]%\}}|dd dd }|| |D ]}|||d |d |  qq|S )N/.r   r   r   )r@   splitappend)r`   metadatacomponent_generatorsra   component_pathcomponent_datar   	generatorr   r   r   generate_classes_files   s   
rp   c                 C   s0   t | ||||}ttd}t|| ||  }|S )zGenerate a Python class object given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    )r   r   )rK   r   r   exec)r%   r   r   r&   r   stringscoperesultr   r   r   generate_class   s   


ru   c                 C   s   dd t |  D S )zPull names of required props from the props object.
    Parameters
    ----------
    props: dict
    Returns
    -------
    list
        List of prop names (str) that are required for the Component
    c                 S   s   g | ]
\}}|d  r|qS )r   r   r   	prop_namepropr   r   r   r     s    z"required_props.<locals>.<listcomp>)r5   r@   r    r   r   r   r;      s   
r;   c                 C   s|   |dur| |v s|durd|v r|nt |}| d  dv r dnd}ddd	 t| D }d
| d|  d| d| S )a5  Create the Dash component docstring.
    Parameters
    ----------
    component_name: str
        Component name
    props: dict
        Dictionary with {propName: propMetadata} structure
    description: str
        Component description
    Returns
    -------
    str
        Dash component docstring
    Nr   r   aeiounr   r   c              
   s   sX    | ]'\}}t |d |v r|d  n|d |d |d |ddd|v o%d |vdV  qdS )typeflowTyper   r   defaultValuer   rw   type_objectr   r   default
indent_numis_flow_typeNcreate_prop_docstringget)r   r   rx   r   r   r   r]   $  s    

z#create_docstring.<locals>.<genexpr>A z component.
z

Keyword arguments:
)r2   lowerr?   r1   r@   )r   r   r   r   rz   r,   r   r   r   r9   	  s    



r9   c                 C   s   d| v sd| v rt ddS )zEvents have been removed. Raise an error if we see dashEvents or
    fireEvents.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Raises
    -------
    ?
    
dashEvents
fireEventsziEvents are no longer supported by dash. Use properties instead, eg `n_clicks` instead of a `click` event.Nr   r    r   r   r   r<   6  s
   r<   c                 C   s,   g }dD ]}|| v r| |dd  q|S )zPull out the wildcard attributes from the Component props.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    list
        List of Dash valid wildcard prefixes
    )zdata-*zaria-*Nrg   )rj   )r   r(   wildcard_attrr   r   r   r4   H  s   r4   c                 C   s@   d| v rdgng }d| v rdgng }t || tt|   S )aV  If "children" is in props, then move it to the front to respect dash
    convention, then 'id', then the remaining props sorted by prop name
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Dictionary with {propName: propMetadata} structure
    r   )r   r   id)r   r   )r   sortedr5   r@   )r   props1props2r   r   r   r2   Z  s   r2   c                 C   s   t | }t| D ]I\}}d|vrd|vr|| qd|v r1|d d }|dv r0|| qd|v rS|d d }|dkrRd|d vsM|d d dkrR|| qt|S )a  Filter props from the Component arguments to exclude:
        - Those without a "type" or a "flowType" field
        - Those with arg.type.name in {'func', 'symbol', 'instanceOf'}
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Filtered dictionary with {propName: propMetadata} structure
    Examples
    --------
    ```python
    prop_args = {
        'prop1': {
            'type': {'name': 'bool'},
            'required': False,
            'description': 'A description',
            'flowType': {},
            'defaultValue': {'value': 'false', 'computed': False},
        },
        'prop2': {'description': 'A prop without a type'},
        'prop3': {
            'type': {'name': 'func'},
            'description': 'A function prop',
        },
    }
    # filtered_prop_args is now
    # {
    #    'prop1': {
    #        'type': {'name': 'bool'},
    #        'required': False,
    #        'description': 'A description',
    #        'flowType': {},
    #        'defaultValue': {'value': 'false', 'computed': False},
    #    },
    # }
    filtered_prop_args = filter_props(prop_args)
    ```
    r{   r|   name>   funcsymbol
instanceOf	signatureobject)copydeepcopyr5   r@   pop
ValueError)r   r'   arg_namer   arg_typearg_type_namer   r   r   r1   o  s$   
*


r1   c                 C   s.   dddd}|  D ]
\}}| ||} q
| S )zM
    replaces javascript keywords true, false, null with Python keywords
    TrueFalseNone)truefalsenull)r@   r:   )txtfix_word
js_keywordpython_keywordr   r   r   fix_keywords  s   r   Fc                 C   s  t |||d}d| }|r|d nd}t|}d}	|rd}	n|r,|dvr,d|d	d }	|r0d
nd}
| d
dd|
 }|d }t|||ddd}|rSd	| nd}|rYdnd}t|}d	|v r|drjdnd}|d\}}}d|  d| | }t|||ddd}d|v r|dd\}}d|d|g}| d| }|	d	
d}|t|krddd | D }d	| d|  d | d!|	 d"| | d#| | S |r| d!nd}d	| d|  d | |	 d"| | 
S )$a  Create the Dash component prop docstring.
    Parameters
    ----------
    prop_name: str
        Name of the Dash component prop
    type_object: dict
        react-docgen-generated prop type dictionary
    required: bool
        Component is required?
    description: str
        Dash component description
    default: dict
        Either None if a default value is not defined, or
        dict containing the key 'value' that defines a
        default value for the prop
    indent_num: int
        Number of indents to use for the context block
        (creates 2 spaces for every indent)
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    Returns
    -------
    str
        Dash component prop docstring
    )r   r   r   z  valuer   optionalr   )r   z{}z[]zdefault r   rh   r^   z\"z    F)initial_indentsubsequent_indentbreak_long_wordsbreak_on_hyphens:r5   zlist of dictsdictz
with keys:`z` is a z| dict with keys:z |r   Orz

  -c                 s   s     | ]}|d krd| V  qdS )r   z

    Nr   )r   liner   r   r   r]     s    
z(create_prop_docstring.<locals>.<genexpr>z- z (z; )z

)js_to_py_typer   r:   stripr   
startswith	partitionri   r?   lstripfindr>   
splitlines)rw   r   r   r   r   r   r   py_type_nameindent_spacingis_requiredperioddesc_indentcolondict_or_listintro1intro2
dict_descrintro
dict_part1
dict_part2current_indenttnr   r   r   r     sl   "	
$r   c                    s    fdd}fdd}fdd}t dd d	d d
d dd dd dd dd dd fddfdd|fdd|||dS )z=Mapping from the PropTypes js type object to the Python type.c                      s,   dd  fddttd  D  S )Ndict with keys:
r   c              	   3   s>    | ]\}}t |||d  |dd|d d dV  qdS )r   r   r   r}      )rw   r   r   r   r   r   Nr   rv   r   r   r   r]   '  s    	

zHmap_js_to_py_types_prop_types.<locals>.shape_or_exact.<locals>.<genexpr>r   )r?   r   r5   r@   r   r   r   r   r   shape_or_exact&  s   	
z5map_js_to_py_types_prop_types.<locals>.shape_or_exactc                     sB   t  d } | rd| dd dkr| d  S | ddd S d	S )
Nr   list of r   r   r   r   dictsr   r5   )r   ri   r:   )innerr   r   r   array_of3  s   z/map_js_to_py_types_prop_types.<locals>.array_ofc                     s.   dd  d D } dt |  dd|  dS )Nc                 S   s   g | ]}t |qS r   r   )r   elementr   r   r   r   >  s    zCmap_js_to_py_types_prop_types.<locals>.tuple_of.<locals>.<listcomp>elementsr   z elements: [r!   ])r>   r?   )r   r   r   r   tuple_of=  s   z/map_js_to_py_types_prop_types.<locals>.tuple_ofc                   S      dS Nr5   r   r   r   r   r   <lambda>B      z/map_js_to_py_types_prop_types.<locals>.<lambda>c                   S   r   Nbooleanr   r   r   r   r   r   C  r   c                   S   r   Nnumberr   r   r   r   r   r   D  r   c                   S   r   Nrr   r   r   r   r   r   r   E  r   c                   S   r   Nr   r   r   r   r   r   r   F  r   c                   S   r   )Nz'boolean | number | string | dict | listr   r   r   r   r   r   G  r   c                   S   r   Nzdash componentr   r   r   r   r   r   H  r   c                   S   r   Nz8a list of or a singular dash component, string or numberr   r   r   r   r   r   I  r   c                      s   dd dd  d D  S )Nza value equal to: r!   c                 s   s    | ]	}t |d  V  qdS )r   N)r7   )r   tr   r   r   r]   M  r_   Bmap_js_to_py_types_prop_types.<locals>.<lambda>.<locals>.<genexpr>r   r?   r   r   r   r   r   K  s   c                         d dd  d D S )N | c                 s   $    | ]}t |d krt |V  qdS r   Nr   r   subTyper   r   r   r]   P      

r   r   r   r   r   r   r   r   P     
 c                      s   dt  d  S )Nz-dict with strings as keys and values of type r   r   r   r   r   r   r   X  s   
)arrayboolr   rr   r   anyr   nodeenumunionarrayOfobjectOfshapeexacttupler   )r   r   r   r   r   r   r   r   map_js_to_py_types_prop_types#  s(   



r   c                    sV   t dd dd dd dd dd dd dd d	d  fd
d fdd fdddS )z2Mapping from the Flow js types to the Python type.c                   S   r   r   r   r   r   r   r   r   g  r   z/map_js_to_py_types_flow_types.<locals>.<lambda>c                   S   r   r   r   r   r   r   r   r   h  r   c                   S   r   r   r   r   r   r   r   r   i  r   c                   S   r   r   r   r   r   r   r   r   j  r   c                   S   r   r   r   r   r   r   r   r   k  r   c                   S   r   )Nz!bool | number | str | dict | listr   r   r   r   r   r   l  r   c                   S   r   r   r   r   r   r   r   r   m  r   c                   S   r   r   r   r   r   r   r   r   n  r   c                      r   )Nr   c                 s   r   r   r   r   r   r   r   r]   p  r   Bmap_js_to_py_types_flow_types.<locals>.<lambda>.<locals>.<genexpr>r   r   r   r   r   r   r   p  r   c                      s6   dt  d d dkrdt  d d  d S d S )Nr5   r   r   r   z of r   r   r   r   r   r   r   v  s    c                    s$   dd  fddd d D  S )Nr   r   c              
   3   sL    | ]!}t |d  |d |d d |d dd|d d ddV  qd	S )
keyr   r   r   r   r}   r   Tr~   Nr   )r   rx   r   r   r   r]     s    


r   r   
propertiesr   r   r   r   r   r   }  s
   

)r   r   r   rr   Objectr   ElementNoder   Arrayr   r   r   r   r   r   map_js_to_py_types_flow_typesd  s   


r  c                 C   sp   | d }|rt | dnt| |d}d| v r| d s!| dddkr#dS ||v r6|dkr1|| |S ||  S dS )	a  Convert JS types to Python types for the component definition.
    Parameters
    ----------
    type_object: dict
        react-docgen-generated prop type dictionary
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    indent_num: int
        Number of indents to use for the docstring for the prop
    Returns
    -------
    str
        Python type string
    r   r   )r   r   computedr{   r   functionr   )r  r   r   )r   r   r   js_type_namejs_to_py_typesr   r   r   r     s&   	
r   )NN)N)F)Fr   )"collectionsr   r   rP   textwrapr   r   dash.development.base_componentr   dash.exceptionsr   _all_keywordsr	   _collect_nodesr
   r   base_componentr   rK   rZ   re   rp   ru   r;   r9   r<   r4   r2   r1   r   r   r   r  r   r   r   r   r   <module>   s@    	
 
&

-D
dA+