a
     h                     @  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 )Nzhandle must be an int)r   
isinstancer   	TypeErrorr   Zregister_with_iocpselfr    r   X/var/www/html/swiplay.fr/scambot/venv/lib/python3.9/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	   Z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sJ W d    n1 s0    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   r0   r1   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   r1   r   r   r   r   acloseT   s    zPipeSendStream.acloseN)	r$   r%   r&   __doc__r   r5   r6   r!   r9   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rtdd t I d H  Y W d    dS 0 ||d = |W  d    S W d    n1 s0    Y  d S )Nr/   zmax_bytes must be integer >= 1r   zanother task closed this pipe    )r,   r+   r    r   r0   DEFAULT_RECEIVE_SIZEr   r   r   
ValueError	bytearrayZreadinto_overlappedr   r2   r1   )r   r<   buffersizer   r   r   receive_somec   s4    


zPipeReceiveStream.receive_somer   c                 C  s   | j   d S r"   r7   r   r   r   r   r!      s    zPipeReceiveStream.closec                   s   |    t I d H  d S r"   r8   r   r   r   r   r9      s    zPipeReceiveStream.aclose)N)r$   r%   r&   r:   r   rC   r!   r9   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   -