XjZddlmZdZddlZddlmZmZmZddlm Z m Z ddl m Z m Z ddlmZmZmZmZdd lmZmZmZmZmZmZej4d k\rdd l mZndd lmZe d GddeZGddeeZGddeZy)) annotations)BufferedByteReceiveStreamBufferedByteStreamBufferedConnectableN)CallableIterableMapping) dataclassfield)Any SupportsIndex)ClosedResourceErrorDelimiterNotFound EndOfStreamIncompleteRead)AnyByteReceiveStream AnyByteStreamAnyByteStreamConnectableByteReceiveStream ByteStreamByteStreamConnectable) )overrideF)eqceZdZUdZded<edeZded<eddZd ed <dd Z e dd Z e dd Z ddZ dddZddZddZy)rz 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 j/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/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*r1z*BufferedByteReceiveStream.extra_attributes2s""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_data6s D!r.cK|dkr td|jrt|jr)t |jd|}|jd|=|St |j tr#|j j|d{S|j jd{}t||kDr#|jj||d|d|S|S7Y79w)Nz$max_bytes must be a positive integer) ValueErrorr%rr"r, isinstancerrreceivelenr3)r) max_byteschunks r*r:z!BufferedByteReceiveStream.receiveCs q=CD D <<% % <<$,,z 23E ZiZ(L ++-> ?,,44Y?? ?--5577E5zI% ##E)*$56Zi(( @8s$BC0C,!C04C.58C0.C0cK |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) r;r"r,r9rrr:rrr3)r)nbytes remainingretvalr=excs r*receive_exactlyz)BufferedByteReceiveStream.receive_exactly[sT\\!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 rNr7) r;r"findr,rrr:rrmaxr3) r) delimiterr<delimiter_sizeoffsetindexfoundr4rBs r* receive_untilz'BufferedByteReceiveStream.receive_untilvsYLL%%i8Ez Ve,LL!;53y>#9!;<U|#4<< I-' 22 .!0088:: T\\*^;a?CF LL   %); .$#- .s=BD C0(C.)C0-AD.C00 D9DDDNreturnNone)rNr,)rNzMapping[Any, Callable[[], Any]])r4zIterable[SupportsIndex]rNrO)i)r<intrNr,)r?rPrNr,)rGr,r<rPrNr,)__name__ __module__ __qualname____doc____annotations__r r!r"r%r'propertyr-r1r5r:rCrLr.r*rrsr )(E9EGYEue4GT4##44 "0'6$&r.rcHeZdZdZdfd ZeddZeddZxZS)rz 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*r[zBufferedByteStream.__init__s   r.cTK|jjd{y7wr0)r\send_eofr(s r*r`zBufferedByteStream.send_eofsll##%%%s (&(cVK|jj|d{y7wr0)r\send)r)items r*rbzBufferedByteStream.sendsll%%%s )'))r]rrM)rcr,rNrO) rQrRrSrTr[rr`rb __classcell__)r^s@r*rrs5 &&&&r.rc*eZdZdZddZeddZy)raw Wraps a byte stream connectable to produce :class:`BufferedByteStream` connections. Use this when you want the streams returned by :meth:`connect` to have the buffered receive API (e.g. :meth:`~BufferedByteReceiveStream.receive_exactly` and :meth:`~BufferedByteReceiveStream.receive_until`). :param connectable: the byte stream connectable to wrap c||_y)z> :param connectable: the connectable to wrap N) connectable)r)rgs r*r[zBufferedConnectable.__init__s 'r.chK|jjd{}t|S7wr0)rgconnectr)r)r]s r*rizBufferedConnectable.connects-''//11!&))2s 202N)rgr)rNr)rQrRrSrTr[rrirWr.r*rrs '**r.r) __future__r__all__syscollections.abcrrr dataclassesr r typingr r rrrrabcrrrrrr version_infortyping_extensionsrrrrWr.r*rts"   77(%RRw* e{& 1{&{&|&2J&.*/*r.