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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
U
Z±d¥8ã@sðddlZddlmZddlZddlmZddlmZm    Z    ddl
m Z m Z dZ ejejhZedd    „ƒZGd
d „d e e    d Zd ddddddddddddddgZeƒZeD].Zze eeeƒ¡Wq¤ek
rÐYq¤Xq¤Gdd„de ee    d ZdS)éN)Úcontextmanageré)Úsocket)ÚConflictDetectorÚFinal)ÚHalfCloseableStreamÚListeneric
cs\z
dVWnLtk
rV}z.|jtkr4t d¡d‚nt d |¡¡|‚W5d}~XYnXdS)Nzthis socket was already closedzsocket connection broken: {})ÚOSErrorÚerrnoÚ_closed_stream_errnosÚtrioÚClosedResourceErrorZBrokenResourceErrorÚformat)Úexc©rúMd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_highlevel_socket.pyÚ)_translate_socket_errors_to_stream_errorss
 
ÿþrc@sTeZdZdZdd„Zdd„Zdd„Zdd    „Zdd d „Zd d„Z    dd„Z
ddd„Z d
S)Ú SocketStreamufAn implementation of the :class:`trio.abc.HalfCloseableStream`
    interface based on a raw network socket.
 
    Args:
      socket: The Trio socket object to wrap. Must have type ``SOCK_STREAM``,
          and be connected.
 
    By default for TCP sockets, :class:`SocketStream` enables ``TCP_NODELAY``,
    and (on platforms where it's supported) enables ``TCP_NOTSENT_LOWAT`` with
    a reasonable buffer size (currently 16 KiB) â€“ see `issue #72
    <https://github.com/python-trio/trio/issues/72>`__ for discussion. You can
    of course override these defaults by calling :meth:`setsockopt`.
 
    Once a :class:`SocketStream` object is constructed, it implements the full
    :class:`trio.abc.HalfCloseableStream` interface. In addition, it provides
    a few extra features:
 
    .. attribute:: socket
 
       The Trio socket object that this stream wraps.
 
    cCsžt|tjƒstdƒ‚|jtjkr(tdƒ‚||_tdƒ|_    z| 
tj tj d¡Wnt k
rbYnXttdƒršz| 
tj tjd¡Wnt k
r˜YnXdS)Nz*SocketStream requires a Trio socket objectz*SocketStream requires a SOCK_STREAM socketz;another task is currently sending data on this SocketStreamTÚTCP_NOTSENT_LOWATi@)Ú
isinstanceÚtsocketÚ
SocketTypeÚ    TypeErrorÚtypeÚ SOCK_STREAMÚ
ValueErrorrrÚ_send_conflict_detectorÚ
setsockoptÚ IPPROTO_TCPÚ TCP_NODELAYr    Úhasattrr)ÚselfrrrrÚ__init__>s"  ÿ
 
zSocketStream.__init__c Ãsà|jjrt d¡‚|j¾tƒ¬t|ƒ˜}|sz|j ¡dkrHt d¡‚tj     ¡IdHW5QR£W5QR£W5QR£dSd}|t
|ƒkr¾||d…}|j  |¡IdH}W5QRX||7}q~W5QRXW5QRXW5QRXdS)Nz!can't send data after sending EOFéÿÿÿÿzsocket was already closedr) rÚdid_shutdown_SHUT_WRr r rrÚ
memoryviewÚfilenoÚlowlevelÚ
checkpointÚlenÚsend)r!ÚdataÚ
total_sentÚ    remainingÚsentrrrÚsend_all`s
 
 
" zSocketStream.send_allc
ÃsL|j<|j ¡dkrtj‚tƒ|j ¡IdHW5QRXW5QRXdS)Nr#)rrr&r r rZ wait_writable©r!rrrÚwait_send_all_might_not_blockqs
z*SocketStream.wait_send_all_might_not_blockc
Ãs\|jLtj ¡IdH|jjr.W5QR£dStƒ|j tj    ¡W5QRXW5QRXdS©N)
rr r'r(rr$rÚshutdownrÚSHUT_WRr0rrrÚsend_eofxs zSocketStream.send_eofNc
ÃsL|dkr t}|dkrtdƒ‚tƒ |j |¡IdHW5QR£SQRXdS)Nrzmax_bytes must be >= 1)ÚDEFAULT_RECEIVE_SIZErrrÚrecv)r!Z    max_bytesrrrÚ receive_some‚s zSocketStream.receive_somecÃs|j ¡tj ¡IdHdSr2©rÚcloser r'r(r0rrrÚacloseŠs
zSocketStream.aclosecCs|j |||¡S)zlSet an option on the underlying socket.
 
        See :meth:`socket.socket.setsockopt` for details.
 
        )rr)r!ÚlevelÚoptionÚvaluerrrrszSocketStream.setsockoptrcCs*|dkr|j ||¡S|j |||¡SdS)zƒCheck the current value of an option on the underlying socket.
 
        See :meth:`socket.socket.getsockopt` for details.
 
        rN)rÚ
getsockopt)r!r<r=Z
buffersizerrrr?˜s    zSocketStream.getsockopt)N)r) Ú__name__Ú
__module__Ú __qualname__Ú__doc__r"r/r1r5r8r;rr?rrrrr&s"
 
r)Ú    metaclassÚEPERMÚ ECONNABORTEDZEPROTOZENETDOWNZ ENOPROTOOPTZ    EHOSTDOWNZENONETZ EHOSTUNREACHÚ
EOPNOTSUPPZ ENETUNREACHZENOSRZESOCKTNOSUPPORTZEPROTONOSUPPORTZ    ETIMEDOUTÚ
ECONNRESETc@s(eZdZdZdd„Zdd„Zdd„ZdS)    ÚSocketListeneraâA :class:`~trio.abc.Listener` that uses a listening socket to accept
    incoming connections as :class:`SocketStream` objects.
 
    Args:
      socket: The Trio socket object to wrap. Must have type ``SOCK_STREAM``,
          and be listening.
 
    Note that the :class:`SocketListener` "takes ownership" of the given
    socket; closing the :class:`SocketListener` will also close the socket.
 
    .. attribute:: socket
 
       The Trio socket object that this stream wraps.
 
    cCsht|tjƒstdƒ‚|jtjkr(tdƒ‚z| tjtj    ¡}Wnt
k
rPYnX|s^tdƒ‚||_ dS)Nz,SocketListener requires a Trio socket objectz,SocketListener requires a SOCK_STREAM socketz*SocketListener requires a listening socket) rrrrrrrr?Ú
SOL_SOCKETÚ SO_ACCEPTCONNr    r)r!rZ    listeningrrrr"Os  zSocketListener.__init__c
Ãsfz|j ¡IdH\}}Wn>tk
rV}z |jtkr:tj‚|jtkrF‚W5d}~XYqXt|ƒSqdS)a#Accept an incoming connection.
 
        Returns:
          :class:`SocketStream`
 
        Raises:
          OSError: if the underlying call to ``accept`` raises an unexpected
              error.
          ClosedResourceError: if you already closed the socket.
 
        This method handles routine errors like ``ECONNABORTED``, but passes
        other errors on to its caller. In particular, it does *not* make any
        special effort to handle resource exhaustion errors like ``EMFILE``,
        ``ENFILE``, ``ENOBUFS``, ``ENOMEM``.
 
        N)    rÚacceptr    r
r r r Ú_ignorable_accept_errnosr)r!ÚsockÚ_rrrrrL_s
 
zSocketListener.acceptcÃs|j ¡tj ¡IdHdS)z.Close this listener and its underlying socket.Nr9r0rrrr;{s
zSocketListener.acloseN)r@rArBrCr"rLr;rrrrrI>srI)r
Ú
contextlibrr ÚrrZ_utilrrÚabcrrr6ÚEBADFÚENOTSOCKr rrZ_ignorable_accept_errno_namesÚsetrMÚnameÚaddÚgetattrÚAttributeErrorrIrrrrÚ<module>sH  ü
|í