a
    ø£Bew  ã                   @   s>   d Z ddlmZmZmZ ddlmZmZmZ G dd„ dƒZ	dS )zBProvides access to variables pertaining to specific call contexts.é    )ÚContextÚ
ContextVarÚcopy_context)ÚAnyÚDictÚListc                   @   s˜   e Zd ZU dZdZeed< dZeeƒZ	ee
eef  ed< eeedœdd„ƒZeeeddœd	d
„ƒZeee dœdd„ƒZee
eef dœdd„ƒZdS )ÚCallContexta6  CallContext essentially acts as a namespace for managing context variables.

    Although not required, it is recommended that any "file-spanning" context variable
    names (i.e., variables that will be set or retrieved from multiple files or services) be
    added as constants to this class definition.
    ÚJUPYTER_HANDLERÚ_name_value_map)ÚnameÚreturnc                 C   s   t  ¡ }||v r|| S dS )a™  Returns the value corresponding the named variable relative to this context.

        If the named variable doesn't exist, None will be returned.

        Parameters
        ----------
        name : str
            The name of the variable to get from the call context

        Returns
        -------
        value: Any
            The value associated with the named variable for this call context
        N©r   Ú_get_map)Úclsr   Úname_value_map© r   úc/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_server/base/call_context.pyÚget   s    zCallContext.getN)r   Úvaluer   c                 C   s   t  ¡ }|||< dS )aY  Sets the named variable to the specified value in the current call context.

        Parameters
        ----------
        name : str
            The name of the variable to store into the call context
        value : Any
            The value of the variable to store into the call context

        Returns
        -------
        None
        Nr   )r   r   r   r   r   r   r   Úset1   s    zCallContext.set)r   c                 C   s   t  ¡ }t| ¡ ƒS )z¾Returns a list of variable names set for this call context.

        Returns
        -------
        names: List[str]
            A list of variable names set for this call context.
        )r   r   ÚlistÚkeys)r   r   r   r   r   Úcontext_variable_namesC   s    	z"CallContext.context_variable_namesc                 C   s&   t ƒ }tj|vrtj i ¡ tj ¡ S )z´Get the map of names to their values from the _NAME_VALUE_MAP context var.

        If the map does not exist in the current context, an empty map is created and returned.
        )r   r   r
   r   r   )r   Úctxr   r   r   r   O   s    
zCallContext._get_map)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   ÚstrÚ__annotations__Z_NAME_VALUE_MAPr   r
   r   r   Úclassmethodr   r   r   r   r   r   r   r   r   r   	   s   
	r   N)
r   Úcontextvarsr   r   r   Útypingr   r   r   r   r   r   r   r   Ú<module>   s   