
    Hwgf                     |    d dl Z d dlmZ d dlmZ d dlmZ d Z	 d dlm	Z	 y# e
$ r d dlmZ  G d d	e      Z	Y yw xY w)
    N)get_running_loopwraps)SynchronousOnlyOperationc                 @      fd}t               r }d  ||      S |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                 2     t                fd       }|S )Nc                      	 t                t        j                  j                  d      st	               | i |S # t
        $ r Y w xY w)NDJANGO_ALLOW_ASYNC_UNSAFE)r   osenvirongetr   RuntimeError)argskwargsfuncmessages     K/var/www/horilla/myenv/lib/python3.12/site-packages/django/utils/asyncio.pyinnerz.async_unsafe.<locals>.decorator.<locals>.inner   sP    < " zz~~&AB27;;(((   s   
? 	A
Ar   )r   r   r   s   ` r   	decoratorzasync_unsafe.<locals>.decorator   s     	t
	) 

	)     zKYou cannot call this from an async context - use a thread or sync_to_async.)callable)r   r   r   s   `  r   async_unsafer      s3    "  	 r   )aclosing)AbstractAsyncContextManagerc                   "    e Zd ZdZd Zd Zd Zy)r   z
        Async context manager for safely finalizing an asynchronously
        cleaned-up resource such as an async generator, calling its
        ``aclose()`` method.
        c                     || _         y Nthing)selfr   s     r   __init__zaclosing.__init__9   s	    DJr   c                 "   K   | j                   S wr   r   )r    s    r   
__aenter__zaclosing.__aenter__<   s     ::s   c                 T   K   | j                   j                          d {    y 7 wr   )r   aclose)r    exc_infos     r   	__aexit__zaclosing.__aexit__?   s     **##%%%s   (&(N)__name__
__module____qualname____doc__r!   r#   r'    r   r   r   r   2   s    				&r   r   )r   asyncior   	functoolsr   django.core.exceptionsr   r   
contextlibr   ImportErrorr   r,   r   r   <module>r2      s>    	 $  ;D&# &6&. &&s   " ;;