python (3.12.0)

(root)/
lib/
python3.12/
asyncio/
__pycache__/
streams.cpython-312.opt-1.pyc

ˑehddZddlZddlZddlZddlZeedredz
ZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlm
Z
ddlmZd
ZdeddZdeddZeedrdeddZdeddZGddej*ZGddeej*ZGddZGddZy))StreamReaderStreamWriterStreamReaderProtocolopen_connectionstart_serverNAF_UNIX)open_unix_connectionstart_unix_server)
coroutines)events)
exceptions)format_helpers)	protocols)logger)sleepi)limitc	Ktj}t||}t||	|j	fd||fi|d{\}}t|	||}||fS7w)aA wrapper for create_connection() returning a (reader, writer) pair.

    The reader returned is a StreamReader instance; the writer is a
    StreamWriter instance.

    The arguments are all the usual arguments to create_connection()
    except protocol_factory; most common are positional host and port,
    with various optional keyword arguments following.

    Additional optional keyword arguments are loop (to set the event loop
    instance to use) and limit (to set the buffer limit passed to the
    StreamReader).

    (If you want to customize the StreamReader and/or
    StreamReaderProtocol classes, just copy the code -- there's
    really nothing special here except some convenience.)
    rlooprcSNprotocolsC/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/asyncio/streams.py<lambda>z!open_connection.<locals>.<lambda>0sN)r
get_running_looprrcreate_connectionr)
hostportrkwdsrreader	transport_writerrs
         @rrrsx&""$D
D
1F#F6H///$.(,..LIq
)Xvt
<F6>.sA
A)
A'A)cKtjfd}j|||fi|d{S7w)aStart a socket server, call back for each client connected.

    The first parameter, `client_connected_cb`, takes two parameters:
    client_reader, client_writer.  client_reader is a StreamReader
    object, while client_writer is a StreamWriter object.  This
    parameter can either be a plain callback function or a coroutine;
    if it is a coroutine, it will be automatically converted into a
    Task.

    The rest of the arguments are all the usual arguments to
    loop.create_server() except protocol_factory; most common are
    positional host and port, with various optional keyword arguments
    following.  The return value is the same as loop.create_server().

    Additional optional keyword arguments are loop (to set the event loop
    instance to use) and limit (to set the buffer limit passed to the
    StreamReader).

    The return value is the same as loop.create_server(), i.e. a
    Server object which can be used to stop the service.
    c>t}t|}|SNrrrrr%rclient_connected_cbrrs  rfactoryzstart_server.<locals>.factoryNs&E5'0C-13rN)r
r 
create_server)r.r"r#rr$r/rs`  `  @rrr5s@.""$D$##GT4@4@@@@s4A>AcKtj}t||}t|||jfd|fi|d{\}}t|||}||fS7w)z@Similar to `open_connection` but works with UNIX Domain Sockets.rrcSrrrsrrz&open_unix_connection.<locals>.<lambda>bsHrN)r
r rrcreate_unix_connectionr)	pathrr$rr%r&r'r(rs	        @rr	r	Zsv&&(E5'T:8T88d,&*,,	1i64@v~,sA	A(A&
A(cKtjfd}j||fi|d{S7w)z=Similar to `start_server` but works with UNIX Domain Sockets.c>t}t|}|Sr+r,r-s  rr/z"start_unix_server.<locals>.factoryks&!D9F+F4G157HOrN)r
r create_unix_server)r.r4rr$r/rs` `  @rr
r
fs>&&(	-T,,WdCdCCCCs3?=?c6eZdZdZd	dZdZdZdZdZdZ	y)
FlowControlMixina)Reusable flow control logic for StreamWriter.drain().

    This implements the protocol methods pause_writing(),
    resume_writing() and connection_lost().  If the subclass overrides
    these it must call the super methods.

    StreamWriter.drain() must wait for _drain_helper() coroutine.
    Nc|tj|_n||_d|_t	j
|_d|_yNF)r
get_event_loop_loop_pausedcollectionsdeque_drain_waiters_connection_lost)selfrs  r__init__zFlowControlMixin.__init__~s><..0DJDJ)//1 %rctd|_|jjrtjd|yy)NTz%r pauses writing)r>r=	get_debugrdebugrCs r
pause_writingzFlowControlMixin.pause_writings-::!LL,d3"rcd|_|jjrtjd||j
D]$}|j
r|jd&y)NFz%r resumes writing)r>r=rFrrGrAdone
set_resultrCwaiters  rresume_writingzFlowControlMixin.resume_writingsT::!LL-t4))	(F;;=!!$'	(rcd|_|jsy|jD]8}|jr||j	d(|j|:yNT)rBr>rArKrL
set_exceptionrCexcrNs   rconnection_lostz FlowControlMixin.connection_lostsS $||))	.F;;=;%%d+((-	.rcNK|jrtd|jsy|jj	}|j
j
|	|d{|j
j|y7 #|j
j|wxYww)NzConnection lost)rBConnectionResetErrorr>r=
create_futurerAappendremoverMs  r
_drain_helperzFlowControlMixin._drain_helpers  &'899||))+""6*	/LL&&v.
&&v.s0AB%B"B#B'B%BB""B%ctr)NotImplementedErrorrCstreams  r_get_close_waiterz"FlowControlMixin._get_close_waiters!!rr)
__name__
__module____qualname____doc__rDrIrOrUr[r`rrrr9r9ts%&4(.
/"rr9cfeZdZdZdZdfd	ZedZdZdZ	fdZ
dZd	Zd
Z
dZxZS)
ra=Helper class to adapt between Protocol and StreamReader.

    (This is a helper class instead of making StreamReader itself a
    Protocol subclass, because the StreamReader has other potential
    uses, and to prevent the user of the StreamReader to accidentally
    call inappropriate methods of the protocol.)
    Nc4t|||,tj||_|j
|_nd|_|||_d|_d|_d|_	d|_
||_d|_|jj|_y)NrF)superrDweakrefref_stream_reader_wr_source_traceback_strong_reader_reject_connection_stream_writer_task
_transport_client_connected_cb	_over_sslr=rX_closed)rC
stream_readerr.r	__class__s    rrDzStreamReaderProtocol.__init__s
d#$%,[[%?D"%2%D%DD"%)D"*#0D"'"
$7!zz//1rc<|jy|jSr)rjrHs r_stream_readerz#StreamReaderProtocol._stream_readers !!)%%''rc|j}|j}||_||_|j	ddu|_y)N
sslcontext)r=r&rnrpget_extra_inforr)rCr(rr&s    r_replace_writerz$StreamReaderProtocol._replace_writers<zz$$	$#"11,?tKrc2|jrKddi}|jr|j|d<|jj||j	y||_|j}||j||jddu|_	|jvt||||j|_|j||j}tj|r |jj||_d|_yy)NmessagezpAn open stream was garbage collected prior to establishing network connection; call "stream.close()" explicitly.source_tracebackry)rmrkr=call_exception_handlerabortrprw
set_transportrzrrrqrrnriscoroutinecreate_taskrorl)rCr&contextr%ress     rconnection_madez$StreamReaderProtocol.connection_mades	""@G
%%.2.D.D*+JJ--g6OO#$$  +"11,?tK$$0".y$/5/3zz#;D++F,0,?,?AC%%c*!ZZ33C8
"&D1rcf|j}|$||jn|j||jj	s9||jjdn|jj|t||d|_d|_	d|_
d|_yr)rwfeed_eofrRrsrKrLrgrUrjrnrorp)rCrTr%rus   rrUz$StreamReaderProtocol.connection_losts$${!$$S)||  "{''-**3/
$!%"
rcD|j}||j|yyr)rw	feed_data)rCdatar%s   r
data_receivedz"StreamReaderProtocol.data_received
s&$$T"rcZ|j}||j|jryy)NFT)rwrrr)rCr%s  reof_receivedz!StreamReaderProtocol.eof_receiveds,$$OO>>rc|jSr)rsr^s  rr`z&StreamReaderProtocol._get_close_waiters||rc	|j}|jr"|js|jyyy#t$rYywxYwr)rsrK	cancelled	exceptionAttributeError)rCcloseds  r__del__zStreamReaderProtocol.__del__ sM	#\\F{{}V%5%5%7  "&8}		sA	A
A
NN)rarbrcrdrkrDpropertyrwr{rrUrrr`r
__classcell__)rus@rrrsM2(((
L'6$#
		#rrczeZdZdZdZdZedZdZdZ	dZ
dZd	Zd
Z
dZdd
ZdZdddddZdZy)ra'Wraps a Transport.

    This exposes write(), writelines(), [can_]write_eof(),
    get_extra_info() and close().  It adds drain() which returns an
    optional Future on which you can wait for flow control.  It also
    adds a transport property which references the Transport
    directly.
    c||_||_||_||_|jj	|_|j
j
dyr)rp	_protocol_readerr=rX
_complete_futrL)rCr&rr%rs     rrDzStreamWriter.__init__6sI#!
!ZZ557%%d+rc|jjd|jg}|j|j	d|jdjdj
|S)N
transport=zreader=<{}> )rurarprrYformatjoinrCinfos  r__repr__zStreamWriter.__repr__@s['':doo5H)IJ<<#KK'$,,!123}}SXXd^,,rc|jSrrprHs rr&zStreamWriter.transportFsrc:|jj|yr)rpwriterCrs  rrzStreamWriter.writeJsd#rc:|jj|yr)rp
writelinesrs  rrzStreamWriter.writelinesMs""4(rc6|jjSr)rp	write_eofrHs rrzStreamWriter.write_eofPs((**rc6|jjSr)rp
can_write_eofrHs rrzStreamWriter.can_write_eofSs,,..rc6|jjSr)rpcloserHs rrzStreamWriter.closeVs$$&&rc6|jjSr)rp
is_closingrHs rrzStreamWriter.is_closingYs))++rcVK|jj|d{y7wr)rr`rHs rwait_closedzStreamWriter.wait_closed\snn..t444s)')Nc:|jj||Sr)rprz)rCnamedefaults   rrzzStreamWriter.get_extra_info_s--dG<<rcK|j|jj}|||jjrt	dd{|j
j
d{y7'7w)zyFlush the write buffer.

        The intended use is to write

          w.write(data)
          await w.drain()
        Nr)rrrprrrr[)rCrTs  rdrainzStreamWriter.drainbsj<<#,,((*C	??%%'(NNnn**,,,
,s$ABA=!B7A?8B?B)server_hostnamessl_handshake_timeoutssl_shutdown_timeoutc	$K|jjdu}|j}|jd{|jj	|j
||||||d{}||_|j
|y7Q7w)z3Upgrade an existing stream-based connection to TLS.N)server_siderrr)rrqrr=	start_tlsrpr{)rCryrrrrr
new_transports        rrzStreamWriter.start_tls{s
nn99E>>jjl"jj22OOXz#_"7!5	377
(  &	7s!8BB3B.B/BBcZ|jjs|jyyr)rprrrHs rrzStreamWriter.__del__s ))+JJL,rr)rarbrcrdrDrrr&rrrrrrrrzrrrrrrrr,sg,-$)+/',5=-4)-.2-1' rrceZdZdZedfdZdZdZdZdZ	dZ
dZd	Zd
Z
dZdZd
ZddZddZdZdZdZy)rNcl|dkrtd||_|tj|_n||_t|_d|_d|_d|_	d|_
d|_|jjr.tjtj d|_yy)NrzLimit cannot be <= 0Fr)
ValueError_limitr
r<r=	bytearray_buffer_eof_waiter
_exceptionrpr>rFr
extract_stacksys	_getframerk)rCrrs   rrDzStreamReader.__init__sA:344<..0DJDJ {	::!%3%A%A

a &"D""rcdg}|jr'|jt|jd|jr|jd|jt
k7r|jd|j|jr|jd|j|jr|jd|j|jr|jd|j|jr|jdd	jd
j|S)Nrz byteseofzlimit=zwaiter=z
exception=rpausedrr)rrYlenrr_DEFAULT_LIMITrrrpr>rrrs  rrzStreamReader.__repr__s<<KK3t||,-V4599KK;;.(KK&
./<<KK'$,,!123??KK*T__$789??KK*T__$789<<KK!}}SXXd^,,rc|jSr)rrHs rrzStreamReader.exceptionsrc||_|j}|*d|_|js|j|yyyr)rrrrRrSs   rrRzStreamReader.set_exceptionsCDL##%$$S)&rct|j}|*d|_|js|jdyyy)z1Wakeup read*() functions waiting for data or EOF.N)rrrLrMs  r_wakeup_waiterzStreamReader._wakeup_waiters<DL##%!!$'&rc||_yrr)rCr&s  rrzStreamReader.set_transports	#rc|jrEt|j|jkr"d|_|jjyyyr;)r>rrrrpresume_readingrHs r_maybe_resume_transportz$StreamReader._maybe_resume_transports;<<C-< DLOO**,=<rc2d|_|jyrQ)rrrHs rrzStreamReader.feed_eofs	rc8|jxr
|jS)z=Return True if the buffer is empty and 'feed_eof' was called.)rrrHs rat_eofzStreamReader.at_eofsyy---rcP|sy|jj||j|jV|jsIt|jd|jzkDr#	|jjd|_yyyy#t$r
d|_YywxYw)NT)	rextendrrpr>rr
pause_readingr]rs  rrzStreamReader.feed_datasD!OO'LLDLL!AO3
$--/ $4!
(
'
'#'	
's-BB%$B%c,K|jt|d|jr!d|_|jj	|j
j
|_	|jd{d|_y7#d|_wxYww)zpWait until feed_data() or feed_eof() is called.

        If stream was paused, automatically resume it.
        NzF() called while another coroutine is already waiting for incoming dataF)rRuntimeErrorr>rprr=rX)rC	func_names  r_wait_for_datazStreamReader._wait_for_datas<<#+456
6<< DLOO**,zz//1	 ,,DL
DLs0A'B*B9B:B>BB	BBcKd}t|}	|j|d{}|S7#tj$r}|jcYd}~Sd}~wtj
$r}|jj||jr|jd|j|z=n|jj|jt|jdd}~wwxYww)aRead chunk of data from the stream until newline (b'
') is found.

        On success, return chunk that ends with newline. If only partial
        line can be read due to EOF, return incomplete line without
        terminating newline. When EOF was reached while no bytes read, empty
        bytes object is returned.

        If limit is reached, ValueError will be raised. In that case, if
        newline was found, complete line including newline will be removed
        from internal buffer. Else, internal buffer will be cleared. Limit is
        compared against part of the line without newline.

        If stream was paused, this function will automatically resume it if
        needed.
        
Nr)
r	readuntilrIncompleteReadErrorpartialLimitOverrunErrorr
startswithconsumedclearrrargs)rCsepseplenlinees     rreadlinezStreamReader.readlines S
	(,,D---	99++	(||&&sAJJ7LL!5!**v"5!56""$((*QVVAY''
	(sJC5.,.C5.C2AC2
C5C2(BC--C22C5cKt|}|dk(rtd|j|jd}	t|j}||z
|k\rO|jj	||}|dk7rn|dz|z
}||j
kDrt
jd||jrEt|j}|jjt
j|d|jdd{||j
kDrt
jd||jd||z}|jd||z=|jt|S7iw)	aVRead data from the stream until ``separator`` is found.

        On success, the data and separator will be removed from the
        internal buffer (consumed). Returned data will include the
        separator at the end.

        Configured stream limit is used to check result. Limit sets the
        maximal length of data that can be returned, not counting the
        separator.

        If an EOF occurs and the complete separator is still not found,
        an IncompleteReadError exception will be raised, and the internal
        buffer will be reset.  The IncompleteReadError.partial attribute
        may contain the separator partially.

        If the data cannot be read because of over limit, a
        LimitOverrunError exception  will be raised, and the data
        will be left in the internal buffer, so it can be read again.
        rz,Separator should be at least one-byte stringNrz2Separator is not found, and chunk exceed the limitrz2Separator is found, but chunk is longer than limit)rrrrfindrrrrbytesrrrr)rC	separatorroffsetbuflenisepchunks       rrzStreamReader.readuntil2sz(YQ;KLL??&//!*&F&(||((F;2: !f,DKK'$66L  yydll+""$ 44UDAA%%k222=@$++..DdL
L^dVm,LL$-($$&U|
3sDE6
E4A*E6cK|j|j|dk(ry|dkrLg}	|j|jd{}|sn|j|8dj	|S|j
s%|js|jdd{tt|j
d|}|j
d|=|j|S77Hw)aRead up to `n` bytes from the stream.

        If `n` is not provided or set to -1,
        read until EOF, then return all read bytes.
        If EOF was received and the internal buffer is empty,
        return an empty bytes object.

        If `n` is 0, return an empty bytes object immediately.

        If `n` is positive, return at most `n` available bytes
        as soon as at least 1 byte is available in the internal buffer.
        If EOF is received before any byte is read, return an empty
        bytes object.

        Returned value is not limited with limit, configured at stream
        creation.

        If stream was paused, this function will automatically resume it if
        needed.
        Nrrread)rrrrYrrrrr
memoryviewr)rCnblocksblockrs     rrzStreamReader.reads,??&//!6q5
F"ii44

e$	
88F##||DII%%f---Z-bq12LL!$$&5
.s&AC)C%AC)C'AC)'C)cK|dkrtd|j|j|dk(ryt|j|kr|jrEt|j}|jj
tj|||jdd{t|j|krt|j|k(r0t|j}|jj
n0tt|jd|}|jd|=|j|S7w)aRead exactly `n` bytes.

        Raise an IncompleteReadError if EOF is reached before `n` bytes can be
        read. The IncompleteReadError.partial attribute of the exception will
        contain the partial read bytes.

        if n is zero, return empty bytes object.

        Returned value is not limited with limit, configured at stream
        creation.

        If stream was paused, this function will automatically resume it if
        needed.
        rz*readexactly size can not be less than zeroNrreadexactly)rrrrrrrrrrrr)rCr
incompleters    rrzStreamReader.readexactlys
q5IJJ??&//!6$,,!#yy"4<<0
""$ 44ZCC%%m444
$,,!#t||!&DLL DLL1"156DRaR $$&
5sB,E.E/EBEc|SrrrHs r	__aiter__zStreamReader.__aiter__srcXK|jd{}|dk(rt|S7w)Nr)rStopAsyncIteration)rCvals  r	__anext__zStreamReader.__anext__s+MMO##:$$
$s*(*)r)r)rarbrcrkrrDrrrRrrrrrrrrrrrrrrrrrrsf+$",-$*($-
.$, 8>Yv1f'Rrrrr)__all__r?socketrrhhasattrrr
rrrlogrtasksrrrrr	r
Protocolr9rrrrrr<module>rs'


69<<G .8A+AD69
)7
D&4D="y))="@u#+Y-?-?u#paaH``r