
6	Pc        7   @   sg  d  Z  e d k r! e d   n  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z y d d l Z Wn e k
 r d Z n Xd d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d2 d3 d9 g7 Z d e f d:     YZ d e f d;     YZ d e j f d<     YZ e j e d=   Z e d>  Z d?   Z d@   Z  d d e dA  Z! dB   Z" dC Z# d Z$ dD a% dD a& d a' dE   Z( dF   Z) dG   Z* dH   Z+ dI   Z, dJ   Z- dK   Z. d dL  Z/ dM Z0 e j1 e j2 dN  Z3 e0 dO  Z4 dP Z5 dQ   Z6 y e7 e Z8 Wn e9 k
 re Z8 n Xe j
 j: dR  Z; e	 j< dR k r.dS Z= n e	 j< dT k rFdU Z= n dV Z= e8 re> dW e7  rjdX Z? n e7 dX dY  Z? e j@   ZA eB e dZ  se jC   d[ d\ k  rd ZD qeE d]  ZD y eD jF d^  Wn eG k
 rqXd_ eD GHn  d` jH e= e	 jI    Z= e	 jJ   ZK e j da e db   ZL eM d dc  ZN dd   ZO de   ZP df   ZQ d dg  ZR dh eS f di     YZT e dj  ZU e j dk    ZV e j dl    ZW d$ eS f dm     YZX d% e jY f dn     YZZ do eS f dp     YZ[ d( eS f dq     YZ\ e j dr d ds   Z] e j dt    Z^ du   Z_ dv   Z` dw   Za dx   Zb dy   Zc d Zd dz ed Ze d\ ee Zf d{ ee Zg e jh Zi d|   Zj d} ed d~  Zk d} ed d  Zl d   Zm d. d d     YZn d   Zo d   Zp d   Zq d d  Zr d   Zs d   Zt d   Zu d   Zv d d  Zw d   Zx d   Zy d   Zz d   Z{ d   Z| d   Z} d   Z~ d S(   s7   Supporting definitions for the Python regression tests.s   test.test_supports3   test_support must be imported from the test packageiNt   Errort
   TestFailedt   ResourceDeniedt   import_modulet   verboset   use_resourcest
   max_memuset   record_original_stdoutt   get_original_stdoutt   unloadt   unlinkt   rmtreet   forgett   is_resource_enabledt   requirest   find_unused_portt	   bind_portt   fcmpt   have_unicodet	   is_jythont   TESTFNt   HOSTt   FUZZt   SAVEDCWDt   temp_cwdt   findfilet   sortdictt   check_syntax_errort   open_urlresourcet   check_warningst   check_py3k_warningst   CleanImportt   EnvironmentVarGuardt   captured_outputt   captured_stdoutt   TransientResourcet   transient_internett   run_with_localet   set_memlimitt
   bigmemtestt   bigaddrspacetestt   BasicTestRunnert   run_unittestt   run_doctestt   threading_setupt   threading_cleanupt   reap_childrent   cpython_onlyt   check_impl_detailt   get_attributet
   py3k_bytest   import_fresh_modulet   strip_python_stderrc           B   s   e  Z d  Z RS(   s*   Base class for regression test exceptions.(   t   __name__t
   __module__t   __doc__(    (    (    s'   /usr/lib/python2.7/test/test_support.pyR    *   s   c           B   s   e  Z d  Z RS(   s   Test failed.(   R5   R6   R7   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR   -   s   c           B   s   e  Z d  Z RS(   s   Test 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.
    (   R5   R6   R7   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR   0   s   c         c   s=   |  r4 t  j    t  j d d t  d VWd QXn d Vd S(   s   Context manager to suppress package and module deprecation
    warnings when importing them.

    If ignore is False, this context manager has no effect.t   ignores   .+ (module|package)N(   t   warningst   catch_warningst   filterwarningst   DeprecationWarning(   R8   (    (    s'   /usr/lib/python2.7/test/test_support.pyt   _ignore_deprecated_imports8   s    c      	   C   sS   t  |  A y t j |   SWn( t k
 rH } t j t |    n XWd QXd S(   s   Import 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	   importlibR   t   ImportErrort   unittestt   SkipTestt   str(   t   namet
   deprecatedt   msg(    (    s'   /usr/lib/python2.7/test/test_support.pyR   G   s
    c         C   s   |  t  j k r& t |   t  j |  =n  xT t t  j  D]C } | |  k s[ | j |  d  r6 t  j | | | <t  j | =q6 q6 Wd S(   sw   Helper function to save and remove a module from sys.modules

       Raise ImportError if the module can't be imported.t   .N(   t   syst   modulest
   __import__t   listt
   startswith(   RC   t   orig_modulest   modname(    (    s'   /usr/lib/python2.7/test/test_support.pyt   _save_and_remove_moduleT   s    
c         C   sF   t  } y t j |  | |  <Wn t k
 r4 t } n Xd t j |  <| S(   s   Helper function to save and block a module in sys.modules

       Return True if the module was in sys.modules, False otherwise.N(   t   TrueRG   RH   t   KeyErrort   Falset   None(   RC   RL   t   saved(    (    s'   /usr/lib/python2.7/test/test_support.pyt   _save_and_block_modulea   s    
c         C   s   t  |   i  } g  } t |  |  z ya x | D] } t | |  q3 Wx- | D]% } t | |  sQ | j |  qQ qQ Wt j |   } Wn t k
 r d } n XWd x' | j   D] \ }	 }
 |
 t	 j
 |	 <q Wx | D] } t	 j
 | =q WX| SWd QXd S(   s  Imports and returns a module, deliberately bypassing the sys.modules cache
    and importing a fresh copy of the module. Once the import is complete,
    the sys.modules cache is restored to its original state.

    Modules named in fresh are also imported anew if needed by the import.
    If one of these modules can't be imported, None is returned.

    Importing of modules named in blocked is prevented while the fresh import
    takes place.

    If deprecated is True, any module or package deprecation messages
    will be suppressed.N(   R=   RN   RT   t   appendR>   R   R?   RR   t   itemsRG   RH   (   RC   t   fresht   blockedRD   RL   t   names_to_removet
   fresh_namet   blocked_namet   fresh_modulet	   orig_namet   modulet   name_to_remove(    (    s'   /usr/lib/python2.7/test/test_support.pyR3   n   s&     c         C   sK   y t  |  |  } Wn- t k
 rB t j d |  j | f   n X| Sd S(   s?   Get an attribute, raising SkipTest if AttributeError is raised.s   module %s has no attribute %sN(   t   getattrt   AttributeErrorR@   RA   R5   (   t   objRC   t	   attribute(    (    s'   /usr/lib/python2.7/test/test_support.pyR1      s    	i   i    c         C   s
   |  a  d  S(   N(   t   _original_stdout(   t   stdout(    (    s'   /usr/lib/python2.7/test/test_support.pyR      s    c           C   s   t  p t j S(   N(   Rd   RG   Re   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR      s    c         C   s&   y t  j |  =Wn t k
 r! n Xd  S(   N(   RG   RH   RP   (   RC   (    (    s'   /usr/lib/python2.7/test/test_support.pyR	      s    c         C   s)   y t  j |   Wn t k
 r$ n Xd  S(   N(   t   osR
   t   OSError(   t   filename(    (    s'   /usr/lib/python2.7/test/test_support.pyR
      s    c         C   sL   y t  j |   Wn4 t k
 rG } | j t j t j f k rH   qH n Xd  S(   N(   t   shutilR   Rg   t   errnot   ENOENTt   ESRCH(   t   patht   e(    (    s'   /usr/lib/python2.7/test/test_support.pyR      s
    c         C   sj   t  |   xY t j D]N } t t j j | |  t j d   t t j j | |  t j d   q Wd S(   sm   "Forget" a module was ever imported by removing it from sys.modules and
    deleting any .pyc and .pyo files.t   pyct   pyoN(   R	   RG   Rm   R
   Rf   t   joint   extsep(   RM   t   dirname(    (    s'   /usr/lib/python2.7/test/test_support.pyR      s    
$c         C   s   t  d k	 o |  t  k S(   sP   Test whether a resource is enabled.  Known resources are set by
    regrtest.py.N(   R   RR   (   t   resource(    (    s'   /usr/lib/python2.7/test/test_support.pyR      s    c         C   s]   t  j d  j j d  d k r% d St |   sY | d k rJ d |  } n  t |   n  d S(   s   Raise 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.i   R5   t   __main__Ns$   Use of the `%s' resource not enabled(   RG   t	   _getframet	   f_globalst   getR   RR   R   (   Rt   RE   (    (    s'   /usr/lib/python2.7/test/test_support.pyR      s    !t	   localhostc         C   s/   t  j  |  |  } 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.(   t   socketR   t   close(   t   familyt   socktypet   tempsockt   port(    (    s'   /usr/lib/python2.7/test/test_support.pyR      s
    6
c         C   s   |  j  t j k r |  j t j k r t t d  rc |  j t j t j  d k rc t	 d   qc n  t t d  r |  j t j t j
  d k r t	 d   q n  t t d  r |  j t j t j d  q n  |  j | d f  |  j   d } | 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_REUSEADDRi   sH   tests should never set the SO_REUSEADDR socket option on TCP/IP sockets!t   SO_REUSEPORTsH   tests should never set the SO_REUSEPORT socket option on TCP/IP sockets!t   SO_EXCLUSIVEADDRUSEi    (   R|   Rz   t   AF_INETt   typet   SOCK_STREAMt   hasattrt
   getsockoptt
   SOL_SOCKETR   R   R   t
   setsockoptR   t   bindt   getsockname(   t   sockt   hostR   (    (    s'   /usr/lib/python2.7/test/test_support.pyR      s    $gư>c         C   s#  t  |  t  s t  | t  rc y8 t |   t |  t } t |  |  | k rU d SWqqXn t |   t |  k rt  |  t t f  rxP t t t	 |   t	 |    D]- } t
 |  | | |  } | d k r | Sq Wt	 |   t	 |  k t	 |   t	 |  k  S|  | k |  | k  S(   Ni    (   t
   isinstancet   floatt   absR   R   t   tupleRJ   t   ranget   mint   lenR   (   t   xt   yt   fuzzt   it   outcome(    (    s'   /usr/lib/python2.7/test/test_support.pyR   @  s    -(,t   javas   $testt   riscost   testfiles   @testt    s   @test-s   latin-1t   getwindowsversioni   i   s'   u"@test-\u5171\u6709\u3055\u308c\u308b"t   Latin1sg   WARNING: The filename %r CAN be encoded by the filesystem.  Unicode filename tests may not be effectives	   {}_{}_tmpt   tempcwdc         c   s  t  |  t  r] y |  j t j   p' d  }  Wq] t k
 rY | sZ t j d   qZ q] Xn  t j	   } t
 } y$ t j |   t j |   t } Wn7 t k
 r | s   n  t j d |  t d d n Xz t j	   VWd t j |  | r t |   n  Xd S(   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.
    t   asciis;   unable to encode the cwd name with the filesystem encoding.s,   tests may fail, unable to change the CWD to t
   stackleveli   N(   R   t   unicodet   encodeRG   t   getfilesystemencodingt   UnicodeEncodeErrorR@   RA   Rf   t   getcwdRQ   t   mkdirt   chdirRO   Rg   R9   t   warnt   RuntimeWarningR   (   RC   t   quiett	   saved_dirt   is_temporary(    (    s'   /usr/lib/python2.7/test/test_support.pyR     s,    

c         C   s   t  j j |   r |  S| d k	 r: t  j j | |   }  n  t j } t  j j |  g | } x9 | D]1 } t  j j | |   } t  j j |  rc | Sqc W|  S(   s   Try 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(   Rf   Rm   t   isabsRR   Rq   RG   Rs   t   exists(   t   filet   heret   subdirRm   t   dnt   fn(    (    s'   /usr/lib/python2.7/test/test_support.pyR     s    	 c         C   sJ   |  j    } | j   g  | D] } d | ^ q } d j |  } d | S(   s%   Like repr(dict), but in sorted order.s   %r: %rs   , s   {%s}(   RV   t   sortRq   (   t   dictRV   t   pairt	   reprpairst
   withcommas(    (    s'   /usr/lib/python2.7/test/test_support.pyR     s
    
c          C   s9   t  t d  }  z |  j   SWd |  j   t t  Xd S(   s`   
    Create an invalid file descriptor by opening and closing a file and return
    its fd.
    t   wbN(   t   openR   t   filenoR{   R
   (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyt   make_bad_fd  s
    
c         C   s   |  j  t t | d d  d  S(   Ns   <test string>t   exec(   t   assertRaisest   SyntaxErrort   compile(   t   testcaset	   statement(    (    s'   /usr/lib/python2.7/test/test_support.pyR     s    c   
         sb  d d  l  } d d  l } | j  |   d j d  d } t j j t j j t  d |  }   f d   } t j j |  r | |  } | d  k	 r | St
 |  n  t d  t   d |  IJ| j |  d d	 } zN t | d
  9 } | j   }	 x# |	 r| j |	  | j   }	 q WWd  QXWd  | j   X| |  } | d  k	 rN| St d |   d  S(   Nii   t   /t   datac            sG   t  |   }   d  k r | S  |  r9 | j d  | S| j   d  S(   Ni    (   R   RR   t   seekR{   (   R   t   f(   t   check(    s'   /usr/lib/python2.7/test/test_support.pyt   check_valid_file  s    t   urlfetchs   	fetching %s ...t   timeouti   R   s   invalid resource "%s"(   t   urlparset   urllib2t   splitRf   Rm   Rq   Rs   t   __file__R   RR   R
   R   R   t   urlopenR   t   readt   writeR{   R   (
   t   urlR   R   R   Rh   R   R   R   t   outt   s(    (   R   s'   /usr/lib/python2.7/test/test_support.pyR     s.     $	
	t   WarningsRecorderc           B   s8   e  Z d  Z d   Z d   Z e d    Z d   Z RS(   sy   Convenience wrapper for the warnings list returned on
       entry to the warnings.catch_warnings() context manager.
    c         C   s   | |  _  d |  _ d  S(   Ni    (   t	   _warningst   _last(   t   selft   warnings_list(    (    s'   /usr/lib/python2.7/test/test_support.pyt   __init__  s    	c         C   s\   t  |  j  |  j k r, t |  j d |  S| t j j k rB d  St d |  | f   d  S(   Nis   %r has no attribute %r(	   R   R   R   R`   R9   t   WarningMessaget   _WARNING_DETAILSRR   Ra   (   R   t   attr(    (    s'   /usr/lib/python2.7/test/test_support.pyt   __getattr__  s
    c         C   s   |  j  |  j S(   N(   R   R   (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR9     s    c         C   s   t  |  j  |  _ d  S(   N(   R   R   R   (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyt   reset  s    (   R5   R6   R7   R   R   t   propertyR9   R   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR     s
   		c         c   sp  t  j d  } | j j d  } | r4 | j   n  t j d t  & } t  j d j	 d  t
 |  VWd QXg  | D] } | j ^ qu } g  } x |  D] \ } }	 t }
 x[ | D]R } t |  } t j | | t j  r t | j |	  r t }
 | j |  q q W|
 r | r | j | |	 j f  q q W| rOt d | d   n  | rlt d	 | d   n  d S(
   s   Catch 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.
    i   t   __warningregistry__t   recordR9   t   alwaysNs   unhandled warning %ri    s)   filter (%r, %s) did not catch any warning(   RG   Rv   Rw   Rx   t   clearR9   R:   RO   RH   t   simplefilterR   t   messageRQ   RB   t   ret   matcht   It
   issubclasst	   __class__t   removeRU   R5   t   AssertionError(   t   filtersR   t   framet   registryt   wt   warningt   reraiset   missingRE   t   catt   seent   excR   (    (    s'   /usr/lib/python2.7/test/test_support.pyt   _filterwarnings  s0    c          O   sI   | j  d  } |  s< d t f f }  | d k r< t } q< n  t |  |  S(   s  Context manager to silence warnings.

    Accept 2-tuples as positional arguments:
        ("message regexp", WarningCategory)

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default True without argument,
         default False if some filters are defined)

    Without argument, it defaults to:
        check_warnings(("", Warning), quiet=True)
    R   R   N(   Rx   t   WarningRR   RO   R   (   R   t   kwargsR   (    (    s'   /usr/lib/python2.7/test/test_support.pyR   A  s    c          O   s@   t  j r$ |  s* d t f f }  q* n d }  t |  | j d   S(   sj  Context 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)
    R   R   (    (   RG   t   py3kwarningR<   R   Rx   (   R   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR   Y  s
    	c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   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
    c         G   so   t  j j   |  _ xV | D]N } | t  j k r t  j | } | j | k rZ t  j | j =n  t  j | =q q Wd  S(   N(   RG   RH   t   copyt   original_modulesR5   (   R   t   module_namest   module_nameR^   (    (    s'   /usr/lib/python2.7/test/test_support.pyR   |  s    c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyt	   __enter__  s    c         G   s   t  j j |  j  d  S(   N(   RG   RH   t   updateR   (   R   t
   ignore_exc(    (    s'   /usr/lib/python2.7/test/test_support.pyt   __exit__  s    (   R5   R6   R7   R   R  R  (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR   p  s   
		c           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s_   Class to help protect the environment variable properly.  Can be used as
    a context manager.c         C   s   t  j |  _ i  |  _ d  S(   N(   Rf   t   environt   _environt   _changed(   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR     s    c         C   s   |  j  | S(   N(   R  (   R   t   envvar(    (    s'   /usr/lib/python2.7/test/test_support.pyt   __getitem__  s    c         C   s<   | |  j  k r+ |  j j |  |  j  | <n  | |  j | <d  S(   N(   R  R  Rx   (   R   R	  t   value(    (    s'   /usr/lib/python2.7/test/test_support.pyt   __setitem__  s    c         C   sK   | |  j  k r+ |  j j |  |  j  | <n  | |  j k rG |  j | =n  d  S(   N(   R  R  Rx   (   R   R	  (    (    s'   /usr/lib/python2.7/test/test_support.pyt   __delitem__  s    c         C   s   |  j  j   S(   N(   R  t   keys(   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    c         C   s   | |  | <d  S(   N(    (   R   R	  R  (    (    s'   /usr/lib/python2.7/test/test_support.pyt   set  s    c         C   s   |  | =d  S(   N(    (   R   R	  (    (    s'   /usr/lib/python2.7/test/test_support.pyt   unset  s    c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    c         G   sh   xU |  j  j   D]D \ } } | d  k rG | |  j k rT |  j | =qT q | |  j | <q W|  j t _ d  S(   N(   R  RV   RR   R  Rf   R  (   R   R  t   kt   v(    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    (   R5   R6   R7   R   R
  R  R  R  R  R  R  R  (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR      s   								t   DirsOnSysPathc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s  Context manager to temporarily add directories to sys.path.

    This makes a copy of sys.path, appends any directories given
    as positional arguments, then reverts sys.path to the copied
    settings when the context ends.

    Note that *all* sys.path modifications in the body of the
    context manager, including replacement of the object,
    will be reverted at the end of the block.
    c         G   s-   t  j |  _ t  j |  _ t  j j |  d  S(   N(   RG   Rm   t   original_valuet   original_objectt   extend(   R   t   paths(    (    s'   /usr/lib/python2.7/test/test_support.pyR     s    c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    c         G   s   |  j  t _ |  j t j (d  S(   N(   R  RG   Rm   R  (   R   R  (    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    (   R5   R6   R7   R   R  R  (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR    s   
		c           B   s2   e  Z d  Z d   Z d   Z d d d d  Z RS(   s   Raise ResourceDenied if an exception is raised while the context manager
    is in effect that matches the specified exception and attributes.c         K   s   | |  _  | |  _ d  S(   N(   R   t   attrs(   R   R   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR     s    	c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    c         C   s}   | d k	 ry t |  j |  ry xX |  j j   D]8 \ } } t | |  sM Pn  t | |  | k r. Pq. q. Wt d   n  d S(   s   If type_ is a subclass of self.exc and value has attributes matching
        self.attrs, raise ResourceDenied.  Otherwise let the exception
        propagate (if any).s%   an optional resource is not availableN(   RR   R   R   R  t	   iteritemsR   R`   R   (   R   t   type_R  t	   tracebackR   t
   attr_value(    (    s'   /usr/lib/python2.7/test/test_support.pyR    s    N(   R5   R6   R7   R   R  RR   R  (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR#     s   		g      >@c         #   s  d d d d d g } d d d g } t  d |     |  g    s g  | D] \ } } t t | |  ^ qM  g  | D] \ } } t t | |  ^ qx  n      f d   } t j   } z y% | d k	 r t j |  n  d VWn t k
 r}	 xx t rt|	 j	 }
 t
 |
  d k r>t |
 d t  r>|
 d }	 q t
 |
  d k rpt |
 d t  rp|
 d }	 q Pq W| |	    n XWd t j |  Xd S(   s   Return a context manager that raises ResourceDenied when various issues
    with the Internet connection manifest themselves as exceptions.t   ECONNREFUSEDio   t
   ECONNRESETih   t   EHOSTUNREACHiq   t   ENETUNREACHie   t	   ETIMEDOUTin   t	   EAI_AGAINit
   EAI_NONAMEit
   EAI_NODATAis   Resource '%s' is not availablec            s   t  |  d d   } t |  t j  sN t |  t j  rB |  k sN |  k r{ t sr t j j	   j
 d d  n     n  d  S(   NRj   i    s   
(   R`   RR   R   Rz   R   t   gaierrorR   RG   t   stderrR   t   args(   t   errt   n(   t   deniedt
   gai_errnost   captured_errnos(    s'   /usr/lib/python2.7/test/test_support.pyt   filter_error  s    Ni   i    i   (   R  io   (   R  ih   (   R  iq   (   R   ie   (   R!  in   (   R"  i(   R#  i(   R$  i(   R   R`   Rj   Rz   t   getdefaulttimeoutRR   t   setdefaulttimeoutt   IOErrorRO   R'  R   R   (   t   resource_nameR   t   errnost   default_errnost   default_gai_errnosRC   t   numR-  t   old_timeoutR(  t   a(    (   R*  R+  R,  s'   /usr/lib/python2.7/test/test_support.pyR$     sD    		(+	 			%%
c         c   s[   d d l  } t t |   } t t |  | j     z t t |   VWd t t |  |  Xd S(   s   Return a context manager used by captured_stdout and captured_stdin
    that temporarily replaces the sys stream *stream_name* with a StringIO.iN(   t   StringIOR`   RG   t   setattr(   t   stream_nameR8  t   orig_stdout(    (    s'   /usr/lib/python2.7/test/test_support.pyR!   0  s    c           C   s
   t  d  S(   s   Capture the output of sys.stdout:

       with captured_stdout() as s:
           print "hello"
       self.assertEqual(s.getvalue(), "hello")
    Re   (   R!   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR"   <  s    c           C   s
   t  d  S(   NR&  (   R!   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyt   captured_stderrE  s    c           C   s
   t  d  S(   Nt   stdin(   R!   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyt   captured_stdinH  s    c           C   s8   t  j   t r  t j d  n  t  j   t  j   d S(   s  Force 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(   t   gct   collectR   t   timet   sleep(    (    (    s'   /usr/lib/python2.7/test/test_support.pyt
   gc_collectK  s
    


c            s      f d   } | S(   Nc            s1       f d   }   j  | _    j | _ | S(   Nc             s   y. d d  l  } t |    } | j |  } Wn$ t k
 rD   nA d  } } n1 Xx-  D]% } y | j | |  PWq\ q\ Xq\ Wz  |  |   SWd  | r | r | j | |  n  Xd  S(   Ni(   t   localeR`   t	   setlocaleRa   RR   (   R'  t   kwdsRD  t   categoryt   orig_localet   loc(   t   catstrt   funct   locales(    s'   /usr/lib/python2.7/test/test_support.pyt   innerb  s$    (   t	   func_nameR7   (   RK  RM  (   RL  RJ  (   RK  s'   /usr/lib/python2.7/test/test_support.pyt	   decoratora  s    (    (   RJ  RL  RO  (    (   RL  RJ  s'   /usr/lib/python2.7/test/test_support.pyR%   `  s    i   i   c         C   s   i d d 6t  d 6t d 6d t d 6} t j d |  t j t j B } | d  k rg t d |  f   n  t t	 | j
 d   | | j
 d	  j    } | a | t k r t } n  | t d k  r t d
 |  f   n  | a d  S(   Ni   R  t   mt   gt   ts   (\d+(\.\d+)?) (K|M|G|T)b?$s   Invalid memory limit %ri   i   s$   Memory limit %r too low to be useful(   t   _1Mt   _1GR   R   t
   IGNORECASEt   VERBOSERR   t
   ValueErrort   intR   t   groupt   lowert   real_max_memuset   MAX_Py_ssize_tt   _2GR   (   t   limitt   sizesRP  t   memlimit(    (    s'   /usr/lib/python2.7/test/test_support.pyR&     s     2	i   c            s       f d   } | S(   sQ  Decorator 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.
    c            s7        f d   }  | _   | _  | _ | S(   Nc            s   t  s. d } |  j |   d t k  n^ t t     } |  k  ru t rq t j j d   j f  n  d  St	 | d t   }   |  |  S(   Ni  i   s)   Skipping %s because of memory constraint
i2   (
   R   t   assertFalseRS  RX  R   RG   R&  R   R5   t   max(   R   t   maxsize(   R   t   memuset   minsizet   overhead(    s'   /usr/lib/python2.7/test/test_support.pyt   wrapper  s    "(   Re  Rd  Rf  (   R   Rg  (   Re  Rf  Rd  (   R   s'   /usr/lib/python2.7/test/test_support.pyRO    s
    			(    (   Re  Rd  Rf  RO  (    (   Re  Rf  Rd  s'   /usr/lib/python2.7/test/test_support.pyR'     s    c            s       f d   } | S(   Nc            s4       f d   }  | _   | _  | _ | S(   Nc            s_   t  s d } nC  } t  rR t  |  k  rR t rN t j j d   j f  n  d  S  |  |  S(   Ni  s)   Skipping %s because of memory constraint
(   R[  R   RG   R&  R   R5   (   R   Rc  (   R   Rd  t   size(    s'   /usr/lib/python2.7/test/test_support.pyRg    s    	(   Rh  Rd  Rf  (   R   Rg  (   Rh  Rf  Rd  (   R   s'   /usr/lib/python2.7/test/test_support.pyRO    s
    			(    (   Rh  Rd  Rf  RO  (    (   Rf  Rd  Rh  s'   /usr/lib/python2.7/test/test_support.pyt   precisionbigmemtest  s    c            s     f d   } | S(   s0   Decorator for tests that fill the address space.c            s@   t  t k  r2 t r< t j j d   j f  q< n
   |   Sd  S(   Ns)   Skipping %s because of memory constraint
(   R   R\  R   RG   R&  R   R5   (   R   (   R   (    s'   /usr/lib/python2.7/test/test_support.pyRg    s
    (    (   R   Rg  (    (   R   s'   /usr/lib/python2.7/test/test_support.pyR(     s    c           B   s   e  Z d    Z RS(   c         C   s   t  j   } | |  | S(   N(   R@   t
   TestResult(   R   t   testt   result(    (    s'   /usr/lib/python2.7/test/test_support.pyt   run  s    
(   R5   R6   Rm  (    (    (    s'   /usr/lib/python2.7/test/test_support.pyR)     s   c         C   s   |  S(   N(    (   Rb   (    (    s'   /usr/lib/python2.7/test/test_support.pyt   _id  s    c         C   s*   t  |   r t St j d j |    Sd  S(   Ns   resource {0!r} is not enabled(   R   Rn  R@   t   skipt   format(   Rt   (    (    s'   /usr/lib/python2.7/test/test_support.pyt   requires_resource  s    c         C   s   t  d t  |   S(   s9   
    Decorator for tests only applicable on CPython.
    t   cpython(   t   impl_detailRO   (   Rk  (    (    s'   /usr/lib/python2.7/test/test_support.pyR/     s    c         K   s}   t  |   r t S|  d  k rp t |  \ } } | r= d }  n d }  t | j    } |  j d j |   }  n  t j	 |   S(   Ns*   implementation detail not available on {0}s%   implementation detail specific to {0}s    or (
   R0   Rn  RR   t   _parse_guardst   sortedR  Rp  Rq   R@   Ro  (   RE   t   guardst
   guardnamest   default(    (    s'   /usr/lib/python2.7/test/test_support.pyRs     s    	c         C   sW   |  s i t  d 6t f S|  j   d } |  j   | g t |   k sL t  |  | f S(   NRr  i    (   RO   RQ   t   valuesR   R   (   Rv  t   is_true(    (    s'   /usr/lib/python2.7/test/test_support.pyRt    s
    %c          K   s.   t  |   \ }  } |  j t j   j   |  S(   s5  This 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
    (   Rt  Rx   t   platformt   python_implementationRZ  (   Rv  Rx  (    (    s'   /usr/lib/python2.7/test/test_support.pyR0     s    c         C   s   t  r! t j t j d d } n	 t   } | j |   } | j   s t | j	  d k rx | j
 rx | j	 d d } nL t | j
  d k r | j	 r | j
 d d } n d } t  s | d 7} n  t |   n  d S(   s2   Run tests from a unittest.TestSuite-derived class.t	   verbosityi   i   i    s   multiple errors occurreds!   ; run in verbose mode for detailsN(   R   R@   t   TextTestRunnerRG   Re   R)   Rm  t   wasSuccessfulR   t   errorst   failuresR   (   t   suitet   runnerRl  R(  (    (    s'   /usr/lib/python2.7/test/test_support.pyt
   _run_suite#  s    	c          G   s   t  j t  j f } t  j   } x |  D] } t | t  rx | t j k ri | j t  j t j |   q t	 d   q% t | |  r | j |  q% | j t  j
 |   q% Wt |  d S(   s1   Run tests from unittest.TestCase-derived classes.s)   str arguments must be keys in sys.modulesN(   R@   t	   TestSuitet   TestCaseR   RB   RG   RH   t   addTestt   findTestCasesRW  t	   makeSuiteR  (   t   classest   valid_typesR  t   cls(    (    s'   /usr/lib/python2.7/test/test_support.pyR*   7  s     c         C   s   d d l  } | d k r! t } n d } t j } t   t _ z> | j |  d | \ } } | ry t d | | f   n  Wd | t _ Xt r d |  j | f GHn  | | f S(   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).
    iNR   s   %d of %d doctests faileds,   doctest (%s) ... %d tests with zero failures(	   t   doctestRR   R   RG   Re   R   t   testmodR   R5   (   R^   R}  R  t   save_stdoutR   RR  (    (    s'   /usr/lib/python2.7/test/test_support.pyR+   K  s    		
c           C   s   t  r t  j   f Sd Sd  S(   Ni   (   i   (   t   threadt   _count(    (    (    s'   /usr/lib/python2.7/test/test_support.pyR,   s  s    c         C   sT   t  s
 d  Sd } x= t |  D]/ } t  j   } | |  k r? Pn  t j d  q Wd  S(   Ni
   g?(   R  R   R  RA  RB  (   t
   nb_threadst
   _MAX_COUNTt   countR)  (    (    s'   /usr/lib/python2.7/test/test_support.pyR-   y  s    c            s,   t  s
   St j      f d    } | S(   s   Use 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.
    c             s)   t    } z   |    SWd  t |   Xd  S(   N(   R,   R-   (   R'  t   key(   RK  (    s'   /usr/lib/python2.7/test/test_support.pyRO    s    	(   R  t	   functoolst   wraps(   RK  RO  (    (   RK  s'   /usr/lib/python2.7/test/test_support.pyt   reap_threads  s    c          C   sc   t  t d  r_ d }  xG t r[ y/ t j |  t j  \ } } | d k rL Pn  Wq Pq Xq Wn  d S(   s   Use 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.
    t   waitpidii    N(   R   Rf   RO   R  t   WNOHANG(   t   any_processt   pidt   status(    (    s'   /usr/lib/python2.7/test/test_support.pyR.     s    		c         C   s\   y |  j    SWnG t k
 rW y d j d   |  D  SWqX t k
 rS t |   SXn Xd S(   sZ   Emulate the py3k bytes() constructor.

    NOTE: This is only a best effort function.
    R   c         s   s   |  ] } t  |  Vq d  S(   N(   t   chr(   t   .0R   (    (    s'   /usr/lib/python2.7/test/test_support.pys	   <genexpr>  s    N(   t   tobytesRa   Rq   t	   TypeErrort   bytes(   t   b(    (    s'   /usr/lib/python2.7/test/test_support.pyR2     s    c          C   s   i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6}  g  } xP |  j    D]B \ } } t t j |  } | d k rQ | j d | |  qQ qQ W| S(   sZ   Return a list of command-line arguments reproducing the current
    settings in sys.flags.R  t   bytes_warningt   Bt   dont_write_bytecodet   Et   ignore_environmentR   t   no_user_sitet   St   no_sitet   Ot   optimizet   3t   py3k_warningR  R   i    t   -(   RV   R`   RG   t   flagsRU   (   t   flag_opt_mapR'  t   flagt   optR  (    (    s'   /usr/lib/python2.7/test/test_support.pyt   args_from_interpreter_flags  s    
c         C   s   t  j d d |   j   }  |  S(   s   Strip 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   t   subt   strip(   R&  (    (    s'   /usr/lib/python2.7/test/test_support.pyR4     s    (    (    (    i   (    (   R7   R5   R?   t
   contextlibRj   R  R?  Rz   RG   Rf   R{  Ri   R9   R@   R>   t   UserDictR   RA  R  RR   t   __all__t	   ExceptionR    R   RA   R   t   contextmanagerRO   R=   RQ   R   RN   RT   R3   R1   R   R   R   R[  Rd   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   t	   NameErrorRK   R   RC   R   R   t   TESTFN_UNICODER   t   TESTFN_ENCODINGR   R   t   TESTFN_UNENCODABLEt   evalR   R   Rp  t   getpidR   R   R   R   R   R   R   R   R   t   objectR   R   R   R   R   t	   DictMixinR    R  R#   R$   R!   R"   R<  R>  RC  R%   RS  RT  R]  t   _4GRc  R\  R&   R'   Ri  R(   R)   Rn  Rq  R/   Rs  Rt  R0   R  R*   R+   R,   R-   R  R.   R2   R  R4   (    (    (    s'   /usr/lib/python2.7/test/test_support.pyt   <module>   s  
									&								<	

					#			*' /=						%


		'					
			(						