[7@sdZddlZddddddd d gZddd dZdd dZd ed ddddZeddddZdd ZGddde Z ddZ ddZ ddZ ddZddddZdddddZGdd d eZGd!d d eZdZyDdd"lmZmZmZmZmZmZeZeZd#ZWn6ek rgZd$ZiZdad%d&ZYnXe ejesyee gZ!e!j"e#xe!D]Z$ed'd(e$qWej%j&Z&e&dkrd)Z'ne&r&d$Z'nd'Z'ee'd(e(d*de)ed+rZd,Z*nd'Z*ee*d(e+d*dn[dS)-z&Python part of the warnings subsystem.Nwarn warn_explicit showwarning formatwarningfilterwarnings simplefilter resetwarningscatch_warningsc Csd|dkr(tj}|dkr(dSny#|jt|||||Wntk r_YnXdS)z7Hook to write a warning to a file; replace if you like.N)sysstderrwriterOSError)messagecategoryfilenamelinenofileliner/usr/lib/python3.4/warnings.pyr s   # cCspddl}d|||j|f}|dkrC|j||n|}|rl|j}|d|7}n|S)z.Function to format a warning the standard way.rNz%s:%s: %s: %s z %s ) linecache__name__getlinestrip)rrrrrrsrrrrs $ FcCsddl}|dks+td |ft|tsFtd t|tsatd t|ts|td t|tstd t|tr|dkstd||j||j ||j||f}|rt j |nt j d|t dS)aInsert 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 rNerrorignorealwaysdefaultmoduleoncezinvalid action: %rzmessage must be a stringzcategory must be a classz#category must be a Warning subclasszmodule must be a stringzlineno must be an int >= 0)zerrorzignorezalwayszdefaultzmodulezonce)reAssertionError isinstancestrtype issubclassWarningintcompileIfiltersappendinsert_filters_mutated)actionrrr rr-r"itemrrrr s  cCs|d kstd|ft|tr:|dksFtd |d |d |f}|rqtj|ntjd|td S) 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 rrrrr r!zinvalid action: %rrzlineno must be an int >= 0N)zerrorzignorezalwayszdefaultzmodulezonce)r#r$r)r,r-r.r/)r0rrr-r1rrrr=s  cCsgtddks z_setoption..$zinvalid lineno %r) r"splitlenr2r- _getactionescape _getcategoryr) ValueError OverflowErrorr)r9r"partsr0rrr rrrrr6ds.        r6cCsU|s dS|dkrdSx!d D]}|j|r!|Sq!Wtd|fdS) Nrallrrr r!rzinvalid action: %r)zdefaultzalwayszignorezmodulezoncezerror) startswithr2)r0arrrrCs  rCcCs>ddl}|stS|jd|rcyt|}Wqtk r_td|fYqXn|jd}|d|}||dd}yt|dd|g}Wn%tk rtd|fYnXyt ||}Wn%t k rtd|fYnXt |ts:td|fn|S)Nrz^[a-zA-Z0-9_]+$zunknown warning category: %r.zinvalid module name: %rzinvalid warning category: %r) r"r(matcheval NameErrorr2rfind __import__ ImportErrorgetattrAttributeErrorr')rr"catir klassmrrrrEs,    rErMc Csot|tr|j}n|dkr0t}nt|tsEtytj|}Wn!tk r{tj }d}YnX|j }|j }d|kr|d}nd}|j d}|r|j }|jd r=|dd }q=nJ|dkr.ytjd }Wq.tk r*d}Yq.Xn|s=|}n|jd i} t|||||| |dS) z:Issue a warning, or maybe ignore it or raise an exception.NrMrz__file__.pyc.pyo__main__rZ__warningregistry__)r[r\)r$r( __class__ UserWarningr'r#r _getframerF__dict__ f_globalsf_linenogetlowerendswithargvrU setdefaultr) rr stacklevelZcallerglobalsrr rZfnlregistryrrrrs<              cCst|}|dkrV|p!d}|ddjdkrV|dd}qVn|dkrki}n|jddtkr|jt|dz.pyversionrrrMrr!rr rz1Unrecognized action (%r) in warnings.filters: %sz:warnings.showwarning() must be set to a function or methodro)r)rfre_filters_versionclearr$r(r%r_r,rNr' defaultactionrgetlines onceregistry RuntimeErrorcallabler TypeError)rrrrr rlmodule_globalstextkeyr1r0r:rVmodZlnrZoncekeyZaltkeyrrrrsn                           c@s:eZdZdZd Zddd d Zd d ZdS)WarningMessagez0Holds the result of a single showwarning() call.rrrrrrNc CsMt}x%|jD]}t||||qW|r@|jnd|_dS)N)locals_WARNING_DETAILSsetattrr_category_name) selfrrrrrr local_valuesattrrrr__init__s zWarningMessage.__init__cCs&d|j|j|j|j|jfS)NzD{message : %r, category : %r, filename : %r, lineno : %s, line : %r})rrrrr)rrrr__str__#s zWarningMessage.__str__)zmessagezcategoryzfilenamezlinenozfilezline)rr3r4r5r~rrrrrrr|s r|c@sReZdZdZddddddZdd Zd 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. recordFr NcCs8||_|dkr"tjdn||_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)_recordr modules_module_entered)rrr rrrr:s "zcatch_warnings.__init__cCsrg}|jr|jdn|jtjdk rL|jd|jnt|j}d|dj|fS)Nz record=Truerz module=%rz%s(%s)z, )rr-rr rr&rjoin)rr8namerrr__repr__Fs zcatch_warnings.__repr__cs|jrtd|nd|_|jj|_|jdd|j_|jj|jj|_|jrgfdd}||j_SdSdS)NzCannot enter %r twiceTcsjt||dS)N)r-r|)r8kwargs)logrrrYsz-catch_warnings.__enter__..showwarning) rrurr,_filtersr/r _showwarningr)rrr)rr __enter__Os     zcatch_warnings.__enter__cGsK|jstd|n|j|j_|jj|j|j_dS)Nz%Cannot exit %r without entering first)rrurrr,r/rr)rexc_inforrr__exit__`s   zcatch_warnings.__exit__)rr3r4r5rrrrrrrrr )s  )r,_defaultaction _onceregistryrrr/TrcCstd7adS)NrM)rprrrrr/sr/rrrr-Zgettotalrefcountr),r5r __all__rrr(rrr Exceptionr2r;r6rCrErrobjectr|r Z_warnings_defaults _warningsr,rrr/rrrtrSrp warnoptions ImportWarningPendingDeprecationWarningZsilencer-DeprecationWarningclsflags bytes_warningZ bytes_action BytesWarninghasattrZresource_actionResourceWarningrrrrsb          )HG.