a c@sddlZddlmZmZmZddlmZmZmZm Z ddl m Z m Z m Z mZmZmZeddGdd d eeZeddGd d d eeZeddGd d d eeZdS)N)InitVar dataclassfield)AnyCallableMappingTuple)AnyByteReceiveStreamAnyByteSendStream AnyByteStreamObjectReceiveStreamObjectSendStream ObjectStreamF)eqc@seZdZUdZeed<dZeeed<dZ eeed<e ddZ e j ed <eed d d d ZedddZd dddZeeeegeffdddZd S)TextReceiveStreama Stream wrapper that decodes bytes to strings using the given encoding. Decoding is done using :class:`~codecs.IncrementalDecoder` which returns any completely received unicode characters as soon as they come in. :param transport_stream: any bytes-based receive stream :param encoding: character encoding to use for decoding bytes to strings (defaults to ``utf-8``) :param errors: handling scheme for decoding errors (defaults to ``strict``; see the `codecs module documentation`_ for a comprehensive list of options) .. _codecs module documentation: https://docs.python.org/3/library/codecs.html#codec-objects transport_streamutf-8encodingstricterrorsFinit_decoderNrrreturncCst|}||d|_dS)N)r)codecsgetincrementaldecoderr)selfrrZ decoder_classr_/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/anyio/streams/text.py __post_init__%s zTextReceiveStream.__post_init__rcs*|jIdH}|j|}|r|SqdSN)rreceiverdecode)rchunkdecodedrrr r$)s zTextReceiveStream.receivecs|jIdH|jdSr#)racloserresetrrrr r(0szTextReceiveStream.aclosecCs|jjSr#rextra_attributesr*rrr r,4sz"TextReceiveStream.extra_attributes)__name__ __module__ __qualname____doc__r __annotations__rrstrrrrrIncrementalDecoderr!r$r(propertyrrrr,rrrr rs rc@seZdZUdZeed<dZeeed<dZ eed<e ddZ e d e eeffed <ed d d dZed dddZd dddZeeee geffdddZd S)TextSendStreama Sends strings to the wrapped stream as bytes using the given encoding. :param AnyByteSendStream transport_stream: any bytes-based send stream :param str encoding: character encoding to use for encoding strings to bytes (defaults to ``utf-8``) :param str errors: handling scheme for encoding errors (defaults to ``strict``; see the `codecs module documentation`_ for a comprehensive list of options) .. _codecs module documentation: https://docs.python.org/3/library/codecs.html#codec-objects rrrrrFr._encoderN)rrcCst||_dSr#)r getencoderr6)rrrrr r!LszTextSendStream.__post_init__itemrcs(|||jd}|j|IdHdS)Nr)r6rrsend)rr9encodedrrr r:OszTextSendStream.sendr"cs|jIdHdSr#)rr(r*rrr r(SszTextSendStream.aclosecCs|jjSr#r+r*rrr r,VszTextSendStream.extra_attributes)r-r.r/r0r r1rrr2rrr6rrbytesintr!r:r(r4rrr,rrrr r59s   "r5c@seZdZUdZeed<dZeeed<dZ eeed<e ddZ e ed <e ddZ eed <eed d d dZedddZed dddZd dddZd dddZeeeegeffdddZd S) TextStreama A bidirectional stream that decodes bytes to strings on receive and encodes strings to bytes on send. Extra attributes will be provided from both streams, with the receive stream providing the values in case of a conflict. :param AnyByteStream transport_stream: any bytes-based stream :param str encoding: character encoding to use for encoding/decoding strings to/from bytes (defaults to ``utf-8``) :param str errors: handling scheme for encoding errors (defaults to ``strict``; see the `codecs module documentation`_ for a comprehensive list of options) .. _codecs module documentation: https://docs.python.org/3/library/codecs.html#codec-objects rrrrrFr_receive_stream _send_streamNrcCs(t|j||d|_t|j||d|_dS)N)rr)rrr?r5r@)rrrrrr r!ss zTextStream.__post_init__r"cs|jIdHSr#)r?r$r*rrr r${szTextStream.receiver8cs|j|IdHdSr#)r@r:)rr9rrr r:~szTextStream.sendcs|jIdHdSr#)rsend_eofr*rrr rAszTextStream.send_eofcs$|jIdH|jIdHdSr#)r@r(r?r*rrr r(szTextStream.aclosecCsi|jj|jjSr#)r@r,r?r*rrr r,s zTextStream.extra_attributes)r-r.r/r0r r1rrr2rrr?rr@r5r!r$r:rAr(r4rrrr,rrrr r>[s r>)rZ dataclassesrrrtypingrrrrabcr r r r rrr2rr5r>rrrr s )!