
    ,h                         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k7  sJ ej                   d	k7  red
Zded<    G d d      Ze G d de	             Zy)    )annotationsN)TYPE_CHECKING   )Stream)ConflictDetectorfinal)Finalwin32posixi   	FinalTypeDEFAULT_RECEIVE_SIZEc                  J    e Zd ZU ded<   d	dZed
d       ZddZddZddZ	y)	_FdHolderintfdc                    d| _         t        |t              st        d      || _         t	        j
                  |      | _        t	        j                  |d       y )Nzfile descriptor must be an intF)r   
isinstancer   	TypeErrorosget_blocking_original_is_blockingset_blockingselfr   s     R/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/trio/_unix_pipes.py__init__z_FdHolder.__init__0   sG     "c"<==%'__R%8"
E"    c                     | j                   dk(  S Nr   )r   r   s    r   closedz_FdHolder.closed;   s    ww"}r   c                    | j                   ry | j                  }d| _        t        j                  || j                         t        j
                  |       y r    )r"   r   r   r   r   closer   s     r   
_raw_closez_FdHolder._raw_close?   s=     ;;WW
D667
r   c                $    | j                          y N)r%   r!   s    r   __del__z_FdHolder.__del__N   s    r   c                    | j                   s:t        j                  j                  | j                         | j                          y y r'   )r"   triolowlevelnotify_closingr   r%   r!   s    r   r$   z_FdHolder.closeQ   s.    {{MM((1OO r   Nr   r   returnNone)r.   boolr.   r/   )
__name__
__module____qualname____annotations__r   propertyr"   r%   r(   r$    r   r   r   r      s1    $ 	G	#  r   r   c                  J    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
y)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.
    c                d    t        |      | _        t        d      | _        t        d      | _        y )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   s/    #B-'78(
$ +;;+
'r   c                *  K   | j                   5  | j                  j                  rt        j                  d      t        j
                  j                          d {    t        |      }t        |      5 }d}||k  rB||d  5 }	 |t        j                  | j                  j                  |      z  }d d d        ||k  rBd d d        d d d        y 7 u# t        $ r? t        j
                  j                  | j                  j                         d {  7   Y ht        $ rI}|j                  t        j                   k(  rt        j                  d      d t        j"                  |d }~ww xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY ww)Nfile was already closedr   )r<   r;   r"   r*   ClosedResourceErrorr+   
checkpointlen
memoryviewr   writer   BlockingIOErrorwait_writableOSErrorerrnoEBADFBrokenResourceError)r   datalengthviewsent	remaininges          r   send_allzFdStream.send_all   sk    )) 	F %%../HII--**,,,YFD! FTVmde F	
F BHHT__-?-?$KKDF VmF	F 	F
 -  / R"&--"="=doo>P>P"QQQ& F ww%++5&*&>&>$='"'+!, '+&>&>A EFF FF F	F 	Fs   FAFCF7E;E/-C3E;F		FF?E,	DE,	E/E,	#AE'	'E,	,E//E84E;;F	 FFFc                f  K   | j                   5  | j                  j                  rt        j                  d      	 t        j
                  j                  | j                  j                         d {    	 d d d        y 7 # t        $ r}t        j                  |d }~ww xY w# 1 sw Y   y xY ww)Nr?   )
r<   r;   r"   r*   r@   r+   rF   r   BrokenPipeErrorrJ   )r   rP   s     r   wait_send_all_might_not_blockz&FdStream.wait_send_all_might_not_block   s     )) 	6%%../HII6mm11$//2D2DEEE		6 	6 F" 6 ..A56	6 	6sK   B1,B%6B2B3B8	B1B	B"BB""B%%B.*B1Nc                  K   | j                   5  |t        }n+t        |t              st	        d      |dk  rt        d      t        j                  j                          d {    	 	 t        j                  | j                  j                  |      }	 |cd d d        S 7 <# t        $ r? t        j                  j                  | j                  j                         d {  7   Y nTt        $ rI}|j                   t         j"                  k(  rt        j$                  d      d t        j&                  |d }~ww xY w# 1 sw Y   y xY ww)Nzmax_bytes must be integer >= 1r   r?   )r=   r   r   r   r   
ValueErrorr*   r+   rA   r   readr;   r   rE   wait_readablerG   rH   rI   r@   rJ   )r   	max_bytesrK   excs       r   receive_somezFdStream.receive_some   s    ,, 	 0	!)S1#$DEEq=$%EFF--**,,,774??#5#5yAD 3	 	 - ' J--55doo6H6HIII @yyEKK/"665#$ #66C?@ 	 	sl   EAE %B"&E ,*B$E 
E"E $?D<#C&$D<)E +D<3AD77D<<E  E	Ec                8    | j                   j                          y r'   )r;   r$   r!   s    r   r$   zFdStream.close   s    r   c                |   K   | j                          t        j                  j                          d {    y 7 wr'   )r$   r*   r+   rA   r!   s    r   aclosezFdStream.aclose   s%     

mm&&(((s   2<:<c                .    | j                   j                  S r'   )r;   r   r!   s    r   filenozFdStream.fileno   s    !!!r   r-   )rK   bytesr.   r/   r1   r'   )rY   z
int | Noner.   ra   )r.   r   )r2   r3   r4   __doc__r   rQ   rT   r[   r$   r^   r`   r7   r   r   r9   r9   W   s,    @
F2	68 )"r   r9   )
__future__r   rH   r   systypingr   r*   _abcr   _utilr   r   r	   r   platformnameImportErrorr   r5   r   r9   r7   r   r   <module>rk      s~    "  	 
     *)CLLG3 377g  #( i '8 8v r"v r" r"r   