a
    ‰©lc‹  ã                   @   s  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZ zd dlZW n eyr   ddlmZ Y n0 g d¢ZedƒZddœed	ef ee
e j ee d
œdd„Zdeg df e
e e
e j ddœdd„Ze	eef e
e dœdd„Ze jdœdd„ZdS )é    N)ÚTracebackType)ÚAnyÚ	AwaitableÚCallableÚDictÚOptionalÚTypeVarÚcasté   )Údummy_contextvars)Úrun_in_executor_with_contextÚcall_soon_threadsafeÚget_traceback_from_contextÚget_event_loopÚ_T)Úloop.)ÚfuncÚargsr   Úreturnc                G   s*   |pt ƒ }t ¡ }|jd|j| g|¢R Ž S )zÐ
    Run a function in an executor, but make sure it uses the same contextvars.
    This is required so that the function will see the right application.

    See also: https://bugs.python.org/issue34014
    N)r   ÚcontextvarsÚcopy_contextÚrun_in_executorÚrun)r   r   r   Úctx© r   úZ/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/eventloop/utils.pyr      s    
r   )r   Úmax_postpone_timer   r   c                    sR   |pt ƒ ‰|du r ˆ ˆ ¡ dS t ¡ | ‰ddœ‡ ‡‡‡fdd„‰ˆ ˆ¡ dS )aó  
    Wrapper around asyncio's `call_soon_threadsafe`.

    This takes a `max_postpone_time` which can be used to tune the urgency of
    the method.

    Asyncio runs tasks in first-in-first-out. However, this is not what we
    want for the render function of the prompt_toolkit UI. Rendering is
    expensive, but since the UI is invalidated very often, in some situations
    we render the UI too often, so much that the rendering CPU usage slows down
    the rest of the processing of the application.  (Pymux is an example where
    we have to balance the CPU time spend on rendering the UI, and parsing
    process output.)
    However, we want to set a deadline value, for when the rendering should
    happen. (The UI should stay responsive).
    N©r   c                      s:   t ˆdg ƒsˆ ƒ  d S t ¡ ˆkr,ˆ ƒ  d S ˆ ˆ¡ d S )NÚ_ready)ÚgetattrÚtimer   r   ©r   Zloop2Zmax_postpone_untilÚscheduler   r   r"   E   s    z&call_soon_threadsafe.<locals>.schedule)r   r   r    )r   r   r   r   r!   r   r   '   s    

r   )Úcontextr   c                 C   s4   |   d¡}|r0t|dƒr$tt|jƒS t ¡ d S dS )z4
    Get the traceback object from the context.
    Ú	exceptionÚ__traceback__é   N)ÚgetÚhasattrr	   r   r%   ÚsysÚexc_info)r#   r$   r   r   r   r   Y   s    

r   r   c                  C   sD   t jdkrtj} ntj} z| ƒ W S  ty>   t ¡  ¡  Y S 0 dS )z-Backward compatible way to get the event loop)é   é   N)r)   Úversion_infoÚasyncioÚget_running_loopr   ÚRuntimeErrorÚget_event_loop_policy)Zgetloopr   r   r   r   j   s    
r   )NN)r.   r)   r    Útypesr   Útypingr   r   r   r   r   r   r	   r   ÚImportErrorÚ r   Ú__all__r   ÚAbstractEventLoopr   Úfloatr   Ústrr   r   r   r   r   r   Ú<module>   s6   $ý
ü  ý
ü2