{G_Tc7@sedZedkr!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/d0d1d2d3d4d5d6d7d8d2d3d9g7Zdefd:YZdefd;YZde jfd<YZejed=Zed>Z d?Z!d@Z"ddedAZ#dBZ$dCZ%dZ&dDa'dDa(da)dEZ*dFZ+dGZ,ej j-dHredIZ.dJZ/dKZ0dLZ1ne j2Z/e j3Z0e j4Z1dMZ2dNZ3dOZ4dPZ5dQZ6dRZ7ddSZ8dTZ9dUZ:ej;ej<dVZ=e9dWZ>dXZ?dYZ@dZAdZByeCeZDWneEk reZDnXej j-d]ZFdZGeDrmxeHd^eHd_eHd`eHdaeHdbeHdceHddeHdeeHdfeHdgeHdhf D]GZIy&eIjJejKjLejKWneMk r^qXeIZGPqWne jNd]krdiZOne jNdjkrdkZOndlZOeDrHePdmeCrdnZQneCdndoZQejKZReSedp sejTdqdrkr dZUqHeVdsZUyeUjJdtWneWk r;qHXdueUGHndvjXeOe jYZOe jZZ[ejdwedxZ\e]ddyZ^dzZ_d{Z`d|Zadd}Zbd~ecfdYZdedZeejdZfejdZgd$ecfdYZhd%ejifdYZjdecfdYZkd(ecfdYZlejdddZmejdZndZodZpdZqdZrdZseSedrdesZsnesdZtdZudZvdZwdZxdZydZzdZ{d[e{Z|dre|Z}dZe|Z~ejZdZde{dZde{edZdZd.ddYZdZdZdZddZdZdZdZdZedepej dkpejdZe jedZddZdZdZdZdZejdZdZdZdZdS(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_stderrcBseZdZRS(s*Base class for regression test exceptions.(t__name__t __module__t__doc__(((s-/usr/local/lib/python2.7/test/test_support.pyR,scBseZdZRS(s Test failed.(R5R6R7(((s-/usr/local/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. (R5R6R7(((s-/usr/local/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(R8((s-/usr/local/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/local/lib/python2.7/test/test_support.pyRIs  cCs|tjkr&t|tj|=nxTttjD]C}||ks[|j|dr6tj|||RR?RRtitemsRGRH( RCtfreshtblockedRDRLtnames_to_removet fresh_namet blocked_namet fresh_modulet orig_nametmoduletname_to_remove((s-/usr/local/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(tgetattrtAttributeErrorR@RAR5(tobjRCt attribute((s-/usr/local/lib/python2.7/test/test_support.pyR1s   iicCs |adS(N(t_original_stdout(tstdout((s-/usr/local/lib/python2.7/test/test_support.pyRscCs tp tjS(N(RdRGRe(((s-/usr/local/lib/python2.7/test/test_support.pyRscCs&ytj|=Wntk r!nXdS(N(RGRHRP(RC((s-/usr/local/lib/python2.7/test/test_support.pyR s twincCs|||r|}n$tjj|\}}|p:d}d}xR|dkrtj|}|rm|n ||ks}dStj||d9}qFWtjd|tdddS(NRFgMbP?g?is)tests may fail, delete still pending for t stackleveli( tostpathtsplittlistdirttimetsleepR9twarntRuntimeWarning(tfunctpathnametwaitalltdirnameRCttimeouttL((s-/usr/local/lib/python2.7/test/test_support.pyt_waitfors     cCsttj|dS(N(RvRhR (tfilename((s-/usr/local/lib/python2.7/test/test_support.pyt_unlinkscCsttj|dS(N(RvRhtrmdir(Rs((s-/usr/local/lib/python2.7/test/test_support.pyt_rmdirscs6fdt|dtttj|dS(Ncsuxntj|D]]}tjj||}tjj|r`t|dttj|qtj|qWdS(NRr( RhRkRitjointisdirRvRORyR (RiRCtfullname(t _rmtree_inner(s-/usr/local/lib/python2.7/test/test_support.pyR~s Rr(RvRORhRy(Ri((R~s-/usr/local/lib/python2.7/test/test_support.pyt_rmtreescCs&yt|Wntk r!nXdS(N(RxtOSError(Rw((s-/usr/local/lib/python2.7/test/test_support.pyR s cCs@yt|Wn+tk r;}|jtjkr<q<nXdS(N(RzRterrnotENOENT(Rsterror((s-/usr/local/lib/python2.7/test/test_support.pyRys cCsIyt|Wn4tk rD}|jtjtjfkrEqEnXdS(N(RRRRtESRCH(Rite((s-/usr/local/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 RGRiR RhR{textsep(RMRs((s-/usr/local/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| rtjdkry'ddlm}|}|j Wqt!k r}t"|}t#|dkrv|d d}ndj$t%|j&|}qXn|t_'| t_tjS(NtresultRfiitUSEROBJECTFLAGScs;eZdjjfdjjfdjjfgZRS(tfInheritt fReservedtdwFlags(R5R6twintypestBOOLtDWORDt_fields_((tctypes(s-/usr/local/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(R5R6R((R(s-/usr/local/lib/python2.7/test/test_support.pyR?s s#cannot run without OS X gui process(tTki2s [...]sTk unavailable due to {}: {}((thasattrt_is_gui_availableRRRRGtplatformRKRtctypes.wintypesRtwindlltuser32tGetProcessWindowStationtWinErrorRRtGetUserObjectInformationWtbyreftsizeoftboolRRRRt ctypes.utilRt LoadLibrarytCGMainDisplayIDtGetCurrentProcesstSetFrontProcesstTkinterRtdestroyt ExceptionRBtlentformatttypeR5treason(Rt UOI_FLAGSt WSF_VISIBLERtdllthtuoftneededtresRRRRt app_servicesRtpsntpsn_pRtrootRt err_string((RRs-/usr/local/lib/python2.7/test/test_support.pyRsd         "        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(RRR(tresource((s-/usr/local/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 RR(RRE((s-/usr/local/lib/python2.7/test/test_support.pyRds    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/local/lib/python2.7/test/test_support.pyRts 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/local/lib/python2.7/test/test_support.pyRs$ 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 isinstancetfloattabsRRttupleRJtrangetminRR(txtytfuzztitoutcome((s-/usr/local/lib/python2.7/test/test_support.pyRs-( ,iiitjavaii0iAiiii 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 RgiN(RRtunicodetencodeRGtgetfilesystemencodingtUnicodeEncodeErrorR@RARhtgetcwdRQtmkdirtchdirRORR9RnRoR (RCtquiett saved_dirt is_temporary((s-/usr/local/lib/python2.7/test/test_support.pyRas,         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(RhRitisabsRRR{RGRstexists(tfiletheretsubdirRitdntfn((s-/usr/local/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}(RVtsortR{(tdictRVtpairt reprpairst withcommas((s-/usr/local/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/local/lib/python2.7/test/test_support.pyt make_bad_fds  cCs|jtt|dddS(Ns texec(t assertRaisest SyntaxErrortcompile(ttestcaset statement((s-/usr/local/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(RRRtseekR(Rtf(tcheck(s-/usr/local/lib/python2.7/test/test_support.pytcheck_valid_files    turlfetchs fetching %s ...RtiRsinvalid resource "%s"(turlparseturllib2RjRhRiR{Rst__file__RRRR RRturlopenRtreadtwriteRR( turlRRRRwRRR toutts((Rs-/usr/local/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/local/lib/python2.7/test/test_support.pyt__init__s cCs\t|j|jkr,t|jd|S|tjjkrBdStd||fdS(Nis%r has no attribute %r( RRRR`R9tWarningMessaget_WARNING_DETAILSRRRa(Rtattr((s-/usr/local/lib/python2.7/test/test_support.pyt __getattr__s cCs|j|jS(N(RR(R((s-/usr/local/lib/python2.7/test/test_support.pyR9scCst|j|_dS(N(RRR(R((s-/usr/local/lib/python2.7/test/test_support.pytresets(R5R6R7RR#tpropertyR9R$(((s-/usr/local/lib/python2.7/test/test_support.pyRs   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__trecordR9talwaysNsunhandled warning %ris)filter (%r, %s) did not catch any warning(RGt _getframet f_globalstgettclearR9R:RORHt simplefilterRtmessageRQRBtretmatchtIt issubclasst __class__tremoveRUR5tAssertionError( tfiltersRtframetregistrytwtwarningtreraisetmissingREtcattseentexcR.((s-/usr/local/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+tWarningRRROR@(R6tkwargsR((s-/usr/local/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((RGt py3kwarningR<R@R+(R6RB((s-/usr/local/lib/python2.7/test/test_support.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(RGRHtcopytoriginal_modulesR5(Rt module_namest module_nameR^((s-/usr/local/lib/python2.7/test/test_support.pyROs  cCs|S(N((R((s-/usr/local/lib/python2.7/test/test_support.pyt __enter__\scGstjj|jdS(N(RGRHtupdateRE(Rt ignore_exc((s-/usr/local/lib/python2.7/test/test_support.pyt__exit___s(R5R6R7RRHRK(((s-/usr/local/lib/python2.7/test/test_support.pyRCs  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(Rhtenviront_environt_changed(R((s-/usr/local/lib/python2.7/test/test_support.pyRhs cCs |j|S(N(RM(Rtenvvar((s-/usr/local/lib/python2.7/test/test_support.pyt __getitem__lscCs<||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 ( R`RRRRRttgaierrorRRGtstderrRtargs(terrtn(tcaptured_errnostdeniedt gai_errnos(s-/usr/local/lib/python2.7/test/test_support.pyt filter_errors Niii(Rcio(Rdih(Reiq(Rfie(Rgin(Rhi(Rii(Rji(Rki(Rli*( RR`RRtgetdefaulttimeoutRRtsetdefaulttimeouttIOErrorRORoRR( t resource_nameRtterrnostdefault_errnostdefault_gai_errnosRCtnumRut old_timeoutRpta((RrRsRts-/usr/local/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(tStringIOR`RGtsetattr(t stream_nameRt orig_stdout((s-/usr/local/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") Re(R!(((s-/usr/local/lib/python2.7/test/test_support.pyR"scCs tdS(NRn(R!(((s-/usr/local/lib/python2.7/test/test_support.pytcaptured_stderrscCs tdS(Ntstdin(R!(((s-/usr/local/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(tgctcollectRRlRm(((s-/usr/local/lib/python2.7/test/test_support.pyt gc_collect"s  t2PtgettotalrefcounttPcCstjt|dS(Nt0P(tstructtcalcsizet_header(tfmt((s-/usr/local/lib/python2.7/test/test_support.pyt calcobjsize8scCstjt|dS(NR(RRt_vheader(R((s-/usr/local/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 _testcapiRGt getsizeofRt __flags__t_TPFLAGS_HEAPTYPEt_TPFLAGS_HAVE_GCtSIZEOF_PYGC_HEADt assertEqual(ttesttotsizeRRRE((s-/usr/local/lib/python2.7/test/test_support.pyt check_sizeofBs %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(tlocaleR`t setlocaleRaRR(RotkwdsRtcategoryt orig_localetloc(tcatstrRptlocales(s-/usr/local/lib/python2.7/test/test_support.pytinnerTs$    (t func_nameR7(RpR(RR(Rps-/usr/local/lib/python2.7/test/test_support.pyt decoratorSs  ((RRR((RRs-/usr/local/lib/python2.7/test/test_support.pyR%RscCsidd6td6td6dtd6}tjd|tjtjB}|dkrgtd|fntt |j d||j d j }|a |t krt }n|tdkrtd |fn|adS( NiRWtmtgtts(\d+(\.\d+)?) (K|M|G|T)b?$sInvalid memory limit %riis$Memory limit %r too low to be useful(t_1Mt_1GR/R0t IGNORECASEtVERBOSERRt ValueErrortintRtgrouptlowertreal_max_memusetMAX_Py_ssize_tt_2GR(tlimittsizesRtmemlimit((s-/usr/local/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 assertFalseRRRRGRnRR5tmax(Rtmaxsize(R tmemusetminsizetoverhead(s-/usr/local/lib/python2.7/test/test_support.pytwrappers"  (RRR(R R(RRR(R s-/usr/local/lib/python2.7/test/test_support.pyRs    ((RRRR((RRRs-/usr/local/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 (RRRGRnRR5(RR(tdry_runR RR(s-/usr/local/lib/python2.7/test/test_support.pyRs   (RRR(R R(RRRR(R s-/usr/local/lib/python2.7/test/test_support.pyRs    ((RRRRR((RRRRs-/usr/local/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 (RRRRGRnRR5(R(R (s-/usr/local/lib/python2.7/test/test_support.pyRs   ((R R((R s-/usr/local/lib/python2.7/test/test_support.pyR(scBseZdZRS(cCstj}|||S(N(R@t TestResult(RRR((s-/usr/local/lib/python2.7/test/test_support.pytruns  (R5R6R(((s-/usr/local/lib/python2.7/test/test_support.pyR)scCs|S(N((Rb((s-/usr/local/lib/python2.7/test/test_support.pyt_idscCsP|dkr&t r&tjtjSt|r6tStjdj|SdS(NRsresource {0!r} is not enabled(RR@tskipRR RR(R((s-/usr/local/lib/python2.7/test/test_support.pytrequires_resources  cCstdt|S(s9 Decorator for tests only applicable on CPython. tcpython(t impl_detailRO(R((s-/usr/local/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 ( R0RRRt _parse_guardstsortedRTRR{R@R(REtguardst guardnamestdefault((s-/usr/local/lib/python2.7/test/test_support.pyRs   cCs2|sitd6tfS|jd}|| fS(NRi(RORQtvalues(Rtis_true((s-/usr/local/lib/python2.7/test/test_support.pyRscKs.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/local/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( RR@tTextTestRunnerRGReR)Rt wasSuccessfulRterrorstfailuresR(tsuitetrunnerRRp((s-/usr/local/lib/python2.7/test/test_support.pyt _run_suites   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( R@t TestSuitetTestCaseRRBRGRHtaddTestt findTestCasesRt makeSuiteR(tclassest valid_typesRtcls((s-/usr/local/lib/python2.7/test/test_support.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( tdoctestRRRRGReRttestmodRR5(R^RRt save_stdoutR R((s-/usr/local/lib/python2.7/test/test_support.pyR+Js      cCstrtjfSdSdS(Ni(i(tthreadt_count(((s-/usr/local/lib/python2.7/test/test_support.pyR,rs cCsTts dSd}x=t|D]/}tj}||kr?PntjdqWdS(Ni g?(RRRRlRm(t nb_threadst _MAX_COUNTtcountRq((s-/usr/local/lib/python2.7/test/test_support.pyR-xs  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-(Rotkey(Rp(s-/usr/local/lib/python2.7/test/test_support.pyRs (Rt functoolstwraps(RpR((Rps-/usr/local/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(RRhRORtWNOHANG(t any_processtpidtstatus((s-/usr/local/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(RR`Rtdelattr(RbR"tnew_valtreal_val((s-/usr/local/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/local/lib/python2.7/test/test_support.pys sN(ttobytesRaR{t TypeErrortbytes(tb((s-/usr/local/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/local/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(Rn((s-/usr/local/lib/python2.7/test/test_support.pyR4s((ii@i@i@ii(i@ii((R7R5R?t contextlibRRRRRGRhRtshutilR9R@R>tUserDictR/RlRt sysconfigRRRt__all__RRRRARtcontextmanagerROR=RQRRNRTR3R1RRRRRdRRR RKRvRxRzRR RyR R RR RRtHOSTv6RRRRRRt PIPE_MAX_SIZEt SOCK_MAX_SIZERRt NameErrorRt FS_NONASCIItunichrt characterRRtdecodet UnicodeErrorRCRRtTESTFN_UNICODEtTESTFN_ENCODINGRRtTESTFN_UNENCODABLEtevalRRtgetpidRRRRRRRRRtobjectRR@RRRt DictMixinR RYR#R$R!R"RRRRRRRRRRR%RRRt_4GRRR&R'RR(R)RRR/RRR0RR*tget_config_vartHAVE_DOCSTRINGSt skipUnlesstrequires_docstringsR+R,R-RR.RR2RR4(((s-/usr/local/lib/python2.7/test/test_support.pyts                                 &     !         J  < $                        #   * ' /A         %     '         (