U
    mfk                     @   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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-siwebuq3/django/utils/deprecation.pyr      s   r   c                   @   s   e Zd ZdS )RemovedInDjango50WarningNr   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|	rt	
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   7   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	   r2   W   s    z*DeprecationInstanceCheck.__instancecheck__)r   r   r   r2   r/   r   r   r,   r	   r0   V   s   r0   c                       sD   e Zd ZdZdZ fddZdd Zdd Zdd	 Zd
d Z	  Z
S )MiddlewareMixinTc                    s,   |d krt d|| _|   t   d S )Nzget_response must be provided.)
ValueErrorget_response_async_checkr   r   )r   r6   r,   r   r	   r   d   s
    zMiddlewareMixin.__init__c                 C   s    d| j jt| jd| jj jf S )Nz<%s get_response=%s>r   )r-   r   getattrr6   r   r   r   r   r	   __repr__k   s    zMiddlewareMixin.__repr__c                 C   s"   t | jrt jj| _nd| _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iscoroutinefunctionr6   Z
coroutines_is_coroutiner9   r   r   r	   r7   u   s    zMiddlewareMixin._async_checkc                 C   sP   | j r| |S d }t| dr(| |}|p4| |}t| drL| ||}|S )Nprocess_requestprocess_response)r=   	__acall__hasattrr>   r6   r?   r   requestresponser   r   r	   r      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?   )rA   r   r>   r6   r?   rB   r   r   r	   r@      s$    


 
zMiddlewareMixin.__acall__)r   r   r   Zsync_capableZasync_capabler   r:   r7   r   r@   r/   r   r   r,   r	   r4   `   s   
r4   )r;   r   r   Zasgiref.syncr   DeprecationWarningr   PendingDeprecationWarningr
   ZRemovedAfterNextVersionWarningr   typer   r0   r4   r   r   r   r	   <module>   s   -
