kWc8@sdZedkr!ednddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZyddlZWnek rdZnXddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d2d3d9d:g8Zdefd;YZdefd<YZde jfd=YZejed>Zed?Z d@Z!dAZ"ddedBZ#dCZ$dDZ%dZ&dEa'dEa(da)dFZ*dGZ+dHZ,ej j-dIredJZ.dKZ/dLZ0dMZ1ne j2Z/e j3Z0e j4Z1dNZ2dOZ3dPZ4dQZ5dRZ6dSZ7ddTZ8dUZ9dVZ:ej;ej<dWZ=e9dXZ>dYZ?e?Z@dZZAd[ZBd\ZCdZDdZEej j-d`ZFyeGeZHWneIk reZHnXe jJeHdaZKdbZLdZMeHrxeNdceNddeNdeeNdfeNdgeNdheNdieNdjeNdkeNdleNdmf D]GZOy&eOjPejQjRejQWneSk rqXXeOZMPqXWne jTd`krdnZUne jTdokrdpZUndqZUeHreVdreGrdsZWneGdsdtZWejQZXeYedu s;ejZdvdwkrDdZ[qe\dxZ[ye[jPdyWne]k rtqXdze[GHnd{j^eUe j_ZUe j`Zaejd|ed}Zbecdd~ZddZedZfdZgddZhdeifdYZjedZkejdZlejdZmd$eifdYZnd%ejofdYZpdeifdYZqd(eifdYZrejdddZsejdZtdZudZvdZwdZxdZyeYedrdeyZyneydZzdZ{dZ|dZ}dZ~dZdZdZd^eZdweZd]eZejZdZdedZdeedZdZd.ddYZdZdZdZddZdZdZdZdZedep(ej dkp(ejdZe jJedZddZdZdZdZdZejdZdZdZdZdS(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_enabledtrequirestfind_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_childrent cpython_onlytcheck_impl_detailt get_attributet py3k_bytestimport_fresh_moduletstrip_python_stderrt IPV6_ENABLEDcBseZdZRS(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.(R6R7R8(((s'/usr/lib/python2.7/test/test_support.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. (R6R7R8(((s'/usr/lib/python2.7/test/test_support.pyR2sccs=|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(R9((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(R>t importlibRt ImportErrortunittesttSkipTesttstr(tnamet deprecatedtmsg((s'/usr/lib/python2.7/test/test_support.pyRIs  cCs|tjkr&t|tj|=nxTttjD]C}||ks[|j|dr6tj|||RORUtappendR?RR@RStitemsRHRI( RDtfreshtblockedRERMtnames_to_removet fresh_namet blocked_namet fresh_modulet orig_nametmoduletname_to_remove((s'/usr/lib/python2.7/test/test_support.pyR3ps&      cCsKyt||}Wn-tk rBtjd|j|fnX|SdS(s?Get an attribute, raising SkipTest if AttributeError is raised.smodule %s has no attribute %sN(tgetattrtAttributeErrorRARBR6(tobjRDt attribute((s'/usr/lib/python2.7/test/test_support.pyR1s   iicCs |adS(N(t_original_stdout(tstdout((s'/usr/lib/python2.7/test/test_support.pyRscCs tp tjS(N(ReRHRf(((s'/usr/lib/python2.7/test/test_support.pyRscCs&ytj|=Wntk r!nXdS(N(RHRIRQ(RD((s'/usr/lib/python2.7/test/test_support.pyR s twincCs|||r|}n$tjj|\}}|p:d}d}xR|dkrtj|}|rm|n ||ks}dStj||d9}qFWtjd|tdddS(NRGgMbP?g?is)tests may fail, delete still pending for t stackleveli( tostpathtsplittlistdirttimetsleepR:twarntRuntimeWarning(tfunctpathnametwaitalltdirnameRDttimeouttL((s'/usr/lib/python2.7/test/test_support.pyt_waitfors     cCsttj|dS(N(RwRiR (tfilename((s'/usr/lib/python2.7/test/test_support.pyt_unlinkscCsttj|dS(N(RwRitrmdir(Rt((s'/usr/lib/python2.7/test/test_support.pyt_rmdirscs6fdt|dtttj|dS(Ncsuxntj|D]]}tjj||}tjj|r`t|dttj|qtj|qWdS(NRs( RiRlRjtjointisdirRwRPRzR (RjRDtfullname(t _rmtree_inner(s'/usr/lib/python2.7/test/test_support.pyRs Rs(RwRPRiRz(Rj((Rs'/usr/lib/python2.7/test/test_support.pyt_rmtreescCs&yt|Wntk r!nXdS(N(RytOSError(Rx((s'/usr/lib/python2.7/test/test_support.pyR s cCs@yt|Wn+tk r;}|jtjkr<q<nXdS(N(R{RterrnotENOENT(Rtterror((s'/usr/lib/python2.7/test/test_support.pyRzs cCsIyt|Wn4tk rD}|jtjtjfkrEqEnXdS(N(RRRRtESRCH(Rjte((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 RHRjR RiR|textsep(RNRt((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|sy1ddlm}|}|j |j!Wqt"k r}t#|}t$|dkrp|d d}ndj%t&|j'|}qXn|t_(| t_tjS(NtresultRgiitUSEROBJECTFLAGScs;eZdjjfdjjfdjjfgZRS(tfInheritt fReservedtdwFlags(R6R7twintypestBOOLtDWORDt_fields_((tctypes(s'/usr/lib/python2.7/test/test_support.pyRss,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(R6R7R((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_availableRRSRHtplatformRLRtctypes.wintypesRtwindlltuser32tGetProcessWindowStationtWinErrorRRtGetUserObjectInformationWtbyreftsizeoftboolRRRRt ctypes.utilRt LoadLibrarytCGMainDisplayIDtGetCurrentProcesstSetFrontProcesstTkinterRtupdatetdestroyt ExceptionRCtlentformatttypeR6treason(Rt UOI_FLAGSt WSF_VISIBLERtdllthtuoftneededtresRRRRt app_servicesRtpsntpsn_pRtrootRt err_string((RRs'/usr/lib/python2.7/test/test_support.pyRsf         "         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(RRS(tresource((s'/usr/lib/python2.7/test/test_support.pyR [scCs`|dkr(t r(ttjnt|s\|dkrMd|}nt|ndS(s@Raise ResourceDenied if the specified resource is not available.tguis$Use of the `%s' resource not enabledN(RRRR RS(RRF((s'/usr/lib/python2.7/test/test_support.pyRcs    s 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.pyRss 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_SOCKETRRRtEnvironmentErrort 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_ipv6RStAF_INET6RRtHOSTv6RPRRRR(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(tIOErrorRCRARB(targstkwargsR(tf(s'/usr/lib/python2.7/test/test_support.pytdecs (t functoolstwraps(RR((Rs'/usr/lib/python2.7/test/test_support.pytsystem_must_validate_certs 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 isinstancetfloattabsRRttupleRKtrangetminRR(txtytfuzztitoutcome((s'/usr/lib/python2.7/test/test_support.pyRs-( ,iiitjavasno unicode supportcCs t|dS(Nsunicode-escape(tunicode(ts((s'/usr/lib/python2.7/test/test_support.pytusii0iAiiii 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 {}_{}_tmpttempcwdccs trct|trcy|jtjp-d}Wqctk r_|s`tjdq`qcXnt j }t }y$t j |t j |t}Wn7tk r|sntjd|tddnXzt j VWdt j ||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 RhiN(RRRtencodeRHtgetfilesystemencodingtUnicodeEncodeErrorRARBRitgetcwdRRtmkdirtchdirRPRR:RoRpR (RDtquiett saved_dirt 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(RiRjtisabsRSR|RHRttexists(tfiletheretsubdirRjtdntfn((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}(RWtsortR|(tdictRWtpairt 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.pyRsc 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(RRStseekR(R R(tcheck(s'/usr/lib/python2.7/test/test_support.pytcheck_valid_files    turlfetchs fetching %s ...RuiRsinvalid resource "%s"(turlparseturllib2RkRiRjR|Rtt__file__RRSR RRturlopenRtreadtwriteRR( turlRR!R"RxR RRtoutR((Rs'/usr/lib/python2.7/test/test_support.pyRs. $           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__s cCs\t|j|jkr,t|jd|S|tjjkrBdStd||fdS(Nis%r has no attribute %r( RR*R+RaR:tWarningMessaget_WARNING_DETAILSRSRb(R,tattr((s'/usr/lib/python2.7/test/test_support.pyt __getattr__s cCs|j|jS(N(R*R+(R,((s'/usr/lib/python2.7/test/test_support.pyR:scCst|j|_dS(N(RR*R+(R,((s'/usr/lib/python2.7/test/test_support.pytreset s(R6R7R8R.R2tpropertyR:R3(((s'/usr/lib/python2.7/test/test_support.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(RHt _getframet f_globalstgettclearR:R;RPRIt simplefilterR)tmessageRRRCtretmatchtIt issubclasst __class__tremoveRVR6tAssertionError( tfiltersRtframetregistrytwtwarningtreraisetmissingRFtcattseentexcR=((s'/usr/lib/python2.7/test/test_support.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) RRN(R:tWarningRSRPRO(RERR((s'/usr/lib/python2.7/test/test_support.pyR6s   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((RHt py3kwarningR=ROR:(RER((s'/usr/lib/python2.7/test/test_support.pyRNs  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(RHRItcopytoriginal_modulesR6(R,t module_namest module_nameR_((s'/usr/lib/python2.7/test/test_support.pyR.qs  cCs|S(N((R,((s'/usr/lib/python2.7/test/test_support.pyt __enter__~scGstjj|jdS(N(RHRIRRS(R,t ignore_exc((s'/usr/lib/python2.7/test/test_support.pyt__exit__s(R6R7R8R.RVRX(((s'/usr/lib/python2.7/test/test_support.pyRes  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(Ritenviront_environt_changed(R,((s'/usr/lib/python2.7/test/test_support.pyR.s cCs |j|S(N(RZ(R,tenvvar((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 ( RaRSRRRutgaierrorRRHtstderrR&R(terrtn(tcaptured_errnostdeniedt gai_errnos(s'/usr/lib/python2.7/test/test_support.pyt filter_errors Niii(Rpio(Rqih(Rriq(Rsie(Rtin(Rui(Rvi(Rwi(Rxi(Ryi*( RRaRRtgetdefaulttimeoutRStsetdefaulttimeoutRRPRRR( t resource_nameRuterrnostdefault_errnostdefault_gai_errnosRDtnumRt old_timeoutR|ta((R~RRs'/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(tStringIORaRHtsetattr(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") Rf(R!(((s'/usr/lib/python2.7/test/test_support.pyR"5scCs tdS(NR{(R!(((s'/usr/lib/python2.7/test/test_support.pytcaptured_stderr>scCs tdS(Ntstdin(R!(((s'/usr/lib/python2.7/test/test_support.pytcaptured_stdinAscCs8tjtr 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(tgctcollectRRmRn(((s'/usr/lib/python2.7/test/test_support.pyt gc_collectDs  t2PtgettotalrefcounttPcCstjt|dS(Nt0P(tstructtcalcsizet_header(tfmt((s'/usr/lib/python2.7/test/test_support.pyt calcobjsizeZscCstjt|dS(NR(RRt_vheader(R((s'/usr/lib/python2.7/test/test_support.pyt calcvobjsize]sii 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 _testcapiRHt getsizeofRt __flags__t_TPFLAGS_HEAPTYPEt_TPFLAGS_HAVE_GCtSIZEOF_PYGC_HEADt assertEqual(ttesttotsizeRRRF((s'/usr/lib/python2.7/test/test_support.pyt check_sizeofds %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(tlocaleRat setlocaleRbRS(RtkwdsRtcategoryt orig_localetloc(tcatstrRqtlocales(s'/usr/lib/python2.7/test/test_support.pytinnervs$    (t func_nameR8(RqR(RR(Rqs'/usr/lib/python2.7/test/test_support.pyt decoratorus  ((RRR((RRs'/usr/lib/python2.7/test/test_support.pyR%tscCsidd6td6td6dtd6}tjd|tjtjB}|dkrgtd|fntt |j d||j d j }|a |t krt }n|tdkrtd |fn|adS( NiRdtmtgtts(\d+(\.\d+)?) (K|M|G|T)b?$sInvalid memory limit %riis$Memory limit %r too low to be useful(t_1Mt_1GR>R?t IGNORECASEtVERBOSERSt ValueErrortintRtgrouptlowertreal_max_memusetMAX_Py_ssize_tt_2GR(tlimittsizesRtmemlimit((s'/usr/lib/python2.7/test/test_support.pyR&s   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 assertFalseRRRRHR{R&R6tmax(R,tmaxsize(Rtmemusetminsizetoverhead(s'/usr/lib/python2.7/test/test_support.pytwrappers"  (RRR(RR(RRR(Rs'/usr/lib/python2.7/test/test_support.pyRs    ((RRRR((RRRs'/usr/lib/python2.7/test/test_support.pyR's csfd}|S(Ncs7fd}|_|_|_|S(Ncsftsd}n}ts" rYt|krYtrUtjjdjfndS||S(Nis)Skipping %s because of memory constraint (RRRHR{R&R6(R,R(tdry_runRRR(s'/usr/lib/python2.7/test/test_support.pyRs   (RRR(RR(RRRR(Rs'/usr/lib/python2.7/test/test_support.pyRs    ((RRRRR((RRRRs'/usr/lib/python2.7/test/test_support.pytprecisionbigmemtestscsfd}|S(s0Decorator for tests that fill the address space.cs@ttkr2tr<tjjdjfq<n |SdS(Ns)Skipping %s because of memory constraint (RRRRHR{R&R6(R,(R(s'/usr/lib/python2.7/test/test_support.pyRs   ((RR((Rs'/usr/lib/python2.7/test/test_support.pyR(scBseZdZRS(cCstj}|||S(N(RAt TestResult(R,RR((s'/usr/lib/python2.7/test/test_support.pytruns  (R6R7R(((s'/usr/lib/python2.7/test/test_support.pyR)scCs|S(N((Rc((s'/usr/lib/python2.7/test/test_support.pyt_idscCsP|dkr&t r&tjtjSt|r6tStjdj|SdS(NRsresource {0!r} is not enabled(RRAtskipRR RR(R((s'/usr/lib/python2.7/test/test_support.pytrequires_resource s  cCstdt|S(s9 Decorator for tests only applicable on CPython. tcpython(t impl_detailRP(R((s'/usr/lib/python2.7/test/test_support.pyR/scKs}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 ( R0RRSt _parse_guardstsortedRaRR|RAR(RFtguardst guardnamestdefault((s'/usr/lib/python2.7/test/test_support.pyRs   cCsW|sitd6tfS|jd}|j|gt|ksLt|| fS(NRi(RPRRtvaluesRRD(Rtis_true((s'/usr/lib/python2.7/test/test_support.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 (RR:Rtpython_implementationR(RR((s'/usr/lib/python2.7/test/test_support.pyR0.scCstr!tjtjdd}n t}|j|}|jst|j dkrx|j rx|j dd}nLt|j dkr|j r|j dd}nd}ts|d7}nt |ndS(s2Run tests from a unittest.TestSuite-derived class.t verbosityiiismultiple errors occurreds!; run in verbose mode for detailsN( RRAtTextTestRunnerRHRfR)Rt wasSuccessfulRterrorstfailuresR(tsuitetrunnerRR|((s'/usr/lib/python2.7/test/test_support.pyt _run_suite:s   cGstjtjf}tj}x|D]}t|trx|tjkri|jtjtj|qt dq%t||r|j|q%|jtj |q%Wt |dS(s1Run tests from unittest.TestCase-derived classes.s)str arguments must be keys in sys.modulesN( RAt TestSuitetTestCaseRRCRHRItaddTestt findTestCasesRt makeSuiteR(tclassest valid_typesRtcls((s'/usr/lib/python2.7/test/test_support.pyR*Ns   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( tdoctestRSRRHRfRttestmodRR6(R_RRt save_stdoutRR((s'/usr/lib/python2.7/test/test_support.pyR+ls      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?(RRRRmRn(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-(Rtkey(Rq(s'/usr/lib/python2.7/test/test_support.pyRs (RRR(RqR((Rqs'/usr/lib/python2.7/test/test_support.pyt reap_threadsscCscttdr_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(RRiRPRtWNOHANG(t any_processtpidtstatus((s'/usr/lib/python2.7/test/test_support.pyR.s   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(RRaRtdelattr(RcR1tnew_valtreal_val((s'/usr/lib/python2.7/test/test_support.pyt swap_attrs   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(ttobytesRbR|t TypeErrortbytes(tb((s'/usr/lib/python2.7/test/test_support.pyR2s  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.pyR4s((ii@i@i@ii(i@ii((R8R6R@t contextlibRRRRRHRiRtshutilR:RAR?tUserDictR>RmRt sysconfigRRSt__all__RRRRBRtcontextmanagerRPR>RRRRORUR3R1RRRRReRRR RLRwRyR{RR RzR R RR RRRRRRRRR5RRRt PIPE_MAX_SIZEt SOCK_MAX_SIZERRRt NameErrort skipUnlesstrequires_unicodeRt FS_NONASCIItunichrt characterRRtdecodet UnicodeErrorRDRRtTESTFN_UNICODEtTESTFN_ENCODINGRRtTESTFN_UNENCODABLEtevalRRtgetpidRRRR#RRRRRtobjectR)RORRRt DictMixinR RfR#R$R!R"RRRRRRRRRRR%RRRt_4GRRR&R'RR(R)RRR/RRR0RR*tget_config_vartHAVE_DOCSTRINGStrequires_docstringsR+R,R-RR.RR2R R4(((s'/usr/lib/python2.7/test/test_support.pyts                                 &     !         I  < $                            #   * ' /A         %     '         (