
    Mf"                        d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZ  ej	        d          Z
e
                    i            d Zd Z G d d	e          Z ed
ddg          Z G d d          Z e            ZdS )    N   )
exceptions)AttributeDictcallback_contextc                 F     t          j                    fd            }|S )Nc                      t                                           s&t          j        dt	          d           d           | i |S )Nzdash.callback_context.__name__z# is only available from a callback!)context_valuegetr   MissingCallbackContextExceptiongetattr)argskwargsfuncs     U/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash/_callback_context.pyassert_contextz#has_context.<locals>.assert_context   s[      "" 	<gz)B)Bggg   tT$V$$$    )	functoolswraps)r   r   s   ` r   has_contextr      s9    _T% % % % % r   c                  4    t                                           S )N)r
   r    r   r   _get_context_valuer      s    r   c                       e Zd Zd Zd ZdS )	FalsyListc                     dS NFr   selfs    r   __bool__zFalsyList.__bool__!       ur   c                     dS r   r   r   s    r   __nonzero__zFalsyList.__nonzero__%   r!   r   N)r	   
__module____qualname__r    r#   r   r   r   r   r       s2              r   r   .)prop_idvaluec                   J   e Zd Zeed                         Zeed                         Zeed                         Zeed                         Zeed                         Z	eed                         Z
eed                         Zeed                         Zeed	                         Zeed
                         Zeed                         Zeedd                        Zeed                         Zeed                         Zeed                         ZdS )CallbackContextc                 <    t          t                      di           S )Ninput_valuesr   r   r   s    r   inputszCallbackContext.inputs/        )++^R@@@r   c                 <    t          t                      di           S )Nstate_valuesr-   r   s    r   stateszCallbackContext.states4   r/   r   c                 J    t          t                      dg           pt          S )a  
        Returns a list of all the Input props that changed and caused the callback to execute. It is empty when the
        callback is called on initial load, unless an Input prop got its value from another initial callback.
        Callbacks triggered by user actions typically have one item in triggered, unless the same action changes
        two props at once or the callback has several Input props that are all modified by another callback based on
        a single user action.

        Example:  To get the id of the component that triggered the callback:
        `component_id = ctx.triggered[0]['prop_id'].split('.')[0]`

        Example:  To detect initial call, empty triggered is not really empty, it's falsy so that you can use:
        `if ctx.triggered:`
        triggered_inputs)r   r   falsy_triggeredr   s    r   	triggeredzCallbackContext.triggered9   s#    ( )++-?DDWWr   c                 :   t          t                      dg           }t          i           }|D ]k}|d                             d          \  }}}|||d         <   |                    d          r*t          t          j        |                    ||d         <   l|S )a>  
        Returns a dictionary of all the Input props that changed and caused the callback to execute. It is empty when
        the callback is called on initial load, unless an Input prop got its value from another initial callback.
        Callbacks triggered by user actions typically have one item in triggered, unless the same action changes
        two props at once or the callback has several Input props that are all modified by another callback based
        on a single user action.

        triggered_prop_ids (dict):
        - keys (str) : the triggered "prop_id" composed of "component_id.component_property"
        - values (str or dict): the id of the component that triggered the callback. Will be the dict id for pattern matching callbacks

        Example - regular callback
        {"btn-1.n_clicks": "btn-1"}

        Example - pattern matching callbacks:
        {'{"index":0,"type":"filter-dropdown"}.value': {"index":0,"type":"filter-dropdown"}}

        Example usage:
        `if "btn-1.n_clicks" in ctx.triggered_prop_ids:
            do_something()`
        r4   r'   r&   {)r   r   r   
rpartition
startswithjsonloads)r   r6   idsitemcomponent_id_s         r   triggered_prop_idsz"CallbackContext.triggered_prop_idsO   s    0 .002DbII	B 	O 	OD!%i!;!;C!@!@L!Q#/CY &&s++ O'4TZ5M5M'N'NDO$
r   c                 d    d}| j         r&| j                                        }| j        |         }|S )at  
        Returns the component id (str or dict) of the Input component that triggered the callback.

        Note - use `triggered_prop_ids` if you need both the component id and the prop that triggered the callback or if
        multiple Inputs triggered the callback.

        Example usage:
        `if "btn-1" == ctx.triggered_id:
            do_something()`

        N)r6   rA   first)r   r?   r'   s      r   triggered_idzCallbackContext.triggered_idp   s:     > 	<-3355G27;Lr   c                 <    t          t                      dg           S )ut  
        args_grouping is a dict of the inputs used with flexible callback signatures. The keys are the variable names
        and the values are dictionaries containing:
        - “id”: (string or dict) the component id. If it’s a pattern matching id, it will be a dict.
        - “id_str”: (str) for pattern matching ids, it’s the stringified dict id with no white spaces.
        - “property”: (str) The component property used in the callback.
        - “value”: the value of the component property at the time the callback was fired.
        - “triggered”: (bool)Whether this input triggered the callback.

        Example usage:
        @app.callback(
            Output("container", "children"),
            inputs=dict(btn1=Input("btn-1", "n_clicks"), btn2=Input("btn-2", "n_clicks")),
        )
        def display(btn1, btn2):
            c = ctx.args_grouping
            if c.btn1.triggered:
                return f"Button 1 clicked {btn1} times"
            elif c.btn2.triggered:
                return f"Button 2 clicked {btn2} times"
            else:
               return "No clicks yet"

        args_groupingr-   r   s    r   rF   zCallbackContext.args_grouping   s    6 )++_bAAAr   c                 <    t          t                      dg           S )Noutputs_groupingr-   r   s    r   rH   z CallbackContext.outputs_grouping   s     )++-?DDDr   c                 ~    | j         rt          j        dt                     t	          t                      dg           S )Nz8outputs_list is deprecated, use outputs_grouping insteadoutputs_list)using_outputs_groupingwarningswarnDeprecationWarningr   r   r   s    r   rJ   zCallbackContext.outputs_list   sD     & 	MJ"  
 )++^R@@@r   c                 ~    | j         rt          j        dt                     t	          t                      dg           S )Nz4inputs_list is deprecated, use args_grouping insteadinputs_listusing_args_groupingrL   rM   rN   r   r   r   s    r   rP   zCallbackContext.inputs_list   sD     # 	MF"  
 )++]B???r   c                 ~    | j         rt          j        dt                     t	          t                      dg           S )Nz4states_list is deprecated, use args_grouping insteadstates_listrQ   r   s    r   rT   zCallbackContext.states_list   sD     # 	MF"   )++]B???r   c                 :    t          t                      d          S )Ndash_responser-   r   s    r   responsezCallbackContext.response   s     )++_===r   Nc                     t          t          j        di           }| |v rt          d|  d          t	          |dz            |d|| <   t          t          j        d|           dS )a  Records timing information for a server resource.

        :param name: The name of the resource.
        :type name: string

        :param duration: The time in seconds to report. Internally, this
            is rounded to the nearest millisecond.
        :type duration: float or None

        :param description: A description of the resource.
        :type description: string or None
        timing_informationzDuplicate resource name "z" found.i  )durdescN)r   flaskgKeyErrorroundsetattr)namedurationdescriptionrY   s       r   record_timingzCallbackContext.record_timing   sz     %UW.BBGG%%%EtEEEFFF+0D+A+A;#W#W4 -/ABBBBBr   c                 <    t          t                      dg           S )z
        Return True if this callback is using dictionary or nested groupings for
        Input/State dependencies, or if Input and State dependencies are interleaved
        rR   r-   r   s    r   rR   z#CallbackContext.using_args_grouping   s     )++-BBGGGr   c                 <    t          t                      dg           S )zw
        Return True if this callback is using dictionary or nested groupings for
        Output dependencies.
        rK   r-   r   s    r   rK   z&CallbackContext.using_outputs_grouping   s     )++-ErJJJr   c                 8    t          t          j        di           S )NrY   )r   r\   r]   r   s    r   rY   z"CallbackContext.timing_information   s     uw 4b999r   )NN)r	   r$   r%   propertyr   r.   r2   r6   rA   rD   rF   rH   rJ   rP   rT   rW   staticmethodrd   rR   rK   rY   r   r   r   r*   r*   .   sd       A A [ XA A A [ XA X X [ XX(   [ X>   [ X$ B B [ XB6 E E [ XE A A [ XA @ @ [ X@ @ @ [ X@ > > [ X> C C C [ \C, H H [ XH K K [ XK : : [ X: : :r   r*   )r   rL   r;   contextvarsr\    r   _utilsr   
ContextVarr
   setr   r   listr   r5   r*   r   r   r   r   <module>rp      s0                    ! ! ! ! ! ! '&'9::   "   	 	 	          )t<<=>>J: J: J: J: J: J: J: J:Z #?$$   r   