
v^                 @   sD   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     r4   } d   | |  S| Sd 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  j       f d d    } | S)Nc                 s\   t  j j d  sO y t j   } Wn t k
 r6 Yn X| j   rO t      |  |   S)NZDJANGO_ALLOW_ASYNC_UNSAFE)osenvirongetasyncioZget_event_loopRuntimeErrorZ
is_runningr   )argskwargsZ
event_loop)funcmessage 6/tmp/pip-build-8lau8j11/django/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   