a
    Pf<                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlZer\d dl	m
Z
 d dlmZ ejddddd	d
ZddddZejdddddddddZdS )    )annotationsN)TYPE_CHECKING)	Generator)	FrameTypestrzGenerator[None, None, None])old_namenew_namereturnc              
   c  s   z
dV  W nt t y~ } z\|js" t|jd }|| |}|f}t|jdkrb||jdd  }||_ W Y d}~n
d}~0 0 dS )z.
    Rewrite the message of an exception.
    Nr      )	Exceptionargsr   replacelen)r   r   errmsgr    r   P/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/util/_exceptions.pyrewrite_exception   s    
r   int)r	   c                  C  sv   ddl } tj| j}tj|d}t }z@d}|rht|}|	|rh|	|sh|j
}|d7 }q2qhq2W ~n~0 |S )zb
    Find the first place in the stack that is not inside pandas
    (tests notwithstanding).
    r   NZtestsr
   )Zpandasospathdirname__file__joininspectcurrentframegetfile
startswithf_back)pdZpkg_dirZtest_dirframenfilenamer   r   r   find_stack_level"   s    

r#   ztype[Warning]ztype[Warning] | None)target_messagetarget_categorynew_messagenew_categoryr	   c           	      c  s   |du r|}t jdd}dV  W d   n1 s40    Y  t|dkrt| }|D ]N}|j|u rt|t|jr|}|}n|j|j }}t j	|||j
|jd qXdS )a  
    Rewrite the message of a warning.

    Parameters
    ----------
    target_message : str
        Warning message to match.
    target_category : Warning
        Warning type to match.
    new_message : str
        New warning message to emit.
    new_category : Warning or None, default None
        New warning type to emit. When None, will be the same as target_category.
    NT)recordr   )messagecategoryr"   lineno)warningscatch_warningsr   recompiler*   searchr   r)   warn_explicitr"   r+   )	r$   r%   r&   r'   r(   matchwarningr*   r)   r   r   r   rewrite_warning?   s&    $

r4   )N)
__future__r   
contextlibr   r   r.   typingr   r,   collections.abcr   typesr   contextmanagerr   r#   r4   r   r   r   r   <module>   s    