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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
U
Z±dnNã@s†ddlmZddlZddlmZddlmZddlmZm    Z    m
Z
m Z ddl m Z Gd    d
„d
ƒZed d „ƒZd d„Zdd„Zdd„ZdS)é)ÚcontextmanagerNé)Ú_core)Úaclose_forcefully)Ú
SendStreamÚ ReceiveStreamÚStreamÚHalfCloseableStreamé)Úassert_checkpointsc@s$eZdZdd„Zdd„Zdd„ZdS)Ú_ForceCloseBothcCst|ƒ|_dS©N)ÚlistÚ_both)ÚselfZboth©rúRd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/testing/_check_streams.pyÚ__init__ sz_ForceCloseBoth.__init__cÃs|jSr )r)rrrrÚ
__aenter__sz_ForceCloseBoth.__aenter__c    Çs4zt|jdƒIdHW5t|jdƒIdHXdS)Nr
r)rr)rÚargsrrrÚ    __aexit__sz_ForceCloseBoth.__aexit__N)Ú__name__Ú
__module__Ú __qualname__rrrrrrrr sr ccs6d}z
dVWn|k
r"YnXtd |¡ƒ‚dS)NTzexpected exception: {})ÚAssertionErrorÚformat)ÚexcZ__tracebackhide__rrrÚ_assert_raisess 
rc ƒs t|ƒIdHƒ4IdHš*\‰‰tˆtƒs.t‚tˆtƒs<t‚‡fdd„‰‡fdd„‰‡fdd„‰dd    „‰t ¡4IdHš}| ˆd
¡| ˆd
¡W5QIdHRX‡fd d „}t ¡4IdHš}| |¡| ˆd ¡W5QIdHRXt ¡4IdHš"}| ˆtdƒ¡| ˆd¡W5QIdHRXt ¡4IdHš"}| ˆt    dƒ¡| ˆd¡W5QIdHRXt
t ƒˆ  d¡IdHW5QRXt
t ƒˆ  d¡IdHW5QRXt
t ƒˆ  d¡IdHW5QRXt ¡4IdHš(}| ˆd
¡ˆƒIdHd
kst‚W5QIdHRXt ¡4IdHš*}| ˆd
¡ˆdƒIdHd
ksHt‚W5QIdHRXt
tjƒ@t ¡4IdHš}| ˆd¡| ˆd¡W5QIdHRXW5QRX‡fdd„}t ¡4IdHš }| ||j¡| ˆd¡W5QIdHRX‡fdd„}t ¡4IdHš}| |¡| ˆˆ¡W5QIdHRXt
tjƒˆdƒIdHW5QRXt
tjƒˆdƒIdHW5QRXˆˆƒIdHˆˆƒIdHˆˆƒIdHt
tjƒˆdƒIdHW5QRXt
tjƒˆdƒIdHW5QRXt
tjƒ&tƒˆ ¡IdHW5QRXW5QRXˆˆƒIdHˆˆƒIdHW5QIdHRXt|ƒIdHƒ4IdHš`\‰‰‡‡‡fdd„}‡‡‡fdd„}t ¡4IdHš}| |¡| |¡W5QIdHRXW5QIdHRXt|ƒIdHƒ4IdHšd\‰‰tˆƒIdHt
tjƒˆdƒIdHq W5QRXt
tjƒˆdƒIdHW5QRXW5QIdHRXt|ƒIdHƒ4IdHšh\‰‰tˆƒIdHt
tjƒˆdƒIdHW5QRXzˆdƒIdHWntjk
rÖYnXW5QIdHRXt|ƒIdHƒ4IdHš¦\‰‰t ¡}| ¡ˆ ¡IdHW5QRXt ¡}| ¡ˆ ¡IdHW5QRXt
tjƒˆdƒIdHW5QRXt
tjƒˆdƒIdHW5QRXW5QIdHRXt|ƒIdHƒ4IdHš¦\‰‰d d!„}    t ¡L}| ¡t ¡4IdHš"}| |    ˆd
¡| |    ˆd¡W5QIdHRXW5QRXt ¡4IdHš}| ˆˆ¡| ˆˆ¡W5QIdHRXW5QIdHRXt|ƒIdHƒ4IdHš^\‰‰‡fd"d#„}
t ¡4IdHš,}| |
¡t ¡IdHtˆƒIdHW5QIdHRXW5QIdHRX|dk     rt|ƒIdHƒ4IdHš†\‰‰g‰‡‡fd$d%„} ‡‡fd&d'„} t ¡4IdHš,}| | |j¡t ¡IdH| | ¡W5QIdHRXˆd(d)d*gks¢t‚W5QIdHRXt|ƒIdHƒ4IdHš¬\‰‰t
tjƒ@t ¡4IdHš}| ˆj¡| ˆj¡W5QIdHRXW5QRXt
tjƒBt ¡4IdHš }| ˆj¡| ˆjd¡W5QIdHRXW5QRXW5QIdHRXt|ƒIdHƒ4IdHš^\‰‰t
tjƒDt ¡4IdHš"}| ˆjd¡| ˆjd¡W5QIdHRXW5QRXW5QIdHRXt|ƒIdHƒ4IdHšX\‰‰‡fd+d,„} ‡fd-d'„} t ¡4IdHš}| | ¡| | ¡W5QIdHRXW5QIdHRXt|ƒIdHƒ4IdHšV\‰‰tˆƒIdHz$tƒˆ ¡IdHW5QRXWntjk

rèYnXW5QIdHRXd.d/„}t|ƒIdHƒ4IdHš^\‰‰t ¡4IdHš8}| |ˆ¡t
tjƒˆ d0¡IdHW5QRXW5QIdHRXW5QIdHRXt|ƒIdHƒ4IdHš\\‰‰t ¡4IdHš6}| |ˆ¡t
tjƒˆ ¡IdHW5QRXW5QIdHRXW5QIdHRXdS)1aÜPerform a number of generic tests on a custom one-way stream
    implementation.
 
    Args:
      stream_maker: An async (!) function which returns a connected
          (:class:`~trio.abc.SendStream`, :class:`~trio.abc.ReceiveStream`)
          pair.
      clogged_stream_maker: Either None, or an async function similar to
          stream_maker, but with the extra property that the returned stream
          is in a state where ``send_all`` and
          ``wait_send_all_might_not_block`` will block until ``receive_some``
          has been called. This allows for more thorough testing of some edge
          cases, especially around ``wait_send_all_might_not_block``.
 
    Raises:
      AssertionError: if a test fails.
 
    Nc    “s.tƒˆ |¡IdHdks t‚W5QRXdSr )r Úsend_allr)Údata©ÚsrrÚ do_send_all<sz)check_one_way_stream.<locals>.do_send_allc
—s.tƒˆj|ŽIdHW5QR£SQRXdSr )r Ú receive_some)r©ÚrrrÚdo_receive_some@sz-check_one_way_stream.<locals>.do_receive_somec“sˆdƒIdH|kst‚dS©Nr
)r)Úexpected)r&rrÚchecked_receive_1Dsz/check_one_way_stream.<locals>.checked_receive_1c    Ós$tƒ| ¡IdHW5QRXdSr )r Úaclose)ÚresourcerrrÚ    do_acloseGsz'check_one_way_stream.<locals>.do_acloseóxc“s ˆdƒIdHˆdƒIdHdS)Nóóyrr©r"rrÚsend_empty_then_yPsz/check_one_way_stream.<locals>.send_empty_then_yr/ó1ó2éÿÿÿÿrgø?r
c    “s,tƒˆ ¡IdHW5QRX| ¡dSr )r Úwait_send_all_might_not_blockÚcancel)Úscoper rrÚ*simple_check_wait_send_all_might_not_block~szHcheck_one_way_stream.<locals>.simple_check_wait_send_all_might_not_blockc    “s*ttjƒˆdƒIdHq W5QRXdS)Nódxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)rrÚBrokenResourceErrorrr0rrÚexpect_broken_stream_on_send‹s z:check_one_way_stream.<locals>.expect_broken_stream_on_sendr9ir.c“s ˆdƒIdHˆˆƒIdHdS)Nr/rr)r,r"r!rrÚsend_then_close¶sz-check_one_way_stream.<locals>.send_then_closec“s<t ¡IdHˆdƒIdHˆdƒIdHˆˆƒIdHdS)Nr/r.)rÚwait_all_tasks_blockedr)r)r,r%rrÚreceive_send_then_closeºsz5check_one_way_stream.<locals>.receive_send_then_closes123c    ×s(ttjƒ||ŽIdHW5QRXdSr )rrZ    Cancelled)ZafnrrrrÚexpect_cancelledûs z.check_one_way_stream.<locals>.expect_cancelledc    “s*ttjƒˆ d¡IdHW5QRXdS)Né
)rrÚClosedResourceErrorr#rr$rrÚreceive_expecting_closed s z6check_one_way_stream.<locals>.receive_expecting_closedc    “s@ˆ d¡tƒˆ ¡IdHW5QRXˆ d¡| ¡dS)Núwaiter sleepingú waiter wokeup)Úappendr r5r6)Ú cancel_scope)Úrecordr!rrÚwaiters
 
 
z$check_one_way_stream.<locals>.waiterc“s.t ¡IdHˆ d¡ˆ d¡IdHqdS)Núreceiver startingiÂA)rr=rEr#r)r%rGrrÚreceiver"s
z&check_one_way_stream.<locals>.receiverrCrIrDc    “s@z$tƒˆ ¡IdHW5QRXWntjk
r:YnXdSr )r r5rr:rr rrÚsenderPs
z$check_one_way_stream.<locals>.senderc“s t ¡IdHtˆƒIdHdSr ©rr=rrr$rrrJWscÓs t ¡IdHt|ƒIdHdSr rLr rrrÚ
close_soonjsz(check_one_way_stream.<locals>.close_soonsxyzzy)r Ú
isinstancerrrrÚ open_nurseryÚ
start_soonÚ    bytearrayÚ
memoryviewrÚ
ValueErrorr#Ú    TypeErrorÚBusyResourceErrorrFr:rAr r5rZ CancelScoper6r*r=r)Ú stream_makerÚclogged_stream_makerÚnurseryr1r8r;r<r>r7r?rBrHrJrKrMr)r)r,r&r"r%rGr!rÚcheck_one_way_stream%sD      
 
 
 
 & (  & ÿ 
     "
 
*  ( 
 
  ( 
( , 
.
ý  &  8 8  
*  :  rYc ƒs”tˆˆƒIdH‡fdd„}ˆdk    r2‡fdd„}nd}t||ƒIdHtˆƒIdHƒ4IdHš$\}‰t|tƒstt‚tˆtƒs‚t‚d}d‰t d¡}| d    |¡}| |d
¡}‡fd d „}    ‡fd d„}
t     
¡4IdHšZ} |   |    ||d¡|   |    ˆ|ddd…d¡|   |
||ddd…d¡|   |
ˆ|d¡W5QIdHRX‡fdd„} t     
¡4IdHš} |   | ¡|   |j ¡W5QIdHRXW5QIdHRXdS)u¸Perform a number of generic tests on a custom two-way stream
    implementation.
 
    This is similar to :func:`check_one_way_stream`, except that the maker
    functions are expected to return objects implementing the
    :class:`~trio.abc.Stream` interface.
 
    This function tests a *superset* of what :func:`check_one_way_stream`
    checks â€“ if you call this, then you don't need to also call
    :func:`check_one_way_stream`.
 
    Nc“stˆƒIdHƒSr ©Úreversedr)rVrrÚflipped_stream_makerŠsz2check_two_way_stream.<locals>.flipped_stream_makerc“stˆƒIdHƒSr rZr)rWrrÚflipped_clogged_stream_makersz:check_two_way_stream.<locals>.flipped_clogged_stream_makerii@réÚlittlec“sLt |¡}t|ƒ}|rH| dˆ¡}| |d|…¡IdH||d…}qdSr')ÚrandomÚRandomrRÚrandintr)r!rÚseedr%ÚmÚ
chunk_size©ÚCHUNK_SIZE_MAXrrrK¢s 
 z$check_two_way_stream.<locals>.senderc“sZt |¡}tƒ}t|ƒt|ƒkrJ| | dˆ¡¡IdH}|s@t‚||7}q||ksVt‚dSr')r`rarQÚlenr#rbr)r!rrcr%ÚgotÚchunkrfrrrJªs
 
z&check_two_way_stream.<locals>.receiverr4r
réc“s*ˆ d¡IdHdkst‚ˆ ¡IdHdS)Nr@r.)r#rr*r)Ús2rrÚexpect_receive_some_empty¹sz7check_two_way_stream.<locals>.expect_receive_some_empty) rYr rNrrr`raÚ getrandbitsÚto_bytesrrOrPr*) rVrWr\r]Ús1ZDUPLEX_TEST_SIZEr%ÚiZ    test_datarKrJrXrmr)rgrWrlrVrÚcheck_two_way_stream{s2   
         
rrc ÃsLt||ƒIdHt|ƒIdHƒ4IdHšð\}}t|tƒs<t‚t|tƒsJt‚dd„}dd„}t ¡4IdHš}| ||¡| ||¡W5QIdHRXttj    ƒ| 
d¡IdHW5QRXt ƒ|  ¡IdHW5QRXt ¡4IdHš}| ||¡| ||¡W5QIdHRXW5QIdHRX|dk    rHt|ƒIdHƒ4IdHšj\}}ttj ƒPt ¡4IdHš.}| |j
d¡t ¡IdH| |j ¡W5QIdHRXW5QRXW5QIdHRXt|ƒIdHƒ4IdHšh\}}ttj ƒNt ¡4IdHš,}| |j¡t ¡IdH| |j ¡W5QIdHRXW5QRXW5QIdHRXdS)uÎPerform a number of generic tests on a custom half-closeable stream
    implementation.
 
    This is similar to :func:`check_two_way_stream`, except that the maker
    functions are expected to return objects that implement the
    :class:`~trio.abc.HalfCloseableStream` interface.
 
    This function tests a *superset* of what :func:`check_two_way_stream`
    checks â€“ if you call this, then you don't need to also call
    :func:`check_two_way_stream`.
 
    Nc    Ós4| d¡IdHtƒ| ¡IdHW5QRXdS)Nr-)rr Úsend_eofr rrrÚsend_x_then_eofÕsz4check_half_closeable_stream.<locals>.send_x_then_eofcÓsBt ¡IdH| d¡IdHdks&t‚| d¡IdHdks>t‚dS)Nr@r-r.)rr=r#rr$rrrÚexpect_x_then_eofÚsz6check_half_closeable_stream.<locals>.expect_x_then_eofr/r-)rrr rNr    rrrOrPrrArr rsrUr=r5)rVrWrprlrtrurXrrrÚcheck_half_closeable_streamÂs:    ,
 6  rv)Ú
contextlibrr`ÚrZ_highlevel_genericrÚ_abcrrrr    Z _checkpointsr r rrYrrrvrrrrÚ<module>s    
 
XG