1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
U
Z±dÊã@slddlZddlZddlmZddlmZmZddlZejdkrBe    ‚dZ
Gdd„dƒZ Gd    d
„d
eed Z dS) éNé)ÚStream)ÚConflictDetectorÚFinalÚposixic@s>eZdZedœdd„Zedd„ƒZdd„Zdd    „Zd
d „Z    d S) Ú    _FdHolder©ÚfdcCs:d|_t|tƒstdƒ‚||_t |¡|_t |d¡dS)Néÿÿÿÿzfile descriptor must be an intF)r    Ú
isinstanceÚintÚ    TypeErrorÚosZ get_blockingÚ_original_is_blockingÚ set_blocking©Úselfr    ©rúGd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_unix_pipes.pyÚ__init__%s 
 z_FdHolder.__init__cCs
|jdkS©Nr
r©rrrrÚclosed0sz_FdHolder.closedcCs2|jr
dS|j}d|_t ||j¡t |¡dSr)rr    rrrÚcloserrrrÚ
_raw_close4s z_FdHolder._raw_closecCs | ¡dS©N)rrrrrÚ__del__Csz_FdHolder.__del__cCs |jstj |j¡| ¡dSr)rÚtrioÚlowlevelZnotify_closingr    rrrrrrFsz_FdHolder.closeN)
Ú__name__Ú
__module__Ú __qualname__r rÚpropertyrrrrrrrrrs  
rc@sbeZdZdZedœdd„Zedœdd„Zdd    œd
d „Zded    œd d „Z    dd„Z
dd„Z dd„Z dS)Ú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.
    rcCs"t|ƒ|_tdƒ|_tdƒ|_dS)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_detectorrrrrrms
ÿÿzFdStream.__init__)Údatac Ãs|jð|jjrt d¡‚tj ¡IdHt|ƒ}t|ƒ²}d}||krè||d…Œ}z|t     
|jj |¡7}Wnlt k
r˜tj  |jj ¡IdHYnDtk
rÚ}z&|jtjkrÂt d¡d‚ntj|‚W5d}~XYnXW5QRXq@W5QRXW5QRXdS)Núfile was already closedr)r%r$rrÚClosedResourceErrorrÚ
checkpointÚlenÚ
memoryviewrÚwriter    ÚBlockingIOErrorÚ wait_writableÚOSErrorÚerrnoÚEBADFÚBrokenResourceError)rr'ÚlengthÚviewÚsentÚ    remainingÚerrrÚsend_allvs*
 
 ÿþzFdStream.send_allN)Úreturnc Ãsn|j^|jjrt d¡‚ztj |jj¡IdHWn*tk
r^}z tj    |‚W5d}~XYnXW5QRXdS)Nr()
r%r$rrr)rr/r    ÚBrokenPipeErrorr3)rr8rrrÚwait_send_all_might_not_blocks
z&FdStream.wait_send_all_might_not_blockc Ãsè|jØ|dkrt}n"t|tƒs(tdƒ‚|dkr8tdƒ‚tj ¡IdHzt     
|j j |¡}WqÎt k
r†tj |j j ¡IdHYqHtk
rÈ}z&|jtjkr°t d¡d‚ntj|‚W5d}~XYqHXqÎqH|W5QR£SQRXdS)Nzmax_bytes must be integer >= 1rr()r&ÚDEFAULT_RECEIVE_SIZEr r r Ú
ValueErrorrrr*rÚreadr$r    r.Z wait_readabler0r1r2r)r3)rZ    max_bytesr'r8rrrÚ receive_somešs,
 ÿþzFdStream.receive_somecCs|j ¡dSr)r$rrrrrr¶szFdStream.closecÃs| ¡tj ¡IdHdSr)rrrr*rrrrÚaclose¹szFdStream.aclosecCs|jjSr)r$r    rrrrÚfileno½szFdStream.fileno)N) rr r!Ú__doc__r rÚbytesr9r<r@rrArBrrrrr#Ls      r#)Ú    metaclass) rr1Ú_abcrZ_utilrrrÚnameÚ ImportErrorr=rr#rrrrÚ<module>s 
9