
     f                        U 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Zddlm	Z	 ddl
mZmZ erd dlmZ erej        dk    sJ ej        d	k    red
Zded<    G d d          Ze G d de	                      ZdS )    )annotationsN)TYPE_CHECKING   )Stream)ConflictDetectorfinal)Finalwin32posixi   	FinalTypeDEFAULT_RECEIVE_SIZEc                  R    e Zd ZU ded<   ddZedd            ZddZdd	Zdd
Z	dS )	_FdHolderintfdreturnNonec                    d| _         t          |t                    st          d          || _         t	          j        |          | _        t	          j        |d           d S )Nzfile descriptor must be an intF)r   
isinstancer   	TypeErrorosget_blocking_original_is_blockingset_blockingselfr   s     S/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/trio/_unix_pipes.py__init__z_FdHolder.__init__0   s]     "c"" 	><===%'_R%8%8"
E"""""    boolc                    | j         dk    S Nr   )r   r   s    r   closedz_FdHolder.closed;   s    w"}r    c                    | j         rd S | j        }d| _        t          j        || j                   t          j        |           d S r#   )r%   r   r   r   r   closer   s     r   
_raw_closez_FdHolder._raw_close?   sG     ; 	FW
D6777
r    c                .    |                                   d S N)r(   r$   s    r   __del__z_FdHolder.__del__N   s    r    c                    | j         s:t          j                            | j                   |                                  d S d S r*   )r%   triolowlevelnotify_closingr   r(   r$   s    r   r'   z_FdHolder.closeQ   sD    { 	M((111OO	 	r    Nr   r   r   r   )r   r!   r   r   )
__name__
__module____qualname____annotations__r   propertyr%   r(   r+   r'    r    r   r   r      s         $ GGG	# 	# 	# 	#    X           r    r   c                  L    e Zd ZdZddZdd	Zdd
ZdddZddZddZ	ddZ
dS )FdStreama<  
    Represents a stream given the file descriptor to a pipe, TTY, etc.

    *fd* must refer to a file that is open for reading and/or writing and
    supports non-blocking I/O (pipes and TTYs will work, on-disk files probably
    not).  The returned stream takes ownership of the fd, so closing the stream
    will close the fd too.  As with `os.fdopen`, you should not directly use
    an fd after you have wrapped it in a stream using this function.

    To be used as a Trio stream, an open file must be placed in non-blocking
    mode.  Unfortunately, this impacts all I/O that goes through the
    underlying open file, including I/O that uses a different
    file descriptor than the one that was passed to Trio. If other threads
    or processes are using file descriptors that are related through `os.dup`
    or inheritance across `os.fork` to the one that Trio is using, they are
    unlikely to be prepared to have non-blocking I/O semantics suddenly
    thrust upon them.  For example, you can use
    ``FdStream(os.dup(sys.stdin.fileno()))`` to obtain a stream for reading
    from standard input, but it is only safe to do so with heavy caveats: your
    stdin must not be shared by any other processes, and you must not make any
    calls to synchronous methods of `sys.stdin` until the stream returned by
    `FdStream` is closed. See `issue #174
    <https://github.com/python-trio/trio/issues/174>`__ for a discussion of the
    challenges involved in relaxing this restriction.

    Args:
      fd (int): The fd to be wrapped.

    Returns:
      A new `FdStream` object.
    r   r   r   r   c                ~    t          |          | _        t          d          | _        t          d          | _        d S )Nz*another task is using this stream for sendz-another task is using this stream for receive)r   
_fd_holderr   _send_conflict_detector_receive_conflict_detectorr   s     r   r   zFdStream.__init__y   sA    #B--'78(
 (
$ +;;+
 +
'''r    databytesc                  K   | j         5  | j        j        rt          j        d          t          j                                         d {V  t          |          }t          |          5 }d}||k     r||d          5 }	 |t          j
        | j        j        |          z  }n# t          $ r2 t          j                            | j        j                   d {V  Y nHt          $ r<}|j        t          j        k    rt          j        d          d t          j        |d }~ww xY wd d d            n# 1 swxY w Y   ||k     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nfile was already closedr   )r<   r;   r%   r-   ClosedResourceErrorr.   
checkpointlen
memoryviewr   writer   BlockingIOErrorwait_writableOSErrorerrnoEBADFBrokenResourceError)r   r>   lengthviewsent	remaininges          r   send_allzFdStream.send_all   s     ) 	F 	F % J./HIII-**,,,,,,,,,YYFD!! FTVmmdee F	
F BHT_-?$K$KKDD. R R R"&-"="=do>P"Q"QQQQQQQQQQ& F F F w%+55&*&>$='" '"'+!, '+&>A EFF F F F F F F F F F F F F F F VmmF F F F F F F F F F F F F F F	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   A#E)-E D4"B%$D4%9D%	D4 	D%	)7D 	 D%	%D4(E4D88E;D8<	EE)E	E)E	E))E-0E-c                ,  K   | j         5  | j        j        rt          j        d          	 t          j                            | j        j                   d {V  n# t          $ r}t          j	        |d }~ww xY w	 d d d            d S # 1 swxY w Y   d S )NrA   )
r<   r;   r%   r-   rB   r.   rH   r   BrokenPipeErrorrL   )r   rQ   s     r   wait_send_all_might_not_blockz&FdStream.wait_send_all_might_not_block   s      ) 	6 	6% J./HIII6m11$/2DEEEEEEEEEE" 6 6 6 .A56 F		6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s4   !B	/AB	
A8&A33A88B		BBN	max_bytes
int | Nonec                f  K   | j         5  |t          }n9t          |t                    st	          d          |dk     rt          d          t          j                                         d {V  	 	 t          j
        | j        j        |          }n# t          $ r2 t          j                            | j        j                   d {V  Y nHt          $ r<}|j        t           j        k    rt          j        d          d t          j        |d }~ww xY w|cd d d            S # 1 swxY w Y   d S )Nzmax_bytes must be integer >= 1r   TrA   )r=   r   r   r   r   
ValueErrorr-   r.   rC   r   readr;   r   rG   wait_readablerI   rJ   rK   rB   rL   )r   rV   r>   excs       r   receive_somezFdStream.receive_some   s     , 	 	 0		!)S11 F#$DEEEq==$%EFFF-**,,,,,,,,,74?#5yAAD  ' J J J-55do6HIIIIIIIIIII @ @ @yEK//"65 #$ #6C?@ 3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sB   A)D&4BD&9DD&	D7DDD&&D*-D*c                8    | j                                          d S r*   )r;   r'   r$   s    r   r'   zFdStream.close   s    r    c                z   K   |                                   t          j                                         d {V  d S r*   )r'   r-   r.   rC   r$   s    r   aclosezFdStream.aclose   s?      

m&&(((((((((((r    c                    | j         j        S r*   )r;   r   r$   s    r   filenozFdStream.fileno   s    !!r    r0   )r>   r?   r   r   r1   r*   )rV   rW   r   r?   )r   r   )r2   r3   r4   __doc__r   rR   rU   r]   r'   r`   rb   r7   r    r   r9   r9   W   s         @
 
 
 
F F F F2	6 	6 	6 	6    8       ) ) ) )" " " " " "r    r9   )
__future__r   rJ   r   systypingr   r-   _abcr   _utilr   r   r	   r   platformnameImportErrorr   r5   r   r9   r7   r    r   <module>rl      sH   " " " " " " "  				 



                    * * * * * * * * *)))))) 3CLG33337g  #(  ' ' ' '8 8 8 8 8 8 8 8v r" r" r" r" r"v r" r" r" r" r"r    