]L iddlmZddlZddlmZmZmZddlmZm Z ddl m Z m Z ddl mZmZmZmZddlmZmZmZmZmZmZej2d k\rdd l mZndd lmZed Gd deZGddeeZGddeZy)) annotationsN)CallableIterableMapping) dataclassfield)Any SupportsIndex)ClosedResourceErrorDelimiterNotFound EndOfStreamIncompleteRead)AnyByteReceiveStream AnyByteStreamAnyByteStreamConnectableByteReceiveStream ByteStreamByteStreamConnectable) )overrideF)eqceZdZUdZded<edeZded<eddZd ed <dd Z e dd Z e dd Z ddZ dddZddZddZy)BufferedByteReceiveStreamz Wraps any bytes-based receive stream and uses a buffer to provide sophisticated receiving capabilities in the form of a byte stream. rreceive_streamF)initdefault_factory bytearray_buffer)rdefaultbool_closedcbK|jjd{d|_y7 w)NT)racloser#selfs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/anyio/streams/buffered.pyr%z BufferedByteReceiveStream.aclose#s*!!((***  +s /- /c,t|jS)z"The bytes currently in the buffer.)bytesr r&s r(bufferz BufferedByteReceiveStream.buffer'sT\\""c.|jjSN)rextra_attributesr&s r(r/z*BufferedByteReceiveStream.extra_attributes,s""333r,c:|jj|y)a; Append data directly into the buffer. Any data in the buffer will be consumed by receive operations before receiving anything from the wrapped stream. :param data: the data to append to the buffer (can be bytes or anything else that supports ``__index__()``) N)r extend)r'datas r( feed_dataz#BufferedByteReceiveStream.feed_data0s D!r,cK|jrt|jr)t|jd|}|jd|=|St |j t r#|j j|d{S|j jd{}t||kDr#|jj||d|d|S|S7Y79wr.) r#r r r* isinstancerrreceivelenr1)r' max_byteschunks r(r6z!BufferedByteReceiveStream.receive=s <<% % <<$,,z 23E ZiZ(L ++-> ?,,44Y?? ?--5577E5zI% ##E)*$56Zi(( @8s$BC C!C $C%8C C cK |t|jz }|dkr)|jd|}|jd|=t|S t|jt r$|jj |d{}n"|jj d{}|jj|7C7"#t$r }t|d}~wwxYww)a- Read exactly the given amount of bytes from the stream. :param nbytes: the number of bytes to read :return: the bytes read :raises ~anyio.IncompleteRead: if the stream was closed before the requested amount of bytes could be read from the stream rN) r7r r*r5rrr6rrr1)r'nbytes remainingretvalr9excs r(receive_exactlyz)BufferedByteReceiveStream.receive_exactlyRsT\\!22IA~gv.LL&)V}$ .d113DE"&"5"5"="=i"HHE"&"5"5"="="??E LL   &I? .$#- .sNAC# 8C C"C &C 'C +C#C C C CC  C#cKt|}d} |jj||}|dk\r5|jd|}|jd|t|z=t|St|j|k\r t | |j j d{}tt|j|z dzd}|jj|7E#t$r }t|d}~wwxYww)aM Read from the stream until the delimiter is found or max_bytes have been read. :param delimiter: the marker to look for in the stream :param max_bytes: maximum number of bytes that will be read before raising :exc:`~anyio.DelimiterNotFound` :return: the bytes read (not including the delimiter) :raises ~anyio.IncompleteRead: if the stream was closed before the delimiter was found :raises ~anyio.DelimiterNotFound: if the delimiter is not found within the bytes read up to the maximum allowed rN) r7r findr*r rr6rrmaxr1) r' delimiterr8delimiter_sizeoffsetindexfoundr2r>s r( receive_untilz'BufferedByteReceiveStream.receive_untilmsYLL%%i8Ez Ve,LL!;53y>#9!;<U|#4<< I-' 22 .!0088:: T\\*^;a?CF LL   %); .$#- .s=BD C0(C.)C0-AD.C00 D9DDDNreturnNone)rKr*)rKzMapping[Any, Callable[[], Any]])r2zIterable[SupportsIndex]rKrL)i)r8intrKr*)r;rMrKr*)rDr*r8rMrKr*)__name__ __module__ __qualname____doc____annotations__rrr r#r%propertyr+r/r3r6r?rIr,r(rrsr )(E9EGYEue4GT4##44 "*'6$&r,rcHeZdZdZdfd ZeddZeddZxZS)BufferedByteStreamz A full-duplex variant of :class:`BufferedByteReceiveStream`. All writes are passed through to the wrapped stream as-is. c2t||||_y)z: :param stream: the stream to be wrapped N)super__init___stream)r'stream __class__s r(rYzBufferedByteStream.__init__s   r,cTK|jjd{y7wr.)rZsend_eofr&s r(r^zBufferedByteStream.send_eofsll##%%%s (&(cVK|jj|d{y7wr.)rZsend)r'items r(r`zBufferedByteStream.sendsll%%%s )'))r[rrJ)rar*rKrL) rNrOrPrQrYrr^r` __classcell__)r\s@r(rVrVs5 &&&&r,rVc&eZdZddZeddZy)BufferedConnectablec||_y)z> :param connectable: the connectable to wrap N) connectable)r'rfs r(rYzBufferedConnectable.__init__s 'r,chK|jjd{}t|S7wr.)rfconnectrV)r'r[s r(rhzBufferedConnectable.connects-''//11!&))2s 202N)rfr)rKrV)rNrOrPrYrrhrTr,r(rdrds'**r,rd) __future__rsyscollections.abcrrr dataclassesrrtypingr r r r rrabcrrrrrr version_infortyping_extensionsrrVrdrTr,r(rrs~" 77(%RRw* ex& 1x&x&v&2J&. */ *r,