a
    (ñ»j÷  ã                   @  s°   d dl mZ d dlZd dlmZ ddlmZ ddlmZm	Z	 ddl
mZmZmZ ddlmZmZ ejd	ksrerrJ ‚d
ZG dd„ dƒZeG dd„ de	ƒƒZeG dd„ deƒƒZdS )é    )ÚannotationsN)ÚTYPE_CHECKINGé   )Ú_core)ÚReceiveStreamÚ
SendStream)Ú_handleÚkernel32Úraise_winerror)ÚConflictDetectorÚfinalÚwin32i   c                   @  sJ   e Zd Zdddœdd„Zeddœdd	„ƒZddœd
d„Zddœdd„ZdS )Ú_HandleHolderÚintÚNone©ÚhandleÚreturnc                 C  s.   d| _ t|tƒstdƒ‚|| _ t | j ¡ d S )Néÿÿÿÿzhandle must be an int)r   Ú
isinstancer   Ú	TypeErrorr   Zregister_with_iocp©Úselfr   © r   ú9E:\soccer\ml_env\Lib\site-packages\trio/_windows_pipes.pyÚ__init__   s
    
z_HandleHolder.__init__Úbool©r   c                 C  s
   | j dkS ©Nr   )r   ©r   r   r   r   Úclosed   s    z_HandleHolder.closedc                 C  s.   | j r
d S | j}d| _t t|ƒ¡s*tƒ  d S r   )r    r   r	   ÚCloseHandler   r
   r   r   r   r   Úclose   s    z_HandleHolder.closec                 C  s   |   ¡  d S ©N)r"   r   r   r   r   Ú__del__'   s    z_HandleHolder.__del__N)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr    r"   r$   r   r   r   r   r      s
   r   c                   @  sZ   e Zd ZdZdddœdd„Zdddœd	d
„Zddœdd„Zddœdd„Zddœdd„ZdS )ÚPipeSendStreamzdRepresents a send stream over a Windows named pipe that has been
    opened in OVERLAPPED mode.
    r   r   r   c                 C  s   t |ƒ| _tdƒ| _d S ©Nz)another task is currently using this pipe©r   Ú_handle_holderr   Ú_conflict_detectorr   r   r   r   r   1   s    
ÿzPipeSendStream.__init__Úbytes)Údatar   c                 Ã  s¶   | j �œ | jjrt d¡‚|s<t ¡ I d H  W d   ƒ d S zt | jj|¡I d H }W n, ty‚ } ztj	|‚W Y d }~n
d }~0 0 |t
|ƒks”J ‚W d   ƒ n1 s¨0    Y  d S )Núthis pipe is already closed)r-   r,   r    r   ÚClosedResourceErrorÚ
checkpointZwrite_overlappedr   ÚBrokenPipeErrorZBrokenResourceErrorÚlen)r   r/   ZwrittenÚexr   r   r   Úsend_all7   s    
zPipeSendStream.send_allr   c                 Ã  sJ   | j �0 | jjrt d¡‚t ¡ I d H  W d   ƒ n1 s<0    Y  d S )NzThis pipe is already closed)r-   r,   r    r   r1   r2   r   r   r   r   Úwait_send_all_might_not_blockI   s    
z,PipeSendStream.wait_send_all_might_not_blockc                 C  s   | j  ¡  d S r#   ©r,   r"   r   r   r   r   r"   Q   s    zPipeSendStream.closec                 Ã  s   |   ¡  t ¡ I d H  d S r#   ©r"   r   r2   r   r   r   r   ÚacloseT   s    zPipeSendStream.acloseN)	r%   r&   r'   Ú__doc__r   r6   r7   r"   r:   r   r   r   r   r)   +   s   r)   c                   @  sN   e Zd ZdZdddœdd„Zddd	d
œdd„Zddœdd„Zddœdd„ZdS )ÚPipeReceiveStreamz3Represents a receive stream over an os.pipe object.r   r   r   c                 C  s   t |ƒ| _tdƒ| _d S r*   r+   r   r   r   r   r   ]   s    
ÿzPipeReceiveStream.__init__Nz
int | Noner.   )Ú	max_bytesr   c              	   Ã  sî   | j �Ô | jjrt d¡‚|d u r(t}n"t|tƒs:tdƒ‚|dk rJt	dƒ‚t
|ƒ}zt | jj|¡I d H }W nB ty®   | jjrŽt d¡d ‚t ¡ I d H  Y W d   ƒ dS 0 ||d …= |W  d   ƒ S W d   ƒ n1 sà0    Y  d S )Nr0   zmax_bytes must be integer >= 1r   zanother task closed this pipeó    )r-   r,   r    r   r1   ÚDEFAULT_RECEIVE_SIZEr   r   r   Ú
ValueErrorÚ	bytearrayZreadinto_overlappedr   r3   r2   )r   r=   ÚbufferÚsizer   r   r   Úreceive_somec   s4    

þÿþ
zPipeReceiveStream.receive_somer   c                 C  s   | j  ¡  d S r#   r8   r   r   r   r   r"   ‹   s    zPipeReceiveStream.closec                 Ã  s   |   ¡  t ¡ I d H  d S r#   r9   r   r   r   r   r:   Ž   s    zPipeReceiveStream.aclose)N)r%   r&   r'   r;   r   rD   r"   r:   r   r   r   r   r<   Y   s
   (r<   )Ú
__future__r   ÚsysÚtypingr   Ú r   Ú_abcr   r   Z_core._windows_cffir   r	   r
   Z_utilr   r   Úplatformr?   r   r)   r<   r   r   r   r   Ú<module>   s   -