a
    "Rh                     @   s   d dl Z d dlZd dlZd dlZd dlZddddddZdd ZG d	d
 d
eZe j	dd Z
e j	dedfddZe j	dd ZdddZe j	dd Zdd ZdS )    N    linenooffsetc                C   s   ddl m} tjdd(}tdt t|dd W d    n1 sF0    Y  | t|d| |\}| 	t
|jt|j |r| t|j| | |jd | |j |d ur| |j| tjdd.}td	t || ||||d
 W d    n1 s0    Y  | |g  d S )Nr   )check_syntax_errorTrecordalwaysz
<testcase>execr   errorr   )test.supportr   warningscatch_warningssimplefilterSyntaxWarningcompileassertEquallenZ
assertTrue
issubclasscategoryZassertRegexstrmessagefilenameZassertIsNotNoner   )testcaseZ	statementZerrtextr   r   r   warnswarn r   D/opt/python-3.9.24/usr/lib/python3.9/test/support/warnings_helper.pycheck_syntax_warning   s*    *&r   c                    s    fdd}|S )zDecorator to suppress deprecation warnings.

    Use of context managers to hide warnings make diffs
    more noisy and tools like 'git blame' less useful.
    c                    s   t   fdd}|S )Nc                    sP   t  4 t jd d | g|R i |W  d    S 1 sB0    Y  d S )Nignorer   )r   r   r   )selfargskwargs)r   testr   r   wrapper-   s    
z3ignore_warnings.<locals>.decorator.<locals>.wrapper)	functoolswraps)r%   r&   r!   )r%   r   	decorator,   s    z"ignore_warnings.<locals>.decoratorr   )r   r)   r   r!   r   ignore_warnings&   s    r*   c                   @   s4   e Zd ZdZdd Zdd Zedd Zdd	 Zd
S )WarningsRecorderzyConvenience wrapper for the warnings list returned on
       entry to the warnings.catch_warnings() context manager.
    c                 C   s   || _ d| _d S )Nr   	_warnings_last)r"   Zwarnings_listr   r   r   __init__:   s    zWarningsRecorder.__init__c                 C   sD   t | j| jkr t| jd |S |tjjv r0d S td| |f d S )Nz%r has no attribute %r)r   r-   r.   getattrr   WarningMessage_WARNING_DETAILSAttributeError)r"   attrr   r   r   __getattr__>   s
    zWarningsRecorder.__getattr__c                 C   s   | j | jd  S Nr,   r"   r   r   r   r   E   s    zWarningsRecorder.warningsc                 C   s   t | j| _d S r7   )r   r-   r.   r8   r   r   r   resetI   s    zWarningsRecorder.resetN)	__name__
__module____qualname____doc__r/   r6   propertyr   r9   r   r   r   r   r+   6   s   
r+   c                  O   s.   | d}| s$dtff} |du r$d}t| |S )a  Context manager to silence warnings.

    Accept 2-tuples as positional arguments:
        ("message regexp", WarningCategory)

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default True without argument,
         default False if some filters are defined)

    Without argument, it defaults to:
        check_warnings(("", Warning), quiet=True)
    quietr   NT)getWarning_filterwarnings)filtersr$   r?   r   r   r   check_warningsM   s    

rD   Fc                 c   sh   ddl m} tjdd0}tjd||d dV  |r:|  W d   n1 sN0    Y  | |g  dS )a  Context manager to check that no warnings are emitted.

    This context manager enables a given warning within its scope
    and checks that no warnings are emitted even with that warning
    enabled.

    If force_gc is True, a garbage collection is attempted before checking
    for warnings. This may help to catch warnings emitted when objects
    are deleted, such as ResourceWarning.

    Other keyword arguments are passed to warnings.filterwarnings().
    r   )
gc_collectTr   r
   )r   r   N)r   rE   r   r   filterwarningsr   )r   r   r   force_gcrE   r   r   r   r   check_no_warningse   s    $rH   c                 c   s8   t | tdd dV  W d   n1 s*0    Y  dS )a"  Context manager to check that no ResourceWarning is emitted.

    Usage:

        with check_no_resource_warning(self):
            f = open(...)
            ...
            del f

    You must remove the object which may emit ResourceWarning before
    the end of the context manager.
    T)r   rG   N)rH   ResourceWarning)r   r   r   r   check_no_resource_warning~   s    rJ   c                 c   s  t d}|jd}|r"|  tjdd*}t jd d t	|V  W d   n1 s^0    Y  t
|}g }| D ]j\}}d}	|dd D ]8}|j}
t|t|
tjrt|
j|rd}	|| q|	sx|sx|||jf qx|rtd	|d
  |rtd|d
  dS )zCatch the warnings, then check if all the expected
    warnings have been raised and re-raise unexpected warnings.
    If 'quiet' is True, only re-raise the unexpected warnings.
       Z__warningregistry__Tr   r   r
   NFzunhandled warning %sr   z)filter (%r, %s) did not catch any warning)sys	_getframe	f_globalsr@   clearr   r   modulesr   r+   listr   rematchr   Ir   	__class__removeappendr:   AssertionError)rC   r?   frameregistrywZreraisemissingmsgcatseenwarningr   r   r   rB      s4    
(
rB   c               
   c   s<   t jd d  } zd V  W | t jd d < n| t jd d < 0 d S r7   )r   rC   )Zold_filtersr   r   r   save_restore_warnings_filters   s    ra   c                   C   s   t jdtdd d S )NzThis is used in test_support test to ensure support.ignore_deprecations_from() works as expected. You should not be seeing this.r   )
stacklevel)r   r   DeprecationWarningr   r   r   r   _warn_about_deprecation   s
    rd   )r   )F)
contextlibr'   rR   rL   r   r   r*   objectr+   contextmanagerrD   rA   rH   rJ   rB   ra   rd   r   r   r   r   <module>   s&   


'
