B
    ܇\[d                 @   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 d
dddZdd Zejdddd ZG dd deZddddhZdd Zejdd Zejdd Zejdd Zejdd Zejd d! Z G d"d# d#eZ!dBd%d&Z"G d'd( d(eZ#e$d)d*d+gZ%G d,d- d-eZ&G d.d/ d/eZ'G d0d1 d1eZ(G d2d3 d3e(Z)G d4d5 d5eZ*G d6d7 d7e*Z+G d8d9 d9ej,Z-d:d; Z.d<d= Z/d>d? Z0d@dA Z1dS )Cz.
per-test stdout/stderr capturing mechanism.

    )absolute_import)division)print_functionN)UnsupportedOperation)TemporaryFile)_PY3)	CaptureIOstdinstdoutstderr)r         c             C   sL   |  d}|jddttdr dndddddgd	d
 |jdddddd d S )NZgeneralz	--captureZstoredupfdsysmethodnoz,per-test capturing method: one of fd|sys|no.)actiondefaultmetavarchoiceshelpz-sZstore_constcapturezshortcut for --capture=no.)r   Zconstdestr   )ZgetgroupZ
_addoptionhasattros)parsergroup r   .lib/python3.7/site-packages/_pytest/capture.pypytest_addoption   s    
r    T)hookwrapperc       
      c   s   | j }|jdkrttj t  t  | j}t|j}|	|d | 
|j dd }| 
| |  d V }|  |jd k	r| \}}	tj| tj|	 d S )Nr   capturemanagerc               S   s   dt jkrdt jd _d S )NZloggingF)r   modulesZraiseExceptionsr   r   r   r   silence_logging_at_shutdown<   s    
zBpytest_load_initial_conftests.<locals>.silence_logging_at_shutdown)Zknown_args_namespacer   !_py36_windowsconsoleio_workaroundr   r
   _colorama_workaround_readline_workaroundpluginmanagerCaptureManagerregisterZadd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureexcinforead_global_capturewriter   )
Zearly_configr   argsnsr(   Zcapmanr$   outcomeouterrr   r   r   pytest_load_initial_conftests-   s$    




r6   c               @   s  e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	d1ddZ
dd Zdd Zdd Zdd Zdd Zejdd Zejdd Zejdd d!d" Zejdd d#d$ Zejdd d%d& Zejdd d'd( Zejdd d)d* Zejdd+d,d- Zejdd+d.d/ Zd0S )2r)   a  
    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)_method_global_capturing_current_item)selfr   r   r   r   __init__Y   s    zCaptureManager.__init__c             C   sR   |dkrt ddtdS |dkr,t ddtdS |dkrBt ddddS td| d S )	Nr   T)r4   r5   Capturer   r   F)r4   r5   in_zunknown capturing method: %r)MultiCapture	FDCapture
SysCapture
ValueError)r:   r   r   r   r   _getcapture^   s    zCaptureManager._getcapturec             C   s
   | j dkS )Nr   )r7   )r:   r   r   r   is_globally_capturingj   s    z$CaptureManager.is_globally_capturingc             C   s*   | j d kst| | j| _ | j   d S )N)r8   AssertionErrorrB   r7   start_capturing)r:   r   r   r   r,   m   s    z%CaptureManager.start_global_capturingc             C   s(   | j d k	r$| j   | j   d | _ d S )N)r8   pop_outerr_to_origstop_capturing)r:   r   r   r   r+   r   s    


z$CaptureManager.stop_global_capturingc             C   s   | j d k	r| j   d S )N)r8   resume_capturing)r:   r   r   r   resume_global_capturex   s    
z$CaptureManager.resume_global_captureFc             C   s$   t | dd }|d k	r |j|d d S )Nr8   )r=   )getattrsuspend_capturing)r:   r=   Zcapr   r   r   r-   ~   s    z%CaptureManager.suspend_global_capturec             C   s
   | j  S )N)r8   
readouterr)r:   r   r   r   r/      s    z"CaptureManager.read_global_capturec             C   s    t |dd}|dk	r|  dS )zIf the current item is using ``capsys`` or ``capfd``, activate them so they take precedence over
        the global capture.
        _capture_fixtureN)rJ   _start)r:   itemfixturer   r   r   activate_fixture   s    zCaptureManager.activate_fixturec             C   s    t |dd}|dk	r|  dS )zEDeactivates the ``capsys`` or ``capfd`` fixture of this item, if any.rM   N)rJ   close)r:   rO   rP   r   r   r   deactivate_fixture   s    z!CaptureManager.deactivate_fixturec             C   s    t |dd }|d k	r|  d S )NrM   )rJ   _suspend)r:   rO   rP   r   r   r   suspend_fixture   s    zCaptureManager.suspend_fixturec             C   s    t |dd }|d k	r|  d S )NrM   )rJ   _resume)r:   rO   rP   r   r   r   resume_fixture   s    zCaptureManager.resume_fixturec          	   c   s>   |  | j | jdd z
dV  W d|   | | j X dS )zMContext manager to temporarily disables global and current fixture capturing.F)r=   N)rU   r9   r-   rI   rW   )r:   r   r   r   global_and_fixture_disabled   s    
z*CaptureManager.global_and_fixture_disabledc          	   c   sb   |    | | z
d V  W d | | | jdd X |  \}}||d| ||d| d S )NF)r=   r
   r   )rI   rQ   rS   r-   r/   Zadd_report_section)r:   ZwhenrO   r4   r5   r   r   r   item_capture   s    


zCaptureManager.item_captureT)r!   c             c   sj   t |tjr`|   d V }|   |  \}}| }|rJ|jd|f |rf|jd|f nd V  d S )NzCaptured stdoutzCaptured stderr)	
isinstancepytestZFilerI   r-   r/   Z
get_resultZsectionsappend)r:   Z	collectorr3   r4   r5   Zrepr   r   r   pytest_make_collect_report   s    z)CaptureManager.pytest_make_collect_reportc             c   s   || _ d V  d | _ d S )N)r9   )r:   rO   r   r   r   pytest_runtest_protocol   s    z&CaptureManager.pytest_runtest_protocolc          	   c   s"   |  d| d V  W d Q R X d S )NZsetup)rY   )r:   rO   r   r   r   pytest_runtest_setup   s    z#CaptureManager.pytest_runtest_setupc          	   c   s"   |  d| d V  W d Q R X d S )NZcall)rY   )r:   rO   r   r   r   pytest_runtest_call   s    z"CaptureManager.pytest_runtest_callc          	   c   s"   |  d| d V  W d Q R X d S )NZteardown)rY   )r:   rO   r   r   r   pytest_runtest_teardown   s    z&CaptureManager.pytest_runtest_teardown)Ztryfirstc             C   s   |    d S )N)r+   )r:   r.   r   r   r   pytest_keyboard_interrupt   s    z(CaptureManager.pytest_keyboard_interruptc             C   s   |    d S )N)r+   )r:   r.   r   r   r   pytest_internalerror   s    z#CaptureManager.pytest_internalerrorN)F)__name__
__module____qualname____doc__r;   rB   rC   r,   r+   rI   r-   r/   rQ   rS   rU   rW   
contextlibcontextmanagerrX   rY   r[   hookimplr]   r^   r_   r`   ra   rb   rc   r   r   r   r   r)   L   s,   
r)   capfdcapfdbinarycapsyscapsysbinaryc             C   sN   t | jt|h @ }|rJt|}t|dkr4|d n|}| d||d S )Nr   r   z%cannot use {} and {} at the same time)setZfixturenamescapture_fixturessortedlen
raiseerrorformat)requestnameZfixturesr   r   r    _ensure_only_one_capture_fixture   s    rw   c          	   c   s*   t | d t| t}|V  W dQ R X dS )zEnable capturing of writes to ``sys.stdout`` and ``sys.stderr`` and make
    captured output available via ``capsys.readouterr()`` method calls
    which return a ``(out, err)`` namedtuple.  ``out`` and ``err`` will be ``text``
    objects.
    rm   N)rw    _install_capture_fixture_on_itemr@   )ru   rP   r   r   r   rm      s    
c          	   c   s>   t | d tjdk r| dt| t}|V  W dQ R X dS )zEnable capturing of writes to ``sys.stdout`` and ``sys.stderr`` and make
    captured output available via ``capsys.readouterr()`` method calls
    which return a ``(out, err)`` tuple.  ``out`` and ``err`` will be ``bytes``
    objects.
    rn   )   z*capsysbinary is only supported on python 3N)rw   r   version_infors   rx   SysCaptureBinary)ru   rP   r   r   r   rn     s
    


c          	   c   s>   t | d ttdstd t| t}|V  W dQ R X dS )zEnable capturing of writes to file descriptors ``1`` and ``2`` and make
    captured output available via ``capfd.readouterr()`` method calls
    which return a ``(out, err)`` tuple.  ``out`` and ``err`` will be ``text``
    objects.
    rk   r   zIcapfd fixture needs os.dup function which is not available in this systemN)rw   r   r   r[   skiprx   r?   )ru   rP   r   r   r   rk     s    

c          	   c   s>   t | d ttdstd t| t}|V  W dQ R X dS )zEnable capturing of write to file descriptors 1 and 2 and make
    captured output available via ``capfdbinary.readouterr`` method calls
    which return a ``(out, err)`` tuple.  ``out`` and ``err`` will be
    ``bytes`` objects.
    rl   r   zOcapfdbinary fixture needs os.dup function which is not available in this systemN)rw   r   r   r[   r|   rx   FDCaptureBinary)ru   rP   r   r   r   rl   $  s    

c             c   sD   t ||  | j_}| jjd}|| j |V  |  | j`dS )a<  
    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)CaptureFixtureZnoderM   configr(   	getpluginrQ   rR   )ru   Zcapture_classrP   
capmanagerr   r   r   rx   4  s    	rx   c               @   sN   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
jdd ZdS )r~   z
    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)captureclassru   _captureEMPTY_BUFFER_captured_out_captured_err)r:   r   ru   r   r   r   r;   N  s
    
zCaptureFixture.__init__c             C   s2   t | dd d kr.tddd| jd| _| j  d S )Nr   TF)r4   r5   r=   r<   )rJ   r>   r   r   rE   )r:   r   r   r   rN   U  s    zCaptureFixture._startc             C   sH   | j d k	rD| j  \}}|  j|7  _|  j|7  _| j   d | _ d S )N)r   rF   r   r   rG   )r:   r4   r5   r   r   r   rR   ]  s    

zCaptureFixture.closec             C   sT   | j | j }}| jdk	r6| j \}}||7 }||7 }| jj| _ | jj| _t||S )zRead 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   rL   r   r   CaptureResult)r:   Zcaptured_outZcaptured_errr4   r5   r   r   r   rL   e  s    


zCaptureFixture.readouterrc             C   s   | j   dS )z2Suspends this fixture's own capturing temporarily.N)r   rK   )r:   r   r   r   rT   s  s    zCaptureFixture._suspendc             C   s   | j   dS )z1Resumes this fixture's own capturing temporarily.N)r   rH   )r:   r   r   r   rV   w  s    zCaptureFixture._resumec          	   c   s.   | j jjd}|  dV  W dQ R X dS )z;Temporarily disables capture while inside the 'with' block.r"   N)ru   r   r(   r   rX   )r:   r   r   r   r   disabled{  s    
zCaptureFixture.disabledN)rd   re   rf   rg   r;   rN   rR   rL   rT   rV   rh   ri   r   r   r   r   r   r~   H  s   r~   UTF8c             C   s   t | dd}y|  }W n2 tk
rJ   dt | ddkrFt| drF| S Y n*X t|}d|krf|d7 }t||d} t| |p~|S )zb return an open text file object that's a duplicate of f on the
        FD-level if possible.
    encodingNbmode r   )rJ   fileno	Exceptionr   r   r   fdopenEncodedFile)fr   Zdefault_encodingr   r   Znewfdr   r   r   safe_text_dupfile  s    

r   c               @   s<   e Zd ZdZdd Zdd Zdd Zedd	 Zd
d Z	dS )r   strictc             C   s   || _ || _d S )N)bufferr   )r:   r   r   r   r   r   r;     s    zEncodedFile.__init__c             C   sD   t |tjr|| jd}ntr4tdt|j	| j
| d S )Nreplacez$write() argument must be str, not {})rZ   six	text_typeencoder   r   	TypeErrorrt   typerd   r   r0   )r:   objr   r   r   r0     s    zEncodedFile.writec             C   s   d |}| | d S )Nr   )joinr0   )r:   Zlinelistdatar   r   r   
writelines  s    
zEncodedFile.writelinesc             C   s
   t | jS )z"Ensure that file.name is a string.)reprr   )r:   r   r   r   rv     s    zEncodedFile.namec             C   s   t t| d|S )Nr   )rJ   object__getattribute__)r:   rv   r   r   r   __getattr__  s    zEncodedFile.__getattr__N)
rd   re   rf   errorsr;   r0   r   propertyrv   r   r   r   r   r   r     s   	r   r   r4   r5   c               @   sT   e Zd Zd Z ZZdddZdd Zdd Zdd
dZ	dd Z
dd Zdd ZdS )r>   NTc             C   s.   |r|d| _ |r|d| _|r*|d| _d S )Nr   r   r   )r=   r4   r5   )r:   r4   r5   r=   r<   r   r   r   r;     s    

zMultiCapture.__init__c             C   s4   | j r| j   | jr | j  | jr0| j  d S )N)r=   startr4   r5   )r:   r   r   r   rE     s    

zMultiCapture.start_capturingc             C   s4   |   \}}|r| j| |r,| j| ||fS )zA pop current snapshot out/err capture and flush to orig streams. )rL   r4   writeorgr5   )r:   r4   r5   r   r   r   rF     s    zMultiCapture.pop_outerr_to_origFc             C   s>   | j r| j   | jr | j  |r:| jr:| j  d| _d S )NT)r4   suspendr5   r=   _in_suspended)r:   r=   r   r   r   rK     s    



zMultiCapture.suspend_capturingc             C   s<   | j r| j   | jr | j  t| dr8| j  | `d S )Nr   )r4   resumer5   r   r=   r   )r:   r   r   r   rH     s    



zMultiCapture.resume_capturingc             C   sL   t | drtdd| _| jr(| j  | jr8| j  | jrH| j  dS )z, stop capturing and reset capturing streams _resetzwas already stoppedTN)r   rA   r   r4   doner5   r=   )r:   r   r   r   rG     s    


zMultiCapture.stop_capturingc             C   s2   t | jdk	r| j nd| jdk	r,| j ndS )z< return snapshot unicode value of stdout/stderr capturings. Nr   )r   r4   snapr5   )r:   r   r   r   rL     s    zMultiCapture.readouterr)TTTN)F)rd   re   rf   r4   r5   r=   r;   rE   rF   rK   rH   rG   rL   r   r   r   r   r>     s   
	
		r>   c               @   s(   e Zd ZdZdd  Z Z Z ZZdS )	NoCaptureNc              G   s   d S )Nr   )r1   r   r   r   <lambda>  s    zNoCapture.<lambda>)	rd   re   rf   r   r;   r   r   r   r   r   r   r   r   r     s   r   c               @   sV   e Zd ZdZdZdddZdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd ZdS )r}   zUCapture IO to/from a given os-level filedescriptor.

    snap() produces `bytes`
        Nc          	   C   s   || _ yt| j | _W n( tk
r@   dd | _dd | _Y nX |dkrn|rVtdttj	d}t
|| _nH|d krt }| t|dd}W d Q R X |tkrt
||| _nt | _|| _| | _d S )	Nc               S   s   d S )Nr   r   r   r   r   r   
  s    z*FDCaptureBinary.__init__.<locals>.<lambda>c               S   s   d S )Nr   r   r   r   r   r     s    r   zcannot set tmpfile with stdinrzwb+)r   )targetfdr   r   targetfd_saveOSErrorr   r   rD   opendevnullr@   
syscapturer   r   patchsysdictr   tmpfiler   
tmpfile_fd)r:   r   r   r   r   r   r   r;     s&    
zFDCaptureBinary.__init__c             C   s   d| j | jf S )Nz<FDCapture %s oldfd=%s>)r   r   )r:   r   r   r   __repr__  s    zFDCaptureBinary.__repr__c          	   C   sP   yt | j W n  ttfk
r0   tdY nX t | j| j | j	
  dS )z6 Start capturing on targetfd using memorized tmpfile. z&saved filedescriptor not valid anymoreN)r   fstatr   AttributeErrorr   rA   dup2r   r   r   r   )r:   r   r   r   r      s    zFDCaptureBinary.startc             C   s0   | j d | j  }| j d | j   |S )Nr   )r   seekreadtruncate)r:   resr   r   r   r   )  s
    

zFDCaptureBinary.snapc             C   s<   | j d}t|| j t| | j  t| j	 dS )za stop capturing, restore streams, return original capture file,
        seeked to position zero. r   N)
__dict__popr   r   r   rR   r   r   _attempt_to_close_capture_filer   )r:   r   r   r   r   r   0  s
    

zFDCaptureBinary.donec             C   s   | j   t| j| j d S )N)r   r   r   r   r   r   )r:   r   r   r   r   9  s    
zFDCaptureBinary.suspendc             C   s   | j   t| j| j d S )N)r   r   r   r   r   r   )r:   r   r   r   r   =  s    
zFDCaptureBinary.resumec             C   s(   t |tjr|d}t| j| dS )z$ write to original file descriptor. utf8N)rZ   r   r   r   r   r0   r   )r:   r   r   r   r   r   A  s    
zFDCaptureBinary.writeorg)N)rd   re   rf   rg   r   r;   r   r   r   r   r   r   r   r   r   r   r   r}     s   
		r}   c               @   s   e Zd ZdZe Zdd ZdS )r?   zRCapture IO to/from a given os-level filedescriptor.

    snap() produces text
    c             C   s8   t | }t| jdd }|r4t|tr4t||d}|S )Nr   r   )r}   r   rJ   r   rZ   bytesr   r   )r:   r   encr   r   r   r   P  s
    
zFDCapture.snapN)rd   re   rf   rg   strr   r   r   r   r   r   r?   H  s   r?   c               @   sL   e Zd Ze ZdddZdd Zdd Zdd	 Zd
d Z	dd Z
dd ZdS )r@   Nc             C   sB   t | }tt|| _|| _|d kr8|dkr2t }nt }|| _d S )Nr	   )r   rJ   r   _oldrv   DontReadFromInputr   r   )r:   r   r   rv   r   r   r   r;   \  s    zSysCapture.__init__c             C   s   t t| j| j d S )N)setattrr   rv   r   )r:   r   r   r   r   g  s    zSysCapture.startc             C   s$   | j  }| j d | j   |S )Nr   )r   getvaluer   r   )r:   r   r   r   r   r   j  s    

zSysCapture.snapc             C   s"   t t| j| j | `t| j d S )N)r   r   rv   r   r   r   )r:   r   r   r   r   p  s    zSysCapture.donec             C   s   t t| j| j d S )N)r   r   rv   r   )r:   r   r   r   r   u  s    zSysCapture.suspendc             C   s   t t| j| j d S )N)r   r   rv   r   )r:   r   r   r   r   x  s    zSysCapture.resumec             C   s   | j | | j   d S )N)r   r0   flush)r:   r   r   r   r   r   {  s    zSysCapture.writeorg)N)rd   re   rf   r   r   r;   r   r   r   r   r   r   r   r   r   r   r@   X  s   
r@   c               @   s   e Zd ZdZdd ZdS )r{   r   c             C   s&   | j j }| j d | j   |S )Nr   )r   r   r   r   r   )r:   r   r   r   r   r     s    
zSysCaptureBinary.snapN)rd   re   rf   r   r   r   r   r   r   r{     s   r{   c               @   sT   e Zd ZdZdZdd ZeZeZeZdd Z	dd Z
d	d
 Zdd Zedd ZdS )r   a  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.
    Nc             G   s   t dd S )Nz+reading from stdin while output is captured)IOError)r:   r1   r   r   r   r     s    zDontReadFromInput.readc             C   s   | S )Nr   )r:   r   r   r   __iter__  s    zDontReadFromInput.__iter__c             C   s   t dd S )Nz/redirected stdin is pseudofile, has no fileno())r   )r:   r   r   r   r     s    zDontReadFromInput.filenoc             C   s   dS )NFr   )r:   r   r   r   isatty  s    zDontReadFromInput.isattyc             C   s   d S )Nr   )r:   r   r   r   rR     s    zDontReadFromInput.closec             C   s   t jdkr| S tdd S )N)ry   r   z(redirected stdin has no attribute buffer)r   rz   r   )r:   r   r   r   r     s    
zDontReadFromInput.buffer)rd   re   rf   rg   r   r   readline	readlines__next__r   r   r   rR   r   r   r   r   r   r   r     s   r   c              C   s6   t jdsdS yddl} W n tk
r0   Y nX dS )a  
    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.
    win32Nr   )r   platform
startswithcoloramaImportError)r   r   r   r   r&     s    
r&   c              C   s6   t jdsdS yddl} W n tk
r0   Y nX dS )aF  
    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   Nr   )r   r   r   r   r   )r   r   r   r   r'     s    r'   c                s   t jdrt jdd dk r"dS t| ds0dS t| jd  rH| jjn| j}t|tj	s^dS  fdd}|t j
d	t _
|t jd
t _|t jd
t _dS )a  
    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   Nr   )ry      r   rawc                sF    s|d dkrd}nd}t tt|  ||| j| j| j| j	S )Nr   w)
ioTextIOWrapperr   r   r   r   r   r   newlinesline_buffering)r   r   	buffering)bufferedr   r   _reopen_stdio  s    z8_py36_windowsconsoleio_workaround.<locals>._reopen_stdiorbwb)r   r   r   rz   r   r   r   rZ   r   Z_WindowsConsoleIOr	   r
   r   )streamZ
raw_stdoutr   r   )r   r   r%     s    
r%   c             C   s6   t jr*y|   W q2 tk
r&   Y q2X n|   dS )z[Suppress IOError when closing the temporary file used for capturing streams in py27 (#2370)N)r   ZPY2rR   r   )r   r   r   r   r     s    r   )r   )2rg   Z
__future__r   r   r   collectionsrh   r   r   r   r   Ztempfiler   r   r[   Z_pytest.compatr   r   r   r    rj   r6   r   r)   rp   rw   rP   rm   rn   rk   rl   ri   rx   r~   r   r   
namedtupler   r>   r   r}   r?   r@   r{   Iteratorr   r&   r'   r%   r   r   r   r   r   <module>   sR     
;
BK(
%6