Lc:@sdZedjoednddkZddkZddkZddkZddkZddkZddk Z ddk Z ddk Z ddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5g1Z de fd6YZdefd7YZdefd8YZdefd9YZed:Zd;ZdZd<ad<adad=Zd>Zd?Zd@ZdAZdBZdCZ ddDZ!dEZ"ei#ei$dFZ%e"dGZ&dHZ'dIZ(ye)e*Z+Wne,j o eZ+nXei-i.dJZ/ei0dJjo dKZ1nei0dLjo dMZ1ndNZ1e+oe2dOe)o dPZ3ne)dPdQZ3ei4Z5e6edR pei7dSdTjo dZ8qOe9dUZ8ye8i:dVWne;j oqOXdWe8GHndZ<ye=e1dXZ<Wnie>j o]ei?i@dYe1ZAye=eAdXZ<eAZ1[AWqe>j odZe1eAfGHqXnXe<dj oe<iBee1n[<eCdd[ZDd\d]ZEd^ZFd_ZGd`ZHdaZIdbZJdceKfddYZLedeZMeiNdfZOeiNdgZPd%eKfdhYZQd&eKfdiYZRd)eKfdjYZSdkZTeiNdlZUdmZVdnZWd~ZXdoeXZYdTeYZZdpeYZ[ei\Z]dqZ^dreXdsZ_dreXdtZ`duZad/ddvYZbdwZcdxZdddyZedzZfd{Zgd|Zhd}ZidS(s7Supporting definitions for the Python regression tests.stest.test_supports3test_support must be imported from the test packageiNtErrort TestFailedt TestSkippedtResourceDeniedt import_moduletverboset use_resourcest max_memusetrecord_original_stdouttget_original_stdouttunloadtunlinktrmtreetforgettis_resource_enabledtrequirestfind_unused_portt bind_porttfcmpt have_unicodet is_jythontTESTFNtHOSTtFUZZtfindfiletverifytvereqtsortdicttcheck_syntax_errortopen_urlresourcetcheck_warningst_check_py3k_warningst CleanImporttEnvironmentVarGuardtcaptured_outputtcaptured_stdouttTransientResourcettransient_internettrun_with_localet set_memlimitt bigmemtesttbigaddrspacetesttBasicTestRunnert run_unittestt run_doctesttthreading_setuptthreading_cleanupt reap_childrentstrip_python_stderrcBseZdZRS(s*Base class for regression test exceptions.(t__name__t __module__t__doc__(((s)/usr/lib64/python2.6/test/test_support.pyRscBseZdZRS(s Test failed.(R1R2R3(((s)/usr/lib64/python2.6/test/test_support.pyR scBseZdZRS(s!Test skipped. This can be raised to indicate that a test was deliberatly skipped, but not because a feature wasn't available. For example, if some resource can't be used, such as the network appears to be unavailable, this should be raised instead of TestFailed. (R1R2R3(((s)/usr/lib64/python2.6/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 be enabled. It is used to distinguish between expected and unexpected skips. (R1R2R3(((s)/usr/lib64/python2.6/test/test_support.pyR-sc Cstiiizb|otiddtnyt|dd}Wn#tj otd|nX|SWdQXdS(sOImport the module to be tested, raising TestSkipped if it is not available.tignores.+ (module|package)tlevelisNo module named N( twarningstcatch_warningst__exit__t __enter__tfilterwarningstDeprecationWarningt __import__t ImportErrorR(tnamet deprecatedtmodule((s)/usr/lib64/python2.6/test/test_support.pyR5s  iicCs |adS(N(t_original_stdout(tstdout((s)/usr/lib64/python2.6/test/test_support.pyRMscCstptiS(N(RAtsysRB(((s)/usr/lib64/python2.6/test/test_support.pyR QscCs(yti|=Wntj onXdS(N(RCtmodulestKeyError(R>((s)/usr/lib64/python2.6/test/test_support.pyR TscCs+yti|Wntj onXdS(N(tosR tOSError(tfilename((s)/usr/lib64/python2.6/test/test_support.pyR ZscCsPyti|Wn8tj o,}|ititifjoqLnXdS(N(tshutilR RGterrnotENOENTtESRCH(tpathte((s)/usr/lib64/python2.6/test/test_support.pyR `s cCsjt|xYtiD]N}ttii||tidttii||tidqWdS(sm"Forget" a module was ever imported by removing it from sys.modules and deleting any .pyc and .pyo files.tpyctpyoN(R RCRMR RFtjointextsep(tmodnametdirname((s)/usr/lib64/python2.6/test/test_support.pyR hs   $cCstdj o |tjS(sPTest whether a resource is enabled. Known resources are set by regrtest.py.N(RtNone(tresource((s)/usr/lib64/python2.6/test/test_support.pyRsscCsctiiiiddjodSt|p+|djod|}nt|ndS(sRaise ResourceDenied if the specified resource is not available. If the caller's module is __main__ then automatically return True. The possibility of False being returned occurs when regrtest.py is executing.R1t__main__Ns$Use of the `%s' resource not enabled(RCt _getframetf_backt f_globalstgetRRUR(RVtmsg((s)/usr/lib64/python2.6/test/test_support.pyRxs "  t localhostcCs/ti||}t|}|i~|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.6/test/test_support.pyRs 6  cCs|itijo|itijottdo3|ititidjot dqinttdoCdt i jo3|ititi djot dqnttdo|i titidqn|i|df|id}|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_REUSEPORTtWITHIN_PYTHON_RPM_BUILDsHtests should never set the SO_REUSEPORT socket option on TCP/IP sockets!tSO_EXCLUSIVEADDRUSEi(R`R^tAF_INETttypet SOCK_STREAMthasattrt getsockoptt SOL_SOCKETRdRRFtenvironRet setsockoptRgtbindt getsockname(tsockthostRc((s)/usr/lib64/python2.6/test/test_support.pyRs&!gư>cCs-t|tpt|toHy:t|t|t}t|||jodSWqqXnt|t|jot|ttfoxRttt |t |D]/}t ||||}|djo|SqWt |t |jt |t |jS||j||jS(Ni( t isinstancetfloattabsRRittupletlisttrangetmintlenR(txtytfuzztitoutcome((s)/usr/lib64/python2.6/test/test_support.pyRs  /"  -tjavas$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 effectivesw+s/tmps6WARNING: tests will fail, unable to write to: %s or %scCstii|o|S|dj otii||}nti}tii|g|}x;|D]3}tii||}tii|o|SqgW|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(RFRMtisabsRURQRCRTtexists(tfiletheretsubdirRMtdntfn((s)/usr/lib64/python2.6/test/test_support.pyR=s   s test failedcCs|pt|ndS(sVerify that condition is true. If not, raise TestFailed. The optional argument reason can be given to provide a better error text. N(R(t conditiontreason((s)/usr/lib64/python2.6/test/test_support.pyRLscCs+||jptd||fndS(s$Raise TestFailed if a == b is false. This is better than verify(a == b) because, in case of failure, the error message incorporates repr(a) and repr(b) so you can see the inputs. Note that "not (a == b)" isn't necessarily the same as "a != b"; the former is tested. s%r == %rN(R(tatb((s)/usr/lib64/python2.6/test/test_support.pyRVs cCsR|i}|ig}|D]}|d|q!~}di|}d|S(s%Like repr(dict), but in sorted order.s%r: %rs, s{%s}(titemstsortRQ(tdictRt_[1]tpairt reprpairst withcommas((s)/usr/lib64/python2.6/test/test_support.pyRds   %cCs9ttd}z|iSWd|ittXdS(s` Create an invalid file descriptor by opening and closing a file and return its fd. twbN(topenRtfilenoR_R (R((s)/usr/lib64/python2.6/test/test_support.pyt make_bad_fdls  cCs?yt|ddWntj onX|id|dS(Ns texecsMissing SyntaxError: "%s"(tcompilet SyntaxErrortfail(ttestcaset statement((s)/usr/lib64/python2.6/test/test_support.pyRxs c Cs:ddk}ddk}td|i|didd}xStiitiigD]9}tii||}tii |o t |Sq[Wt d|IJ|i |dd}zdt |di i}zA|~}|i} x%| o|i| |i} qWWdQXWd|iXt |S( Niturlfetchit/s fetching %s ...ttimeoutiR(turlparseturllib2RtsplitRFRMtcurdirtpardirRQRRR turlopenR8R9treadtwriteR_( turlRRRHRMRtfRtoutts((s)/usr/lib64/python2.6/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/lib64/python2.6/test/test_support.pyt__init__s cCs`t|i|ijot|id|S|tiijodStd||fdS(Nis%r has no attribute %r( R{RRtgetattrR6tWarningMessaget_WARNING_DETAILSRUtAttributeError(Rtattr((s)/usr/lib64/python2.6/test/test_support.pyt __getattr__s cCs|i|iS(N(RR(R((s)/usr/lib64/python2.6/test/test_support.pyR6scCst|i|_dS(N(R{RR(R((s)/usr/lib64/python2.6/test/test_support.pytresets(R1R2R3RRtpropertyR6R(((s)/usr/lib64/python2.6/test/test_support.pyRs   c cstid}|iid}|o|intidtii }z,|~}ti di dt |VWdQXg}|D]}||i q~}g} x|D]\} } t} x^|D]U} t| }ti| |tio*t| i| ot} |i| qqW| o"| o| i| | ifqqW|otd|dn| otd | 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__trecordR6talwaysNsunhandled warning %ris)filter (%r, %s) did not catch any warning(RCRXRZR[tclearR6R7tTrueR8R9RDt simplefilterRtmessagetFalsetstrtretmatchtIt issubclasst __class__tremovetappendR1tAssertionError(tfilterstquiettframetregistryRtwt_[2]twarningtreraisetmissingR\tcattseentexcR((s)/usr/lib64/python2.6/test/test_support.pyt_filterwarningss4)$  cOsM|id}|p*dtff}|djo 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[tWarningRURR(RtkwargsR((s)/usr/lib64/python2.6/test/test_support.pyRs  cOsDtio|pdtff}q.nd}t||idS(skContext 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((RCt py3kwarningR;RR[(RR((s)/usr/lib64/python2.6/test/test_support.pyRs  cBs)eZdZdZdZdZRS(sContext 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"): __import__("foo") # new reference cGsstii|_xZ|D]R}|tijo<ti|}|i|joti|i=nti|=qqWdS(N(RCRDtcopytoriginal_modulesR1(Rt module_namest module_nameR@((s)/usr/lib64/python2.6/test/test_support.pyRs cCs|S(N((R((s)/usr/lib64/python2.6/test/test_support.pyR9scGstii|idS(N(RCRDtupdateR(Rt ignore_exc((s)/usr/lib64/python2.6/test/test_support.pyR8!s(R1R2R3RR9R8(((s)/usr/lib64/python2.6/test/test_support.pyR s  cBs;eZdZdZdZdZdZdZRS(s_Class to help protect the environment variable properly. Can be used as a context manager.cCs h|_dS(N(t_changed(R((s)/usr/lib64/python2.6/test/test_support.pyR*scCs>||ijotii||i|t save_stdoutRR((s)/usr/lib64/python2.6/test/test_support.pyR,=s      cCs(ddk}t|it|ifS(Ni(t threadingR{t_activet_limbo(RA((s)/usr/lib64/python2.6/test/test_support.pyR-]s cCsddk}ddk}d}d}x?t|i|jo(||jo|d7}|idq'Wd}x?t|i|jo(||jo|d7}|idqoWdS(Nii iig?(RAttimeR{RBtsleepRC(t num_activet num_limboRARDt _MAX_COUNTtcount((s)/usr/lib64/python2.6/test/test_support.pyR.as  # # cCsittdoUd}xLto@y1ti|ti\}}|djoPnWqPqXqWndS(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(RkRFRRJtWNOHANG(t any_processtpidtstatus((s)/usr/lib64/python2.6/test/test_support.pyR/ps   cCstidd|i}|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(Rtsubtstrip(R((s)/usr/lib64/python2.6/test/test_support.pyR0si((jR3R1R=RRJR^RCRFRIR6R(Rt__all__t ExceptionRRRRRRRRURRRRARR R R R R RRRRhRjRRRRtunicodeRRt NameErrortplatformt startswithRR>RRttTESTFN_UNICODEtgetfilesystemencodingtTESTFN_ENCODINGRkRtTESTFN_UNICODE_UNENCODEABLEtevaltencodetUnicodeEncodeErrortfpRRRMRQt TMP_TESTFNR_t__file__RRRRRRRtobjectRRtcontextmanagerRRR R!R$R%R"R#R&RRRt_4GR!RR'R(R'R)R*R5R+R,R-R.R/R0(((s)/usr/lib64/python2.6/test/test_support.pyts                          <                  ' !   %     '