U
    gëdr  ã                   @   s8   d dl Z d dlmZ d dlmZ d dlmZ dd„ ZdS )é    N)Úget_running_loop©Úwraps)Ú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                     s>   z
t ƒ  W n tk
r   Y nX tj d¡s4tˆƒ‚ˆ | |ŽS )NZDJANGO_ALLOW_ASYNC_UNSAFE)r   ÚRuntimeErrorÚosÚenvironÚgetr   )ÚargsÚkwargs)ÚfuncÚmessage© ú8/tmp/pip-unpacked-wheel-_p7c4jiu/django/utils/asyncio.pyÚinner   s    
z.async_unsafe.<locals>.decorator.<locals>.innerr   )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   Zasyncior   Ú	functoolsr   Zdjango.core.exceptionsr   r   r   r   r   r   Ú<module>   s   