o
    éT•jÁ  ã                   @   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 s#w   Y  |  t|ƒd|¡ |\}|  	t
|jtƒ|j¡ |rJ|  t|jƒ|¡ |  |jd¡ |  |j¡ |d urb|  |j|¡ tjdd��}t d	t¡ || ||||d
� W d   ƒ n1 s‚w   Y  |  |g ¡ d S )Nr   )Úcheck_syntax_errorT©ÚrecordÚalwaysz
<testcase>Úexecr   Úerrorr   )Útest.supportr   ÚwarningsÚcatch_warningsÚsimplefilterÚSyntaxWarningÚcompileÚassertEqualÚlenÚ
assertTrueÚ
issubclassÚcategoryÚassertRegexÚstrÚmessageÚfilenameÚassertIsNotNoner   )ÚtestcaseÚ	statementÚerrtextr   r   r   ÚwarnsÚwarn© r"   ú3/usr/lib/python3.10/test/support/warnings_helper.pyÚcheck_syntax_warning   s.   þÿÿþr$   c                    s   ‡ fdd„}|S )z”Decorator to suppress 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  ¡ � t jdˆ d� ˆ| g|¢R i |¤ŽW  d   ƒ S 1 s!w   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'   Úwarnings_listr"   r"   r#   Ú__init__:   s   
zWarningsRecorder.__init__c                 C   s@   t | jƒ| jkrt| jd |ƒS |tjjv rd S td| |f ƒ‚)Néÿÿÿÿz%r has no attribute %r)r   r2   r3   Úgetattrr   ÚWarningMessageÚ_WARNING_DETAILSÚAttributeError)r'   Úattrr"   r"   r#   Ú__getattr__>   s
   zWarningsRecorder.__getattr__c                 C   s   | j | jd … S ©Nr1   ©r'   r"   r"   r#   r   E   s   zWarningsRecorder.warningsc                 C   s   t | jƒ| _d S r=   )r   r2   r3   r>   r"   r"   r#   ÚresetI   s   zWarningsRecorder.resetN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   r<   Úpropertyr   r?   r"   r"   r"   r#   r0   6   s    
r0   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)   rE   r"   r"   r#   Úcheck_warningsM   s   


rJ   Fc                 c   sj   � ddl m} tjdd��}tjd||d� dV  |r|ƒ  W d  ƒ n1 s(w   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   rK   r   r   Úfilterwarningsr   )r   r   r   Úforce_gcrK   r    r"   r"   r#   Úcheck_no_warningse   s   €þ€úrN   c                 c   s<   � t | tdd�� dV  W d  ƒ dS 1 sw   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   rM   N)rN   ÚResourceWarning)r   r"   r"   r#   Úcheck_no_resource_warning~   s   €"ÿrP   c                 c   s  � t  d¡}|j d¡}|r| ¡  tjdd��}t jd  d¡ t	|ƒV  W d  ƒ n1 s0w   Y  t
|ƒ}g }| D ]5\}}d}	|dd… D ]}|j}
t |t|
ƒtj¡ret|
j|ƒred}	| |¡ qI|	sr|sr| ||jf¡ q=|r}td	|d
  ƒ‚|r‡td|d
  ƒ‚dS )z¶Catch 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.
    é   Ú__warningregistry__Tr   r   r
   NFzunhandled warning %sr   z)filter (%r, %s) did not catch any warning)ÚsysÚ	_getframeÚ	f_globalsrF   Úclearr   r   Úmodulesr   r0   Úlistr   ÚreÚmatchr   ÚIr   Ú	__class__ÚremoveÚappendr@   ÚAssertionError)rI   rE   ÚframeÚregistryÚwÚreraiseÚmissingÚmsgÚcatÚseenÚwarningr"   r"   r#   rH   �   s>   €
û
ÿ
€€ÿÿrH   c               
   c   s<   � t jd d … } zd V  W | t jd d …< d S | t jd d …< w r=   )r   rI   )Úold_filtersr"   r"   r#   Úsave_restore_warnings_filters·   s
   €"rj   c                   C   s   t jdtdd� d S )Nz€This 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
   
ûrm   )r   )F)Ú
contextlibr,   rY   rS   r   r$   r/   Úobjectr0   ÚcontextmanagerrJ   rG   rN   rP   rH   rj   rm   r"   r"   r"   r#   Ú<module>   s(    ÿ


'
