
    $gX                         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
Z	 	 ddZd Zd Z	 ddZd ZddZd Zd Zd Zd Zd Z	 ddZd Zd Z ddZ!y)    )OrderedDictN)filldedent)_explicitize_argsNonExistentEventException   )python_keywords)collect_nodesfilter_base_nodes)	Componentc                    d}|| |v s|d|v rt        |      nt        t        |            }t        t        |            }t        t	        t        t        |j                                           }	t        | |||      j                  dd      }
t        |      }d|v }|D cg c]
  }|dk7  s	| }}t        |       t	        |j                               }d|v rd|	v r|j                  d       d}d	}d
}nd}d}d}t        |      dk(  rd}nd| d}|r|dz  }|D cg c]4  }|j                  d      s!|t        vr|dk7  r||   d   r|ddn|dd6 }}|r#|d|v rdndz
  }t        |      |kD  r
|d| }|
dz  }
|dj!                  |dgz         z  }t#        |j%                         D ci c]  \  }}|dk7  s|| c}}      }t'        |j)                  | ||||	|
|||||t+        |      dgz               S c c}w c c}w c c}}w )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

childrenz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.')
        z-*setPropsrequiredsz=Component.REQUIREDz=Component.UNDEFINEDr	   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**kwargs)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endswithr
   joinr   itemsr   formatr   )r   r   r   r   r   	max_propscr   wildcard_prefixesr   r    required_argsis_children_requiredarg	prop_keysr!   r"   r#   r$   pdefault_arglistfinal_max_propskvnodess                            g/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/dash/development/_py_components_generation.pygenerate_class_stringrG      s   J	A0 $/H@W4W#/E=T4T 	U <./	  _U34d3sN,?,?,A#BCD  7	
 gfd  #>2M%6$1GSSJ5FSGMGE UZZ\"IUz-??$+K-8
=Q # !	    	  zz$A_$<j	 Qx
# e&'a5,-.O  #J%,?qQG/1-.>?O?I tyyJ<!?@@OEKKMMDAqQ*_1a4MNE	)1B1+ 3 (/:,> 	 	
 q H@, Ns   $
G?/G?!9H1H	
?H	
c                    d}t        | |||||      }| dd}t        j                  j                  ||      }	t	        |	dd      5 }
|
j                  |       |
j                  |       ddd       t        d|        y# 1 sw Y   xY w)	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 )rG   ospathr6   openwriteprint)r   r   r   r   r   r9   import_stringclass_string	file_name	file_pathfs              rF   generate_class_filerW      s    (	/  )%i1H)L A,c"IY	2I	iw	/ 1		 
Jyk
"#	 s   #BB
c                    t        t        j                  j                  | d      dd      5 }dj                  d |D              }dj                  d |D              }| d	| d
}|j	                  |       d d d        y # 1 sw Y   y xY w)Nz_imports_.pyrI   rJ   rK   r   c              3   ,   K   | ]  }d | d|   yw)zfrom .z import N .0xs     rF   	<genexpr>z#generate_imports.<locals>.<genexpr>   s     %R!qc!&=%Rs   z,
c              3   (   K   | ]
  }d | d  yw)z    ""NrZ   r[   s     rF   r^   z#generate_imports.<locals>.<genexpr>   s     ?qaSl?s   z

__all__ = [
z
])rO   rM   rN   r6   rP   )project_shortname
componentsrV   component_importsall_listimports_strings         rF   generate_importsrf      s    	
&7w
  	
 II%Rz%RR::?J??-..?zM	     s   A
B  B	c                     g }|j                         D ]T  \  }}|j                  d      d   j                  d      d   }|j                  |       |D ]  } |||d   |d   |         V |S )N/.r   r   r   )r7   splitappend)ra   metadatacomponent_generatorsrb   component_pathcomponent_datar   	generators           rF   generate_classes_filesrr      s    J*2..*: 
&'--c226<<SA!D.)- 	Iw'}-!			
     c                 `    t        | ||||      }t        t        d}t        ||       ||    }|S )zGenerate a Python class object given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    )r   r   )rG   r   r   exec)r   r   r   r   r   stringscoperesults           rF   generate_classry      s?     #%i1HF $:KLE8_FMrs   c                 r    t        | j                               D cg c]  \  }}|d   s| c}}S c c}}w )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
    r   )r+   r7   )r   	prop_nameprops      rF   r1   r1      s.     .2%++--@U/)TDDTIUUUs   33c                     || |v s|d|v r|n
t        |      }| d   j                         dv rdnd}dj                  d t        |      j	                         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
    r   r   aeiounr   r   c              3      K   | ]B  \  }}t        |d |v r|d    n|d   |d   |d   |j                  d      dd|v xr d |v       D yw)typeflowTyper   r   defaultValuer   r{   type_objectr   r   default
indent_numis_flow_typeNcreate_prop_docstringget)r\   r@   r|   s      rF   r^   z#create_docstring.<locals>.<genexpr>$  sp       At 	(.$VD<L*%]+HH^,#t+Bd0B	
 	
s   AA
A z component.
z

Keyword arguments:
)r(   lowerr6   r'   r7   )r   r   r   r   r   r"   s         rF   r/   r/   	  s    & $/"99#/E=T4T 	 5! 
 a &&(G3A99  $E*002 D A3a}[M9QRVQWXrs   c                 *    d| v sd| v rt        d      y)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   s    rF   r2   r2   6  s*     u 5'8
 	
 !6rs   c                 J    g }dD ]  }|| v s|j                  |dd         |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-*Nri   )rl   )r   r   wildcard_attrs      rF   r*   r*   H  s@     ,.(- LE!077cr8JKL 0/rs   c           	          d| v rdgng }d| v rdgng }t        ||z   t        t        | j                                     z         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   sortedr+   r7   )r   props1props2s      rF   r(   r(   Z  sI      $.#6BF!U]j\FvU[[]0C)DDEErs   c                 d   t        j                  |       }t        |j                               D ]~  \  }}d|vrd|vr|j	                  |        d|v r|d   d   }|dv s1|j	                  |       Cd|v r3|d   d   }|dk(  sUd|d   vs|d   d   dk7  sh|j	                  |       zt
         |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deepcopyr+   r7   pop
ValueError)r   r   arg_namer>   arg_typearg_type_names         rF   r'   r'   o  s    T ]]5)Nn2245 #3!6x( S=6{6*H;;""8,3
OF3M+ Z0C
OF4Kx4W"&&x0'* rs   c                 f    dddd}|j                         D ]  \  }}| j                  ||      }  | S )zM
    replaces javascript keywords true, false, null with Python keywords
    TrueFalseNone)truefalsenull)r7   r0   )txtfix_word
js_keywordpython_keywords       rF   fix_keywordsr     s@     &AH&.nn&6 6"
Nkk*n56Jrs   c                 h   t        |||      }d|z  }|r|d   nd}t        |      }d}	|rd}	n|r|dvrd|j                  d	d      z   }	|rd
nd}
|j                         j                  d
      j                  dd      |
z   }|dz   }t	        |||dd      }|rd	| nd}|rdnd}t        |      }d	|v r|j                  d      rdnd}|j                  d      \  }}}d|  d| | }t	        |||dd      }d|v r0|j                  dd      \  }}dj                  |d|g      }| d| }|j                  d	      j                  d      }|t        |      k(  r&dj                  d |j                         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   rj   r`   z\"z    F)initial_indentsubsequent_indentbreak_long_wordsbreak_on_hyphens:r+   zlist of dictsdictz
with keys:`z` is a z| dict with keys:z |r	   Orz

  -c              3   2   K   | ]  }|d k7  s	d|z     yw)r   z

    NrZ   )r\   lines     rF   r^   z(create_prop_docstring.<locals>.<genexpr>  s!      !&*QS
T!!s   

z- z (z; )z

)js_to_py_typer   r0   stripr   
startswith	partitionrk   r6   lstripfindr4   
splitlines)r{   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tns                         rF   r   r     sS   D !lzL J&N")ggrG7#GK 	W$88 7??4#<<  SRF##%++C088eDvMK 6)K"%K )4B{m$KCBE{+K|*6*A*A&*Iv &2%;%;L%I"
I;gfXfX6&)""
 *,%/%5%5dA%>"J
+tZ!@AJ&<vj\:J $**4055c:S00 !.8.C.C.E! J
  9+R~R}AeWm5'*'	

 !-L>	"Br)Brd;-q}UUrs   c                 |      fd} fd} fd}t        d d d d d d	 d
 d  fd fd| fd|||      S )z=Mapping from the PropTypes js type object to the Python type.c            
          ddj                   fdt        t        d   j                                     D              z   S )Ndict with keys:
r   c           
   3      K   | ]=  \  }}t        |||d    |j                  dd      |j                  d      dz          ? yw)r   r   r   r      )r{   r   r   r   r   r   Nr   )r\   r{   r|   r   s      rF   r^   zHmap_js_to_py_types_prop_types.<locals>.shape_or_exact.<locals>.<genexpr>'  sX      
/
  	4 "# j) HH]B70%> 
/
s   AAr   )r6   r   r+   r7   r   r   s   rF   shape_or_exactz5map_js_to_py_types_prop_types.<locals>.shape_or_exact&  sB    "TYY 
/
 $*${7/C/I/I/K*L#M
/
 
&
 

 
	
rs   c                      t        d         } | r4d| j                  d      d   dk7  r| dz   z   S | j                  ddd      z   S y	)
Nr   list of r   r   r   r   dictsr	   r+   )r   rk   r0   )innerr   s    rF   array_ofz/map_js_to_py_types_prop_types.<locals>.array_of3  sb    k'23;;s#A&&0   ]]67A6 
 rs   c                      d   D  cg c]  } t        |        }} dt        |       ddj                  |       dS c c} w )Nelementsr   z elements: [r   ])r   r4   r6   )elementr   r   s     rF   tuple_ofz/map_js_to_py_types_prop_types.<locals>.tuple_of=  sI    :Ej:QRwM'*RR#h-TYYx5H4IKK Ss   >c                       yNr+   rZ   rZ   rs   rF   <lambda>z/map_js_to_py_types_prop_types.<locals>.<lambda>B      rs   c                       yNbooleanrZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>C  r   rs   c                       yNnumberrZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>D  r   rs   c                       yNrv   rZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>E  r   rs   c                       yNr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>F  r   rs   c                       y)Nz'boolean | number | string | dict | listrZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>G  r   rs   c                       yNzdash componentrZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>H  r   rs   c                       yNz8a list of or a singular dash component, string or numberrZ   rZ   rs   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>I  r   rs   c                  @    ddj                  d  d   D              z   S )Nza value equal to: r   c              3   8   K   | ]  }t        |d            yw)r   N)r-   )r\   ts     rF   r^   zBmap_js_to_py_types_prop_types.<locals>.<lambda>.<locals>.<genexpr>M  s     FAAgJFs   r   r6   r   s   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>K  s(     iiFW1EFFG rs   c                  :    dj                  d  d   D              S )N | c              3   N   K   | ]  }t        |      d k7  rt        |        ywr   Nr   r\   subTypes     rF   r^   zBmap_js_to_py_types_prop_types.<locals>.<lambda>.<locals>.<genexpr>P  *      !
W%+ '"!
   #%r   r   r   s   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>P  s"    ejj !
&w/!
 
 rs   c                  &    dt         d         z   S )Nz-dict with strings as keys and values of type r   r  r   s   rF   r   z/map_js_to_py_types_prop_types.<locals>.<lambda>X  s    ;K012 rs   )arrayboolr   rv   r   anyr   nodeenumunionarrayOfobjectOfshapeexacttupler   )r   r   r   r   r   s   ``   rF   map_js_to_py_types_prop_typesr  #  sY    
L =(O


 

 ?   rs   c                 R     t        d d d d d d d d  fd	 fd
 fd      S )z2Mapping from the Flow js types to the Python type.c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>g  r   rs   c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>h  r   rs   c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>i  r   rs   c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>j  r   rs   c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>k  r   rs   c                       y)Nz!bool | number | str | dict | listrZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>l  r   rs   c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>m  r   rs   c                       yr   rZ   rZ   rs   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>n  r   rs   c                  :    dj                  d  d   D              S )Nr  c              3   N   K   | ]  }t        |      d k7  rt        |        ywr  r  r  s     rF   r^   zBmap_js_to_py_types_flow_types.<locals>.<lambda>.<locals>.<genexpr>p  r  r	  r   r   r   s   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>p  s"    ejj !
&z2!
 
 rs   c                  d    dt         d   d         dk7  rdt         d   d          dz   S dz   S )Nr+   r   r   r   z of r   r  r   s   rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>v  sO    f [4Q78B> =Z!8!;<=Q?
  	
 rs   c                 L     ddj                   fdd   d   D              z   S )Nr   r   c           
   3      K   | ]G  }t        |d    |d   |d   d   |d   j                  dd      |j                  d      dz   d       I y	w)
keyr   r   r   r   r   r   Tr   Nr   )r\   r|   r   s     rF   r^   zBmap_js_to_py_types_flow_types.<locals>.<lambda>.<locals>.<genexpr>  si        &"5k $W!']:6 $W 1 1- D HH^4)A~!% s   AAr   
propertiesr   r   s   `rF   r   z/map_js_to_py_types_flow_types.<locals>.<lambda>}  s5    ii  (4\B  rs   )r  r   r   rv   Objectr  ElementNoder  Arrayr   r  r   s   `rF   map_js_to_py_types_flow_typesr,  d  s7    !7(O


/& &rs   c                     | d   }|rt        |       nt        | |      }d| v r| d   s| j                  dd      dk(  ry||v r|dk(  r ||   |      S  ||          S y)	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_typess        rF   r   r     s      v&L  	&+>*#

  	k!
#??62&*4~%;&/>,/
;;+~l+--rs   )NN)N)F)Fr   )"collectionsr   r   rM   textwrapr   r   dash.development.base_componentr   dash.exceptionsr   _all_keywordsr
   _collect_nodesr   r   base_componentr   rG   rW   rf   rr   ry   r1   r/   r2   r*   r(   r'   r   r   r  r,  r   rZ   rs   rF   <module>r9     s    #  	 ! = 5 * < % !Rt !#$L $ FJ.
V*Z
$0$F*AH& aVH>B(V$rs   