B Y6dpN@sdZddlZddddddd d gZdd+dZd?d,dZGd-d.d.eZGd/d d eZd0d1Zy0dd2lmZm Z m!Z!mZmZm"Z"e Z#e!Z$d3Z%Wn2e&k rngZd4Z#iZ$d*a'd5d6Z"dZ%YnXeej(e%se)ed7se d4e*d8d*d9e d:e*d*d;e d:e+d*d;e d:e,d*d;e d:e-d*d;[%dS)@z&Python part of the warnings subsystem.Nwarn warn_explicit showwarning formatwarningfilterwarnings simplefilter resetwarningscatch_warningscCst||||||}t|dS)z7Hook to write a warning to a file; replace if you like.N)WarningMessage_showwarnmsg_impl)messagecategoryfilenamelinenofilelinemsgr$/usr/local/lib/python3.7/warnings.pyr scCst||||d|}t|S)z.Function to format a warning the standard way.N)r _formatwarnmsg_impl)r r rrrrrrrrscCsP|j}|dkr tj}|dkr dSt|}y||Wntk rJYnXdS)N)rsysstderr_formatwarnmsgwriteOSError)rrtextrrrr sr c Cs|jj}|jd|jd|d|jd}|jdkrpyddl}||j|j}Wqvtk rld}d}YqvXn|j}|r| }|d|7}|j dk ry ddl }Wntk rd}d}Yn4X| }y| |j }Wntk rd}YnX|dk r|d7}x|D]t}|d|j|jf7}y$|dk rD||j|j}nd}Wntk rdd}YnX|r| }|d |7}qWn|s||d 7}|S) N:z:  rz %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__rrr r linecachegetline Exceptionstripsource tracemallocZ is_tracingZget_object_traceback) rr srrr$Ztracingtbframerrrr#sR"           rcCsdyt}Wntk rYn= 0N)append) AssertionError isinstancestrtype issubclassWarningintrecompileI _add_filter)actionr r r3rr5r=rrrrs"   cCsH|dkstd|ft|tr(|dks0tdt|d|d||ddS)aInsert 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 )r/r0r1r2r3r4zinvalid action: %rrzlineno must be an int >= 0N)r5)r6r7r<r@)rAr rr5rrrrs  cGsR|s6yt|Wntk r&YnXtd|n|tkrHt|tdS)Nr)filtersremove ValueErrorinsertr5_filters_mutated)r5itemrrrr@s r@cCsgtdd<tdS)zAClear the list of warning filters, so that no filters are active.N)rBrFrrrrrs c@seZdZdZdS) _OptionErrorz,Exception used by option processing helpers.N)r __module__ __qualname____doc__rrrrrHsrHc CsRxL|D]D}y t|Wqtk rH}ztd|tjdWdd}~XYqXqWdS)NzInvalid -W option ignored:)r) _setoptionrHprintrr)argsargrrrr_processoptionss   rPc Cs|d}t|dkr$td|fxt|dkr>|dq&Wdd|D\}}}}}t|}t|}|sp|rxddl}|r||}|r||d}|ryt|}|dkrt Wqt t fk rtd |fdYqXnd}t |||||dS) Nrztoo many fields (max 5): %rr.cSsg|] }|qSr)r").0r%rrr sz_setoption..rz\Zzinvalid lineno %r) splitlenrHr5 _getaction _getcategoryr=escaper<rD OverflowErrorr)rOpartsrAr r r3rr=rrrrLs0   rLcCsB|sdS|dkrdSxdD]}||r|SqWtd|fdS)Nr2allr1)r2r1r0r3r4r/zinvalid action: %r) startswithrH)rAarrrrVs  rVcCs|stSd|krddl}|}nJ|d\}}}yt|dd|g}Wn$tk rftd|fdYnXyt||}Wn$tk rtd|fdYnXt|tstd|f|S)N.rzinvalid module name: %rzunknown warning category: %rzinvalid warning category: %r) r;builtins rpartition __import__ ImportErrorrHgetattrAttributeErrorr:)r mklassr3_catrrrrWs" rWcCs|jj}d|kod|kS)zFSignal whether the frame is an internal CPython implementation detail. importlib _bootstrap)f_code co_filename)r'rrrr_is_internal_framesrmcCs&|j}x|dk r t|r |j}qW|S)z;Find the next frame that doesn't involve CPython internals.N)f_backrm)r'rrr_next_external_frames roc Csvt|tr|j}|dkrt}t|tr0t|tsDtdt|jyZ|dks\t t drht |}n4t d}x(t |dD]}t |}|dkrtqWWntk rt j}d}YnX|j}|j}d|kr|d}nd}|d} | r| } | drP| dd} n>|d krFyt jd } Wntk rDd } YnX| sP|} |d i} t||| ||| ||dS) z:Issue a warning, or maybe ignore it or raise an exception.Nz/category must be a Warning subclass, not '{:s}'rprz__file__z.pyc__main__rZ__warningregistry__)r7r; __class__ UserWarningr9r:r+formatrrmr _getframerangerorD__dict__ f_globalsf_linenogetlowerendswithargvrd setdefaultr) r r stacklevelr#r'xglobalsrr3rZfnlregistryrrrrsL           cCst|}|dkr8|pd}|dddkr8|dd}|dkrDi}|ddtkrd|t|d<t|tr~t|}|j}n |}||}|||f} || rdSx^t D]R} | \} } } }}| dks| |rt || r|dks| |r|dks||krPqWt } | dkrdSddl }|||| dkr2|| dkrfd || <||f}t|r\dSd t|<nf| d krrnZ| d krd || <||df}||rdSd ||<n$| d krd || <ntd | | ft|||||} t| dS)Nz z.pyversionrr0r/r4rpr1r3r2z1Unrecognized action (%r) in warnings.filters: %s)r<r}r|_filters_versionclearr7r;r8rtrBmatchr: defaultactionrgetlines onceregistry RuntimeErrorr r,)r r rrr3rmodule_globalsr#rkeyrGrArrhmodZlnrZoncekeyZaltkeyrrrrSsj                    c@s"eZdZdZdddZddZdS)r )r r rrrrr#NcCs>||_||_||_||_||_||_||_|r4|jnd|_dS)N) r r rrrrr#r_category_name)selfr r rrrrr#rrr__init__szWarningMessage.__init__cCsd|j|j|j|j|jfS)NzD{message : %r, category : %r, filename : %r, lineno : %s, line : %r})r rrrr)rrrr__str__szWarningMessage.__str__)NNN)rrIrJZ_WARNING_DETAILSrrrrrrr s r c@s8eZdZdZdddddZddZd d Zd d ZdS) r aA 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)recordr3cCs(||_|dkrtjdn||_d|_dS)zSpecify 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. NwarningsF)_recordrmodules_module_entered)rrr3rrrrszcatch_warnings.__init__cCsPg}|jr|d|jtjdk r4|d|jt|j}d|d|fS)Nz record=Truerz module=%rz%s(%s)z, )rr5rrrr9rjoin)rrNnamerrr__repr__s  zcatch_warnings.__repr__cCs~|jrtd|d|_|jj|_|jdd|j_|j|jj|_|jj|_|j rvg}|j |j_|jj |j_|SdSdS)NzCannot enter %r twiceT) rrrrB_filtersrFr _showwarningr rr5r))rlogrrr __enter__s       zcatch_warnings.__enter__cGs>|jstd||j|j_|j|j|j_|j|j_dS)Nz%Cannot exit %r without entering first) rrrrrBrFrrr )rexc_inforrr__exit__s     zcatch_warnings.__exit__)rrIrJrKrrrrrrrrr s   cszdjdg}jdk rVddlddl}fdd}|d||t|7}d|d}t |t d d dS) Nz coroutine 'z' was never awaited rc3s8x2tjD]$\}}}||}||||fVq WdS)N)reversed cr_originr )rrfuncnamer)cororrrextracts z*_warn_unawaited_coroutine..extractz-Coroutine created at (most recent call last) r.r)r rr#) rJrr tracebackr5 format_listlistrrstriprRuntimeWarning)rZ msg_linesrrrr)rrr_warn_unawaited_coroutines  r)rB_defaultaction _onceregistryrrrFTr2cCs td7adS)Nrp)rrrrrrFsrFZgettotalrefcountrs)r r3r5r0)r r5)NN)N)NrpN)NNNN).rKr__all__rrr rr)r,r-rr;rrr@rr!rHrPrLrVrWrmrorrobjectr r r _warningsrBrrrFrrZ_warnings_defaultsrbr warnoptionshasattrDeprecationWarningPendingDeprecationWarning ImportWarningResourceWarningrrrrsh  ;  "  5 EC