a cU@sjddlmZmZddlmZmZmZddlmZm Z m Z m Z ddl m Z mZeddGdd d eZd S) ) dataclassfield)AnyCallableMapping)ClosedResourceErrorDelimiterNotFound EndOfStreamIncompleteRead)AnyByteReceiveStreamByteReceiveStreamF)eqc@seZdZUdZeed<ededZeed<edddZ e ed<dd d d Z e e d d d Ze eeegeffd ddZdee dddZee dddZe ee dddZdS)BufferedByteReceiveStreamz Wraps any bytes-based receive stream and uses a buffer to provide sophisticated receiving capabilities in the form of a byte stream. receive_streamF)initdefault_factory_buffer)rdefault_closedN)returncs|jIdHd|_dS)NT)racloserselfrc/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/anyio/streams/buffered.pyrsz BufferedByteReceiveStream.aclosecCs t|jS)z"The bytes currently in the buffer.)bytesrrrrrbuffersz BufferedByteReceiveStream.buffercCs|jjSN)rextra_attributesrrrrrsz*BufferedByteReceiveStream.extra_attributes) max_bytesrcs|jr t|jr2t|jd|}|jd|=|St|jtrP|j|IdHS|jIdH}t||kr|j ||d|d|S|SdSr) rrrr isinstancerr receivelenextend)rr!chunkrrrr# s    z!BufferedByteReceiveStream.receive)nbytesrc s|t|j}|dkr8|jd|}|jd|=t|Sz4t|jtrZ|j|IdH}n|jIdH}Wn*ty}zt|WYd}~n d}~00|j |qdS)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$rrr"rr r#r r r%)rr' remainingretvalr&excrrrreceive_exactly5s   z)BufferedByteReceiveStream.receive_exactly) delimiterr!rc st|}d}|j||}|dkrL|jd|}|jd|t|=t|St|j|krbt|z|jIdH}Wn*ty}zt|WYd}~n d}~00t t|j|dd}|j |q dS)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) r$rfindrr rr#r r maxr%) rr,r!Zdelimiter_sizeoffsetindexfounddatar*rrr receive_untilPsz'BufferedByteReceiveStream.receive_until)r )__name__ __module__ __qualname____doc__r __annotations__r bytearrayrrboolrpropertyrrrrrrintr#r+r4rrrrrs  rN)Z dataclassesrrtypingrrrrr r r abcr r rrrrrs