o
    [h2                     @   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
lm
Z
 d$dd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)_hash_limit_string)	decorator)inject_docstring_text)inject_param_text   )exc   c                 C      t j| tj|d d S N
stacklevelwarningswarnr	   SADeprecationWarningmsgr    r   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/sqlalchemy/util/deprecations.pywarn_deprecated      r   c                 C   s$   |rt | d|} t| tj| dS )zhIssue a deprecation warning with a parameterized string,
    limiting the number of registrations.

    
   N)r   r   r   r	   r   )r   argsr   r   r   r   warn_deprecated_limited   s   r   c                 C   r   r   )r   r   r	   SAPendingDeprecationWarningr   r   r   r   warn_pending_deprecation$   r   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                    8   |rd| pdf  nd du 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                       t | tjt| jd  S r!   )_decorate_with_warningr	   r   r%   __name__fnr)   r*   r   r   r+   P      zdeprecated.<locals>.decorater   r,   r*   Zadd_deprecation_to_docstringr+   r   r5   r   
deprecated7   s   r8   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 ur.tt|jt|jt|j d  |jt t	nd tt
 fdd}| jd urG| jpHd}|rWt|dd  D }|| }||_|S )Nr   c                    sf    D ]}|| | krt j| tjdd qD ]}||v r+t j| tjdd q| |i |S Nr
   r   r   )r4   r   kwargsm)check_defaultscheck_kwdefaultsmessagesr   r   warned~   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_getfullargspecr>   r%   zipr   lensetintersection
differencer   __doc__r   items)r4   specr@   doc	decoratedr?   specs)r<   r=   r>   r   r+   o   s2   

z#deprecated_params.<locals>.decorate)rJ   _sanitize_restructured_text)rO   rB   r,   r*   r+   r   rN   r   deprecated_params[   s
   +rQ   c                    r.   )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                    r0   r!   )r1   r	   r   r%   r2   r3   r5   r   r   r+      r6   z%pending_deprecation.<locals>.decorater   r7   r   r5   r   pending_deprecation   s   rR   c                 C   s   | d u r|S t | | S N)r   )Zparameter_valuedefault_valueZwarning_textr   r   r   deprecated_option_value   s   rU   c                 C   s   dd }t d|| S )Nc                 S   s$   |  dd\}}|dv r|d7 }|S )Nr   r   )r#   methz())group)r;   type_namer   r   r   repl   s   z)_sanitize_restructured_text.<locals>.replz\:(\w+)\:`~?(?:_\w+)?\.?(.+?)`)resub)textrZ   r   r   r   rP      s   rP   c                 C   s   | j d ur| j p	d}|d ur?|t|d; }t||d}t| tu r7t| j}||d< t| j| j|} || }n|| _ t| |}t| |t	|||d  | S )Nr    r"   r   rI   )
rI   r%   r   type__dict__r2   	__bases__getattrsetattrr1   )r&   r(   wtyper*   docstring_headerrL   ZclsdictZconstructor_fnr   r   r   r$      s"   


r$   c                    st   t   t fdd}| jdur| jpd}|dur)|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 | |i |S r9   r   r   )r4   r   r:   r*   rc   r   r   r@      s   z&_decorate_with_warning.<locals>.warnedNr    r"   r   c                      s   t j ddS r9   re   r   rf   r   r   <lambda>  s    z(_decorate_with_warning.<locals>.<lambda>)rP   r   rI   r%   r2   r   Z_sa_warn)r#   rc   r*   rd   r@   rL   rM   r   rf   r   r1      s   r1   )r
   )r   )NTrS   )rI   r[   r   r    r   Zlanghelpersr   r   r   r   r	   r   r   r   r-   r8   rQ   rR   rU   rP   r$   r1   r   r   r   r   <module>   s,   





$C
&
