U
    8ÄT_�  ã                   @   s0   d dl Z d dlZd dlZd dlmZ dd„ ZdS )é    N)ÚSynchronousOnlyOperationc                    s,   ‡ fdd„}t ˆ ƒr$ˆ }d‰ ||ƒS |S dS )z•
    Decorator to mark functions as async-unsafe. Someone trying to access
    the function while in an async context will get an error message.
    c                    s   t  ˆ ¡‡ ‡fdd„ƒ}|S )Nc                     sH   t j d¡s>zt ¡ }W n tk
r,   Y nX | ¡ r>tˆƒ‚ˆ | |ŽS )NZDJANGO_ALLOW_ASYNC_UNSAFE)ÚosÚenvironÚgetÚasyncioZget_event_loopÚRuntimeErrorZ
is_runningr   )ÚargsÚkwargsZ
event_loop)ÚfuncÚmessage© ú8/tmp/pip-unpacked-wheel-dv63caxw/django/utils/asyncio.pyÚinner   s    z.async_unsafe.<locals>.decorator.<locals>.inner)Ú	functoolsÚwraps)r
   r   ©r   )r
   r   Ú	decorator   s    zasync_unsafe.<locals>.decoratorzKYou cannot call this from an async context - use a thread or sync_to_async.N)Úcallable)r   r   r
   r   r   r   Úasync_unsafe   s    r   )r   r   r   Zdjango.core.exceptionsr   r   r   r   r   r   Ú<module>   s   