o
    HEDi/                  	   @   s   d dl Z d dlZd dlZd dlZd dlmZmZmZmZm	Z	 ddefddZ
edfddZdd
edededefddZddededefddZedZedZG dd deeef ZdS )    N)CallableGenericTypeVarTypeOptional   returnc                    sv   t trfdd}|S tstr3 t r"dndt  fdd}|S ttt	)a  
    This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.

    Source: https://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically
    c                    s4   t  rdndt  fdd}|S )Nz+Call to deprecated class {name} ({reason}).z.Call to deprecated function {name} ({reason}).c                     s2   t j jdd tdt  | i |S )N)namereason
stackleveldefault)warn_deprecatedformat__name__warningssimplefilterDeprecationWarningargskwargs)funcmsgr
   r    g/var/www/www-root/data/www/ovozai.pdev.uz/venv/lib/python3.10/site-packages/aiogram/utils/deprecated.pywrapper"   s   z.deprecated.<locals>.decorator.<locals>.wrapper)inspectisclass	functoolswraps)r   r   )r
   r   )r   r   r   	decorator   s   
zdeprecated.<locals>.decoratorz Call to deprecated class {name}.z#Call to deprecated function {name}.c                     s$   t j jdd  | i |S )N)r	   r   )r   r   r   r   )func1msg1r   r   r   wrapper1=   s   zdeprecated.<locals>.wrapper1)

isinstancestrr   r   
isfunctionr   r   	TypeErrorreprtype)r
   r   r    r#   r   )r!   r"   r
   r   r   
deprecated   s   
	


r*   c                 C   s,   t d| t j| ||d t d| d S )Nalways)categoryr   r   )r   r   warn)messagewarningr   r   r   r   r   G   s   r      old_namenew_nameuntil_versionr   c                    s    fdd}|S )al  
    A meta-decorator to mark an argument as deprecated.

    .. code-block:: python3

        @renamed_argument("chat", "chat_id", "3.0")  # stacklevel=3 by default
        @renamed_argument("user", "user_id", "3.0", stacklevel=4)
        def some_function(user_id, chat_id=None):
            print(f"user_id={user_id}, chat_id={chat_id}")

        some_function(user=123)  #  prints 'user_id=123, chat_id=None' with warning
        some_function(123)  #  prints 'user_id=123, chat_id=None' without warning
        some_function(user_id=123)  #  prints 'user_id=123, chat_id=None' without warning


    :param old_name:
    :param new_name:
    :param until_version: the version in which the argument is scheduled to be removed
    :param stacklevel: leave it to default if it's the first decorator used.
    Increment with any new decorator used.
    :return: decorator
    c                    s\   t fdd r t fdd}|S t fdd}|S )Nc                    s`   rdnd}| v r.t d| d j d d d 
d |  } | | i | S )	<
            Returns updated version of kwargs.
            	coroutinefunctionIn z 'z' argument 'z' is renamed to 'z!' and will be removed in aiogram r   )r   r   copyupdatepopr   routine_type)r   is_coroutiner2   r1   r   r3   r   r   	_handlingh   s   z6renamed_argument.<locals>.decorator.<locals>._handlingc                         |}| i |I d H S Nr   r   r>   r   r   r   wrappedw      z4renamed_argument.<locals>.decorator.<locals>.wrappedc                         |}| i |S r@   r   r   rA   r   r   rB   |      asyncioiscoroutinefunctionr   r   r   rB   r2   r1   r   r3   r>   r   r=   r   r    e   s   
	z#renamed_argument.<locals>.decoratorr   )r1   r2   r3   r   r    r   rJ   r   renamed_argumentM   s   rL   r	   c                    s    fdd}|S )a  
    A meta-decorator to mark an argument as removed.

    .. code-block:: python3

        @removed_argument("until_date", "3.0")  # stacklevel=3 by default
        def some_function(user_id, chat_id=None):
            print(f"user_id={user_id}, chat_id={chat_id}")

    :param name:
    :param until_version: the version in which the argument is scheduled to be removed
    :param stacklevel: leave it to default if it's the first decorator used.
    Increment with any new decorator used.
    :return: decorator
    c                    sZ   t fdd rt fdd}|S t fdd}|S )Nc              	      sL   rdnd}| v r$t d| d jdd d |  } | = | S )r4   r5   r6   r7    z
 argument z% is planned to be removed in aiogram r   )r   r   r8   r;   )r   r=   r	   r   r3   r   r   r>      s   z6removed_argument.<locals>.decorator.<locals>._handlingc                     r?   r@   r   r   rA   r   r   rB      rC   z4removed_argument.<locals>.decorator.<locals>.wrappedc                     rD   r@   r   r   rA   r   r   rB      rE   rF   rI   r	   r   r3   rK   r   r       s   
	z#removed_argument.<locals>.decoratorr   )r	   r3   r   r    r   rN   r   removed_argument   s   rO   _VT	_OwnerClsc                   @   sJ   e Zd ZdZdZdedeegef fddZ	de
e dee fd	d
ZdS )DeprecatedReadOnlyClassVaraf  
    DeprecatedReadOnlyClassVar[Owner, ValueType]

    :param warning_message: Warning message when getter gets called
    :param new_value_getter: Any callable with (owner_class: Type[Owner]) -> ValueType
                             signature that will be executed

    Usage example:

    >>> class MyClass:
    ...     some_attribute: DeprecatedReadOnlyClassVar[MyClass, int] =     ...            DeprecatedReadOnlyClassVar(
    ...                  "Warning message.", lambda owner: 15)
    ...
    >>> MyClass.some_attribute  # does warning.warn with `Warning message` and returns 15 in the current case
    )_new_value_getter_warning_messagewarning_messagenew_value_getterc                 C   s   || _ || _d S r@   )rT   rS   )selfrU   rV   r   r   r   __init__   s   
z#DeprecatedReadOnlyClassVar.__init__instanceownerc                 C   s   t | jdd | |S )Nr0   r   )r   rT   rS   )rW   rY   rZ   r   r   r   __get__   s   
z"DeprecatedReadOnlyClassVar.__get__N)r   
__module____qualname____doc__	__slots__r%   r   rQ   rP   rX   r   r   r[   r   r   r   r   rR      s
    rR   )r   )r0   )rG   r   r   r   typingr   r   r   r   r   r*   r   r   r%   intrL   rO   rP   rQ   rR   r   r   r   r   <module>   s    ?93