,bc;@s dZedkr!ednddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZyddlZWnek r"dZnXddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d3d;d<d=d>g;Zdefd?YZdefd@YZdejfdAYZejedBZe dCZ!dDZ"dEZ#dde dFZ$dGZ%dHZ&dZ'dIa(dIa)da*dJZ+dKZ,dLZ-dMZ.e j j/dNre dOZ0dPZ1dQZ2dRZ3ne j4Z1e j5Z2dSZ3dTZ4dUZ5dVZ6dWZ7dXZ8dYZ9ddZZ:d[Z;d\Z<d]Z=ej>ej?d^Z@e<d_ZAd`ZBeBZCdaZDdbZEdcZFdZGdZHe j j/dgZIyeJeZKWneLk re ZKnXejMeKdhZNdiZOdZPeKrxeQdjeQdkeQdleQdmeQdneQdoeQdpeQdqeQdreQdseQdtf D]GZRy&eRjSe jTjUe jTWneVk rqXeRZPPqWne jWdgkrduZXne jWdvkrdwZXndxZXeKreYdyeJr!dzZZneJdzd{ZZe jTZ[e\e d| sbe j]d}d~krkdZ^qe_dZ^ye^jSdWne`k rqXde^GHndjaeXe jbZXe jcZdeje dZeejde dZfegddZhdZidZjdZkddZldemfdYZne dZoejdZpejdZqd%emfdYZrd&ejsfdYZtdemfdYZud)emfdYZvejdddZwejdZxdZydZzdZ{dZ|dZ}e\e dr@de}Z}ne}dZ~dZdZdZdZdZdZdZdZdeeZd~eZddeZe jZdZdedZdeedZdZd/ddYZdZdZdZddZdZdZdZdZede pme j dkpmejdZejMedZddZdZdZdZdZejddZejdZdZdZdZddZdS(s7Supporting definitions for the Python regression tests.stest.test_supports3test_support must be imported from the test packageiNtErrort TestFailedtResourceDeniedt 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_tzcBseZdZRS(s*Base class for regression test exceptions.(t__name__t __module__t__doc__(((s'/usr/lib/python2.7/test/test_support.pyR.scBseZdZRS(s Test failed.(R:R;R<(((s'/usr/lib/python2.7/test/test_support.pyR1scBseZdZRS(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/lib/python2.7/test/test_support.pyR4sccs=|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/lib/python2.7/test/test_support.pyt_ignore_deprecated_imports<s   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(RBt importlibRt ImportErrortunittesttSkipTesttstr(tnamet deprecatedtmsg((s'/usr/lib/python2.7/test/test_support.pyRKs  cCs|tjkr&t|tj|=nxTttjD]C}||ks[|j|dr6tj|||twarntRuntimeWarning(RrtpathnametwaitalltdirnameRHttimeouttL((s'/usr/lib/python2.7/test/test_support.pyt_waitfors     cCsttj|dS(N(RRmR (tfilename((s'/usr/lib/python2.7/test/test_support.pyt_unlinkscCsttj|dS(N(RRmtrmdir(R((s'/usr/lib/python2.7/test/test_support.pyt_rmdirscs6fdt|dttd|dS(Ncsxt|tj|D]i}tjj||}tjj|rlt|dtt|tj|qt|tj |qWdS(NR( RuRmRyRqtjointisdirRRTRR (RqRHtfullname(t _rmtree_inner(s'/usr/lib/python2.7/test/test_support.pyRs RcSst|tj|S(N(RuRmR(tp((s'/usr/lib/python2.7/test/test_support.pyts(RRT(Rq((Rs'/usr/lib/python2.7/test/test_support.pyt_rmtreescsSytj|dSWntk r(nXfd|tj|dS(Ncsxt|tj|D]}tjj||}ytj|j}Wntk r`d}nXtj |r|t|tj |qt|tj |qWdS(Ni( RuRmRyRqRtlstattst_modeRkRotS_ISDIRRR (RqRHRtmode(R(s'/usr/lib/python2.7/test/test_support.pyRs   (tshutilR RkRmR(Rq((Rs'/usr/lib/python2.7/test/test_support.pyRs   cCs&yt|Wntk r!nXdS(N(RtOSError(R((s'/usr/lib/python2.7/test/test_support.pyR s cCs@yt|Wn+tk r;}|jtjkr<q<nXdS(N(RRterrnotENOENT(Rterror((s'/usr/lib/python2.7/test/test_support.pyRs cCsIyt|Wn4tk rD}|jtjtjfkrEqEnXdS(N(RRRRtESRCH(Rqte((s'/usr/lib/python2.7/test/test_support.pyR s 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 RLRqR RmRtextsep(RRR((s'/usr/lib/python2.7/test/test_support.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(NtresultRviitUSEROBJECTFLAGScs;eZdjjfdjjfdjjfgZRS(tfInheritt fReservedtdwFlags(R:R;twintypestBOOLtDWORDt_fields_((tctypes(s'/usr/lib/python2.7/test/test_support.pyR>ss,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/lib/python2.7/test/test_support.pyR`s s#cannot run without OS X gui process(tTki2s [...]sTk unavailable due to {}: {}(*thasattrt_is_gui_availableRRWRLtplatformRPRtctypes.wintypesRtwindlltuser32tGetProcessWindowStationtWinErrorRRtGetUserObjectInformationWtbyreftsizeoftboolRRRRt ctypes.utilRt LoadLibrarytCGMainDisplayIDtGetCurrentProcesstSetFrontProcesstTkinterRtwithdrawtupdatetdestroyt ExceptionRGtlentformatttypeR:treason(Rt UOI_FLAGSt WSF_VISIBLERtdllthtuoftneededtresRRRRt app_servicesRtpsntpsn_pRtrootRt err_string((RRs'/usr/lib/python2.7/test/test_support.pyR3sh         "          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(RRW(tresource((s'/usr/lib/python2.7/test/test_support.pyR }scCs`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(R RWRRR(RRJ((s'/usr/lib/python2.7/test/test_support.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(NRiRKs&Mac OS X %s or higher required, not %s( RLRtmac_verttupletmaptintRxt ValueErrorRRGRERF(Rstkwt version_txttversiontmin_version_txt(Rrt min_version(s'/usr/lib/python2.7/test/test_support.pytwrappers"  (t functoolstwrapsR(RrR(R(Rrs'/usr/lib/python2.7/test/test_support.pyt decorators! ((RR((Rs'/usr/lib/python2.7/test/test_support.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/lib/python2.7/test/test_support.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_INETRt SOCK_STREAMRt getsockoptt SOL_SOCKETRRRRkt setsockoptRtbindt getsockname(tsockthostR((s'/usr/lib/python2.7/test/test_support.pyRs$ cCs{tjrwd}zNy3tjtjtj}|jtdftSWntjk r[nXWd|rs|j nXnt S(s+Check whether IPv6 is enabled on this host.iN( Rthas_ipv6RWtAF_INET6RRtHOSTv6RTRRRV(R((s'/usr/lib/python2.7/test/test_support.pyt_is_ipv6_enableds 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(tIOErrorRGRERF(RstkwargsR(tf(s'/usr/lib/python2.7/test/test_support.pytdec#s (RR(RR((Rs'/usr/lib/python2.7/test/test_support.pytsystem_must_validate_cert!s gư>cCs#t|tst|trcy8t|t|t}t|||krUdSWqqXnt|t|krt|ttfrxPttt |t |D]-}t ||||}|dkr|SqWt |t |kt |t |kS||k||kS(Ni( t isinstancetfloattabsRRRROtrangetminRR(txtytfuzztitoutcome((s'/usr/lib/python2.7/test/test_support.pyR0s-( ,iiitjavasno unicode supportcCs t|dS(Nsunicode-escape(tunicode(ts((s'/usr/lib/python2.7/test/test_support.pytuYsii0iAiiii i*iii s$testtriscosttestfiles@testts@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 {}_{}_tmpccs{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: RwiN(RmtgetcwdtchdirRR>R|R}(Rqtquiett saved_dir((s'/usr/lib/python2.7/test/test_support.pyt change_cwds   ttempcwdccstrpt|trptjj rpy|jtjp:d}Wqpt k rl|smt j dqmqpXntj }t }y$tj|tj|t}Wn7tk r|sntjd|tddnXztj VWdtj||rt|nXdS(sR Context manager that creates a temporary directory and set it as CWD. The new CWD is created in the current directory and it's named *name*. If *quiet* is False (default) and it's not possible to create or change the CWD, an error is raised. If it's True, only a warning is raised and the original CWD is used. tasciis;unable to encode the cwd name with the filesystem encoding.s,tests may fail, unable to change the CWD to RwiN(RRRRmRqtsupports_unicode_filenamestencodeRLtgetfilesystemencodingtUnicodeEncodeErrorRERFRRVtmkdirRRTRR>R|R}R (RHRRt is_temporary((s'/usr/lib/python2.7/test/test_support.pyRs.          cCstjj|r|S|dk r:tjj||}ntj}tjj|g|}x9|D]1}tjj||}tjj|rc|SqcW|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(RmRqtisabsRWRRLRtexists(tfiletheretsubdirRqtdntfn((s'/usr/lib/python2.7/test/test_support.pyRs   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/lib/python2.7/test/test_support.pyRs   cCs9ttd}z|jSWd|jttXdS(s` Create an invalid file descriptor by opening and closing a file and return its fd. twbN(topenRtfilenoRR (R&((s'/usr/lib/python2.7/test/test_support.pyt make_bad_fds  cCs|jtt|dddS(Ns texec(t assertRaisest SyntaxErrortcompile(ttestcaset statement((s'/usr/lib/python2.7/test/test_support.pyR#sc sbddl}ddl}|j|djdd}tjjtjjtd|}fd}tjj|r||}|dk r|St |nt dt d|IJ|j |dd }zNt|d 9}|j} x#| r|j| |j} qWWdQXWd|jX||}|dk rN|Std |dS( Niit/tdatacsGt|}dkr|S|r9|jd|S|jdS(Ni(R1RWtseekR(R*R(tcheck(s'/usr/lib/python2.7/test/test_support.pytcheck_valid_file.s    turlfetchs fetching %s ...RiR0sinvalid resource "%s"(turlparseturllib2RxRmRqRRt__file__R%RWR RRturlopenR1treadtwriteRR( turlR=R@RARR*R>RtoutR((R=s'/usr/lib/python2.7/test/test_support.pyR's. $           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/lib/python2.7/test/test_support.pyt__init__Us cCs\t|j|jkr,t|jd|S|tjjkrBdStd||fdS(Nis%r has no attribute %r( RRIRJReR>tWarningMessaget_WARNING_DETAILSRWRf(RKtattr((s'/usr/lib/python2.7/test/test_support.pyt __getattr__Ys cCs|j|jS(N(RIRJ(RK((s'/usr/lib/python2.7/test/test_support.pyR>`scCst|j|_dS(N(RRIRJ(RK((s'/usr/lib/python2.7/test/test_support.pytresetds(R:R;R<RMRQtpropertyR>RR(((s'/usr/lib/python2.7/test/test_support.pyRHQs   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(RLt _getframet f_globalstgettclearR>R?RTRMt simplefilterRHtmessageRVRGtretmatchtIt issubclassRltremoveRZR:tAssertionError( tfiltersRtframetregistrytwtwarningtreraisetmissingRJtcattseentexcR\((s'/usr/lib/python2.7/test/test_support.pyt_filterwarningshs0  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) RRN(RYtWarningRWRTRm(RcRR((s'/usr/lib/python2.7/test/test_support.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((RLt py3kwarningRARmRY(RcR((s'/usr/lib/python2.7/test/test_support.pyRs  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(RLRMtcopytoriginal_modulesR:(RKt module_namest module_nameRc((s'/usr/lib/python2.7/test/test_support.pyRMs  cCs|S(N((RK((s'/usr/lib/python2.7/test/test_support.pyt __enter__scGstjj|jdS(N(RLRMRRq(RKt ignore_exc((s'/usr/lib/python2.7/test/test_support.pyt__exit__s(R:R;R<RMRtRv(((s'/usr/lib/python2.7/test/test_support.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(Rmtenviront_environt_changed(RK((s'/usr/lib/python2.7/test/test_support.pyRMs cCs |j|S(N(Rx(RKtenvvar((s'/usr/lib/python2.7/test/test_support.pyt __getitem__scCs<||jkr+|jj||j|@c #sdddddg}d d!d"d#d$g}td||gsg|D]\}}tt||^qSg|D]\}}tt||^q~nfd}tj}zy%|dk rtj|ndVWntk r} xxtrz| j } t | dkrDt | dtrD| d} qt | dkrvt | dtrv| 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 EAI_AGAINitEAI_FAILit EAI_NONAMEit EAI_NODATAit WSANO_DATAi*sResource '%s' is not availablecst|dd}t|tjsNt|tjrB|ksN|kr{tsrtjj j ddnndS(NRis ( ReRWRRRtgaierrorRRLtstderrRERs(Rttn(tcaptured_errnostdeniedt gai_errnos(s'/usr/lib/python2.7/test/test_support.pyt filter_error^s Niii(Rio(Rih(Riq(Rie(Rin(Ri(Ri(Ri(Ri(Ri*( RReRRtgetdefaulttimeoutRWtsetdefaulttimeoutRRTRsRR( t resource_nameRterrnostdefault_errnostdefault_gai_errnosRHtnumRt old_timeoutRtta((RRRs'/usr/lib/python2.7/test/test_support.pyR%@sH  (+     % %   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(tStringIOReRLtsetattr(t stream_nameRt orig_stdout((s'/usr/lib/python2.7/test/test_support.pyR"s  cCs tdS(sCapture the output of sys.stdout: with captured_stdout() as s: print "hello" self.assertEqual(s.getvalue(), "hello") Rj(R"(((s'/usr/lib/python2.7/test/test_support.pyR#scCs tdS(NR(R"(((s'/usr/lib/python2.7/test/test_support.pytcaptured_stderrscCs tdS(Ntstdin(R"(((s'/usr/lib/python2.7/test/test_support.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(tgctcollectRRzR{(((s'/usr/lib/python2.7/test/test_support.pyt gc_collects  t2PtgettotalrefcounttPcCstjt|dS(Nt0P(tstructtcalcsizet_header(tfmt((s'/usr/lib/python2.7/test/test_support.pyt calcobjsizescCstjt|dS(NR(RRt_vheader(R((s'/usr/lib/python2.7/test/test_support.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 _testcapiRLt getsizeofRt __flags__t_TPFLAGS_HEAPTYPEt_TPFLAGS_HAVE_GCtSIZEOF_PYGC_HEADt assertEqual(ttesttotsizeRRRJ((s'/usr/lib/python2.7/test/test_support.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(tlocaleRet setlocaleRfRW(RstkwdsRtcategoryt orig_localetloc(tcatstrRrtlocales(s'/usr/lib/python2.7/test/test_support.pytinners$    (t func_nameR<(RrR(RR(Rrs'/usr/lib/python2.7/test/test_support.pyRs  ((RRR((RRs'/usr/lib/python2.7/test/test_support.pyR&scsfd}|S(Ncs.fd}j|_j|_|S(Ncsy tj}Wn tk r/tjdnXdtjkrOtjd}nd}tjd<|z||SWd|dkrtjd=n |tjd|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( tdoctestRWRRLRjRttestmodRR:(RcRRt save_stdoutRR((s'/usr/lib/python2.7/test/test_support.pyR,s      cCstrtjfSdSdS(Ni(i(tthreadt_count(((s'/usr/lib/python2.7/test/test_support.pyR-s cCsTts dSd}x=t|D]/}tj}||kr?PntjdqWdS(Ni g?(RRRRzR{(t nb_threadst _MAX_COUNTtcountR((s'/usr/lib/python2.7/test/test_support.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.(Rstkey(Rr(s'/usr/lib/python2.7/test/test_support.pyR(s (RRR(RrR((Rrs'/usr/lib/python2.7/test/test_support.pyR/ scCscttdr_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(RRmRTRtWNOHANG(t any_processtpidtstatus((s'/usr/lib/python2.7/test/test_support.pyR61s   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( ROtstartRZRRRzRRRtisAliveRb(tthreadstunlocktstartedRtendtimet starttimeR((s'/usr/lib/python2.7/test/test_support.pyR0Es:       $%%ccs|t||rNt||}t|||z dVWdt|||Xn*t|||z dVWdt||XdS(smTemporary 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. N(RReRtdelattr(RgRPtnew_valtreal_val((s'/usr/lib/python2.7/test/test_support.pyt swap_attrfs   cCs\y|jSWnGtk rWydjd|DSWqXtk rSt|SXnXdS(sZEmulate the py3k bytes() constructor. NOTE: This is only a best effort function. Rcss|]}t|VqdS(N(tchr(t.0R ((s'/usr/lib/python2.7/test/test_support.pys sN(ttobytesRfRt TypeErrortbytes(tb((s'/usr/lib/python2.7/test/test_support.pyR4s  cCsddl}|jS(sZReturn a list of command-line arguments reproducing the current settings in sys.flags.iN(t subprocesst_args_from_interpreter_flags(R-((s'/usr/lib/python2.7/test/test_support.pytargs_from_interpreter_flagss 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(R]tsubtstrip(R((s'/usr/lib/python2.7/test/test_support.pyR7scsid|ffdY}tg||||jttt|jddS(NtAcseZfdZRS(cs0tdRERCtUserDictR]RzRt sysconfigRRWt__all__RRRRFRtcontextmanagerRTRBRVRRSRYR5R3RRRRRiRRR RuRPRRRRR RR R RR RRRRRRRRRR8RRRt PIPE_MAX_SIZEt SOCK_MAX_SIZERRRt NameErrort skipUnlesstrequires_unicodeRt FS_NONASCIItunichrt characterRR tdecodet UnicodeErrorRHRRtTESTFN_UNICODEtTESTFN_ENCODINGRRtTESTFN_UNENCODABLEtevalR!RtgetpidRRRRRBRRR3RRtobjectRHRmRRR t DictMixinR!RR$R%R"R#RRRRRRRRRRR&R9RRRt_4GRRR'R(RR)R*RRR1RRR2RR+tget_config_vartHAVE_DOCSTRINGStrequires_docstringsR,R-R.R/R6R0R&R4R/R7R:(((s'/usr/lib/python2.7/test/test_support.pyts                                 &      !         J  < $                            $   * ' /A         $ "     '         (