a
    jCièL  ã                   @   sÌ  d Z ddlZg d¢Zd=dd„Zd>dd„Zdd	„ Zd
d„ ZeZdd„ ZeZ	dd„ Z
dedddfdd„Zeddfdd„Zdd„ Zdd„ ZG dd„ deƒZdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd?d)d*„Zd@d+d,„ZG d-d.„ d.eƒZG d/d0„ d0eƒZd1d2„ Zz0dd3lmZm Z m!Z!mZmZm"Z" e Z#e!Z$d4Z%W n0 e&�y`   g Zd5Z#i Z$d(a'd6d7„ Z"dZ%Y n0 eej(ƒ e%�sÆe)ed8ƒ�sÆed5e*d9d(d:� ed;e*d(d<� ed;e+d(d<� ed;e,d(d<� ed;e-d(d<� [%dS )Az&Python part of the warnings subsystem.é    N)ÚwarnÚwarn_explicitÚshowwarningÚformatwarningÚfilterwarningsÚsimplefilterÚresetwarningsÚcatch_warningsc                 C   s   t | |||||ƒ}t|ƒ dS )ú7Hook to write a warning to a file; replace if you like.N)ÚWarningMessageÚ_showwarnmsg_impl)ÚmessageÚcategoryÚfilenameÚlinenoÚfileÚlineÚmsg© r   ú$/usr/local/lib/python3.9/warnings.pyr   
   s    r   c                 C   s   t | |||d|ƒ}t|ƒS )ú.Function to format a warning the standard way.N)r   Ú_formatwarnmsg_impl)r   r   r   r   r   r   r   r   r   r      s    r   c                 C   sN   | j }|d u r tj}|d u r d S t| ƒ}z| |¡ W n tyH   Y n0 d S ©N)r   ÚsysÚstderrÚ_formatwarnmsgÚwriteÚOSError)r   r   Útextr   r   r   r      s    r   c           	   	   C   s”  | j j}| j› d| j› d|› d| j› d�}| jd u rnzdd l}| | j| j¡}W qt tyj   d }d }Y qt0 n| j}|rŒ| 	¡ }|d| 7 }| j
d u�r�zdd l}W n ty¾   d}d }Y n20 | ¡ }z| | j
¡}W n tyî   d }Y n0 |d u�r||d7 }|D ]r}|d|j|jf 7 }z$|d u�r<| |j|j¡}nd }W n t�yZ   d }Y n0 |�r| 	¡ }|d	| 7 }�qn|�s�||› d
�7 }|S )Nú:z: Ú
r   z  %s
Tz-Object allocated at (most recent call last):
z  File "%s", lineno %s
z    %s
z<: Enable tracemalloc to get the object allocation traceback
)r   Ú__name__r   r   r   r   Ú	linecacheÚgetlineÚ	ExceptionÚstripÚsourceÚtracemallocZ
is_tracingZget_object_traceback)	r   r   Úsr"   r   r'   ZtracingÚtbÚframer   r   r   r   #   sT    "




ÿ

r   c                 C   sb   zt }W n ty   Y n<0 |turVt|ƒs4tdƒ‚|| j| j| j| j| j	| j
ƒ dS t| ƒ dS )r
   z:warnings.showwarning() must be set to a function or methodN)r   Ú	NameErrorÚ_showwarning_origÚcallableÚ	TypeErrorr   r   r   r   r   r   r   )r   Zswr   r   r   Ú_showwarnmsg`   s    ÿr/   c                 C   sF   zt }W n ty   Y n$0 |tur>|| j| j| j| j| jƒS t| ƒS )r   )	r   r+   Ú_formatwarning_origr   r   r   r   r   r   )r   Zfwr   r   r   r   u   s    
ÿr   Ú Fc                 C   sÌ   | dv sJ d| f ƒ‚t |tƒs(J dƒ‚t |tƒs:J dƒ‚t|tƒsLJ dƒ‚t |tƒs^J dƒ‚t |tƒrp|dksxJ dƒ‚|s€|rˆdd	l}|rœ| ||j¡}nd	}|r°| |¡}nd	}t	| |||||d
� d	S )aÖ  Insert an entry into the list of warnings filters (at the front).

    'action' -- one of "error", "ignore", "always", "default", "module",
                or "once"
    'message' -- a regex that the warning message must match
    'category' -- a class that the warning must be a subclass of
    'module' -- a regex that the module name must match
    'lineno' -- an integer line number, 0 matches all warnings
    'append' -- if true, append to the list of filters
    ©ÚerrorÚignoreÚalwaysÚdefaultÚmoduleÚonceúinvalid action: %rzmessage must be a stringzcategory must be a classz#category must be a Warning subclasszmodule must be a stringr   úlineno must be an int >= 0N©Úappend)
Ú
isinstanceÚstrÚtypeÚ
issubclassÚWarningÚintÚreÚcompileÚIÚ_add_filter)Úactionr   r   r7   r   r<   rC   r   r   r   r   ‚   s&    
ÿÿr   c                 C   sH   | dv sJ d| f ƒ‚t |tƒr(|dks0J dƒ‚t| d|d||d� dS )a�  Insert a simple entry into the list of warnings filters (at the front).

    A simple filter matches all modules and messages.
    'action' -- one of "error", "ignore", "always", "default", "module",
                or "once"
    'category' -- a class that the warning must be a subclass of
    'lineno' -- an integer line number, 0 matches all warnings
    'append' -- if true, append to the list of filters
    r2   r9   r   r:   Nr;   )r=   rB   rF   )rG   r   r   r<   r   r   r   r   ¥   s    

ÿÿr   c                 G   sP   | s4zt  |¡ W n ty$   Y n0 t  d|¡ n|t vrFt  |¡ tƒ  d S )Nr   )ÚfiltersÚremoveÚ
ValueErrorÚinsertr<   Ú_filters_mutated)r<   Úitemr   r   r   rF   µ   s    
rF   c                   C   s   g t dd…< tƒ  dS )zAClear the list of warning filters, so that no filters are active.N)rH   rL   r   r   r   r   r   Ã   s    r   c                   @   s   e Zd ZdZdS )Ú_OptionErrorz,Exception used by option processing helpers.N)r!   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   rN   È   s   rN   c                 C   sP   | D ]F}zt |ƒ W q tyH } ztd|tjd� W Y d }~qd }~0 0 qd S )NzInvalid -W option ignored:)r   )Ú
_setoptionrN   Úprintr   r   )ÚargsÚargr   r   r   r   Ú_processoptionsÍ   s
    rV   c              	   C   sò   |   d¡}t|ƒdkr$td| f ƒ‚t|ƒdk r<| d¡ q$dd„ |D ƒ\}}}}}t|ƒ}t|ƒ}|sl|rtdd l}|r‚| |¡}|r”| |¡d }|rÚzt|ƒ}|dk r®t	‚W qÞ t	t
fyÖ   td	|f ƒd ‚Y qÞ0 nd}t|||||ƒ d S )
Nr   é   ztoo many fields (max 5): %rr1   c                 S   s   g | ]}|  ¡ ‘qS r   )r%   )Ú.0r(   r   r   r   Ú
<listcomp>Û   s   ÿz_setoption.<locals>.<listcomp>r   z\Zzinvalid lineno %r)ÚsplitÚlenrN   r<   Ú
_getactionÚ_getcategoryrC   ZescaperB   rJ   ÚOverflowErrorr   )rU   ZpartsrG   r   r   r7   r   rC   r   r   r   rR   Õ   s2    
ÿ
rR   c                 C   sB   | sdS | dkrdS dD ]}|  | ¡r|  S qtd| f ƒ‚d S )Nr6   Úallr5   )r6   r5   r4   r7   r8   r3   r9   )Ú
startswithrN   )rG   Úar   r   r   r\   ñ   s    

r\   c                 C   s´   | st S d| vrdd l}| }nH|  d¡\}}}zt|d d |gƒ}W n" tyd   td|f ƒd ‚Y n0 zt||ƒ}W n" ty–   td| f ƒd ‚Y n0 t|t ƒs°td| f ƒ‚|S )NÚ.r   zinvalid module name: %rzunknown warning category: %rzinvalid warning category: %r)	rA   ÚbuiltinsÚ
rpartitionÚ
__import__ÚImportErrorrN   ÚgetattrÚAttributeErrorr@   )r   ÚmZklassr7   Ú_Úcatr   r   r   r]   û   s"    
r]   c                 C   s   | j j}d|v od|v S )zFSignal whether the frame is an internal CPython implementation detail.Ú	importlibÚ
_bootstrap)Úf_codeÚco_filename)r*   r   r   r   r   Ú_is_internal_frame  s    rp   c                 C   s"   | j } | durt| ƒr| j } q| S )z;Find the next frame that doesn't involve CPython internals.N)Úf_backrp   )r*   r   r   r   Ú_next_external_frame  s    rr   é   c              	   C   s  t | tƒr| j}|du rt}t |tƒr0t|tƒsDtd t|ƒj¡ƒ‚zV|dks\t	t
 d¡ƒrht
 |¡}n0t
 d¡}t|d ƒD ]}t|ƒ}|du r~t‚q~W n  tyº   t
j}d}d}Y n0 |j}|jj}|j}d|v râ|d }	nd}	| di ¡}
t| ||||	|
||ƒ dS )z:Issue a warning, or maybe ignore it or raise an exception.Nz/category must be a Warning subclass, not '{:s}'rs   r   r!   z<string>Z__warningregistry__)r=   rA   Ú	__class__ÚUserWarningr?   r@   r.   Úformatr!   rp   r   Ú	_getframeÚrangerr   rJ   Ú__dict__Ú	f_globalsrn   ro   Úf_linenoÚ
setdefaultr   )r   r   Ú
stacklevelr&   r*   ÚxÚglobalsr   r   r7   Úregistryr   r   r   r     s<    
ÿ



ÿr   c                 C   sè  t |ƒ}|d u r8|pd}|dd …  ¡ dkr8|d d… }|d u rDi }| dd¡tkrd| ¡  t|d< t| tƒr~t| ƒ}| j}n| }|| ƒ} |||f}	| |	¡r¢d S t	D ]V}
|
\}}}}}|d u sÊ| 
|¡r¦t||ƒr¦|d u sæ| 
|¡r¦|dksö||kr¦ �qq¦t}|dk�rd S dd l}| ||¡ |dk�r2| ‚|dk�rfd	||	< ||f}t |¡�r\d S d	t|< nf|d
k�rrnZ|dk�r¨d	||	< ||df}| |¡�ržd S d	||< n$|dk�r¼d	||	< ntd||
f ƒ‚t| ||||ƒ}t|ƒ d S )Nz	<unknown>éýÿÿÿz.pyÚversionr   r4   r3   r8   rs   r5   r7   r6   z1Unrecognized action (%r) in warnings.filters:
 %s)rB   ÚlowerÚgetÚ_filters_versionÚclearr=   rA   r>   rt   rH   Úmatchr@   Údefaultactionr"   ZgetlinesÚonceregistryÚRuntimeErrorr   r/   )r   r   r   r   r7   r€   Zmodule_globalsr&   r   ÚkeyrM   rG   r   rk   ÚmodZlnr"   ZoncekeyZaltkeyr   r   r   r   G  s|    


ÿþþýý









ÿÿr   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )r   )r   r   r   r   r   r   r&   Nc                 C   s>   || _ || _|| _|| _|| _|| _|| _|r4|jnd | _d S r   )	r   r   r   r   r   r   r&   r!   Ú_category_name)Úselfr   r   r   r   r   r   r&   r   r   r   Ú__init__“  s    zWarningMessage.__init__c                 C   s   d| j | j| j| j| jf S )NzD{message : %r, category : %r, filename : %r, lineno : %s, line : %r})r   r�   r   r   r   )rŽ   r   r   r   Ú__str__ž  s
    ÿÿzWarningMessage.__str__)NNN)r!   rO   rP   Z_WARNING_DETAILSr�   r�   r   r   r   r   r   Ž  s
     ÿ
r   c                   @   s8   e Zd ZdZdddœdd„Zdd„ Zd	d
„ Zdd„ ZdS )r	   a�  A context manager that copies and restores the warnings filter upon
    exiting the context.

    The 'record' argument specifies whether warnings should be captured by a
    custom implementation of warnings.showwarning() and be appended to a list
    returned by the context manager. Otherwise None is returned by the context
    manager. The objects appended to the list are arguments whose attributes
    mirror the arguments to showwarning().

    The 'module' argument is to specify an alternative module to the module
    named 'warnings' and imported under that name. This argument is only useful
    when testing the warnings module itself.

    FN)Úrecordr7   c                C   s(   || _ |du rtjd n|| _d| _dS )zêSpecify whether to record warnings and if an alternative module
        should be used other than sys.modules['warnings'].

        For compatibility with Python 3.0, please consider all arguments to be
        keyword-only.

        NÚwarningsF)Ú_recordr   ÚmodulesÚ_moduleÚ_entered)rŽ   r‘   r7   r   r   r   r�   µ  s    zcatch_warnings.__init__c                 C   sP   g }| j r| d¡ | jtjd ur4| d| j ¡ t| ƒj}d|d |¡f S )Nzrecord=Truer’   z	module=%rz%s(%s)z, )r“   r<   r•   r   r”   r?   r!   Újoin)rŽ   rT   Únamer   r   r   Ú__repr__Á  s    

zcatch_warnings.__repr__c                 C   s~   | j rtd|  ƒ‚d| _ | jj| _| jd d … | j_| j ¡  | jj| _| jj| _| j	rvg }|j
| j_| jj| j_|S d S d S )NzCannot enter %r twiceT)r–   rŠ   r•   rH   Ú_filtersrL   r   Ú_showwarningr   r“   r<   r,   )rŽ   Zlogr   r   r   Ú	__enter__Ê  s    




zcatch_warnings.__enter__c                 G   s>   | j std|  ƒ‚| j| j_| j ¡  | j| j_| j| j_d S )Nz%Cannot exit %r without entering first)	r–   rŠ   rš   r•   rH   rL   r›   r   r   )rŽ   Úexc_infor   r   r   Ú__exit__Ý  s    


zcatch_warnings.__exit__)r!   rO   rP   rQ   r�   r™   rœ   rž   r   r   r   r   r	   ¤  s
   	r	   c                    sz   dˆ j › d�g}ˆ jd urVdd l‰dd l}‡ ‡fdd„}| d¡ || t|ƒ ƒ¡7 }d |¡ d¡}t	|t
d	ˆ d
� d S )Nzcoroutine 'z' was never awaited
r   c                  3   s4   t ˆ jƒD ]$\} }}ˆ | |¡}| |||fV  q
d S r   )ÚreversedÚ	cr_originr#   )r   r   Úfuncnamer   ©Úcoror"   r   r   Úextractí  s    z*_warn_unawaited_coroutine.<locals>.extractz-Coroutine created at (most recent call last)
r1   r    é   )r   r}   r&   )rP   r    r"   Ú	tracebackr<   Zformat_listÚlistr—   Úrstripr   ÚRuntimeWarning)r£   Z	msg_linesr¦   r¤   r   r   r¢   r   Ú_warn_unawaited_coroutineç  s    ÿ

rª   )rH   Ú_defaultactionÚ_onceregistryr   r   rL   Tr6   c                   C   s   t d7 a d S )Nrs   )r…   r   r   r   r   rL     s    rL   ZgettotalrefcountÚ__main__)r   r7   r<   r4   )r   r<   )NN)N)Nrs   N)NNNN).rQ   r   Ú__all__r   r   r   r   r,   r/   r0   r   rA   r   r   rF   r   r$   rN   rV   rR   r\   r]   rp   rr   r   r   Úobjectr   r	   rª   Ú	_warningsrH   r«   r¬   rL   rˆ   r‰   Z_warnings_defaultsrf   r…   ÚwarnoptionsÚhasattrÚDeprecationWarningÚPendingDeprecationWarningÚImportWarningÚResourceWarningr   r   r   r   Ú<module>   sj   

;ÿ
#
	
)  þ
GC 

ÿ