
    i,                         % S SK Jr  S SKrS SKrS SKrS SKJrJr  S SK	r	SSK
Jr  SSKJrJr  \(       a  \R                  S:w  d   eSrS	\S
'    " S S5      r\ " S S\5      5       rg)    )annotationsN)TYPE_CHECKINGFinal   )Stream)ConflictDetectorfinalwin32i   	FinalTypeDEFAULT_RECEIVE_SIZEc                  \    \ rS rSr% S\S'   SS jr\SS j5       rSS jrSS jr	SS jr
S	rg
)	_FdHolder   intfdc                    SU l         [        U[        5      (       d  [        S5      eXl         [        R
                  " U5      U l        [        R                  " US5        g )Nzfile descriptor must be an intF)r   
isinstancer   	TypeErrorosget_blocking_original_is_blockingset_blockingselfr   s     =C:\des-py\RoboSAPF\venv\Lib\site-packages\trio/_unix_pipes.py__init___FdHolder.__init__(   sH     "c""<==%'__R%8"
E"    c                     U R                   S:H  $ Nr   )r   r   s    r   closed_FdHolder.closed3   s    ww"}r   c                    U R                   (       a  g U R                  nSU l        [        R                  " XR                  5        [        R
                  " U5        g r!   )r#   r   r   r   r   closer   s     r   
_raw_close_FdHolder._raw_close7   s;     ;;WW
667
r   c                $    U R                  5         g N)r'   r"   s    r   __del___FdHolder.__del__F   s    r   c                    U R                   (       d:  [        R                  R                  U R                  5        U R                  5         g g r*   )r#   triolowlevelnotify_closingr   r'   r"   s    r   r&   _FdHolder.closeI   s.    {{MM((1OO r   )r   r   Nr   r   returnNone)r3   boolr3   r4   )__name__
__module____qualname____firstlineno____annotations__r   propertyr#   r'   r+   r&   __static_attributes__ r   r   r   r      s1    $ 	G	#  r   r   c                  b    \ rS rSrSrSS jrSS jrSS jrSSS jjrSS jr	SS	 jr
SS
 jrSrg)FdStreamO   a  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.

.. warning:: one specific consequence of non-blocking mode
  applying to the entire open file description is that when
  your program is run with multiple standard streams connected to
  a TTY (as in a terminal emulator), all of the streams become
  non-blocking when you construct an `FdStream` for any of them.
  For example, if you construct an `FdStream` for standard input,
  you might observe Python loggers begin to fail with
  `BlockingIOError`.

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

Returns:
  A new `FdStream` object.
c                d    [        U5      U l        [        S5      U l        [        S5      U l        g )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   FdStream.__init__y   s/    #B-'78(
$ +;;+
'r   c                ^  #    U R                      U R                  R                  (       a  [        R                  " S5      e[        R
                  R                  5       I S h  vN   [        U5      n[        U5       nSnXB:  aC  X4S   n U[        R                  " U R                  R                  U5      -  nS S S 5        XB:  a  MC  S S S 5        S S S 5        g  Nv! [         a?    [        R
                  R                  U R                  R                  5      I S h  vN     Nj[         aK  nUR                  [        R                   :X  a  [        R                  " S5      S e[        R"                  UeS nAff = f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g = f7f)Nfile was already closedr   )rD   rC   r#   r.   ClosedResourceErrorr/   
checkpointlen
memoryviewr   writer   BlockingIOErrorwait_writableOSErrorerrnoEBADFBrokenResourceError)r   datalengthviewsent	remaininges          r   send_allFdStream.send_all   s?    )) %%../HII--**,,,YFD!Tme	
F BHHT__-?-?$KKD % m " *)
 -  / R"&--"="=doo>P>P"QQQ& F ww%++5&*&>&>$='"'+!, '+&>&>A EF % "! *)s   F-AF"C#F=F	E:.C9FF	F-FA E7	DE7	!E:#	E7	,AE2	2E7	7E::
FF
F	F
F*&F-c                4  #    U R                      U R                  R                  (       a  [        R                  " S5      e[        R
                  R                  U R                  R                  5      I S h  vN   S S S 5        g  N! , (       d  f       g = f7f)NrH   )rD   rC   r#   r.   rI   r/   rO   r   r"   s    r   wait_send_all_might_not_block&FdStream.wait_send_all_might_not_block   se     ))%%../HII----doo.@.@AAA *) B *)s/   BA(B7B8B<	BB
BBNc                  #    U R                      Uc  [        nO1[        U[        5      (       d  [	        S5      eUS:  a  [        S5      e[        R                  R                  5       I S h  vN     [        R                  " U R                  R                  U5      n UsS S S 5        $  N=! [         a?    [        R                  R                  U R                  R                  5      I S h  vN     OW[         aK  nUR                   [         R"                  :X  a  [        R$                  " S5      S e[        R&                  UeS nAff = fM  ! , (       d  f       g = f7f)Nzmax_bytes must be integer >= 1r   rH   )rE   r   r   r   r   
ValueErrorr.   r/   rJ   r   readrC   r   rN   wait_readablerP   rQ   rR   rI   rS   )r   	max_bytesrT   excs       r   receive_someFdStream.receive_some   s    ,, 0	!)S1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?@  -,sm   EAE,B*-E3+B,E 
E*E,A E,C/-E2E4	E=AEEE
EEc                8    U R                   R                  5         g r*   )rC   r&   r"   s    r   r&   FdStream.close   s    r   c                |   #    U R                  5         [        R                  R                  5       I S h  vN   g  N7fr*   )r&   r.   r/   rJ   r"   s    r   acloseFdStream.aclose   s$     

mm&&(((s   2<:<c                .    U R                   R                  $ r*   )rC   r   r"   s    r   filenoFdStream.fileno   s    !!!r   )rC   rE   rD   r2   )rT   bytesr3   r4   r6   r*   )rc   z
int | Noner3   ro   )r3   r   )r7   r8   r9   r:   __doc__r   rZ   r]   re   r&   rj   rm   r=   r>   r   r   r@   r@   O   s-    &P
F2B8 )"r   r@   )
__future__r   rQ   r   systypingr   r   r   r.   _abcr   _utilr   r	   platformr   r;   r   r@   r>   r   r   <module>rw      sg    "  	 
 4   *CLLG3 33 #( i '8 8v u"v u" u"r   