{fc=@s dZedkr!ednddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZyddlZWnek r:dZnXddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d4d<d=d>d?d@g=ZdAZdefdBYZdefdCYZdefdDYZdejfdEYZ ej!e"dFZ#e$dGZ%dHZ&dIZ'dde$dJZ(dKZ)dLZ*dZ+dMa,dMa-e$Z.da/dNZ0dOZ1dPZ2dQZ3e j j4dRr+e$dSZ5dTZ6dUZ7dVZ8ne j9Z6e j:Z7dWZ8dXZ9dYZ:dZZ;d[Z<d\Z=d]Z>dd^Z?d_Z@d`ZAdaZBejCejDdbZEeAdcZFddZGeGZHdeZIdfZJdgZKdZLdZMe j j4dkZNyeOe"ZPWneQk r-e$ZPnXejRePdlZSdmZTdZUePrxeVdneVdoeVdpeVdqeVdreVdseVdteVdueVdveVdweVdxf D]XZWy7eWjXe jYjZe jYeWkre[nWne[k rqXeWZUPqWne j\dkkr6dyZ]ne j\dzkrNd{Z]nd|Z]ePre^d}eOrrd~Z_neOd~dZ_e jYZ`eae d se jbddkrdZcqeddZcyecjXdWneek rqXdecGHndjfe]e jgZ]dZhe jiZjej!de$dZkej!e$dZlej!de$dZme jnjoe jnjpeqZre jnjoerZse jnjtesdZuddZvdZwdZxd}dddZyddZzde{fdYZ|e$dZ}ej!dZ~ej!dZd&e{fdYZd'ejfdYZde{fdYZd*e{fdYZej!dAddZej!dZdZdZdZdZdZeae drdeZnedZdZdZdZdZdZdZdZdZdieZdeZdheZe jZdZdedZdee"dZdZd0ddYZdZdZdZddZdZdZdZdZdadadZdZdZdZede$pW e j dkpW ejdZejRedZddZe$ZdZdZdZej!ddZdZej!ddZej!dZej!dZdZejeae ddZdZdZddZej!dZdZd@ddYZdZdZdddYZdS(s7Supporting definitions for the Python regression tests.s test.supports3test.support must be imported from the test packageiNtErrort TestFailedt TestDidNotRuntResourceDeniedt import_moduletverboset use_resourcest max_memusetrecord_original_stdouttget_original_stdouttunloadtunlinktrmtreetforgettis_resource_enabledtrequirestrequires_mac_vertfind_unused_portt bind_porttfcmpt have_unicodet is_jythontTESTFNtHOSTtFUZZtSAVEDCWDttemp_cwdtfindfiletsortdicttcheck_syntax_errortopen_urlresourcetcheck_warningstcheck_py3k_warningst CleanImporttEnvironmentVarGuardtcaptured_outputtcaptured_stdouttTransientResourcettransient_internettrun_with_localet set_memlimitt bigmemtesttbigaddrspacetesttBasicTestRunnert run_unittestt run_doctesttthreading_setuptthreading_cleanupt reap_threadst start_threadst cpython_onlytcheck_impl_detailt get_attributet py3k_bytestimport_fresh_modulet reap_childrentstrip_python_stderrt IPV6_ENABLEDt run_with_tztSuppressCrashReportg>@cBseZdZRS(s*Base class for regression test exceptions.(t__name__t __module__t__doc__(((s-/usr/lib64/python2.7/test/support/__init__.pyR4scBseZdZRS(s Test failed.(R<R=R>(((s-/usr/lib64/python2.7/test/support/__init__.pyR7scBseZdZRS(sTest did not run any subtests.(R<R=R>(((s-/usr/lib64/python2.7/test/support/__init__.pyR:scBseZdZRS(sTest skipped because it requested a disallowed resource. This is raised when a test calls requires() for a resource that has not been enabled. It is used to distinguish between expected and unexpected skips. (R<R=R>(((s-/usr/lib64/python2.7/test/support/__init__.pyR=sccs=|r4tjtjddtdVWdQXndVdS(sContext manager to suppress package and module deprecation warnings when importing them. If ignore is False, this context manager has no effect.tignores.+ (module|package)N(twarningstcatch_warningstfilterwarningstDeprecationWarning(R?((s-/usr/lib64/python2.7/test/support/__init__.pyt_ignore_deprecated_importsEs   c CsSt|Aytj|SWn(tk rH}tjt|nXWdQXdS(sImport and return the module to be tested, raising SkipTest if it is not available. If deprecated is True, any module or package deprecation messages will be suppressed.N(RDt importlibRt ImportErrortunittesttSkipTesttstr(tnamet deprecatedtmsg((s-/usr/lib64/python2.7/test/support/__init__.pyRTs  cCs|tjkr&t|tj|=nxTttjD]C}||ks[|j|dr6tj|||t|t rd|j|f}ndt |j|f}t j |nX|SdS(s?Get an attribute, raising SkipTest if AttributeError is raised.smodule %r has no attribute %rsclass %s has no attribute %rs%s instance has no attribute %rs"type object %r has no attribute %rs%r object has no attribute %rN( tgetattrtAttributeErrort isinstancettypest ModuleTypeR<t ClassTypet InstanceTypet __class__ttypeRGRH(tobjRJt attributeRL((s-/usr/lib64/python2.7/test/support/__init__.pyR4s iicCs |adS(N(t_original_stdout(tstdout((s-/usr/lib64/python2.7/test/support/__init__.pyRscCs tp tjS(N(RrRNRs(((s-/usr/lib64/python2.7/test/support/__init__.pyR scCs&ytj|=Wntk r!nXdS(N(RNRORW(RJ((s-/usr/lib64/python2.7/test/support/__init__.pyR s cGsxy||SWnctk rs}tdkrVd|jj|fGHd|j|fGHntj|tj||SXdS(Nis%s: %ss re-run %s%r(tEnvironmentErrorRRnR<tostchmodtstattS_IRWXU(tpathtfunctargsterr((s-/usr/lib64/python2.7/test/support/__init__.pyt _force_runs twincCs|||r|}n$tjj|\}}|p:d}d}xR|dkrtj|}|rm|n ||ks}dStj||d9}qFWtjd|tdddS(NRMgMbP?g?is)tests may fail, delete still pending for t stackleveli( RuRytsplittlistdirttimetsleepR@twarntRuntimeWarning(RztpathnametwaitalltdirnameRJttimeouttL((s-/usr/lib64/python2.7/test/support/__init__.pyt_waitfors     cCsttj|dS(N(RRuR (tfilename((s-/usr/lib64/python2.7/test/support/__init__.pyt_unlinkscCsttj|dS(N(RRutrmdir(R((s-/usr/lib64/python2.7/test/support/__init__.pyt_rmdirscs6fdt|dttd|dS(Ncsxt|tj|D]i}tjj||}tjj|rlt|dtt|tj|qt|tj |qWdS(NR( R}RuRRytjointisdirRRVRR (RyRJtfullname(t _rmtree_inner(s-/usr/lib64/python2.7/test/support/__init__.pyRs RcSst|tj|S(N(R}RuR(tp((s-/usr/lib64/python2.7/test/support/__init__.pyt t(RRV(Ry((Rs-/usr/lib64/python2.7/test/support/__init__.pyt_rmtreescsSytj|dSWntk r(nXfd|tj|dS(Ncsxt|tj|D]}tjj||}ytj|j}Wntk r`d}nXtj |r|t|tj |qt|tj |qWdS(Ni( R}RuRRyRtlstattst_modeRtRwtS_ISDIRRR (RyRJRtmode(R(s-/usr/lib64/python2.7/test/support/__init__.pyRs   (tshutilR RtRuR(Ry((Rs-/usr/lib64/python2.7/test/support/__init__.pyRs   cCsIyt|Wn4tk rD}|jtjtjfkrEqEnXdS(N(RtOSErrorterrnotENOENTtENOTDIR(Rtexc((s-/usr/lib64/python2.7/test/support/__init__.pyR $s cCs@yt|Wn+tk r;}|jtjkr<q<nXdS(N(RRRR(Rterror((s-/usr/lib64/python2.7/test/support/__init__.pyR+s cCsIyt|Wn4tk rD}|jtjtjfkrEqEnXdS(N(RRRRtESRCH(Ryte((s-/usr/lib64/python2.7/test/support/__init__.pyR 3s cCsjt|xYtjD]N}ttjj||tjdttjj||tjdqWdS(sm"Forget" a module was ever imported by removing it from sys.modules and deleting any .pyc and .pyo files.tpyctpyoN(R RNRyR RuRtextsep(RTR((s-/usr/lib64/python2.7/test/support/__init__.pyR ;s $csttdrtjSd}tjjdr ddlddld}d}dj ffdY}j j }|j }|sj n|}jj}|j||j|j|j|}|sj nt|j|@sd}qntjdkrdd lm} mm} m } dd lm} | j| d } | jd krd }qd| ffdY}|}| |}| j|d ks| j|d krd}qn|sy;ddlm}|}|j |j!|j"Wqt#k r}t$|}t%|dkrz|d d}ndj&t'|j(|}qXn|t_)| t_tjS(NtresultR~iitUSEROBJECTFLAGScs;eZdjjfdjjfdjjfgZRS(tfInheritt fReservedtdwFlags(R<R=twintypestBOOLtDWORDt_fields_((tctypes(s-/usr/lib64/python2.7/test/support/__init__.pyRRss,gui not available (WSF_VISIBLE flag not set)tdarwin(tcdlltc_inttpointert Structure(t find_librarytApplicationServicesis0gui tests cannot run without OS X window managertProcessSerialNumbercs eZdfdfgZRS(t highLongOfPSNt lowLongOfPSN(R<R=R((R(s-/usr/lib64/python2.7/test/support/__init__.pyRts s#cannot run without OS X gui process(tTki2s [...]sTk unavailable due to {}: {}(*thasattrt_is_gui_availableRRYRNtplatformRRRtctypes.wintypesRtwindlltuser32tGetProcessWindowStationtWinErrorRRtGetUserObjectInformationWtbyreftsizeoftboolRRRRt ctypes.utilRt LoadLibrarytCGMainDisplayIDtGetCurrentProcesstSetFrontProcesstTkinterRtwithdrawtupdatetdestroyt ExceptionRItlentformatRoR<treason(Rt UOI_FLAGSt WSF_VISIBLERtdllthtuoftneededtresRRRRt app_servicesRtpsntpsn_pRtrootRt err_string((RRs-/usr/lib64/python2.7/test/support/__init__.pyRGsh         "          cCstdkp|tkS(sTest whether a resource is enabled. Known resources are set by regrtest.py. If not running under regrtest.py, all resources are assumed enabled unless use_resources has been set. N(RRY(tresource((s-/usr/lib64/python2.7/test/support/__init__.pyRscCs`t|s4|dkr%d|}nt|n|dkr\t r\ttjndS(s@Raise ResourceDenied if the specified resource is not available.s$Use of the `%s' resource not enabledtguiN(RRYRRR(RRL((s-/usr/lib64/python2.7/test/support/__init__.pyRs    csfd}|S(sDecorator raising SkipTest if the OS is Mac OS X and the OS X version if less than min_version. For example, @requires_mac_ver(10, 5) raises SkipTest if the OS X version is lesser than 10.5. cs.tjfd}|_|S(Ncstjdkrtjd}y"ttt|jd}Wntk rTqX|krdjtt }t j d||fqn||S(NRiRMs&Mac OS X %s or higher required, not %s( RNRtmac_verttupletmaptintRt ValueErrorRRIRGRH(R{tkwt version_txttversiontmin_version_txt(Rzt min_version(s-/usr/lib64/python2.7/test/support/__init__.pytwrappers"  (t functoolstwrapsR(RzR(R(Rzs-/usr/lib64/python2.7/test/support/__init__.pyt decorators! ((RR((Rs-/usr/lib64/python2.7/test/support/__init__.pyRss 127.0.0.1s::1cCs/tj||}t|}|j~|S(s Returns an unused port that should be suitable for binding. This is achieved by creating a temporary socket with the same family and type as the 'sock' parameter (default is AF_INET, SOCK_STREAM), and binding it to the specified host address (defaults to 0.0.0.0) with the port set to 0, eliciting an unused ephemeral port from the OS. The temporary socket is then closed and deleted, and the ephemeral port is returned. Either this method or bind_port() should be used for any tests where a server socket needs to be bound to a particular port for the duration of the test. Which one to use depends on whether the calling code is creating a python socket, or if an unused port needs to be provided in a constructor or passed to an external program (i.e. the -accept argument to openssl's s_server mode). Always prefer bind_port() over find_unused_port() where possible. Hard coded ports should *NEVER* be used. As soon as a server socket is bound to a hard coded port, the ability to run multiple instances of the test simultaneously on the same host is compromised, which makes the test a ticking time bomb in a buildbot environment. On Unix buildbots, this may simply manifest as a failed test, which can be recovered from without intervention in most cases, but on Windows, the entire python process can completely and utterly wedge, requiring someone to log in to the buildbot and manually kill the affected process. (This is easy to reproduce on Windows, unfortunately, and can be traced to the SO_REUSEADDR socket option having different semantics on Windows versus Unix/Linux. On Unix, you can't have two AF_INET SOCK_STREAM sockets bind, listen and then accept connections on identical host/ports. An EADDRINUSE socket.error will be raised at some point (depending on the platform and the order bind and listen were called on each socket). However, on Windows, if SO_REUSEADDR is set on the sockets, no EADDRINUSE will ever be raised when attempting to bind two identical host/ports. When accept() is called on each socket, the second caller's process will steal the port from the first caller, leaving them both in an awkwardly wedged state where they'll no longer respond to any signals or graceful kills, and must be forcibly killed via OpenProcess()/TerminateProcess(). The solution on Windows is to use the SO_EXCLUSIVEADDRUSE socket option instead of SO_REUSEADDR, which effectively affords the same semantics as SO_REUSEADDR on Unix. Given the propensity of Unix developers in the Open Source world compared to Windows ones, this is a common mistake. A quick look over OpenSSL's 0.9.8g source shows that they use SO_REUSEADDR when openssl.exe is called with the 's_server' option, for example. See http://bugs.python.org/issue2550 for more info. The following site also has a very thorough description about the implications of both REUSEADDR and EXCLUSIVEADDRUSE on Windows: http://msdn2.microsoft.com/en-us/library/ms740621(VS.85).aspx) XXX: although this approach is a vast improvement on previous attempts to elicit unused ports, it rests heavily on the assumption that the ephemeral port returned to us by the OS won't immediately be dished back out to some other process when we close and delete our temporary socket but before our calling code has a chance to bind the returned port. We can deal with this issue if/when we come across it.(tsocketRtclose(tfamilytsocktypettempsocktport((s-/usr/lib64/python2.7/test/support/__init__.pyRs 6  cCs|jtjkr|jtjkrttdrc|jtjtjdkrct dqcnttdry1|jtjtj dkrt dnWqt k rqXnttdr|j tjtj dqn|j|df|jd}|S(s%Bind the socket to a free port and return the port number. Relies on ephemeral ports in order to ensure we are using an unbound port. This is important as many tests may be running simultaneously, especially in a buildbot environment. This method raises an exception if the sock.family is AF_INET and sock.type is SOCK_STREAM, *and* the socket has SO_REUSEADDR or SO_REUSEPORT set on it. Tests should *never* set these socket options for TCP/IP sockets. The only case for setting these options is testing multicasting via multiple UDP sockets. Additionally, if the SO_EXCLUSIVEADDRUSE socket option is available (i.e. on Windows), it will be set on the socket. This will prevent anyone else from bind()'ing to our host/port for the duration of the test. t SO_REUSEADDRisHtests should never set the SO_REUSEADDR socket option on TCP/IP sockets!t SO_REUSEPORTsHtests should never set the SO_REUSEPORT socket option on TCP/IP sockets!tSO_EXCLUSIVEADDRUSEi(RRtAF_INETRot SOCK_STREAMRt getsockoptt SOL_SOCKETRRRRtt setsockoptRtbindt getsockname(tsockthostR((s-/usr/lib64/python2.7/test/support/__init__.pyRs$ cCs{tjrwd}zNy3tjtjtj}|jtdftSWntjk r[nXWd|rs|j nXnt S(s+Check whether IPv6 is enabled on this host.iN( Rthas_ipv6RYtAF_INET6RRtHOSTv6RVRRRX(R((s-/usr/lib64/python2.7/test/support/__init__.pyt_is_ipv6_enabled$s cs"tjfd}|S(s5Skip the test on TLS certificate validation failures.csRy||Wn:tk rM}dt|krGtjdnnXdS(NtCERTIFICATE_VERIFY_FAILEDs.system does not contain necessary certificates(tIOErrorRIRGRH(R{tkwargsR(tf(s-/usr/lib64/python2.7/test/support/__init__.pytdec7s (RR(R R ((R s-/usr/lib64/python2.7/test/support/__init__.pytsystem_must_validate_cert5s gư>cCs#t|tst|trcy8t|t|t}t|||krUdSWqqXnt|t|krt|ttfrxPttt |t |D]-}t ||||}|dkr|SqWt |t |kt |t |kS||k||kS(Ni( RitfloattabsRRoRRQtrangetminRR(txtytfuzztitoutcome((s-/usr/lib64/python2.7/test/support/__init__.pyRDs-( ,iiitjavasno unicode supportcCs t|dS(Nsunicode-escape(tunicode(ts((s-/usr/lib64/python2.7/test/support/__init__.pytumsii0iAiiii i*iii s$testtriscosttestfiles@testRs@test-slatin-1tgetwindowsversioniis'u"@test-\u5171\u6709\u3055\u308c\u308b"tLatin1sgWARNING: The filename %r CAN be encoded by the filesystem. Unicode filename tests may not be effectives {}_{}_tmpshttp://www.pythontest.netccsQt}|dkrEddl}|j}t}tjj|}ntrt |t rtjj ry|j t jpd}Wqtk r|stjdqqXnytj|t}Wn7tk r|sntjd|tddnX|rtj}nz |VWd|rL|tjkrLt|nXdS(sReturn a context manager that creates a temporary directory. Arguments: path: the directory to create temporarily. If omitted or None, defaults to creating a temporary directory using tempfile.mkdtemp. quiet: if False (the default), the context manager raises an exception on error. Otherwise, if the path is specified and cannot be created, only a warning is issued. iNtasciis;unable to encode the cwd name with the filesystem encoding.s+tests may fail, unable to create temp dir: Ri(RXRYttempfiletmkdtempRVRuRytrealpathRRiRtsupports_unicode_filenamestencodeRNtgetfilesystemencodingtUnicodeEncodeErrorRGRHtmkdirRR@RRtgetpidR (Rytquiett dir_createdR tpid((s-/usr/lib64/python2.7/test/support/__init__.pyttemp_dirs6          ccs{tj}ytj|Wn7tk rV|s9ntjd|tddnXztjVWdtj|XdS(sgReturn a context manager that changes the current working directory. Arguments: path: the directory to use as the temporary current working directory. quiet: if False (the default), the context manager raises an exception on error. Otherwise, it issues only a warning and keeps the current working directory the same. s)tests may fail, unable to change CWD to: RiN(RutgetcwdtchdirRR@RR(RyR)t saved_dir((s-/usr/lib64/python2.7/test/support/__init__.pyt change_cwd s   ttempcwdc csBtd|d|'}t|d| }|VWdQXWdQXdS(s Context manager that temporarily creates and changes the CWD. The function temporarily changes the current working directory after creating a temporary directory in the current directory with name *name*. If *name* is None, the temporary directory is created using tempfile.mkdtemp. If *quiet* is False (default) and it is not possible to create or change the CWD, an error is raised. If *quiet* is True, only a warning is raised and the original CWD is used. RyR)N(R,R0(RJR)t temp_pathtcwd_dir((s-/usr/lib64/python2.7/test/support/__init__.pyR&stdatacCstjj|r|S|dk r:tjj||}ntgtj}x9|D]1}tjj||}tjj|rQ|SqQW|S(sTry to find a file on sys.path and the working directory. If it is not found the argument passed to the function is returned (this does not necessarily signal failure; could still be the legitimate path).N(RuRytisabsRYRt TEST_HOME_DIRRNtexists(tfiletsubdirRytdntfn((s-/usr/lib64/python2.7/test/support/__init__.pyRAs  cCsJ|j}|jg|D]}d|^q}dj|}d|S(s%Like repr(dict), but in sorted order.s%r: %rs, s{%s}(R]tsortR(tdictR]tpairt reprpairst withcommas((s-/usr/lib64/python2.7/test/support/__init__.pyROs   cCs9ttd}z|jSWd|jttXdS(s` Create an invalid file descriptor by opening and closing a file and return its fd. twbN(topenRtfilenoRR (R8((s-/usr/lib64/python2.7/test/support/__init__.pyt make_bad_fdWs  cCs||jt|}t|ddWdQX|j}|dk rV|j|j|n|dk rx|j|j|ndS(Ns texec(tassertRaisesRegexpt SyntaxErrortcompilet exceptionRYt assertEqualtlinenotoffset(ttestcaset statementterrtextRKRLtcmR|((s-/usr/lib64/python2.7/test/support/__init__.pyRcs   c sSddl}ddl}|j|djdd}tjjt|}fd}tjj|r||}|dk r|St |nt dt d|IJ|j |dd}zNt |d 9}|j} x#| r |j| |j} qWWdQXWd|jX||}|dk r?|Std |dS( Niit/csGt|}dkr|S|r9|jd|S|jdS(Ni(RBRYtseekR(R;R (tcheck(s-/usr/lib64/python2.7/test/support/__init__.pytcheck_valid_filess    turlfetchs fetching %s ...RiRAsinvalid resource "%s"(turlparseturllib2RRuRyRt TEST_DATA_DIRR7RYR RR turlopenRBtreadtwriteRR( turlRSRVRWRR;RTR toutR((RSs-/usr/lib64/python2.7/test/support/__init__.pyRls.            tWarningsRecordercBs8eZdZdZdZedZdZRS(syConvenience wrapper for the warnings list returned on entry to the warnings.catch_warnings() context manager. cCs||_d|_dS(Ni(t _warningst_last(tselft warnings_list((s-/usr/lib64/python2.7/test/support/__init__.pyt__init__s cCs\t|j|jkr,t|jd|S|tjjkrBdStd||fdS(Nis%r has no attribute %r( RR_R`RgR@tWarningMessaget_WARNING_DETAILSRYRh(Ratattr((s-/usr/lib64/python2.7/test/support/__init__.pyt __getattr__s cCs|j|jS(N(R_R`(Ra((s-/usr/lib64/python2.7/test/support/__init__.pyR@scCst|j|_dS(N(RR_R`(Ra((s-/usr/lib64/python2.7/test/support/__init__.pytresets(R<R=R>RcRgtpropertyR@Rh(((s-/usr/lib64/python2.7/test/support/__init__.pyR^s   c csptjd}|jjd}|r4|jntjdt&}tjdj dt |VWdQXg|D]}|j ^qu}g}x|D]\}} t } x[|D]R} t | } tj|| tjrt| j| rt} |j| qqW| r| r|j|| jfqqW|rOtd|dn|rltd |dndS( sCatch 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. it__warningregistry__trecordR@talwaysNsunhandled warning %ris)filter (%r, %s) did not catch any warning(RNt _getframet f_globalstgettclearR@RARVROt simplefilterR^tmessageRXRItretmatchtIt issubclassRntremoveR\R<tAssertionError( tfiltersR)tframetregistrytwtwarningtreraisetmissingRLtcattseenRRr((s-/usr/lib64/python2.7/test/support/__init__.pyt_filterwarningss0  cOsI|jd}|s<dtff}|dkr<t}q<nt||S(sContext 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) R)RN(RotWarningRYRVR(RyR R)((s-/usr/lib64/python2.7/test/support/__init__.pyRs   cOs@tjr$|s*dtff}q*nd}t||jdS(sjContext manager to silence py3k 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 False) Without argument, it defaults to: check_py3k_warnings(("", DeprecationWarning), quiet=False) RR)((RNt py3kwarningRCRRo(RyR ((s-/usr/lib64/python2.7/test/support/__init__.pyR s  cBs)eZdZdZdZdZRS(s,Context manager to force import to return a new module reference. This is useful for testing module-level behaviours, such as the emission of a DeprecationWarning on import. Use like this: with CleanImport("foo"): importlib.import_module("foo") # new reference cGsotjj|_xV|D]N}|tjkrtj|}|j|krZtj|j=ntj|=qqWdS(N(RNROtcopytoriginal_modulesR<(Rat module_namest module_nameRe((s-/usr/lib64/python2.7/test/support/__init__.pyRcs  cCs|S(N((Ra((s-/usr/lib64/python2.7/test/support/__init__.pyt __enter__scGstjj|jdS(N(RNRORR(Rat ignore_exc((s-/usr/lib64/python2.7/test/support/__init__.pyt__exit__s(R<R=R>RcRR(((s-/usr/lib64/python2.7/test/support/__init__.pyR!s  cBs_eZdZdZdZdZdZdZdZdZ dZ d Z RS( s_Class to help protect the environment variable properly. Can be used as a context manager.cCstj|_i|_dS(N(Rutenviront_environt_changed(Ra((s-/usr/lib64/python2.7/test/support/__init__.pyRc(s cCs |j|S(N(R(Ratenvvar((s-/usr/lib64/python2.7/test/support/__init__.pyt __getitem__,scCs<||jkr+|jj||j|RcRRRRRRRR(((s-/usr/lib64/python2.7/test/support/__init__.pyR"#s        t DirsOnSysPathcBs)eZdZdZdZdZRS(sContext manager to temporarily add directories to sys.path. This makes a copy of sys.path, appends any directories given as positional arguments, then reverts sys.path to the copied settings when the context ends. Note that *all* sys.path modifications in the body of the context manager, including replacement of the object, will be reverted at the end of the block. cGs-tj|_tj|_tjj|dS(N(RNRytoriginal_valuetoriginal_objecttextend(Ratpaths((s-/usr/lib64/python2.7/test/support/__init__.pyRc^s  cCs|S(N((Ra((s-/usr/lib64/python2.7/test/support/__init__.pyRcscGs|jt_|jtj(dS(N(RRNRyR(RaR((s-/usr/lib64/python2.7/test/support/__init__.pyRfs (R<R=R>RcRR(((s-/usr/lib64/python2.7/test/support/__init__.pyRRs   cBs2eZdZdZdZddddZRS(sRaise ResourceDenied if an exception is raised while the context manager is in effect that matches the specified exception and attributes.cKs||_||_dS(N(Rtattrs(RaRR ((s-/usr/lib64/python2.7/test/support/__init__.pyRcps cCs|S(N((Ra((s-/usr/lib64/python2.7/test/support/__init__.pyRtscCs}|dk ryt|j|ryxX|jjD]8\}}t||sMPnt|||kr.Pq.q.WtdndS(sIf type_ is a subclass of self.exc and value has attributes matching self.attrs, raise ResourceDenied. Otherwise let the exception propagate (if any).s%an optional resource is not availableN(RYRvRRt iteritemsRRgR(Rattype_Rt tracebackRft attr_value((s-/usr/lib64/python2.7/test/support/__init__.pyRwsN(R<R=R>RcRRYR(((s-/usr/lib64/python2.7/test/support/__init__.pyR%ks  c #sdddd d!d"g}d#d$d%d&d'g}td||gsg|D]\}}tt||^qVg|D]\}}tt||^qnfd}tj}zy%|dk rtj|ndVWntk r} xxtr}| j } t | dkrGt | dtrG| d} qt | dkryt | dtry| d} qPqW|| nXWdtj|XdS((sReturn a context manager that raises ResourceDenied when various issues with the Internet connection manifest themselves as exceptions.t ECONNREFUSEDiot ECONNRESETiht EHOSTUNREACHiqt ENETUNREACHiet ETIMEDOUTint EADDRNOTAVAILict EAI_AGAINitEAI_FAILit EAI_NONAMEit EAI_NODATAit WSANO_DATAi*sResource '%s' is not availablecst|dd}t|tjsNt|tjrB|ksN|kr{tsrtjj j ddnndS(NRis ( RgRYRiRRtgaierrorRRNtstderrR[R{(R|tn(tcaptured_errnostdeniedt gai_errnos(s-/usr/lib64/python2.7/test/support/__init__.pyt filter_errors Niii(Rio(Rih(Riq(Rie(Rin(Ric(Ri(Ri(Ri(Ri(Ri*( RRgRRtgetdefaulttimeoutRYtsetdefaulttimeoutR RVR{RRi( t resource_nameRterrnostdefault_errnostdefault_gai_errnosRJtnumRt old_timeoutR|ta((RRRs-/usr/lib64/python2.7/test/support/__init__.pyR&sJ  (+     % %   ccs[ddl}tt|}tt||jztt|VWdtt||XdS(sReturn a context manager used by captured_stdout and captured_stdin that temporarily replaces the sys stream *stream_name* with a StringIO.iN(tStringIORgRNtsetattr(t stream_nameRt orig_stdout((s-/usr/lib64/python2.7/test/support/__init__.pyR#s  cCs tdS(sCapture the output of sys.stdout: with captured_stdout() as s: print "hello" self.assertEqual(s.getvalue(), "hello") Rs(R#(((s-/usr/lib64/python2.7/test/support/__init__.pyR$scCs tdS(NR(R#(((s-/usr/lib64/python2.7/test/support/__init__.pytcaptured_stderrscCs tdS(Ntstdin(R#(((s-/usr/lib64/python2.7/test/support/__init__.pytcaptured_stdinscCs8tjtr tjdntjtjdS(sForce as many objects as possible to be collected. In non-CPython implementations of Python, this is needed because timely deallocation is not guaranteed by the garbage collector. (Even in CPython this can be the case in case of reference cycles.) This means that __del__ methods may be called later than expected and weakrefs may remain alive for longer than expected. This function tries its best to force all garbage objects to disappear. g?N(tgctcollectRRR(((s-/usr/lib64/python2.7/test/support/__init__.pyt gc_collects  t2PtgettotalrefcounttPcCstjt|dS(Nt0P(tstructtcalcsizet_header(tfmt((s-/usr/lib64/python2.7/test/support/__init__.pyt calcobjsizescCstjt|dS(NR(RRt_vheader(R((s-/usr/lib64/python2.7/test/support/__init__.pyt calcvobjsizesii cCsddl}tj|}t|tkr:|jt@s_t|tkrot|jt@ro||j7}ndt|||f}|j|||dS(Nis&wrong size for %s: got %d, expected %d( t _testcapiRNt getsizeofRot __flags__t_TPFLAGS_HEAPTYPEt_TPFLAGS_HAVE_GCtSIZEOF_PYGC_HEADRJ(ttesttotsizeRRRL((s-/usr/lib64/python2.7/test/support/__init__.pyt check_sizeofs %csfd}|S(Ncs1fd}j|_j|_|S(Ncsy.ddl}t|}|j|}Wn$tk rDnAd}}n1Xx-D]%}y|j||PWq\q\Xq\Wz||SWd|r|r|j||nXdS(Ni(tlocaleRgt setlocaleRhRY(R{tkwdsRtcategoryt orig_localetloc(tcatstrRztlocales(s-/usr/lib64/python2.7/test/support/__init__.pytinners$    (t func_nameR>(RzR(RR(Rzs-/usr/lib64/python2.7/test/support/__init__.pyRs  ((RRR((RRs-/usr/lib64/python2.7/test/support/__init__.pyR'scsfd}|S(Ncs.fd}j|_j|_|S(Ncsy tj}Wn tk r/tjdnXdtjkrOtjd}nd}tjd<|z||SWd|dkrtjd=n |tjd(RzR(R(Rzs-/usr/lib64/python2.7/test/support/__init__.pyR:s  ((RR((Rs-/usr/lib64/python2.7/test/support/__init__.pyR:9scCsidd6td6td6dtd6}tjd|tjtjB}|dkrgtd|fntt |j d||j d j }|a |t krt }n|tdkrtd |fn|adS( NiRtmtgtts(\d+(\.\d+)?) (K|M|G|T)b?$sInvalid memory limit %riis$Memory limit %r too low to be useful(t_1Mt_1GRsRtt IGNORECASEtVERBOSERYRRRtgrouptlowertreal_max_memusetMAX_Py_ssize_tt_2GR(tlimittsizesRtmemlimit((s-/usr/lib64/python2.7/test/support/__init__.pyR(bs   2  icsfd}|S(sQDecorator for bigmem tests. 'minsize' is the minimum useful size for the test (in arbitrary, test-interpreted units.) 'memuse' is the number of 'bytes per size' for the test, or a good estimate of it. 'overhead' specifies fixed overhead, independent of the testsize, and defaults to 5Mb. The decorator tries to guess a good value for 'size' and passes it to the decorated test function. If minsize * memuse is more than the allowed memory use (as defined by max_memuse), the test is skipped. Otherwise, minsize is adjusted upward to use up to max_memuse. cs7fd}|_|_|_|S(Ncsts.d}|j|dtkn^tt}|krutrqtjjdjfndSt |dt}||S(Niis)Skipping %s because of memory constraint i2( Rt assertFalseRRRRNRR[R<tmax(Ratmaxsize(R tmemusetminsizetoverhead(s-/usr/lib64/python2.7/test/support/__init__.pyRs"  (RRR(R R(RRR(R s-/usr/lib64/python2.7/test/support/__init__.pyRs    ((RRRR((RRRs-/usr/lib64/python2.7/test/support/__init__.pyR)ws csfd}|S(Ncs7fd}|_|_|_|S(Ncsftsd}n}ts" rYt|krYtrUtjjdjfndS||S(Nis)Skipping %s because of memory constraint (RRRNRR[R<(RaR(tdry_runR RR(s-/usr/lib64/python2.7/test/support/__init__.pyRs   (RRR(R R(RRRR(R s-/usr/lib64/python2.7/test/support/__init__.pyRs    ((RRRRR((RRRRs-/usr/lib64/python2.7/test/support/__init__.pytprecisionbigmemtestscsfd}|S(s0Decorator for tests that fill the address space.cs@ttkr2tr<tjjdjfq<n |SdS(Ns)Skipping %s because of memory constraint (RRRRNRR[R<(Ra(R (s-/usr/lib64/python2.7/test/support/__init__.pyRs   ((R R((R s-/usr/lib64/python2.7/test/support/__init__.pyR*scBseZdZRS(cCstj}|||S(N(RGt TestResult(RaRR((s-/usr/lib64/python2.7/test/support/__init__.pytruns  (R<R=R(((s-/usr/lib64/python2.7/test/support/__init__.pyR+scCs|S(N((Rp((s-/usr/lib64/python2.7/test/support/__init__.pyt_idscCsP|dkr&t r&tjtjSt|r6tStjdj|SdS(NRsresource {0!r} is not enabled(RRGtskipRRRR(R((s-/usr/lib64/python2.7/test/support/__init__.pytrequires_resources  cCstdt|S(s9 Decorator for tests only applicable on CPython. tcpython(t impl_detailRV(R((s-/usr/lib64/python2.7/test/support/__init__.pyR2scKs}t|rtS|dkrpt|\}}|r=d}nd}t|j}|jdj|}ntj |S(Ns*implementation detail not available on {0}s%implementation detail specific to {0}s or ( R3RRYt _parse_guardstsortedRRRRGR(RLtguardst guardnamestdefault((s-/usr/lib64/python2.7/test/support/__init__.pyRs   cCsW|sitd6tfS|jd}|j|gt|ksLt|| fS(NRi(RVRXtvaluesRRx(R tis_true((s-/usr/lib64/python2.7/test/support/__init__.pyR s %cKs.t|\}}|jtjj|S(s5This function returns True or False depending on the host platform. Examples: if check_impl_detail(): # only on CPython (default) if check_impl_detail(jython=True): # only on Jython if check_impl_detail(cpython=False): # everywhere except on CPython (R RoRtpython_implementationR(R R ((s-/usr/lib64/python2.7/test/support/__init__.pyR3scCsrg}x\|jD]Q}t|tjrEt|||j|q||r|j|qqW||_dS(s>Recursively filter test cases in a suite based on a predicate.N(t_testsRiRGt TestSuitet _filter_suiteR\(tsuitetpredtnewtestsR((s-/usr/lib64/python2.7/test/support/__init__.pyRs  cCstr'tjtjdddt}n t}|j|}|j r\|j r\t n|j st |j dkr|j r|j dd}nLt |jdkr|j r|jdd}nd}ts|d7}nt|ndS( s2Run tests from a unittest.TestSuite-derived class.t verbosityitfailfastiismultiple errors occurreds!; run in verbose mode for detailsN(RRGtTextTestRunnerRNRsRR+RttestsRuntskippedRt wasSuccessfulRterrorstfailuresR(RtrunnerRR|((s-/usr/lib64/python2.7/test/support/__init__.pyt _run_suites      cCs$tdkrtSt|jSdS(N(t_match_test_funcRYRVtid(R((s-/usr/lib64/python2.7/test/support/__init__.pyt match_test#s cCsd|kotjd| S(NRMs[?*\[\]](Rstsearch(tpattern((s-/usr/lib64/python2.7/test/support/__init__.pyt_is_full_match_test+scs|tkrdS|s%d}d}nittt|rLt|j}nBdjttj |}t j |j fd}|}t |a|adS(Nt|cs0|rtStt|jdSdS(NRM(RVtanyRR(ttest_id(t regex_match(s-/usr/lib64/python2.7/test/support/__init__.pytmatch_test_regexJs ((t_match_test_patternsRYtallRR&Rt __contains__Rtfnmatcht translateRsRHRtRR!(tpatternsRztregexR+((R*s-/usr/lib64/python2.7/test/support/__init__.pytset_match_tests5s    cGstjtjf}tj}x|D]}t|trx|tjkri|jtjtj|qt dq%t||r|j|q%|jtj |q%Wt |t t |dS(s1Run tests from unittest.TestCase-derived classes.s)str arguments must be keys in sys.modulesN(RGRtTestCaseRiRIRNROtaddTestt findTestCasesRt makeSuiteRR#R (tclassest valid_typesRtcls((s-/usr/lib64/python2.7/test/support/__init__.pyR,]s    Rtwin32tWITH_DOC_STRINGSstest requires docstringscCsddl}|dkr!t}nd}tj}tt_z>|j|d|\}}|rytd||fnWd|t_Xtrd|j|fGHn||fS(s Run doctest on the given module. Return (#failures, #tests). If optional argument verbosity is not specified (or is None), pass test.support's belief about verbosity on to doctest. Else doctest's usual behavior is used (it searches sys.argv for -v). iNRs%d of %d doctests faileds,doctest (%s) ... %d tests with zero failures( tdoctestRYRRNRsR ttestmodRR<(ReRR=t save_stdoutR R((s-/usr/lib64/python2.7/test/support/__init__.pyR-|s      cCstrtjfSdSdS(Ni(i(tthreadt_count(((s-/usr/lib64/python2.7/test/support/__init__.pyR.s cCsTts dSd}x=t|D]/}tj}||kr?PntjdqWdS(Ni g?(R@RRARR(t nb_threadst _MAX_COUNTtcountR((s-/usr/lib64/python2.7/test/support/__init__.pyR/s  cs,ts Stjfd}|S(sUse this function when threads are being used. This will ensure that the threads are cleaned up even when the test fails. If threading is unavailable this function does nothing. cs)t}z|SWdt|XdS(N(R.R/(R{tkey(Rz(s-/usr/lib64/python2.7/test/support/__init__.pyRs (R@RR(RzR((Rzs-/usr/lib64/python2.7/test/support/__init__.pyR0sgN@ccstj}z dVWdtj}||}xtrtj}||krSPntj|krtj|}d|||||f}t|ntjdtq1WXdS(sE bpo-31234: Context manager to wait until all threads created in the with statement exit. Use thread.count() to check if threads exited. Indirectly, wait until threads exit the internal t_bootstrap() C function of the thread module. threading_setup() and threading_cleanup() are designed to emit a warning if a test leaves running threads in the background. This context manager is designed to cleanup threads started by the thread.start_new_thread() which doesn't allow to wait for thread exit, whereas thread.Thread has a join() method. NsYwait_threads() failed to cleanup %s threads after %.1f seconds (count: %s, old count: %s)g{Gz?(R@RARRVRxRR(Rt old_countt start_timetdeadlineRDtdtRL((s-/usr/lib64/python2.7/test/support/__init__.pytwait_threads_exits         cCscttdr_d}xGtr[y/tj|tj\}}|dkrLPnWqPqXqWndS(sUse this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) stick around to hog resources and create problems when looking for refleaks. twaitpidiiN(RRuRVRKtWNOHANG(t any_processR+tstatus((s-/usr/lib64/python2.7/test/support/__init__.pyR7s   c cst|}g}zfy,x%|D]}|j|j|qWWn.trkdt|t|fGHnnXdVWd|r|ntj}}xtddD]}|d7}x.|D]&}|jt|tjdqWg|D]}|j r|^q}|sPntrdt||fGHqqWXg|D]}|j rE|^qE}|rt dt|ndS(Ns/Can't start %d threads, only %d threads startediii<g{Gz?s7Unable to join %d threads during a period of %d minutessUnable to join %d threads( RQtstartR\RRRRRRtisAliveRx(tthreadstunlocktstartedRtendtimet starttimeR((s-/usr/lib64/python2.7/test/support/__init__.pyR1s:       $%%ccst||rNt||}t|||z |VWdt|||Xn<t|||z dVWdt||rt||nXdS(sTemporary swap out an attribute with a new object. Usage: with swap_attr(obj, "attr", 5): ... This will set obj.attr to 5 for the duration of the with: block, restoring the old value at the end of the block. If `attr` doesn't exist on `obj`, it will be created and then deleted at the end of the block. The old value (or None if it doesn't exist) will be assigned to the target of the "as" clause, if there is one. N(RRgRtdelattr(RpRftnew_valtreal_val((s-/usr/lib64/python2.7/test/support/__init__.pyt swap_attr)s  ccsk||kr:||}|||rsN(ttobytesRhRt TypeErrortbytes(tb((s-/usr/lib64/python2.7/test/support/__init__.pyR5gs  t getcountss-types are immortal if COUNT_ALLOCS is definedcCsddl}|jS(sZReturn a list of command-line arguments reproducing the current settings in sys.flags.iN(t subprocesst_args_from_interpreter_flags(Rc((s-/usr/lib64/python2.7/test/support/__init__.pytargs_from_interpreter_flagsys cCstjdd|j}|S(sStrip the stderr of a Python process from potential debug output emitted by the interpreter. This will typically be run on the result of the communicate() method of a subprocess.Popen object. s\[\d+ refs\]\r?\n?$R(Rstsubtstrip(R((s-/usr/lib64/python2.7/test/support/__init__.pyR8scsid|ffdY}tg||||jttt|jddS(NtAcseZfdZRS(cs0tdRYRRRR(((s-/usr/lib64/python2.7/test/support/__init__.pyR;s  GcCs*ddl}t|jWdQXdS(sDeliberate crash of Python. Python can be killed by a segmentation fault (SIGSEGV), a bus error (SIGBUS), or a different error depending on the platform. Use SuppressCrashReport() to prevent a crash report from popping up. iN(RR;t _read_null(R((s-/usr/lib64/python2.7/test/support/__init__.pyt _crash_pythons  c Cstjjd rdy!tjd}t|dSWqdtk r`}|jtjkraqaqdXnd}t tdrytj d}Wqtk rqXnd }tjdkr+yd d l }|j Wnttfk rq+Xi}x9|j|j|jfD]}|j |d ||RcRR(((s-/usr/lib64/python2.7/test/support/__init__.pyR_s ((ii@i@i@ii(i@ii(((((R>R<RFt contextlibRR/RRRRwRNRuRRR@RGREtUserDictRsRRRxRjR@RYt__all__t SHORT_TIMEOUTRRRRRHRtcontextmanagerRVRDRXRRUR[R6R4RRRRRRrRR R R}RRRRRRR RR R RRRRRRRRRRRR9R RRt PIPE_MAX_SIZEt SOCK_MAX_SIZERRRt NameErrort skipUnlesstrequires_unicodeRt FS_NONASCIItunichrt characterR$R%tdecodet UnicodeErrorRJRRitTESTFN_UNICODEtTESTFN_ENCODINGRRtTESTFN_UNENCODABLEtevalR&RR(t TEST_HTTP_URLR-RR,R0RRyRtabspatht__file__tTEST_SUPPORT_DIRR6RRXRRRDRRtobjectR^RRR R!t DictMixinR"RR%R&R#R$RRRRRRRRRRR'R:RRRt_4GRRR(R)RR*R+RRR2RR R3RR R!R,R#R&R3R,RytHAVE_DOCSTRINGStrequires_docstringsR-tenvironment_alteredR.R/R0RJR7R1RYR[R5tskipIftrequires_type_collectingReR8RqRvR}R;RRR(((s-/usr/lib64/python2.7/test/support/__init__.pyts                                    &      !         J  < $                               .    * ' /D         $ "     '       (    &  #       e  <