
    MfQO              	          d dl Z d dlZd dlmZ d dlZddlmZmZmZ ddl	m
Z
mZmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ  G d d          Z g Z!i Z"g Z#ddddddddddZ$d Z%d Z&	 ddZ'd Z(dZ)d Z*dS )    N)wraps   )handle_callback_argshandle_grouped_callback_argsOutput)PreventUpdateWildcardInLongCallbackDuplicateCallbackMissingLongCallbackManagerErrorLongCallbackError)flatten_groupingmake_grouping_by_indexgrouping_len)create_callback_idstringify_idto_jsoncoerce_to_listAttributeDictclean_property_name)	_validate)BaseLongCallbackManager)context_valuec                   *    e Zd Zd Zed             ZdS )NoUpdatec                 
    ddiS N_dash_no_update )selfs    M/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash/_callback.pyto_plotly_jsonzNoUpdate.to_plotly_json(   s    !#455    c                 f    t          | t                    pt          | t                    o| ddik    S r   )
isinstancer   dict)objs    r    is_no_updatezNoUpdate.is_no_update+   s7    #x(( 
sD!!Sc.?AR-S&S	
r"   N)__name__
__module____qualname__r!   staticmethodr'   r   r"   r    r   r   '   s>        6 6 6 
 
 \
 
 
r"   r   Fi  )
backgroundintervalprogressprogress_defaultrunningcancelmanagercache_args_to_ignorec                     d}
|	                     dd          }|	                     dt                    }|	                     dt                    }| r'd|i}
r|
d<   |r't          |          |
d<   t	          |
d                    |rMt          |          |
d	<   t          |
d                   t          |
d	                   k    st          d
          |r1t          |          |
d<   t	          d |
d         D                        |rht          |          }t	          |           d |D             }	 t          ||d          fd            }n# t          $ r Y nw xY wd |D             |
d<   |r||
d<   t          |||g|R i |	d|
iS )a  
    Normally used as a decorator, `@dash.callback` provides a server-side
    callback relating the values of one or more `Output` items to one or
    more `Input` items which will trigger the callback when they change,
    and optionally `State` items which provide additional information but
    do not trigger the callback directly.

    `@dash.callback` is an alternative to `@app.callback` (where `app = dash.Dash()`)
    introduced in Dash 2.0.
    It allows you to register callbacks without defining or importing the `app`
    object. The call signature is identical and it can be used instead of `app.callback`
    in all cases.

    The last, optional argument `prevent_initial_call` causes the callback
    not to fire when its outputs are first added to the page. Defaults to
    `False` and unlike `app.callback` is not configurable at the app level.

    :Keyword Arguments:
        :param background:
            Mark the callback as a long callback to execute in a manager for
            callbacks that take a long time without locking up the Dash app
            or timing out.
        :param manager:
            A long callback manager instance. Currently, an instance of one of
            `DiskcacheManager` or `CeleryManager`.
            Defaults to the `background_callback_manager` instance provided to the
            `dash.Dash constructor`.
            - A diskcache manager (`DiskcacheManager`) that runs callback
              logic in a separate process and stores the results to disk using the
              diskcache library. This is the easiest backend to use for local
              development.
            - A Celery manager (`CeleryManager`) that runs callback logic
              in a celery worker and returns results to the Dash app through a Celery
              broker like RabbitMQ or Redis.
        :param running:
            A list of 3-element tuples. The first element of each tuple should be
            an `Output` dependency object referencing a property of a component in
            the app layout. The second element is the value that the property
            should be set to while the callback is running, and the third element
            is the value the property should be set to when the callback completes.
        :param cancel:
            A list of `Input` dependency objects that reference a property of a
            component in the app's layout.  When the value of this property changes
            while a callback is running, the callback is canceled.
            Note that the value of the property is not significant, any change in
            value will result in the cancellation of the running job (if any).
        :param progress:
            An `Output` dependency grouping that references properties of
            components in the app's layout. When provided, the decorated function
            will be called with an extra argument as the first argument to the
            function.  This argument, is a function handle that the decorated
            function should call in order to provide updates to the app on its
            current progress. This function accepts a single argument, which
            correspond to the grouping of properties specified in the provided
            `Output` dependency grouping
        :param progress_default:
            A grouping of values that should be assigned to the components
            specified by the `progress` argument when the callback is not in
            progress. If `progress_default` is not provided, all the dependency
            properties specified in `progress` will be set to `None` when the
            callback is not running.
        :param cache_args_to_ignore:
            Arguments to ignore when caching is enabled. If callback is configured
            with keyword arguments (Input/State provided in a dict),
            this should be a list of argument names as strings. Otherwise,
            this should be a list of argument indices as integers.
        :param interval:
            Time to wait between the long callback update requests.
    N config_prevent_initial_callbacksFcallback_mapcallback_listr-   r2   r.   progressDefaultz8Progress and progress default needs to be of same lengthr0   c              3   &   K   | ]}|d          V  dS )r   Nr   ).0xs     r    	<genexpr>zcallback.<locals>.<genexpr>   s&       D D!1 D D D D D Dr"   c                 8    g | ]}t          |j        d           S )id)r   component_idr:   cs     r    
<listcomp>zcallback.<locals>.<listcomp>   s$    RRRqfQ^T::RRRr"   T)prevent_initial_callc                      t           j        j                            d          }pt	          j                    j        }|r|D ]}|                    |           t                      S )N	cancelJob)	flaskrequestargsgetlistr   getbackground_callback_managerterminate_jobr   )_job_idsexecutorjob_idr2   s       r    cancel_callzcallback.<locals>.cancel_call   sn    #m088EEGR=#4#6#6#R   ;&- ; ;F$226::::#::%r"   c                 6    g | ]}|                                 S r   to_dictr@   s     r    rB   zcallback.<locals>.<listcomp>   s     "F"F"F1199;;"F"F"Fr"   r1   r3   long)
popGLOBAL_CALLBACK_MAPGLOBAL_CALLBACK_LISTr   validate_long_inputslen	Exceptioncallbackr
   register_callback)r,   r-   r.   r/   r0   r1   r2   r3   _args_kwargs	long_specr5   r6   r7   cancel_inputscancels_outputrQ   s         `          r    r\   r\   8   sM   d I'.{{*E( ($ ;;~/BCCLKK1EFFM 1E
	  	+#*Ii  	8$28$<$<Ij! :!6777 	+9:J+K+KI'(y,--Y?P5Q1R1RRRN    	E#1'#:#:Ii   D Dy/C D D DDDD 	G*622M ///RRMRRRN.-dSSS& & & & TS& & %    #G"F"F"F"FIh 	E0DI,-( 
	  
      s   6E 
E! E!c                 x    | D ]6}|                                 r t          dt          |           d          7d S )Nz
                long callbacks does not support dependencies with
                pattern-matching ids
                    Received: 
)has_wildcardr	   repr)depsdeps     r    rY   rY      se       	(/  $Cyy/ / /  	 r"   c                 H    t          t          t          dt          | g|R i |S )NF)register_clientside_callbackrX   rW   GLOBAL_INLINE_SCRIPTS)clientside_functionrH   kwargss      r    clientside_callbackrn      sA    ' 
     r"   c
                    ||}t          j        |||           t          ||          }
|
d |D             d |D             d |du |	o	d|	d         id}|d         |d         |||	||d||
<   |                     |           |
S )	Nc                 6    g | ]}|                                 S r   rS   r@   s     r    rB   z#insert_callback.<locals>.<listcomp>   s     ///1199;;///r"   c                 6    g | ]}|                                 S r   rS   r@   s     r    rB   z#insert_callback.<locals>.<listcomp>   s     ---!!))++---r"   Tr-   )outputinputsstaterl   rC   rU   rs   rt   )rs   rt   outputs_indicesinputs_state_indicesrU   rr   
raw_inputs)r   validate_duplicate_outputr   append)r7   r6   r5   rr   ru   rs   rt   rv   rC   rU   callback_idcallback_specs               r    insert_callbackr|      s     #?'$&F   %VV44K/////--u---# !5 < 
Z(
 M  )w'* 4! !L '''r"   c                 v  
 t          ||          \  }}}t          t                    rdnt                    d|                    d          t          t          t          t                                                  }t          | |||||
  
        

fd}	|	S )NFTrU   )rU   c           	           +t          j                             d          d u          t                      	fd            }|         d<    S )Nr.   c                  
  ! |                     d          }|                     dd           }|                     di           }&o&                    d|          }t          j        %|t                     t          j        |           t          j        | $          \  }}ddi}&)|st          d          &                    d          }	t          j
        j                            d	          }
t          j
        j                            d
          }t          j
        j                            d          }|                    #|r|n|&                    dg                     }|r|D ]}|                    |           |
s|}
|j                            '          }|                    |
||r|n|t#          |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        d                    }|
|d}&                    d          }|rd |D             |d<   d |D             |d<   &                    d          }|r||d<   &                    d          }|rd t9          |	|          D             |d<   t;          |          S |	r5|                    |
          !!r!fdt?          |	          D             |d<   |                     |
|          }|!                    |          }|s||j"        u rtG                      }nOtI          |tJ                    r:d|v r6|                    d          }tM          d|d          d|d                    |r||j"        ur|                    |           (r(tI          |tN          tP          f          rd |D             }||j"        u rt;          |          S n #|i |}tF          )                    |          rtT          (s	|g|g}}|}n;tI          |tN          tP          f          rtO          |          }tW          |)          }t          j,        ||"           t[          j.        tJ                    }d}t9          ||          D ]\  }}tI          |tF                    rtI          |tN                    rt9          ||          n||ggD ]Q\  }}tI          |tF                    s7d}t_          |d                   }ta          |d                   }|||         |<   R|stT          ||d <   	 t;          |          } n%# tb          $ r t          j2        |)           Y nw xY w| S )!Noutputs_listlong_callback_managercallback_contextr2   multiTa5  Running `long` callbacks requires a manager to be installed.
Available managers:
- Diskcache (`pip install dash[diskcache]`) to run callbacks in a separate Process and store results on the local filesystem.
- Celery (`pip install dash[celery]`) to run callbacks in a celery worker and store results on redis.
r.   cacheKeyjoboldJobr3   )args_groupingusing_args_groupingoutputs_groupingusing_outputs_groupinginputs_liststates_listr   input_valuesstate_valuestriggered_inputsignore_register_page)r   r   r0   c                 F    i | ]}t          |d                    |d         S )r   r   strr:   rs     r    
<dictcomp>zMregister_callback.<locals>.wrap_func.<locals>.add_context.<locals>.<dictcomp>  s(    *L*L*Lq3qt99ad*L*L*Lr"   c                 F    i | ]}t          |d                    |d         S )r      r   r   s     r    r   zMregister_callback.<locals>.wrap_func.<locals>.add_context.<locals>.<dictcomp>  s(    -O-O-O!c!A$ii1-O-O-Or"   
runningOffr1   r8   c                 4    i | ]\  }}t          |          |S r   r   )r:   or;   s      r    r   zMregister_callback.<locals>.wrap_func.<locals>.add_context.<locals>.<dictcomp>  s4     3 3 3 $1  FFA3 3 3r"   c                 B    i | ]\  }}t          |          |         S r   r   )r:   ir;   r.   s      r    r   zMregister_callback.<locals>.wrap_func.<locals>.add_context.<locals>.<dictcomp>  s6     0 0 048AqCFFHQK0 0 0r"   long_callback_errorz*An error occurred inside a long callback: msgrd   tbc                 b    g | ],}t                               |          rt                      n|-S r   )r   r'   r   s     r    rB   zMregister_callback.<locals>.wrap_func.<locals>.add_context.<locals>.<listcomp>  sC     $ $ $ '/&;&;A&>&>E


A$ $ $r"   Fr>   propertyresponse)3rV   rJ   r   validate_output_specr   r   setvalidate_and_group_input_argsr   rF   rG   rH   rI   build_cache_keyrL   func_registrycall_job_fnr   r   r   r   r   r   r   r   r   r   r   zipr   get_progress	enumerate
get_resultjob_running	UNDEFINEDr   r$   r%   r   listtupler'   r   r   validate_multi_returncollectionsdefaultdictr   r   	TypeErrorfail_callback_output)*rH   rm   output_specapp_callback_managercallback_ctxcallback_manager	func_argsfunc_kwargsr   progress_outputs	cache_keyrP   old_jobcurrent_keyr   job_fndatar0   r1   r/   output_valuer   errorflat_output_valuescomponent_ids
has_updatevalspecvalispeciid_strpropjsonResponser.   rz   funcrv   insert_outputrU   long_keyr   rr   s*                                    @r    add_contextz9register_callback.<locals>.wrap_func.<locals>.add_contextD  sw    **^44K#)::.Et#L#L !::&8"==L#Q<P(Q(Q*=+vNNNl+++%.%L*& &"I{  H' 99   $(88J#7#7 !M.22:>>	+//66-,44X>>.>>!*;IIHH3R88	   <& < <(66s;;;;  ,) +I-;??IIF*66!%.?		K%*6*D0<0P-9-J3?3V(4(@(4(@)5)B)5)B)5)B-9-J15  	 C( %." D
 #hhy11G P*L*LG*L*L*LY-O-Ow-O-O-O\*!XXh//F 0)/X'+xx0A'B'B$' 3 3(+,<>N(O(O3 3 3./ #4==(# /<<YGGH 0 0 0 0<EFV<W<W0 0 0,  0::9fMM.::6BB" |7G7Q'Q'Q#+::LL |T22-==(,,-BCCE+bU5\bbUZ[_U`bb    ;<7G7Q#Q#Q$226::: ZtUmDD $ $!-$ $ $L
  #3#==="8,,, >  $tY>+>>$$\22 $## 
L-9N[Mk%1""lT5M:: 6 $(#5#5L &6lF%K%K"+/   (3D99MJ !3[AA 
; 
;	Tc8,, &0t&<&<OCTNNNC;-; ;KD% &dH55 ;%)
!-eDk!:!:253DEE6:f-d3;  $###0HZ E&x00 E E E.|VDDDDDE  s   *T: :UUr\   )r   register_funcrJ   r   )
r   r   r   rz   r6   rv   r   rU   r   rr   s
   ` @r    	wrap_funcz$register_callback.<locals>.wrap_func;  s    .<$$D0 H 
tj	  j	  j	  j	  j	  j	  j	  j	  j	  j	  j	  
j	 X 1<[!*-r"   )
r   r$   r   r   rJ   r   r   ranger   r|   )r7   r6   r5   r^   r_   flat_inputs
flat_staterC   output_indicesr   rz   rv   r   rU   r   rr   s    `        @@@@@@r    r]   r]     s    	%UG44&&!!  )00;;vD+FD|F?S?S9T9T4U4UVVN!(  Kx x x x x x x x x x xt r"   z
var clientside = window.dash_clientside = window.dash_clientside || {{}};
var ns = clientside["{namespace}"] = clientside["{namespace}"] || {{}};
ns["{function_name}"] = {clientside_function};
c                    t          ||          \  }}}	}
t          | |||d ||	d |
	  	         t          |t                    rld}t	          j        |                    d                                                    }|                    t          
                    |||                     n|j        }|j        }||d| d         d<   d S )N_dashprivate_clientside_funcszutf-8)	namespacefunction_namerl   )r   r   rl   )r   r|   r$   r   hashlibmd5encode	hexdigestry   _inline_clientside_templateformatr   r   )r7   r6   r5   inline_scriptsrl   rH   rm   rr   rs   rt   rC   r   r   s                r    rj   rj     s    3GtV2T2T/FFE/(
 
 
 %s++ :3	$7$>$>w$G$GHHRRTT'..#+$7 /  	
 	
 	
 	
 (1	+9 &0 0M"+,,,r"   )N)+r   r   	functoolsr   rF   dependenciesr   r   r   
exceptionsr   r	   r
   r   r   	_groupingr   r   r   _utilsr   r   r   r   r   r    r   long_callback.managersr   _callback_contextr   r   rX   rW   rk   r\   rY   rn   r|   r]   r   rj   r   r"   r    <module>r      sH                       
                      
                      ; ; ; ; ; ; , , , , , ,
 
 
 
 
 
 
 
     T T T T Tn  	 	 	, 
- - - -b^ ^ ^B - - - - -r"   