U
    7hf                     @   sz   d dl Z d dlmZ d dlmZ d dlmZ dd Zzd dlm	Z	 W n0 e
k
rt   d dlmZ G d	d
 d
eZ	Y nX 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 N/var/www/formularioweb/env/lib/python3.8/site-packages/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   )aclosing)AbstractAsyncContextManagerc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r   z
        Async context manager for safely finalizing an asynchronously
        cleaned-up resource such as an async generator, calling its
        ``aclose()`` method.
        c                 C   s
   || _ d S Nthing)selfr   r   r   r   __init__9   s    zaclosing.__init__c                    s   | j S r   r   )r   r   r   r   
__aenter__<   s    zaclosing.__aenter__c                    s   | j  I d H  d S r   )r   aclose)r   exc_infor   r   r   	__aexit__?   s    zaclosing.__aexit__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   2   s   r   )r   Zasyncior   	functoolsr   Zdjango.core.exceptionsr   r   
contextlibr   ImportErrorr   r   r   r   r   <module>   s   "