U
    8ÄT_  ã                   @   s„   d dl Z d dlZd dlZd dlmZ G dd„ deƒZG dd„ deƒZG dd„ dƒZ	G d	d
„ d
e
ƒZG dd„ de
ƒZG dd„ dƒZdS )é    N)Úsync_to_asyncc                   @   s   e Zd ZdS )ÚRemovedInNextVersionWarningN©Ú__name__Ú
__module__Ú__qualname__© r   r   ú</tmp/pip-unpacked-wheel-dv63caxw/django/utils/deprecation.pyr      s   r   c                   @   s   e Zd ZdS )ÚRemovedInDjango40WarningNr   r   r   r   r	   r
      s   r
   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Úwarn_about_renamed_methodc                 C   s   || _ || _|| _|| _d S ©N)Ú
class_nameÚold_method_nameÚnew_method_nameÚdeprecation_warning)Úselfr   r   r   r   r   r   r	   Ú__init__   s    z"warn_about_renamed_method.__init__c                    s   ‡ ‡fdd„}|S )Nc                     s*   t  dˆjˆjˆjf ˆjd¡ ˆ | |ŽS )Nz(`%s.%s` is deprecated, use `%s` instead.é   )ÚwarningsÚwarnr   r   r   r   )ÚargsÚkwargs©Úfr   r   r	   Úwrapped   s    ÿ ýz3warn_about_renamed_method.__call__.<locals>.wrappedr   )r   r   r   r   r   r	   Ú__call__   s    z"warn_about_renamed_method.__call__N)r   r   r   r   r   r   r   r   r	   r      s   r   c                       s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )ÚRenameMethodsBasea#  
    Handles the deprecation paths when renaming a method.

    It does the following:
        1) Define the new method if missing and complain about it.
        2) Define the old method if missing.
        3) Complain whenever an old method is called.

    See #15363 for more details.
    r   c                    sÊ   t ƒ  | |||¡}t |¡D ]¨}|j}| jD ]–}|d }|j |¡}	|d }
|j |
¡}|d }t|f|žŽ }|sª|	rªt	 
d|||
f |d¡ t||
|	ƒ t||||	ƒƒ |	s,|r,t||||ƒƒ q,q|S )Nr   é   r   z&`%s.%s` method should be renamed `%s`.)ÚsuperÚ__new__ÚinspectÚgetmror   Úrenamed_methodsÚ__dict__Úgetr   r   r   Úsetattr)ÚclsÚnameÚbasesÚattrsÚ	new_classÚbaser   Zrenamed_methodr   Z
old_methodr   Z
new_methodr   Úwrapper©Ú	__class__r   r	   r   /   s.    
ÿ ýzRenameMethodsBase.__new__)r   r   r   Ú__doc__r"   r   Ú__classcell__r   r   r-   r	   r   !   s   r   c                       s   e Zd Z‡ fdd„Z‡  ZS )ÚDeprecationInstanceCheckc                    s(   t  d| j| jf | jd¡ tƒ  |¡S )Nz%`%s` is deprecated, use `%s` instead.r   )r   r   r   Úalternativer   r   Ú__instancecheck__)r   Úinstancer-   r   r	   r3   M   s     þz*DeprecationInstanceCheck.__instancecheck__)r   r   r   r3   r0   r   r   r-   r	   r1   L   s   r1   c                       sF   e Zd ZdZdZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Z	‡  Z
S )ÚMiddlewareMixinTNc                    s&   |   |¡ || _|  ¡  tƒ  ¡  d S r   )Ú_get_response_none_deprecationÚget_responseÚ_async_checkr   r   ©r   r7   r-   r   r	   r   [   s    
zMiddlewareMixin.__init__c                 C   s   t  | j¡rt jj| _dS )z�
        If get_response is a coroutine function, turns us into async mode so
        a thread is not consumed during a whole request.
        N)ÚasyncioÚiscoroutinefunctionr7   Z
coroutinesZ_is_coroutine)r   r   r   r	   r8   a   s    zMiddlewareMixin._async_checkc                 C   sV   t  | j¡r|  |¡S d }t| dƒr.|  |¡}|p:|  |¡}t| dƒrR|  ||¡}|S )NÚprocess_requestÚprocess_response)r:   r;   r7   Ú	__acall__Úhasattrr<   r=   ©r   ÚrequestÚresponser   r   r	   r   k   s    



zMiddlewareMixin.__call__c                 Ã   sb   d}t | dƒr&t| jdd�|ƒI dH }|p8|  |¡I dH }t | dƒr^t| jdd�||ƒI dH }|S )zh
        Async version of __call__ that is swapped in when an async request
        is running.
        Nr<   T)Zthread_sensitiver=   )r?   r   r<   r7   r=   r@   r   r   r	   r>   w   s$    
þý

þ ý
zMiddlewareMixin.__acall__c                 C   s   |d krt jdtdd� d S )NzDPassing None for the middleware get_response argument is deprecated.é   )Ú
stacklevel)r   r   r
   r9   r   r   r	   r6   Š   s     ýz.MiddlewareMixin._get_response_none_deprecation)N)r   r   r   Zsync_capableZasync_capabler   r8   r   r>   r6   r0   r   r   r-   r	   r5   U   s   
r5   )r:   r    r   Zasgiref.syncr   ÚDeprecationWarningr   ÚPendingDeprecationWarningr
   r   Útyper   r1   r5   r   r   r   r	   Ú<module>   s   +	