U
    ouf¤  ã                   @  st   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 dgZdddd	œd
d„Zedddœdd„ƒZdS )é    )ÚannotationsN)Úcontextmanager)ÚIOÚIteratorÚTextIOÚflush_stdoutr   ÚstrÚNone)ÚstdoutÚdataÚreturnc              
   C  s¶   t | dƒot | dƒ}zJt| ƒ8 |r@| j | | jp6dd¡¡ n
|  |¡ |  ¡  W 5 Q R X W nR tk
r° } z4|jrˆ|jd t	j
krˆn|jrž|jd dkržn‚ W 5 d }~X Y nX d S )NÚencodingÚbufferzutf-8Úreplacer   )ÚhasattrÚ_blocking_ior   ÚwriteÚencoder   ÚflushÚOSErrorÚargsÚerrnoZEINTR)r
   r   Zhas_binary_ioÚe© r   úF/tmp/pip-unpacked-wheel-8milen2s/prompt_toolkit/output/flush_stdout.pyr      s    

zIO[str]zIterator[None])Úior   c              
   c  sn   t jdkrdV  dS z|  ¡ }t |¡}W n   d}Y nX z|sNt |d¡ dV  W 5 |sht ||¡ X dS )zA
    Ensure that the FD for `io` is set to blocking in here.
    Úwin32NT)ÚsysÚplatformÚfilenoÚosÚget_blockingÚset_blocking)r   ÚfdÚblockingr   r   r   r   8   s    


r   )Ú
__future__r   r   r    r   Ú
contextlibr   Útypingr   r   r   Ú__all__r   r   r   r   r   r   Ú<module>   s   ,