
i\c           @` s  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l m
 Z
 d d l m Z d d l Z d d l Z d d l m Z d d	 l m Z i d
 d 6d d 6d d 6Z d   Z e j d e  d    Z d e f d     YZ d d d d h Z d   Z e j d    Z e j d    Z e j d    Z e j d    Z e j  d    Z! d e f d     YZ" d  d!  Z# d" e f d#     YZ$ e j% d$ d% d& g  Z& d' e f d(     YZ' d) e f d*     YZ( d+ e f d,     YZ) d- e) f d.     YZ* d/ e f d0     YZ+ d1 e+ f d2     YZ, d3 e j- f d4     YZ. d5   Z/ d6   Z0 d7   Z1 d8   Z2 d S(9   s.   
per-test stdout/stderr capturing mechanism.

i    (   t   absolute_import(   t   division(   t   print_functionN(   t   UnsupportedOperation(   t   TemporaryFile(   t   _PY3(   t	   CaptureIOt   stdint   stdouti   t   stderri   c         C` s   |  j  d  } | j d d d d t t d  r6 d n d d	 d
 d d d d g d d | j d d d d d d d d d d  S(   Nt   generals	   --capturet   actiont   storet   defaultt   dupt   fdt   syst   metavart   methodt   choicest   not   helps,   per-test capturing method: one of fd|sys|no.s   -st   store_constt   constt   destt   captures   shortcut for --capture=no.(   t   getgroupt
   _addoptiont   hasattrt   os(   t   parsert   group(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_addoption   s    t   hookwrapperc   	      c` s   |  j  } | j d k r( t t j  n  t   t   |  j } t | j  } | j	 | d  |  j
 | j  | j   d  V} | j   | j d  k	 r | j   \ } } t j j |  t j j |  n  d  S(   NR   t   capturemanager(   t   known_args_namespaceR   t!   _py36_windowsconsoleio_workaroundR   R   t   _colorama_workaroundt   _readline_workaroundt   pluginmanagert   CaptureManagert   registert   add_cleanupt   stop_global_capturingt   start_global_capturingt   suspend_global_capturet   excinfot   Nonet   read_global_capturet   writeR	   (	   t   early_configR   t   argst   nsR'   t   capmant   outcomet   outt   err(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_load_initial_conftests.   s     		

R(   c           B` s  e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e d	  Z e d
  Z d   Z d   Z d   Z d   Z d   Z d   Z e j d    Z e j d    Z e j d e  d    Z e j d e  d    Z e j d e  d    Z e j d e  d    Z e j d e  d    Z e j d e  d    Z  e j d e  d    Z! RS(   s  
    Capture plugin, manages that the appropriate capture method is enabled/disabled during collection and each
    test phase (setup, call, teardown). After each of those points, the captured output is obtained and
    attached to the collection/runtest report.

    There are two levels of capture:
    * global: which is enabled by default and can be suppressed by the ``-s`` option. This is always enabled/disabled
      during collection and each test phase.
    * fixture: when a test function or one of its fixture depend on the ``capsys`` or ``capfd`` fixtures. In this
      case special handling is needed to ensure the fixtures take precedence over the global capture.
    c         C` s   | |  _  d  |  _ d  |  _ d  S(   N(   t   _methodR/   t   _global_capturingt   _current_item(   t   selfR   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   __init__S   s    		c         C` s   d |  j  |  j |  j f S(   NsA   <CaptureManager _method=%r _global_capturing=%r _current_item=%r>(   R:   R;   R<   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   __repr__X   s    c         C` s   | d k r% t  d t d t d t  S| d k rJ t  d t d t d t  S| d k ro t  d t d t d t  St d |   d  S(	   NR   R7   R8   t   CaptureR   R   t   in_s   unknown capturing method: %r(   t   MultiCapturet   Truet	   FDCapturet
   SysCapturet   Falset
   ValueError(   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   _getcapture_   s    c         C` sI   |  j    r d St |  j d d   } | d  k	 rE d |  j j j j St S(   Nt   globalt   _capture_fixtures
   fixture %s(   t   is_globally_capturingt   getattrR<   R/   RJ   t   requestt   fixturenameRF   (   R=   t   capture_fixture(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   is_capturingh   s    c         C` s   |  j  d k S(   NR   (   R:   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRK   t   s    c         C` s;   |  j  d  k s t  |  j |  j  |  _  |  j  j   d  S(   N(   R;   R/   t   AssertionErrorRH   R:   t   start_capturing(   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR,   w   s    c         C` s9   |  j  d  k	 r5 |  j  j   |  j  j   d  |  _  n  d  S(   N(   R;   R/   t   pop_outerr_to_origt   stop_capturing(   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR+   |   s    c         C` s#   |  j  d  k	 r |  j  j   n  d  S(   N(   R;   R/   t   resume_capturing(   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   resume_global_capture   s    c         C` s5   t  |  d d   } | d  k	 r1 | j d |  n  d  S(   NR;   RA   (   RL   R/   t   suspend_capturing(   R=   RA   t   cap(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR-      s    c         C` s!   |  j  |  j  |  j |  d  S(   N(   t   suspend_fixtureR<   R-   (   R=   RA   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   suspend   s    c         C` s   |  j    |  j |  j  d  S(   N(   RV   t   resume_fixtureR<   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   resume   s    
c         C` s   |  j  j   S(   N(   R;   t
   readouterr(   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR0      s    c         C` s/   t  | d d  } | d k	 r+ | j   n  d S(   s   If the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over
        the global capture.
        RJ   N(   RL   R/   t   _start(   R=   t   itemt   fixture(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   activate_fixture   s    c         C` s/   t  | d d  } | d k	 r+ | j   n  d S(   sE   Deactivates the ``capsys`` or ``capfd`` fixture of this item, if any.RJ   N(   RL   R/   t   close(   R=   R_   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   deactivate_fixture   s    c         C` s/   t  | d d   } | d  k	 r+ | j   n  d  S(   NRJ   (   RL   R/   t   _suspend(   R=   R_   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRY      s    c         C` s/   t  | d d   } | d  k	 r+ | j   n  d  S(   NRJ   (   RL   R/   t   _resume(   R=   R_   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR[      s    c         c` s%   |  j    z	 d VWd |  j   Xd S(   sL   Context manager to temporarily disable global and current fixture capturing.N(   RZ   R\   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   global_and_fixture_disabled   s    
	c         c` s}   |  j    |  j |  z	 d  VWd  |  j |  |  j d t  X|  j   \ } } | j | d |  | j | d |  d  S(   NRA   R   R	   (   RV   Ra   Rc   R-   RF   R0   t   add_report_section(   R=   t   whenR_   R7   R8   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   item_capture   s    
	R!   c         c` s   t  | t j  r |  j   d  V} |  j   |  j   \ } } | j   } | rj | j j d | f  n  | r | j j d | f  q n d  Vd  S(   Ns   Captured stdouts   Captured stderr(	   t
   isinstancet   pytestt   FileRV   R-   R0   t
   get_resultt   sectionst   append(   R=   t	   collectorR6   R7   R8   t   rep(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_make_collect_report   s    

c         c` s   | |  _  d  Vd  |  _  d  S(   N(   R<   R/   (   R=   R_   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_runtest_protocol   s    	c         c` s"   |  j  d |  
 d  VWd  QXd  S(   Nt   setup(   Ri   (   R=   R_   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_runtest_setup   s    c         c` s"   |  j  d |  
 d  VWd  QXd  S(   Nt   call(   Ri   (   R=   R_   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_runtest_call   s    c         c` s"   |  j  d |  
 d  VWd  QXd  S(   Nt   teardown(   Ri   (   R=   R_   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_runtest_teardown   s    t   tryfirstc         C` s   |  j    d  S(   N(   R+   (   R=   R.   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_keyboard_interrupt   s    c         C` s   |  j    d  S(   N(   R+   (   R=   R.   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   pytest_internalerror   s    ("   t   __name__t
   __module__t   __doc__R>   R?   RH   RP   RK   R,   R+   RV   RF   R-   RZ   R\   R0   Ra   Rc   RY   R[   t
   contextlibt   contextmanagerRf   Ri   Rk   t   hookimplRC   Rr   Rs   Ru   Rw   Ry   R{   R|   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR(   F   s4   																t   capfdt   capfdbinaryt   capsyst   capsysbinaryc         C` sp   t  |  j  t | h @} | rl t |  } t |  d k rH | d n | } |  j d j | |    n  d  S(   Ni   i    s%   cannot use {} and {} at the same time(   t   sett   fixturenamest   capture_fixturest   sortedt   lent
   raiseerrort   format(   RM   t   namet   fixtures(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt    _ensure_only_one_capture_fixture   s    "c         c` s.   t  |  d  t |  t   } | VWd QXd S(   s   Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.

    The captured output is made available via ``capsys.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.
    R   N(   R   t    _install_capture_fixture_on_itemRE   (   RM   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         c` sO   t  |  d  t j d k  r. |  j d   n  t |  t   } | VWd QXd S(   s  Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.

    The captured output is made available via ``capsysbinary.readouterr()``
    method calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``bytes`` objects.
    R   i   s*   capsysbinary is only supported on Python 3N(   i   (   R   R   t   version_infoR   R   t   SysCaptureBinary(   RM   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s
    c         c` sM   t  |  d  t t d  s, t j d  n  t |  t   } | VWd QXd S(   s   Enable text capturing of writes to file descriptors ``1`` and ``2``.

    The captured output is made available via ``capfd.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.
    R   R   sI   capfd fixture needs os.dup function which is not available in this systemN(   R   R   R   Rk   t   skipR   RD   (   RM   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   &  s    
c         c` sM   t  |  d  t t d  s, t j d  n  t |  t   } | VWd QXd S(   s   Enable bytes capturing of writes to file descriptors ``1`` and ``2``.

    The captured output is made available via ``capfd.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``byte`` objects.
    R   R   sO   capfdbinary fixture needs os.dup function which is not available in this systemN(   R   R   R   Rk   R   R   t   FDCaptureBinary(   RM   R`   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   7  s    
c         c` sZ   t  | |   |  j _ } |  j j j d  } | j |  j  | V| j   |  j ` d S(   s<  
    Context manager which creates a ``CaptureFixture`` instance and "installs" it on
    the item/node of the given request. Used by ``capsys`` and ``capfd``.

    The CaptureFixture is added as attribute of the item because it needs to accessed
    by ``CaptureManager`` during its ``pytest_runtest_*`` hooks.
    R"   N(   t   CaptureFixturet   nodeRJ   t   configR'   t	   getpluginRa   Rb   (   RM   t   capture_classR`   t
   capmanager(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   H  s    	
R   c           B` sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e	 j
 d    Z RS(   s   
    Object returned by :py:func:`capsys`, :py:func:`capsysbinary`, :py:func:`capfd` and :py:func:`capfdbinary`
    fixtures.
    c         C` s=   | |  _  | |  _ d  |  _ |  j  j |  _ |  j  j |  _ d  S(   N(   t   captureclassRM   R/   t   _capturet   EMPTY_BUFFERt   _captured_outt   _captured_err(   R=   R   RM   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR>   b  s
    			c      	   C` sJ   |  j  d  k rF t d t d t d t d |  j  |  _  |  j  j   n  d  S(   NR7   R8   RA   R@   (   R   R/   RB   RC   RF   R   RR   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR^   i  s    !c         C` s_   |  j  d  k	 r[ |  j  j   \ } } |  j | 7_ |  j | 7_ |  j  j   d  |  _  n  d  S(   N(   R   R/   RS   R   R   RT   (   R=   R7   R8   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRb   p  s    c         C` sy   |  j  |  j } } |  j d k	 rN |  j j   \ } } | | 7} | | 7} n  |  j j |  _  |  j j |  _ t | |  S(   s   Read and return the captured output so far, resetting the internal buffer.

        :return: captured content as a namedtuple with ``out`` and ``err`` string attributes
        N(   R   R   R   R/   R]   R   R   t   CaptureResult(   R=   t   captured_outt   captured_errR7   R8   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR]   x  s    
c         C` s#   |  j  d k	 r |  j  j   n  d S(   s2   Suspends this fixture's own capturing temporarily.N(   R   R/   RW   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRd     s    c         C` s#   |  j  d k	 r |  j  j   n  d S(   s1   Resumes this fixture's own capturing temporarily.N(   R   R/   RU   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRe     s    c         c` s4   |  j  j j j d  } | j   
 d VWd QXd S(   s;   Temporarily disables capture while inside the 'with' block.R"   N(   RM   R   R'   R   Rf   (   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   disabled  s    (   R}   R~   R   R>   R^   Rb   R]   Rd   Re   R   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   \  s   						t   UTF8c         C` s   t  |  d d  } y |  j   } Wn< t k
 r` d t  |  d d  k r t |  d  r |  Sn> Xt j |  } d | k r | d 7} n  t j | | d  }  t |  | p |  S(   sb    return an open text file object that's a duplicate of f on the
        FD-level if possible.
    t   encodingt   bt   modet    i    N(	   RL   R/   t   filenot	   ExceptionR   R   R   t   fdopent   EncodedFile(   t   fR   t   default_encodingR   R   t   newfd(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   safe_text_dupfile  s    'R   c           B` sP   e  Z d  Z d   Z d   Z d   Z e d    Z e d    Z d   Z	 RS(   t   strictc         C` s   | |  _  | |  _ d  S(   N(   t   bufferR   (   R=   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR>     s    	c         C` se   t  | t j  r* | j |  j d  } n' t rQ t d j t |  j	    n  |  j
 j |  d  S(   Nt   replaces$   write() argument must be str, not {}(   Rj   t   sixt	   text_typet   encodeR   R   t	   TypeErrorR   t   typeR}   R   R1   (   R=   t   obj(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR1     s    c         C` s    d j  |  } |  j |  d  S(   NR   (   t   joinR1   (   R=   t   linelistt   data(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt
   writelines  s    c         C` s   t  |  j  S(   s"   Ensure that file.name is a string.(   t   reprR   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s   |  j  j j d d  S(   NR   R   (   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s   t  t j |  d  |  S(   NR   (   RL   t   objectt   __getattribute__(   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   __getattr__  s    (
   R}   R~   t   errorsR>   R1   R   t   propertyR   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s   				R   R7   R8   RB   c           B` ss   e  Z d Z Z Z d Z e e e d d   Z d   Z	 d   Z
 d   Z e d  Z d   Z d   Z d   Z RS(	   c         C` sL   | r | d  |  _  n  | r0 | d  |  _ n  | rH | d  |  _ n  d  S(   Ni    i   i   (   RA   R7   R8   (   R=   R7   R8   RA   R@   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR>     s    c      	   C` s/   d |  j  |  j |  j |  j t |  d d  f S(   Ns>   <MultiCapture out=%r err=%r in_=%r _state=%r _in_suspended=%r>t   _in_suspendeds   <UNSET>(   R7   R8   RA   t   _stateRL   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR?     s    c         C` sX   d |  _  |  j r" |  j j   n  |  j r; |  j j   n  |  j rT |  j j   n  d  S(   Nt   started(   R   RA   t   startR7   R8   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRR     s    				c         C` sN   |  j    \ } } | r+ |  j j |  n  | rD |  j j |  n  | | f S(   sA    pop current snapshot out/err capture and flush to orig streams. (   R]   R7   t   writeorgR8   (   R=   R7   R8   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRS     s    c         C` sg   d |  _  |  j r" |  j j   n  |  j r; |  j j   n  | rc |  j rc |  j j   t |  _ n  d  S(   Nt	   suspended(   R   R7   RZ   R8   RA   RC   R   (   R=   RA   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRW     s    			c         C` sd   d |  _  |  j r" |  j j   n  |  j r; |  j j   n  t |  d  r` |  j j   |  ` n  d  S(   Nt   resumedR   (   R   R7   R\   R8   R   RA   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRU      s    			c         C` sv   |  j  d k r t d   n  d |  _  |  j r@ |  j j   n  |  j rY |  j j   n  |  j rr |  j j   n  d S(   s,    stop capturing and reset capturing streams t   stoppeds   was already stoppedN(   R   RG   R7   t   doneR8   RA   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRT   
  s    				c         C` sI   t  |  j d k	 r! |  j j   n d |  j d k	 rB |  j j   n d  S(   s<    return snapshot unicode value of stdout/stderr capturings. R   N(   R   R7   R/   t   snapR8   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR]     s    !N(   R}   R~   R/   R7   R8   RA   R   RC   R>   R?   RR   RS   RF   RW   RU   RT   R]   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRB     s   						
	
	t	   NoCapturec           B` s'   e  Z d Z d    Z Z Z Z Z RS(   c          G` s   d  S(   N(   R/   (   R3   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   <lambda>   R   N(	   R}   R~   R/   R   R>   R   R   RZ   R\   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s   R   c           B` se   e  Z d  Z d Z d
 Z d
 d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(   sU   Capture IO to/from a given os-level filedescriptor.

    snap() produces `bytes`
    R   c         C` s  | |  _  y t j |  j   |  _ Wn) t k
 rM d   |  _ d   |  _ n X| d k r | sm t d   t t j	 d  } t
 |  |  _ nd | d  k r t   } |  t | d d } Wd  QXn  | t k r t
 | |  |  _ n t   |  _ | |  _ | j   |  _ d  S(   Nc           S` s   d  S(   N(   R/   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   1  R   c           S` s   d  S(   N(   R/   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   2  R   i    s   cannot set tmpfile with stdint   rR   s   wb+(   t   targetfdR   R   t   targetfd_savet   OSErrorR   R   RQ   t   opent   devnullRE   t
   syscaptureR/   R   R   t   patchsysdictR   t   tmpfileR   t
   tmpfile_fd(   R=   R   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR>   ,  s&    			c         C` s#   d |  j  t |  d d   |  j f S(   Ns!   <FDCapture %s oldfd=%s _state=%r>R   (   R   RL   R/   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR?   D  s    c         C` sj   y t  j |  j  Wn# t t f k
 r9 t d   n Xt  j |  j |  j  |  j	 j
   d |  _ d S(   s6    Start capturing on targetfd using memorized tmpfile. s&   saved filedescriptor not valid anymoreR   N(   R   t   fstatR   t   AttributeErrorR   RG   t   dup2R   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   K  s    c         C` s@   |  j  j d  |  j  j   } |  j  j d  |  j  j   | S(   Ni    (   R   t   seekt   readt   truncate(   R=   t   res(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   U  s
    c         C` sY   |  j  j d  } t j | |  j  t j |  |  j j   t |  j	  d |  _
 d S(   sa    stop capturing, restore streams, return original capture file,
        seeked to position zero. R   R   N(   t   __dict__t   popR   R   R   Rb   R   R   t   _attempt_to_close_capture_fileR   R   (   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   \  s    c         C` s0   |  j  j   t j |  j |  j  d |  _ d  S(   NR   (   R   RZ   R   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRZ   f  s    c         C` s0   |  j  j   t j |  j |  j  d |  _ d  S(   NR   (   R   R\   R   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR\   k  s    c         C` s;   t  | t j  r$ | j d  } n  t j |  j |  d S(   s$    write to original file descriptor. t   utf8N(   Rj   R   R   R   R   R1   R   (   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   p  s    N(   R}   R~   R   R   R/   R   R>   R?   R   R   R   RZ   R\   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   #  s   		
		
		RD   c           B` s    e  Z d  Z e   Z d   Z RS(   sR   Capture IO to/from a given os-level filedescriptor.

    snap() produces text
    c         C` s[   t  t |   j   } t |  j d d   } | rW t | t  rW t j	 | | d  } n  | S(   NR   R   (
   t   superRD   R   RL   R   R/   Rj   t   bytesR   R   (   R=   R   t   enc(    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s
    (   R}   R~   R   t   strR   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRD   w  s   	RE   c           B` sb   e  Z e   Z d Z d d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z RS(	   c         C` sb   t  | } t t |  |  _ | |  _ | d  k rU | d k rI t   } qU t   } n  | |  _ d  S(   NR   (	   R   RL   R   t   _oldR   R/   t   DontReadFromInputR   R   (   R=   R   R   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR>     s    
	c         C` s    d |  j  |  j |  j |  j f S(   Ns-   <SysCapture %s _old=%r, tmpfile=%r _state=%r>(   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR?     s
    c         C` s#   t  t |  j |  j  d |  _ d  S(   NR   (   t   setattrR   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s0   |  j  j   } |  j  j d  |  j  j   | S(   Ni    (   R   t   getvalueR   R   (   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s6   t  t |  j |  j  |  ` t |  j  d |  _ d  S(   NR   (   R   R   R   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s#   t  t |  j |  j  d |  _ d  S(   NR   (   R   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRZ     s    c         C` s#   t  t |  j |  j  d |  _ d  S(   NR   (   R   R   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR\     s    c         C` s!   |  j  j |  |  j  j   d  S(   N(   R   R1   t   flush(   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    N(   R}   R~   R   R   R/   R   R>   R?   R   R   R   RZ   R\   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRE     s   							R   c           B` s   e  Z d  Z d   Z RS(   R   c         C` s3   |  j  j j   } |  j  j d  |  j  j   | S(   Ni    (   R   R   R   R   R   (   R=   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    (   R}   R~   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s   R   c           B` sb   e  Z d  Z d Z d   Z e Z e Z e Z d   Z	 d   Z
 d   Z d   Z e d    Z RS(   s  Temporary stub class.  Ideally when stdin is accessed, the
    capturing should be turned off, with possibly all data captured
    so far sent to the screen.  This should be configurable, though,
    because in automated test runs it is better to crash than
    hang indefinitely.
    c         G` s   t  d   d  S(   Ns+   reading from stdin while output is captured(   t   IOError(   R=   R3   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s   |  S(   N(    (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   __iter__  s    c         C` s   t  d   d  S(   Ns/   redirected stdin is pseudofile, has no fileno()(   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    c         C` s   t  S(   N(   RF   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   isatty  s    c         C` s   d  S(   N(    (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyRb     s    c         C` s#   t  j d k r |  St d   d  S(   Ni   i    s(   redirected stdin has no attribute buffer(   i   i    (   R   R   R   (   R=   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s    N(   R}   R~   R   R/   R   R   t   readlinet	   readlinest   __next__R   R   R   Rb   R   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR     s   					c          C` s=   t  j j d  r9 y d d l }  Wq9 t k
 r5 q9 Xn  d S(   s  
    Ensure colorama is imported so that it attaches to the correct stdio
    handles on Windows.

    colorama uses the terminal on import time. So if something does the
    first import of colorama while I/O capture is active, colorama will
    fail in various ways.
    t   win32i    N(   R   t   platformt
   startswitht   coloramat   ImportError(   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR%     s
    	c          C` s=   t  j j d  r9 y d d l }  Wq9 t k
 r5 q9 Xn  d S(   sF  
    Ensure readline is imported so that it attaches to the correct stdio
    handles on Windows.

    Pdb uses readline support where available--when not running from the Python
    prompt, the readline module is not imported until running the pdb REPL.  If
    running pytest with the --pdb option this means the readline module is not
    imported until after I/O capture has been started.

    This is a problem for pyreadline, which is often used to implement readline
    support on Windows, as it does not attach to the correct handles for stdout
    and/or stdin if they have been redirected by the FDCapture mechanism.  This
    workaround ensures that readline is imported before I/O capture is setup so
    that it can attach to the actual stdin/out for the console.

    See https://github.com/pytest-dev/pytest/pull/1281
    R   i    N(   R   R   R   R   R   (   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR&     s
    c         ` s   t  j j d  s& t  j d  d k  r* d St |  d  s= d St |  j d      ra |  j j n |  j } t | t j	  s d S  f d   } | t  j
 d	  t  _
 | t  j d
  t  _ | t  j d
  t  _ d S(   s  
    Python 3.6 implemented unicode console handling for Windows. This works
    by reading/writing to the raw console handle using
    ``{Read,Write}ConsoleW``.

    The problem is that we are going to ``dup2`` over the stdio file
    descriptors when doing ``FDCapture`` and this will ``CloseHandle`` the
    handles used by Python to write to the console. Though there is still some
    weirdness and the console handle seems to only be closed randomly and not
    on the first call to ``CloseHandle``, or maybe it gets reopened with the
    same handle value when we suspend capturing.

    The workaround in this case will reopen stdio with a different fd which
    also means a different handle by replicating the logic in
    "Py_lifecycle.c:initstdio/create_stdio".

    :param stream: in practice ``sys.stdout`` or ``sys.stderr``, but given
        here as parameter for unittesting purposes.

    See https://github.com/pytest-dev/py/issues/103
    R   i   i   i   NR   t   rawc         ` sf     r  | d d k r  d } n d } t  j t t j |  j    | |  |  j |  j |  j |  j	  S(   Ni    t   wi(
   t   iot   TextIOWrapperR   R   R   R   R   R   t   newlinest   line_buffering(   R   R   t	   buffering(   t   buffered(    s.   lib/python2.7/site-packages/_pytest/capture.pyt   _reopen_stdio7  s    	t   rbt   wb(   i   i   (   R   R   R   R   R   R   R   Rj   R   t   _WindowsConsoleIOR   R   R	   (   t   streamt
   raw_stdoutR  (    (   R  s.   lib/python2.7/site-packages/_pytest/capture.pyR$     s    &c         C` s<   t  j r. y |  j   Wq8 t k
 r* q8 Xn
 |  j   d S(   s[   Suppress IOError when closing the temporary file used for capturing streams in py27 (#2370)N(   R   t   PY2Rb   R   (   R   (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyR   J  s    	(3   R   t
   __future__R    R   R   t   collectionsR   R   R   R   R   t   tempfileR   R   Rk   t   _pytest.compatR   R   R   R    R   RC   R9   R   R(   R   R   R`   R   R   R   R   R   R   R   R   R   t
   namedtupleR   RB   R   R   RD   RE   R   t   IteratorR   R%   R&   R$   R   (    (    (    s.   lib/python2.7/site-packages/_pytest/capture.pyt   <module>   sP   		
<!OT5
%			6