U
    x^                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dd	lm	Z	 d!ddZ
d"ddZd#ddZd$ddZdd Zd%ddZdd Zdd Zd&ddZd'dd ZdS )(zSHelpers related to deprecation of functions, methods, classes, other
functionality.    N   )compat)	decorator)inject_docstring_text)inject_param_text   )exc   c                 C   s   t j| tj|d d S N
stacklevelwarningswarnr   SADeprecationWarningmsgr    r   D/tmp/pip-install-dq5v43_d/SQLAlchemy/sqlalchemy/util/deprecations.pywarn_deprecated   s    r   c                 C   s   t j| tj|d d S r
   )r   r   r   SAPendingDeprecationWarningr   r   r   r   warn_pending_deprecation   s    r   __init__c                    s$   d| p
df  fdd}|S )N.. deprecated:: %s %s c                    s   t |  tjt d S Nfunc)_decorate_cls_with_warningr   r   dict)clsconstructorheadermessager   r   decorate    s    z deprecated_cls.<locals>.decorater   )versionr$   r"   r%   r   r!   r   deprecated_cls   s    	r'   Tc                    s8   |rd| pdf  nd dkr&d fdd}|S )a  Decorates a function and issues a deprecation warning on use.

    :param version:
      Issue version in the warning.

    :param message:
      If provided, issue message in the warning.  A sensible default
      is used if not provided.

    :param add_deprecation_to_docstring:
      Default True.  If False, the wrapped function's __doc__ is left
      as-is.  If True, the 'message' is prepended to the docs if
      provided, or sensible default if message is omitted.

    r   r   N$Call to deprecated function %(func)sc                    s   t | tjt| jd  S r   )_decorate_with_warningr   r   r   __name__fnr#   r$   r   r   r%   E   s    zdeprecated.<locals>.decorater   r&   r$   Zadd_deprecation_to_docstringr%   r   r-   r   
deprecated,   s    r/   c                     s8   i    D ]\}\}}t| |< q fdd}|S )a"  Decorates a function to warn on use of certain parameters.

    e.g. ::

        @deprecated_params(
            weak_identity_map=(
                "0.7",
                "the :paramref:`.Session.weak_identity_map parameter "
                "is deprecated."
            )

        )

    c                    s   t | }|jd k	r\tt|jt|jt|j d  |jt t	nd tt
 fdd}| jd k	r| jpd}|rt|dd  D }|| }||_|S )Nr   c                    sb    D ]*}|| | krt j| tjdd qD ]"}||kr4t j| tjdd q4| ||S Nr	   r   r   )r,   argskwargsm)check_defaultscheck_kwdefaultsmessagesr   r   warneds   s        z3deprecated_params.<locals>.decorate.<locals>.warnedr   c                 S   s&   i | ]\}\}}|d ||pdf qS )r   r   r   ).0paramr&   r$   r   r   r   
<dictcomp>   s   
 z7deprecated_params.<locals>.decorate.<locals>.<dictcomp>)r   Zinspect_getfullargspecr6   r   zipr1   lensetintersection
differencer   __doc__r   items)r,   specr8   doc	decoratedr7   specs)r4   r5   r6   r   r%   d   s2    

z#deprecated_params.<locals>.decorate)rB   _sanitize_restructured_text)rG   r:   r&   r$   r%   r   rF   r   deprecated_paramsP   s
    +rI   c                    s8   |rd| pdf  nd dkr&d fdd}|S )aE  Decorates a function and issues a pending deprecation warning on use.

    :param version:
      An approximate future version at which point the pending deprecation
      will become deprecated.  Not used in messaging.

    :param message:
      If provided, issue message in the warning.  A sensible default
      is used if not provided.

    :param add_deprecation_to_docstring:
      Default True.  If False, the wrapped function's __doc__ is left
      as-is.  If True, the 'message' is prepended to the docs if
      provided, or sensible default if message is omitted.
    z.. deprecated:: %s (pending) %sr   Nr(   c                    s   t | tjt| jd  S r   )r)   r   r   r   r*   r+   r-   r   r   r%      s    z%pending_deprecation.<locals>.decorater   r.   r   r-   r   pending_deprecation   s    rJ   c                 C   s   | d kr|S t | | S d S )N)r   )Zparameter_valuedefault_valueZwarning_textr   r   r   deprecated_option_value   s    rL   c                 C   s   dd }t d|| S )Nc                 S   s$   |  dd\}}|dkr |d7 }|S )Nr   r   )r   methz())group)r3   type_namer   r   r   repl   s    z)_sanitize_restructured_text.<locals>.replz\:(\w+)\:`~?\.?(.+?)`)resub)textrQ   r   r   r   rH      s    rH   c                 C   s   | j d k	r| j pd}|d k	r~|t|d; }t||d}t| tkrnt| j}||d< t| j| j|} || }n|| _ t| |}t| |t	|||d  | S )Nr   r   r   rA   )
rA   r   r   type__dict__r*   	__bases__getattrsetattrr)   )r    r"   wtyper$   docstring_headerrD   ZclsdictZconstructor_fnr   r   r   r      s"    


r   c                    st   t   t fdd}| jdk	r*| jp,d}|dk	rR|t| jd; }t||d}|| }||_ fdd|_|S )	z=Wrap a function with a warnings.warn and augmented docstring.c                    s   t j dd | ||S r0   r   r   )r,   r1   r2   r$   rZ   r   r   r8      s    z&_decorate_with_warning.<locals>.warnedNr   r   r   c                      s   t j ddS r0   r\   r   r]   r   r   <lambda>       z(_decorate_with_warning.<locals>.<lambda>)rH   r   rA   r   r*   r   Z_sa_warn)r   rZ   r$   r[   r8   rD   rE   r   r]   r   r)      s    r)   )r	   )r	   )r   )NT)NT)N)N)rA   rR   r   r   r   Zlanghelpersr   r   r   r   r   r   r'   r/   rI   rJ   rL   rH   r   r)   r   r   r   r   <module>   s(   



$C   
& 
