o
    i                     @  s   d Z ddlmZ ddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZ ejr7ddlmZ ddl	mZ G d	d
 d
eeejf ZedZedZedZ	ddddZdS )	Utilities    )annotationsN)Mappingcopy_context)partialwraps)Callable)Contextc                   @  s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )LazyDictzLazy evaluated read-only dictionary.

    Initialised with a dictionary of key-value pairs where the values are either
    constants or callables. Callables are evaluated each time the respective item is
    read.
    c                 C  s
   || _ d S N)_dict)selfdict r   J/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/ipykernel/utils.py__init__      
zLazyDict.__init__c                 C  s   | j |}t|r| S |S r   )r   getcallable)r   keyitemr   r   r   __getitem__   s   zLazyDict.__getitem__c                 C  
   t | jS r   )lenr   r   r   r   r   __len__    r   zLazyDict.__len__c                 C  r   r   )iterr   r   r   r   r   __iter__#   r   zLazyDict.__iter__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s    r   TUVf#Callable[..., t.Coroutine[T, U, V]]contextContext | Nonereturnc                   s`    du rt   tjdkrt fdd}|S  gfddtfdd}|S )	z
    Wrapper to run a coroutine in a persistent ContextVar Context.

    Backports asyncio.create_task(context=...) behavior from Python 3.11
    N)      c                    s$   | i |}t j| dI d H S )N)r(   )asynciocreate_task)argskwargscoro)r(   r&   r   r   run_in_context9   s   z)_async_in_context.<locals>.run_in_contextc              	     s0   z| |i |I dH W t   d< S t   d< w )z;call a coroutine, preserving the context after it is calledNr   r   )r&   r/   r0   )context_holderr   r   preserve_contextD   s   z+_async_in_context.<locals>.preserve_contextc                    s4    d }| ttjg| R i |I d H S )Nr   )runr   r-   r.   )r/   r0   ctx)r3   r&   r4   r   r   run_in_context_pre311L   s   *z0_async_in_context.<locals>.run_in_context_pre311)r   sysversion_infor   )r&   r(   r2   r7   r   )r(   r3   r&   r4   r   _async_in_context,   s   
r:   r   )r&   r'   r(   r)   r*   r'   )r"   
__future__r   r-   r8   typingtcollections.abcr   contextvarsr   	functoolsr   r   TYPE_CHECKINGr	   r
   strAnyr   TypeVarr#   r$   r%   r:   r   r   r   r   <module>   s"    


