{
    "file_diffs": [
        {
            "old_file_content": "",
            "new_file_content": "Add __repr__ to EmptyStreamReader to avoid AttributeErrors.\n",
            "header": {
                "file": {
                    "path": "CHANGES/6916.bugfix"
                },
                "misc_line": "new file mode 100644"
            },
            "index_line": {
                "old_commit_hash": "00000000",
                "new_commit_hash": "4c4329c1",
                "mode": ""
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "/dev/null"
            },
            "plus_file": {
                "path": "b/CHANGES/6916.bugfix"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 0,
                            "length": 0
                        },
                        "new_range": {
                            "start": 1,
                            "length": null
                        },
                        "section": ""
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "Add __repr__ to EmptyStreamReader to avoid AttributeErrors.",
                                "type": "added"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "- Contributors -\n----------------\nA. Jesse Jiryu Davis\nAdam Bannister\nAdam Cooper\nAdam Horacek\nAdam Mills\nAdrian Krupa\nAdrián Chaves\nAhmed Tahri\nAlan Tse\nAlec Hanefeld\nAlejandro Gómez\nAleksandr Danshyn\nAleksey Kutepov\nAlex Hayes\nAlex Key\nAlex Khomchenko\nAlex Kuzmenko\nAlex Lisovoy\nAlexander Bayandin\nAlexander Karpinsky\nAlexander Koshevoy\nAlexander Malev\nAlexander Mohr\nAlexander Shorin\nAlexander Travov\nAlexandru Mihai\nAlexey Firsov\nAlexey Popravka\nAlexey Stepanov\nAmin Etesamian\nAmit Tulshyan\nAmy Boyle\nAnas El Amraoui\nAnders Melchiorsen\nAndrei Ursulenko\nAndrej Antonov\nAndrew Leech\nAndrew Lytvyn\nAndrew Svetlov\nAndrew Zhou\nAndrii Soldatenko\nAnes Abismail\nAntoine Pietri\nAnton Kasyanov\nAnton Zhdan-Pushkin\nArseny Timoniq\nArtem Yushkovskiy\nArthur Darcet\nAustin Scola\nBen Bader\nBen Greiner\nBen Timby\nBenedikt Reinartz\nBob Haddleton\nBoris Feld\nBoyi Chen\nBrett Cannon\nBrian Bouterse\nBrian C. Lane\nBrian Muller\nBruce Merry\nBruno Souza Cabral\nBryan Kok\nBryce Drennan\nCarl George\nCecile Tonglet\nChien-Wei Huang\nChih-Yuan Chen\nChris AtLee\nChris Laws\nChris Moore\nChristopher Schmitt\nClaudiu Popa\nColin Dunklau\nCong Xu\nDamien Nadé\nDan King\nDan Xu\nDaniel García\nDaniel Grossmann-Kavanagh\nDaniel Nelson\nDanny Song\nDavid Bibb\nDavid Michael Brown\nDenilson Amorim\nDenis Matiychuk\nDenis Moshensky\nDennis Kliban\nDima Veselov\nDimitar Dimitrov\nDmitriy Safonov\nDmitry Doroshev\nDmitry Erlikh\nDmitry Lukashin\nDmitry Marakasov\nDmitry Shamov\nDmitry Trofimov\nDmytro Bohomiakov\nDmytro Kuznetsov\nDustin J. Mitchell\nEduard Iskandarov\nEli Ribble\nElizabeth Leddy\nEnrique Saez\nEric Sheng\nErich Healy\nErik Peterson\nEugene Chernyshov\nEugene Naydenov\nEugene Nikolaiev\nEugene Tolmachev\nEvan Kepner\nEvert Lammerts\nFelix Yan\nFernanda Guimarães\nFichteFoll\nFlorian Scheffler\nFranek Magiera\nFrederik Gladhorn\nFrederik Peter Aalund\nGabriel Tremblay\nGary Wilson Jr.\nGennady Andreyev\nGeorges Dubus\nGreg Holt\nGregory Haynes\nGus Goulart\nGustavo Carneiro\nGünther Jena\nHans Adema\nHarmon Y.\nHarry Liu\nHiroshi Ogawa\nHrishikesh Paranjape\nHu Bo\nHugh Young\nHugo Herter\nHugo van Kemenade\nHynek Schlawack\nIgor Alexandrov\nIgor Davydenko\nIgor Mozharovsky\nIgor Pavlov\nIllia Volochii\nIlya Chichak\nIlya Gruzinov\nIngmar Steen\nIvan Lakovic\nIvan Larin\nJacob Champion\nJaesung Lee\nJake Davis\nJakob Ackermann\nJakub Wilk\nJan Buchar\nJashandeep Sohi\nJean-Baptiste Estival\nJens Steinhauser\nJeonghun Lee\nJeongkyu Shin\nJeroen van der Heijden\nJesus Cea\nJian Zeng\nJinkyu Yi\nJoel Watts\nJon Nabozny\nJonas Krüger Svensson\nJonas Obrist\nJonathan Wright\nJonny Tan\nJoongi Kim\nJordan Borean\nJosep Cugat\nJosh Junon\nJoshu Coats\nJulia Tsemusheva\nJulien Duponchelle\nJungkook Park\nJunjie Tao\nJunyeong Jeong\nJustas Trimailovas\nJustin Foo\nJustin Turner Arthur\nKay Zheng\nKevin Samuel\nKimmo Parviainen-Jalanko\nKirill Klenov\nKirill Malovitsa\nKonstantin Valetov\nKrzysztof Blazewicz\nKyrylo Perevozchikov\nKyungmin Lee\nLars P. Søndergaard\nLiu Hua\nLouis-Philippe Huberdeau\nLoïc Lajeanne\nLu Gong\nLubomir Gelo\nLudovic Gasc\nLuis Pedrosa\nLukasz Marcin Dobrzanski\nMakc Belousow\nManuel Miranda\nMarat Sharafutdinov\nMarco Paolini\nMariano Anaya\nMariusz Masztalerczuk\nMarko Kohtala\nMartijn Pieters\nMartin Melka\nMartin Richard\nMathias Fröjdman\nMathieu Dugré\nMatthieu Hauglustaine\nMatthieu Rigal\nMatvey Tingaev\nMeet Mangukiya\nMichael Ihnatenko\nMichał Górny\nMikhail Burshteyn\nMikhail Kashkin\nMikhail Lukyanchenko\nMikhail Nacharov\nMisha Behersky\nMitchell Ferree\nMorgan Delahaye-Prat\nMoss Collum\nMun Gwan-gyeong\nNavid Sheikhol\nNicolas Braem\nNikolay Kim\nNikolay Novik\nNikolay Tiunov\nNándor Mátravölgyi\nOisin Aylward\nOlaf Conradi\nPahaz Blinov\nPanagiotis Kolokotronis\nPankaj Pandey\nPau Freixes\nPaul Colomiets\nPaulius Šileikis\nPaulus Schoutsen\nPavel Kamaev\nPavel Polyakov\nPavel Sapezhko\nPavol Vargovčík\nPawel Kowalski\nPawel Miech\nPepe Osca\nPhilipp A.\nPieter van Beek\nQiao Han\nRafael Viotti\nRaphael Bialon\nRaúl Cumplido\nRequired Field\nRobert Lu\nRobert Nikolich\nRoman Podoliaka\nSamir Akarioh\nSamuel Colvin\nSean Hunt\nSebastian Acuna\nSebastian Hanula\nSebastian Hüther\nSebastien Geffroy\nSeongSoo Cho\nSergey Ninua\nSergey Skripnick\nSerhii Charykov\nSerhii Kostel\nSerhiy Storchaka\nSimon Kennedy\nSin-Woo Bang\nStanislas Plum\nStanislav Prokop\nStefan Tjarks\nStepan Pletnev\nStephan Jaensch\nStephen Cirelli\nStephen Granade\nSteven Seguin\nSunghyun Hwang\nSunit Deshpande\nSviatoslav Bulbakha\nSviatoslav Sydorenko\nTaha Jahangir\nTaras Voinarovskyi\nTerence Honles\nThanos Lefteris\nThijs Vermeir\nThomas Forbes\nThomas Grainger\nTolga Tezel\nTomasz Trebski\nToshiaki Tanaka\nTrinh Hoang Nhu\nVadim Suharnikov\nVaibhav Sagar\nVamsi Krishna Avula\nVasiliy Faronov\nVasyl Baran\nViacheslav Greshilov\nVictor Collod\nVictor Kovtun\nVikas Kawadia\nViktor Danyliuk\nVille Skyttä\nVincent Maillol\nVitalik Verhovodov\nVitaly Haritonsky\nVitaly Magerya\nVladimir Kamarzin\nVladimir Kozlovski\nVladimir Rutsky\nVladimir Shulyak\nVladimir Zakharov\nVladyslav Bohaichuk\nVladyslav Bondar\nW. Trevor King\nWei Lin\nWeiwei Wang\nWill Fatherley\nWill McGugan\nWillem de Groot\nWilliam Grzybowski\nWilliam S.\nWilson Ong\nwouter bolsterlee\nYang Zhou\nYannick Koechlin\nYannick Péroux\nYe Cao\nYegor Roganov\nYifei Kong\nYoung-Ho Cha\nYuriy Shatrov\nYury Pliner\nYury Selivanov\nYusuke Tsutsumi\nYuval Ofir\nZainab Lawal\nZeal Wierslee\nZlatan Sičanica\nМарк Коренберг\nСемён Марьясин\n",
            "new_file_content": "- Contributors -\n----------------\nA. Jesse Jiryu Davis\nAdam Bannister\nAdam Cooper\nAdam Horacek\nAdam Mills\nAdrian Krupa\nAdrián Chaves\nAhmed Tahri\nAlan Tse\nAlec Hanefeld\nAlejandro Gómez\nAleksandr Danshyn\nAleksey Kutepov\nAlex Hayes\nAlex Key\nAlex Khomchenko\nAlex Kuzmenko\nAlex Lisovoy\nAlexander Bayandin\nAlexander Karpinsky\nAlexander Koshevoy\nAlexander Malev\nAlexander Mohr\nAlexander Shorin\nAlexander Travov\nAlexandru Mihai\nAlexey Firsov\nAlexey Popravka\nAlexey Stepanov\nAmin Etesamian\nAmit Tulshyan\nAmy Boyle\nAnas El Amraoui\nAnders Melchiorsen\nAndrei Ursulenko\nAndrej Antonov\nAndrew Leech\nAndrew Lytvyn\nAndrew Svetlov\nAndrew Zhou\nAndrii Soldatenko\nAnes Abismail\nAntoine Pietri\nAnton Kasyanov\nAnton Zhdan-Pushkin\nArseny Timoniq\nArtem Yushkovskiy\nArthur Darcet\nAustin Scola\nBen Bader\nBen Greiner\nBen Timby\nBenedikt Reinartz\nBob Haddleton\nBoris Feld\nBoyi Chen\nBrett Cannon\nBrian Bouterse\nBrian C. Lane\nBrian Muller\nBruce Merry\nBruno Souza Cabral\nBryan Kok\nBryce Drennan\nCarl George\nCecile Tonglet\nChien-Wei Huang\nChih-Yuan Chen\nChris AtLee\nChris Laws\nChris Moore\nChristopher Schmitt\nClaudiu Popa\nColin Dunklau\nCong Xu\nDamien Nadé\nDan King\nDan Xu\nDaniel García\nDaniel Grossmann-Kavanagh\nDaniel Nelson\nDanny Song\nDavid Bibb\nDavid Michael Brown\nDenilson Amorim\nDenis Matiychuk\nDenis Moshensky\nDennis Kliban\nDima Veselov\nDimitar Dimitrov\nDmitriy Safonov\nDmitry Doroshev\nDmitry Erlikh\nDmitry Lukashin\nDmitry Marakasov\nDmitry Shamov\nDmitry Trofimov\nDmytro Bohomiakov\nDmytro Kuznetsov\nDustin J. Mitchell\nEduard Iskandarov\nEli Ribble\nElizabeth Leddy\nEnrique Saez\nEric Sheng\nErich Healy\nErik Peterson\nEugene Chernyshov\nEugene Naydenov\nEugene Nikolaiev\nEugene Tolmachev\nEvan Kepner\nEvert Lammerts\nFelix Yan\nFernanda Guimarães\nFichteFoll\nFlorian Scheffler\nFranek Magiera\nFrederik Gladhorn\nFrederik Peter Aalund\nGabriel Tremblay\nGary Wilson Jr.\nGennady Andreyev\nGeorges Dubus\nGreg Holt\nGregory Haynes\nGus Goulart\nGustavo Carneiro\nGünther Jena\nHans Adema\nHarmon Y.\nHarry Liu\nHiroshi Ogawa\nHrishikesh Paranjape\nHu Bo\nHugh Young\nHugo Herter\nHugo van Kemenade\nHynek Schlawack\nIgor Alexandrov\nIgor Davydenko\nIgor Mozharovsky\nIgor Pavlov\nIllia Volochii\nIlya Chichak\nIlya Gruzinov\nIngmar Steen\nIvan Lakovic\nIvan Larin\nJacob Champion\nJaesung Lee\nJake Davis\nJakob Ackermann\nJakub Wilk\nJan Buchar\nJarno Elonen\nJashandeep Sohi\nJean-Baptiste Estival\nJens Steinhauser\nJeonghun Lee\nJeongkyu Shin\nJeroen van der Heijden\nJesus Cea\nJian Zeng\nJinkyu Yi\nJoel Watts\nJon Nabozny\nJonas Krüger Svensson\nJonas Obrist\nJonathan Wright\nJonny Tan\nJoongi Kim\nJordan Borean\nJosep Cugat\nJosh Junon\nJoshu Coats\nJulia Tsemusheva\nJulien Duponchelle\nJungkook Park\nJunjie Tao\nJunyeong Jeong\nJustas Trimailovas\nJustin Foo\nJustin Turner Arthur\nKay Zheng\nKevin Samuel\nKimmo Parviainen-Jalanko\nKirill Klenov\nKirill Malovitsa\nKonstantin Valetov\nKrzysztof Blazewicz\nKyrylo Perevozchikov\nKyungmin Lee\nLars P. Søndergaard\nLiu Hua\nLouis-Philippe Huberdeau\nLoïc Lajeanne\nLu Gong\nLubomir Gelo\nLudovic Gasc\nLuis Pedrosa\nLukasz Marcin Dobrzanski\nMakc Belousow\nManuel Miranda\nMarat Sharafutdinov\nMarco Paolini\nMariano Anaya\nMariusz Masztalerczuk\nMarko Kohtala\nMartijn Pieters\nMartin Melka\nMartin Richard\nMathias Fröjdman\nMathieu Dugré\nMatthieu Hauglustaine\nMatthieu Rigal\nMatvey Tingaev\nMeet Mangukiya\nMichael Ihnatenko\nMichał Górny\nMikhail Burshteyn\nMikhail Kashkin\nMikhail Lukyanchenko\nMikhail Nacharov\nMisha Behersky\nMitchell Ferree\nMorgan Delahaye-Prat\nMoss Collum\nMun Gwan-gyeong\nNavid Sheikhol\nNicolas Braem\nNikolay Kim\nNikolay Novik\nNikolay Tiunov\nNándor Mátravölgyi\nOisin Aylward\nOlaf Conradi\nPahaz Blinov\nPanagiotis Kolokotronis\nPankaj Pandey\nPau Freixes\nPaul Colomiets\nPaulius Šileikis\nPaulus Schoutsen\nPavel Kamaev\nPavel Polyakov\nPavel Sapezhko\nPavol Vargovčík\nPawel Kowalski\nPawel Miech\nPepe Osca\nPhilipp A.\nPieter van Beek\nQiao Han\nRafael Viotti\nRaphael Bialon\nRaúl Cumplido\nRequired Field\nRobert Lu\nRobert Nikolich\nRoman Podoliaka\nSamir Akarioh\nSamuel Colvin\nSean Hunt\nSebastian Acuna\nSebastian Hanula\nSebastian Hüther\nSebastien Geffroy\nSeongSoo Cho\nSergey Ninua\nSergey Skripnick\nSerhii Charykov\nSerhii Kostel\nSerhiy Storchaka\nSimon Kennedy\nSin-Woo Bang\nStanislas Plum\nStanislav Prokop\nStefan Tjarks\nStepan Pletnev\nStephan Jaensch\nStephen Cirelli\nStephen Granade\nSteven Seguin\nSunghyun Hwang\nSunit Deshpande\nSviatoslav Bulbakha\nSviatoslav Sydorenko\nTaha Jahangir\nTaras Voinarovskyi\nTerence Honles\nThanos Lefteris\nThijs Vermeir\nThomas Forbes\nThomas Grainger\nTolga Tezel\nTomasz Trebski\nToshiaki Tanaka\nTrinh Hoang Nhu\nVadim Suharnikov\nVaibhav Sagar\nVamsi Krishna Avula\nVasiliy Faronov\nVasyl Baran\nViacheslav Greshilov\nVictor Collod\nVictor Kovtun\nVikas Kawadia\nViktor Danyliuk\nVille Skyttä\nVincent Maillol\nVitalik Verhovodov\nVitaly Haritonsky\nVitaly Magerya\nVladimir Kamarzin\nVladimir Kozlovski\nVladimir Rutsky\nVladimir Shulyak\nVladimir Zakharov\nVladyslav Bohaichuk\nVladyslav Bondar\nW. Trevor King\nWei Lin\nWeiwei Wang\nWill Fatherley\nWill McGugan\nWillem de Groot\nWilliam Grzybowski\nWilliam S.\nWilson Ong\nwouter bolsterlee\nYang Zhou\nYannick Koechlin\nYannick Péroux\nYe Cao\nYegor Roganov\nYifei Kong\nYoung-Ho Cha\nYuriy Shatrov\nYury Pliner\nYury Selivanov\nYusuke Tsutsumi\nYuval Ofir\nZainab Lawal\nZeal Wierslee\nZlatan Sičanica\nМарк Коренберг\nСемён Марьясин\n",
            "header": {
                "file": {
                    "path": "CONTRIBUTORS.txt"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "23ea188a",
                "new_commit_hash": "7c633b30",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/CONTRIBUTORS.txt"
            },
            "plus_file": {
                "path": "b/CONTRIBUTORS.txt"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 155,
                            "length": 6
                        },
                        "new_range": {
                            "start": 155,
                            "length": 7
                        },
                        "section": "Jake Davis"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "Jakob Ackermann",
                                "type": "context"
                            },
                            {
                                "content": "Jakub Wilk",
                                "type": "context"
                            },
                            {
                                "content": "Jan Buchar",
                                "type": "context"
                            },
                            {
                                "content": "Jarno Elonen",
                                "type": "added"
                            },
                            {
                                "content": "Jashandeep Sohi",
                                "type": "context"
                            },
                            {
                                "content": "Jean-Baptiste Estival",
                                "type": "context"
                            },
                            {
                                "content": "Jens Steinhauser",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "import asyncio\nimport collections\nimport warnings\nfrom typing import Awaitable, Callable, Deque, Generic, List, Optional, Tuple, TypeVar\n\nfrom .base_protocol import BaseProtocol\nfrom .helpers import BaseTimerContext, set_exception, set_result\nfrom .log import internal_logger\nfrom .typedefs import Final\n\n__all__ = (\n    \"EMPTY_PAYLOAD\",\n    \"EofStream\",\n    \"StreamReader\",\n    \"DataQueue\",\n    \"FlowControlDataQueue\",\n)\n\n_T = TypeVar(\"_T\")\n\n\nclass EofStream(Exception):\n    \"\"\"eof stream indication.\"\"\"\n\n\nclass AsyncStreamIterator(Generic[_T]):\n    def __init__(self, read_func: Callable[[], Awaitable[_T]]) -> None:\n        self.read_func = read_func\n\n    def __aiter__(self) -> \"AsyncStreamIterator[_T]\":\n        return self\n\n    async def __anext__(self) -> _T:\n        try:\n            rv = await self.read_func()\n        except EofStream:\n            raise StopAsyncIteration\n        if rv == b\"\":\n            raise StopAsyncIteration\n        return rv\n\n\nclass ChunkTupleAsyncStreamIterator:\n    def __init__(self, stream: \"StreamReader\") -> None:\n        self._stream = stream\n\n    def __aiter__(self) -> \"ChunkTupleAsyncStreamIterator\":\n        return self\n\n    async def __anext__(self) -> Tuple[bytes, bool]:\n        rv = await self._stream.readchunk()\n        if rv == (b\"\", False):\n            raise StopAsyncIteration\n        return rv\n\n\nclass AsyncStreamReaderMixin:\n    def __aiter__(self) -> AsyncStreamIterator[bytes]:\n        return AsyncStreamIterator(self.readline)  # type: ignore[attr-defined]\n\n    def iter_chunked(self, n: int) -> AsyncStreamIterator[bytes]:\n        \"\"\"Returns an asynchronous iterator that yields chunks of size n.\"\"\"\n        return AsyncStreamIterator(\n            lambda: self.read(n)  # type: ignore[attr-defined,no-any-return]\n        )\n\n    def iter_any(self) -> AsyncStreamIterator[bytes]:\n        \"\"\"Yield all available data as soon as it is received.\"\"\"\n        return AsyncStreamIterator(self.readany)  # type: ignore[attr-defined]\n\n    def iter_chunks(self) -> ChunkTupleAsyncStreamIterator:\n        \"\"\"Yield chunks of data as they are received by the server.\n\n        The yielded objects are tuples\n        of (bytes, bool) as returned by the StreamReader.readchunk method.\n        \"\"\"\n        return ChunkTupleAsyncStreamIterator(self)  # type: ignore[arg-type]\n\n\nclass StreamReader(AsyncStreamReaderMixin):\n    \"\"\"An enhancement of asyncio.StreamReader.\n\n    Supports asynchronous iteration by line, chunk or as available::\n\n        async for line in reader:\n            ...\n        async for chunk in reader.iter_chunked(1024):\n            ...\n        async for slice in reader.iter_any():\n            ...\n\n    \"\"\"\n\n    total_bytes = 0\n\n    def __init__(\n        self,\n        protocol: BaseProtocol,\n        limit: int,\n        *,\n        timer: Optional[BaseTimerContext] = None,\n        loop: Optional[asyncio.AbstractEventLoop] = None,\n    ) -> None:\n        self._protocol = protocol\n        self._low_water = limit\n        self._high_water = limit * 2\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n        self._size = 0\n        self._cursor = 0\n        self._http_chunk_splits: Optional[List[int]] = None\n        self._buffer: Deque[bytes] = collections.deque()\n        self._buffer_offset = 0\n        self._eof = False\n        self._waiter: Optional[asyncio.Future[None]] = None\n        self._eof_waiter: Optional[asyncio.Future[None]] = None\n        self._exception: Optional[BaseException] = None\n        self._timer = timer\n        self._eof_callbacks: List[Callable[[], None]] = []\n\n    def __repr__(self) -> str:\n        info = [self.__class__.__name__]\n        if self._size:\n            info.append(\"%d bytes\" % self._size)\n        if self._eof:\n            info.append(\"eof\")\n        if self._low_water != 2**16:  # default limit\n            info.append(\"low=%d high=%d\" % (self._low_water, self._high_water))\n        if self._waiter:\n            info.append(\"w=%r\" % self._waiter)\n        if self._exception:\n            info.append(\"e=%r\" % self._exception)\n        return \"<%s>\" % \" \".join(info)\n\n    def get_read_buffer_limits(self) -> Tuple[int, int]:\n        return (self._low_water, self._high_water)\n\n    def exception(self) -> Optional[BaseException]:\n        return self._exception\n\n    def set_exception(self, exc: BaseException) -> None:\n        self._exception = exc\n        self._eof_callbacks.clear()\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_exception(waiter, exc)\n\n        waiter = self._eof_waiter\n        if waiter is not None:\n            self._eof_waiter = None\n            set_exception(waiter, exc)\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        if self._eof:\n            try:\n                callback()\n            except Exception:\n                internal_logger.exception(\"Exception in eof callback\")\n        else:\n            self._eof_callbacks.append(callback)\n\n    def feed_eof(self) -> None:\n        self._eof = True\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n        waiter = self._eof_waiter\n        if waiter is not None:\n            self._eof_waiter = None\n            set_result(waiter, None)\n\n        for cb in self._eof_callbacks:\n            try:\n                cb()\n            except Exception:\n                internal_logger.exception(\"Exception in eof callback\")\n\n        self._eof_callbacks.clear()\n\n    def is_eof(self) -> bool:\n        \"\"\"Return True if  'feed_eof' was called.\"\"\"\n        return self._eof\n\n    def at_eof(self) -> bool:\n        \"\"\"Return True if the buffer is empty and 'feed_eof' was called.\"\"\"\n        return self._eof and not self._buffer\n\n    async def wait_eof(self) -> None:\n        if self._eof:\n            return\n\n        assert self._eof_waiter is None\n        self._eof_waiter = self._loop.create_future()\n        try:\n            await self._eof_waiter\n        finally:\n            self._eof_waiter = None\n\n    def unread_data(self, data: bytes) -> None:\n        \"\"\"rollback reading some data from stream, inserting it to buffer head.\"\"\"\n        warnings.warn(\n            \"unread_data() is deprecated \"\n            \"and will be removed in future releases (#3260)\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        if not data:\n            return\n\n        if self._buffer_offset:\n            self._buffer[0] = self._buffer[0][self._buffer_offset :]\n            self._buffer_offset = 0\n        self._size += len(data)\n        self._cursor -= len(data)\n        self._buffer.appendleft(data)\n        self._eof_counter = 0\n\n    # TODO: size is ignored, remove the param later\n    def feed_data(self, data: bytes, size: int = 0) -> None:\n        assert not self._eof, \"feed_data after feed_eof\"\n\n        if not data:\n            return\n\n        self._size += len(data)\n        self._buffer.append(data)\n        self.total_bytes += len(data)\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n        if self._size > self._high_water and not self._protocol._reading_paused:\n            self._protocol.pause_reading()\n\n    def begin_http_chunk_receiving(self) -> None:\n        if self._http_chunk_splits is None:\n            if self.total_bytes:\n                raise RuntimeError(\n                    \"Called begin_http_chunk_receiving when\" \"some data was already fed\"\n                )\n            self._http_chunk_splits = []\n\n    def end_http_chunk_receiving(self) -> None:\n        if self._http_chunk_splits is None:\n            raise RuntimeError(\n                \"Called end_chunk_receiving without calling \"\n                \"begin_chunk_receiving first\"\n            )\n\n        # self._http_chunk_splits contains logical byte offsets from start of\n        # the body transfer. Each offset is the offset of the end of a chunk.\n        # \"Logical\" means bytes, accessible for a user.\n        # If no chunks containig logical data were received, current position\n        # is difinitely zero.\n        pos = self._http_chunk_splits[-1] if self._http_chunk_splits else 0\n\n        if self.total_bytes == pos:\n            # We should not add empty chunks here. So we check for that.\n            # Note, when chunked + gzip is used, we can receive a chunk\n            # of compressed data, but that data may not be enough for gzip FSM\n            # to yield any uncompressed data. That's why current position may\n            # not change after receiving a chunk.\n            return\n\n        self._http_chunk_splits.append(self.total_bytes)\n\n        # wake up readchunk when end of http chunk received\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    async def _wait(self, func_name: str) -> None:\n        # StreamReader uses a future to link the protocol feed_data() method\n        # to a read coroutine. Running two read coroutines at the same time\n        # would have an unexpected behaviour. It would not possible to know\n        # which coroutine would get the next data.\n        if self._waiter is not None:\n            raise RuntimeError(\n                \"%s() called while another coroutine is \"\n                \"already waiting for incoming data\" % func_name\n            )\n\n        waiter = self._waiter = self._loop.create_future()\n        try:\n            if self._timer:\n                with self._timer:\n                    await waiter\n            else:\n                await waiter\n        finally:\n            self._waiter = None\n\n    async def readline(self) -> bytes:\n        return await self.readuntil()\n\n    async def readuntil(self, separator: bytes = b\"\\n\") -> bytes:\n        seplen = len(separator)\n        if seplen == 0:\n            raise ValueError(\"Separator should be at least one-byte string\")\n\n        if self._exception is not None:\n            raise self._exception\n\n        chunk = b\"\"\n        chunk_size = 0\n        not_enough = True\n\n        while not_enough:\n            while self._buffer and not_enough:\n                offset = self._buffer_offset\n                ichar = self._buffer[0].find(separator, offset) + 1\n                # Read from current offset to found separator or to the end.\n                data = self._read_nowait_chunk(\n                    ichar - offset + seplen - 1 if ichar else -1\n                )\n                chunk += data\n                chunk_size += len(data)\n                if ichar:\n                    not_enough = False\n\n                if chunk_size > self._high_water:\n                    raise ValueError(\"Chunk too big\")\n\n            if self._eof:\n                break\n\n            if not_enough:\n                await self._wait(\"readuntil\")\n\n        return chunk\n\n    async def read(self, n: int = -1) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        # migration problem; with DataQueue you have to catch\n        # EofStream exception, so common way is to run payload.read() inside\n        # infinite loop. what can cause real infinite loop with StreamReader\n        # lets keep this code one major release.\n        if __debug__:\n            if self._eof and not self._buffer:\n                self._eof_counter = getattr(self, \"_eof_counter\", 0) + 1\n                if self._eof_counter > 5:\n                    internal_logger.warning(\n                        \"Multiple access to StreamReader in eof state, \"\n                        \"might be infinite loop.\",\n                        stack_info=True,\n                    )\n\n        if not n:\n            return b\"\"\n\n        if n < 0:\n            # This used to just loop creating a new waiter hoping to\n            # collect everything in self._buffer, but that would\n            # deadlock if the subprocess sends more than self.limit\n            # bytes.  So just call self.readany() until EOF.\n            blocks = []\n            while True:\n                block = await self.readany()\n                if not block:\n                    break\n                blocks.append(block)\n            return b\"\".join(blocks)\n\n        # TODO: should be `if` instead of `while`\n        # because waiter maybe triggered on chunk end,\n        # without feeding any data\n        while not self._buffer and not self._eof:\n            await self._wait(\"read\")\n\n        return self._read_nowait(n)\n\n    async def readany(self) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        # TODO: should be `if` instead of `while`\n        # because waiter maybe triggered on chunk end,\n        # without feeding any data\n        while not self._buffer and not self._eof:\n            await self._wait(\"readany\")\n\n        return self._read_nowait(-1)\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        \"\"\"Returns a tuple of (data, end_of_http_chunk).\n\n        When chunked transfer\n        encoding is used, end_of_http_chunk is a boolean indicating if the end\n        of the data corresponds to the end of a HTTP chunk , otherwise it is\n        always False.\n        \"\"\"\n        while True:\n            if self._exception is not None:\n                raise self._exception\n\n            while self._http_chunk_splits:\n                pos = self._http_chunk_splits.pop(0)\n                if pos == self._cursor:\n                    return (b\"\", True)\n                if pos > self._cursor:\n                    return (self._read_nowait(pos - self._cursor), True)\n                internal_logger.warning(\n                    \"Skipping HTTP chunk end due to data \"\n                    \"consumption beyond chunk boundary\"\n                )\n\n            if self._buffer:\n                return (self._read_nowait_chunk(-1), False)\n                # return (self._read_nowait(-1), False)\n\n            if self._eof:\n                # Special case for signifying EOF.\n                # (b'', True) is not a final return value actually.\n                return (b\"\", False)\n\n            await self._wait(\"readchunk\")\n\n    async def readexactly(self, n: int) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        blocks: List[bytes] = []\n        while n > 0:\n            block = await self.read(n)\n            if not block:\n                partial = b\"\".join(blocks)\n                raise asyncio.IncompleteReadError(partial, len(partial) + n)\n            blocks.append(block)\n            n -= len(block)\n\n        return b\"\".join(blocks)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        # default was changed to be consistent with .read(-1)\n        #\n        # I believe the most users don't know about the method and\n        # they are not affected.\n        if self._exception is not None:\n            raise self._exception\n\n        if self._waiter and not self._waiter.done():\n            raise RuntimeError(\n                \"Called while some coroutine is waiting for incoming data.\"\n            )\n\n        return self._read_nowait(n)\n\n    def _read_nowait_chunk(self, n: int) -> bytes:\n        first_buffer = self._buffer[0]\n        offset = self._buffer_offset\n        if n != -1 and len(first_buffer) - offset > n:\n            data = first_buffer[offset : offset + n]\n            self._buffer_offset += n\n\n        elif offset:\n            self._buffer.popleft()\n            data = first_buffer[offset:]\n            self._buffer_offset = 0\n\n        else:\n            data = self._buffer.popleft()\n\n        self._size -= len(data)\n        self._cursor += len(data)\n\n        chunk_splits = self._http_chunk_splits\n        # Prevent memory leak: drop useless chunk splits\n        while chunk_splits and chunk_splits[0] < self._cursor:\n            chunk_splits.pop(0)\n\n        if self._size < self._low_water and self._protocol._reading_paused:\n            self._protocol.resume_reading()\n        return data\n\n    def _read_nowait(self, n: int) -> bytes:\n        \"\"\"Read not more than n bytes, or whole buffer if n == -1\"\"\"\n        chunks = []\n\n        while self._buffer:\n            chunk = self._read_nowait_chunk(n)\n            chunks.append(chunk)\n            if n != -1:\n                n -= len(chunk)\n                if n == 0:\n                    break\n\n        return b\"\".join(chunks) if chunks else b\"\"\n\n\nclass EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]\n    def __init__(self) -> None:\n        pass\n\n    def exception(self) -> Optional[BaseException]:\n        return None\n\n    def set_exception(self, exc: BaseException) -> None:\n        pass\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        try:\n            callback()\n        except Exception:\n            internal_logger.exception(\"Exception in eof callback\")\n\n    def feed_eof(self) -> None:\n        pass\n\n    def is_eof(self) -> bool:\n        return True\n\n    def at_eof(self) -> bool:\n        return True\n\n    async def wait_eof(self) -> None:\n        return\n\n    def feed_data(self, data: bytes, n: int = 0) -> None:\n        pass\n\n    async def readline(self) -> bytes:\n        return b\"\"\n\n    async def read(self, n: int = -1) -> bytes:\n        return b\"\"\n\n    # TODO add async def readuntil\n\n    async def readany(self) -> bytes:\n        return b\"\"\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        return (b\"\", True)\n\n    async def readexactly(self, n: int) -> bytes:\n        raise asyncio.IncompleteReadError(b\"\", n)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        return b\"\"\n\n\nEMPTY_PAYLOAD: Final[StreamReader] = EmptyStreamReader()\n\n\nclass DataQueue(Generic[_T]):\n    \"\"\"DataQueue is a general-purpose blocking queue with one reader.\"\"\"\n\n    def __init__(self, loop: asyncio.AbstractEventLoop) -> None:\n        self._loop = loop\n        self._eof = False\n        self._waiter: Optional[asyncio.Future[None]] = None\n        self._exception: Optional[BaseException] = None\n        self._size = 0\n        self._buffer: Deque[Tuple[_T, int]] = collections.deque()\n\n    def __len__(self) -> int:\n        return len(self._buffer)\n\n    def is_eof(self) -> bool:\n        return self._eof\n\n    def at_eof(self) -> bool:\n        return self._eof and not self._buffer\n\n    def exception(self) -> Optional[BaseException]:\n        return self._exception\n\n    def set_exception(self, exc: BaseException) -> None:\n        self._eof = True\n        self._exception = exc\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_exception(waiter, exc)\n\n    def feed_data(self, data: _T, size: int = 0) -> None:\n        self._size += size\n        self._buffer.append((data, size))\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    def feed_eof(self) -> None:\n        self._eof = True\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    async def read(self) -> _T:\n        if not self._buffer and not self._eof:\n            assert not self._waiter\n            self._waiter = self._loop.create_future()\n            try:\n                await self._waiter\n            except (asyncio.CancelledError, asyncio.TimeoutError):\n                self._waiter = None\n                raise\n\n        if self._buffer:\n            data, size = self._buffer.popleft()\n            self._size -= size\n            return data\n        else:\n            if self._exception is not None:\n                raise self._exception\n            else:\n                raise EofStream\n\n    def __aiter__(self) -> AsyncStreamIterator[_T]:\n        return AsyncStreamIterator(self.read)\n\n\nclass FlowControlDataQueue(DataQueue[_T]):\n    \"\"\"FlowControlDataQueue resumes and pauses an underlying stream.\n\n    It is a destination for parsed data.\n    \"\"\"\n\n    def __init__(\n        self, protocol: BaseProtocol, limit: int, *, loop: asyncio.AbstractEventLoop\n    ) -> None:\n        super().__init__(loop=loop)\n\n        self._protocol = protocol\n        self._limit = limit * 2\n\n    def feed_data(self, data: _T, size: int = 0) -> None:\n        super().feed_data(data, size)\n\n        if self._size > self._limit and not self._protocol._reading_paused:\n            self._protocol.pause_reading()\n\n    async def read(self) -> _T:\n        try:\n            return await super().read()\n        finally:\n            if self._size < self._limit and self._protocol._reading_paused:\n                self._protocol.resume_reading()\n",
            "new_file_content": "import asyncio\nimport collections\nimport warnings\nfrom typing import Awaitable, Callable, Deque, Generic, List, Optional, Tuple, TypeVar\n\nfrom .base_protocol import BaseProtocol\nfrom .helpers import BaseTimerContext, set_exception, set_result\nfrom .log import internal_logger\nfrom .typedefs import Final\n\n__all__ = (\n    \"EMPTY_PAYLOAD\",\n    \"EofStream\",\n    \"StreamReader\",\n    \"DataQueue\",\n    \"FlowControlDataQueue\",\n)\n\n_T = TypeVar(\"_T\")\n\n\nclass EofStream(Exception):\n    \"\"\"eof stream indication.\"\"\"\n\n\nclass AsyncStreamIterator(Generic[_T]):\n    def __init__(self, read_func: Callable[[], Awaitable[_T]]) -> None:\n        self.read_func = read_func\n\n    def __aiter__(self) -> \"AsyncStreamIterator[_T]\":\n        return self\n\n    async def __anext__(self) -> _T:\n        try:\n            rv = await self.read_func()\n        except EofStream:\n            raise StopAsyncIteration\n        if rv == b\"\":\n            raise StopAsyncIteration\n        return rv\n\n\nclass ChunkTupleAsyncStreamIterator:\n    def __init__(self, stream: \"StreamReader\") -> None:\n        self._stream = stream\n\n    def __aiter__(self) -> \"ChunkTupleAsyncStreamIterator\":\n        return self\n\n    async def __anext__(self) -> Tuple[bytes, bool]:\n        rv = await self._stream.readchunk()\n        if rv == (b\"\", False):\n            raise StopAsyncIteration\n        return rv\n\n\nclass AsyncStreamReaderMixin:\n    def __aiter__(self) -> AsyncStreamIterator[bytes]:\n        return AsyncStreamIterator(self.readline)  # type: ignore[attr-defined]\n\n    def iter_chunked(self, n: int) -> AsyncStreamIterator[bytes]:\n        \"\"\"Returns an asynchronous iterator that yields chunks of size n.\"\"\"\n        return AsyncStreamIterator(\n            lambda: self.read(n)  # type: ignore[attr-defined,no-any-return]\n        )\n\n    def iter_any(self) -> AsyncStreamIterator[bytes]:\n        \"\"\"Yield all available data as soon as it is received.\"\"\"\n        return AsyncStreamIterator(self.readany)  # type: ignore[attr-defined]\n\n    def iter_chunks(self) -> ChunkTupleAsyncStreamIterator:\n        \"\"\"Yield chunks of data as they are received by the server.\n\n        The yielded objects are tuples\n        of (bytes, bool) as returned by the StreamReader.readchunk method.\n        \"\"\"\n        return ChunkTupleAsyncStreamIterator(self)  # type: ignore[arg-type]\n\n\nclass StreamReader(AsyncStreamReaderMixin):\n    \"\"\"An enhancement of asyncio.StreamReader.\n\n    Supports asynchronous iteration by line, chunk or as available::\n\n        async for line in reader:\n            ...\n        async for chunk in reader.iter_chunked(1024):\n            ...\n        async for slice in reader.iter_any():\n            ...\n\n    \"\"\"\n\n    total_bytes = 0\n\n    def __init__(\n        self,\n        protocol: BaseProtocol,\n        limit: int,\n        *,\n        timer: Optional[BaseTimerContext] = None,\n        loop: Optional[asyncio.AbstractEventLoop] = None,\n    ) -> None:\n        self._protocol = protocol\n        self._low_water = limit\n        self._high_water = limit * 2\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n        self._size = 0\n        self._cursor = 0\n        self._http_chunk_splits: Optional[List[int]] = None\n        self._buffer: Deque[bytes] = collections.deque()\n        self._buffer_offset = 0\n        self._eof = False\n        self._waiter: Optional[asyncio.Future[None]] = None\n        self._eof_waiter: Optional[asyncio.Future[None]] = None\n        self._exception: Optional[BaseException] = None\n        self._timer = timer\n        self._eof_callbacks: List[Callable[[], None]] = []\n\n    def __repr__(self) -> str:\n        info = [self.__class__.__name__]\n        if self._size:\n            info.append(\"%d bytes\" % self._size)\n        if self._eof:\n            info.append(\"eof\")\n        if self._low_water != 2**16:  # default limit\n            info.append(\"low=%d high=%d\" % (self._low_water, self._high_water))\n        if self._waiter:\n            info.append(\"w=%r\" % self._waiter)\n        if self._exception:\n            info.append(\"e=%r\" % self._exception)\n        return \"<%s>\" % \" \".join(info)\n\n    def get_read_buffer_limits(self) -> Tuple[int, int]:\n        return (self._low_water, self._high_water)\n\n    def exception(self) -> Optional[BaseException]:\n        return self._exception\n\n    def set_exception(self, exc: BaseException) -> None:\n        self._exception = exc\n        self._eof_callbacks.clear()\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_exception(waiter, exc)\n\n        waiter = self._eof_waiter\n        if waiter is not None:\n            self._eof_waiter = None\n            set_exception(waiter, exc)\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        if self._eof:\n            try:\n                callback()\n            except Exception:\n                internal_logger.exception(\"Exception in eof callback\")\n        else:\n            self._eof_callbacks.append(callback)\n\n    def feed_eof(self) -> None:\n        self._eof = True\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n        waiter = self._eof_waiter\n        if waiter is not None:\n            self._eof_waiter = None\n            set_result(waiter, None)\n\n        for cb in self._eof_callbacks:\n            try:\n                cb()\n            except Exception:\n                internal_logger.exception(\"Exception in eof callback\")\n\n        self._eof_callbacks.clear()\n\n    def is_eof(self) -> bool:\n        \"\"\"Return True if  'feed_eof' was called.\"\"\"\n        return self._eof\n\n    def at_eof(self) -> bool:\n        \"\"\"Return True if the buffer is empty and 'feed_eof' was called.\"\"\"\n        return self._eof and not self._buffer\n\n    async def wait_eof(self) -> None:\n        if self._eof:\n            return\n\n        assert self._eof_waiter is None\n        self._eof_waiter = self._loop.create_future()\n        try:\n            await self._eof_waiter\n        finally:\n            self._eof_waiter = None\n\n    def unread_data(self, data: bytes) -> None:\n        \"\"\"rollback reading some data from stream, inserting it to buffer head.\"\"\"\n        warnings.warn(\n            \"unread_data() is deprecated \"\n            \"and will be removed in future releases (#3260)\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        if not data:\n            return\n\n        if self._buffer_offset:\n            self._buffer[0] = self._buffer[0][self._buffer_offset :]\n            self._buffer_offset = 0\n        self._size += len(data)\n        self._cursor -= len(data)\n        self._buffer.appendleft(data)\n        self._eof_counter = 0\n\n    # TODO: size is ignored, remove the param later\n    def feed_data(self, data: bytes, size: int = 0) -> None:\n        assert not self._eof, \"feed_data after feed_eof\"\n\n        if not data:\n            return\n\n        self._size += len(data)\n        self._buffer.append(data)\n        self.total_bytes += len(data)\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n        if self._size > self._high_water and not self._protocol._reading_paused:\n            self._protocol.pause_reading()\n\n    def begin_http_chunk_receiving(self) -> None:\n        if self._http_chunk_splits is None:\n            if self.total_bytes:\n                raise RuntimeError(\n                    \"Called begin_http_chunk_receiving when\" \"some data was already fed\"\n                )\n            self._http_chunk_splits = []\n\n    def end_http_chunk_receiving(self) -> None:\n        if self._http_chunk_splits is None:\n            raise RuntimeError(\n                \"Called end_chunk_receiving without calling \"\n                \"begin_chunk_receiving first\"\n            )\n\n        # self._http_chunk_splits contains logical byte offsets from start of\n        # the body transfer. Each offset is the offset of the end of a chunk.\n        # \"Logical\" means bytes, accessible for a user.\n        # If no chunks containig logical data were received, current position\n        # is difinitely zero.\n        pos = self._http_chunk_splits[-1] if self._http_chunk_splits else 0\n\n        if self.total_bytes == pos:\n            # We should not add empty chunks here. So we check for that.\n            # Note, when chunked + gzip is used, we can receive a chunk\n            # of compressed data, but that data may not be enough for gzip FSM\n            # to yield any uncompressed data. That's why current position may\n            # not change after receiving a chunk.\n            return\n\n        self._http_chunk_splits.append(self.total_bytes)\n\n        # wake up readchunk when end of http chunk received\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    async def _wait(self, func_name: str) -> None:\n        # StreamReader uses a future to link the protocol feed_data() method\n        # to a read coroutine. Running two read coroutines at the same time\n        # would have an unexpected behaviour. It would not possible to know\n        # which coroutine would get the next data.\n        if self._waiter is not None:\n            raise RuntimeError(\n                \"%s() called while another coroutine is \"\n                \"already waiting for incoming data\" % func_name\n            )\n\n        waiter = self._waiter = self._loop.create_future()\n        try:\n            if self._timer:\n                with self._timer:\n                    await waiter\n            else:\n                await waiter\n        finally:\n            self._waiter = None\n\n    async def readline(self) -> bytes:\n        return await self.readuntil()\n\n    async def readuntil(self, separator: bytes = b\"\\n\") -> bytes:\n        seplen = len(separator)\n        if seplen == 0:\n            raise ValueError(\"Separator should be at least one-byte string\")\n\n        if self._exception is not None:\n            raise self._exception\n\n        chunk = b\"\"\n        chunk_size = 0\n        not_enough = True\n\n        while not_enough:\n            while self._buffer and not_enough:\n                offset = self._buffer_offset\n                ichar = self._buffer[0].find(separator, offset) + 1\n                # Read from current offset to found separator or to the end.\n                data = self._read_nowait_chunk(\n                    ichar - offset + seplen - 1 if ichar else -1\n                )\n                chunk += data\n                chunk_size += len(data)\n                if ichar:\n                    not_enough = False\n\n                if chunk_size > self._high_water:\n                    raise ValueError(\"Chunk too big\")\n\n            if self._eof:\n                break\n\n            if not_enough:\n                await self._wait(\"readuntil\")\n\n        return chunk\n\n    async def read(self, n: int = -1) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        # migration problem; with DataQueue you have to catch\n        # EofStream exception, so common way is to run payload.read() inside\n        # infinite loop. what can cause real infinite loop with StreamReader\n        # lets keep this code one major release.\n        if __debug__:\n            if self._eof and not self._buffer:\n                self._eof_counter = getattr(self, \"_eof_counter\", 0) + 1\n                if self._eof_counter > 5:\n                    internal_logger.warning(\n                        \"Multiple access to StreamReader in eof state, \"\n                        \"might be infinite loop.\",\n                        stack_info=True,\n                    )\n\n        if not n:\n            return b\"\"\n\n        if n < 0:\n            # This used to just loop creating a new waiter hoping to\n            # collect everything in self._buffer, but that would\n            # deadlock if the subprocess sends more than self.limit\n            # bytes.  So just call self.readany() until EOF.\n            blocks = []\n            while True:\n                block = await self.readany()\n                if not block:\n                    break\n                blocks.append(block)\n            return b\"\".join(blocks)\n\n        # TODO: should be `if` instead of `while`\n        # because waiter maybe triggered on chunk end,\n        # without feeding any data\n        while not self._buffer and not self._eof:\n            await self._wait(\"read\")\n\n        return self._read_nowait(n)\n\n    async def readany(self) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        # TODO: should be `if` instead of `while`\n        # because waiter maybe triggered on chunk end,\n        # without feeding any data\n        while not self._buffer and not self._eof:\n            await self._wait(\"readany\")\n\n        return self._read_nowait(-1)\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        \"\"\"Returns a tuple of (data, end_of_http_chunk).\n\n        When chunked transfer\n        encoding is used, end_of_http_chunk is a boolean indicating if the end\n        of the data corresponds to the end of a HTTP chunk , otherwise it is\n        always False.\n        \"\"\"\n        while True:\n            if self._exception is not None:\n                raise self._exception\n\n            while self._http_chunk_splits:\n                pos = self._http_chunk_splits.pop(0)\n                if pos == self._cursor:\n                    return (b\"\", True)\n                if pos > self._cursor:\n                    return (self._read_nowait(pos - self._cursor), True)\n                internal_logger.warning(\n                    \"Skipping HTTP chunk end due to data \"\n                    \"consumption beyond chunk boundary\"\n                )\n\n            if self._buffer:\n                return (self._read_nowait_chunk(-1), False)\n                # return (self._read_nowait(-1), False)\n\n            if self._eof:\n                # Special case for signifying EOF.\n                # (b'', True) is not a final return value actually.\n                return (b\"\", False)\n\n            await self._wait(\"readchunk\")\n\n    async def readexactly(self, n: int) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        blocks: List[bytes] = []\n        while n > 0:\n            block = await self.read(n)\n            if not block:\n                partial = b\"\".join(blocks)\n                raise asyncio.IncompleteReadError(partial, len(partial) + n)\n            blocks.append(block)\n            n -= len(block)\n\n        return b\"\".join(blocks)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        # default was changed to be consistent with .read(-1)\n        #\n        # I believe the most users don't know about the method and\n        # they are not affected.\n        if self._exception is not None:\n            raise self._exception\n\n        if self._waiter and not self._waiter.done():\n            raise RuntimeError(\n                \"Called while some coroutine is waiting for incoming data.\"\n            )\n\n        return self._read_nowait(n)\n\n    def _read_nowait_chunk(self, n: int) -> bytes:\n        first_buffer = self._buffer[0]\n        offset = self._buffer_offset\n        if n != -1 and len(first_buffer) - offset > n:\n            data = first_buffer[offset : offset + n]\n            self._buffer_offset += n\n\n        elif offset:\n            self._buffer.popleft()\n            data = first_buffer[offset:]\n            self._buffer_offset = 0\n\n        else:\n            data = self._buffer.popleft()\n\n        self._size -= len(data)\n        self._cursor += len(data)\n\n        chunk_splits = self._http_chunk_splits\n        # Prevent memory leak: drop useless chunk splits\n        while chunk_splits and chunk_splits[0] < self._cursor:\n            chunk_splits.pop(0)\n\n        if self._size < self._low_water and self._protocol._reading_paused:\n            self._protocol.resume_reading()\n        return data\n\n    def _read_nowait(self, n: int) -> bytes:\n        \"\"\"Read not more than n bytes, or whole buffer if n == -1\"\"\"\n        chunks = []\n\n        while self._buffer:\n            chunk = self._read_nowait_chunk(n)\n            chunks.append(chunk)\n            if n != -1:\n                n -= len(chunk)\n                if n == 0:\n                    break\n\n        return b\"\".join(chunks) if chunks else b\"\"\n\n\nclass EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]\n    def __init__(self) -> None:\n        pass\n\n    def __repr__(self) -> str:\n        return \"<%s>\" % self.__class__.__name__\n\n    def exception(self) -> Optional[BaseException]:\n        return None\n\n    def set_exception(self, exc: BaseException) -> None:\n        pass\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        try:\n            callback()\n        except Exception:\n            internal_logger.exception(\"Exception in eof callback\")\n\n    def feed_eof(self) -> None:\n        pass\n\n    def is_eof(self) -> bool:\n        return True\n\n    def at_eof(self) -> bool:\n        return True\n\n    async def wait_eof(self) -> None:\n        return\n\n    def feed_data(self, data: bytes, n: int = 0) -> None:\n        pass\n\n    async def readline(self) -> bytes:\n        return b\"\"\n\n    async def read(self, n: int = -1) -> bytes:\n        return b\"\"\n\n    # TODO add async def readuntil\n\n    async def readany(self) -> bytes:\n        return b\"\"\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        return (b\"\", True)\n\n    async def readexactly(self, n: int) -> bytes:\n        raise asyncio.IncompleteReadError(b\"\", n)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        return b\"\"\n\n\nEMPTY_PAYLOAD: Final[StreamReader] = EmptyStreamReader()\n\n\nclass DataQueue(Generic[_T]):\n    \"\"\"DataQueue is a general-purpose blocking queue with one reader.\"\"\"\n\n    def __init__(self, loop: asyncio.AbstractEventLoop) -> None:\n        self._loop = loop\n        self._eof = False\n        self._waiter: Optional[asyncio.Future[None]] = None\n        self._exception: Optional[BaseException] = None\n        self._size = 0\n        self._buffer: Deque[Tuple[_T, int]] = collections.deque()\n\n    def __len__(self) -> int:\n        return len(self._buffer)\n\n    def is_eof(self) -> bool:\n        return self._eof\n\n    def at_eof(self) -> bool:\n        return self._eof and not self._buffer\n\n    def exception(self) -> Optional[BaseException]:\n        return self._exception\n\n    def set_exception(self, exc: BaseException) -> None:\n        self._eof = True\n        self._exception = exc\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_exception(waiter, exc)\n\n    def feed_data(self, data: _T, size: int = 0) -> None:\n        self._size += size\n        self._buffer.append((data, size))\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    def feed_eof(self) -> None:\n        self._eof = True\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    async def read(self) -> _T:\n        if not self._buffer and not self._eof:\n            assert not self._waiter\n            self._waiter = self._loop.create_future()\n            try:\n                await self._waiter\n            except (asyncio.CancelledError, asyncio.TimeoutError):\n                self._waiter = None\n                raise\n\n        if self._buffer:\n            data, size = self._buffer.popleft()\n            self._size -= size\n            return data\n        else:\n            if self._exception is not None:\n                raise self._exception\n            else:\n                raise EofStream\n\n    def __aiter__(self) -> AsyncStreamIterator[_T]:\n        return AsyncStreamIterator(self.read)\n\n\nclass FlowControlDataQueue(DataQueue[_T]):\n    \"\"\"FlowControlDataQueue resumes and pauses an underlying stream.\n\n    It is a destination for parsed data.\n    \"\"\"\n\n    def __init__(\n        self, protocol: BaseProtocol, limit: int, *, loop: asyncio.AbstractEventLoop\n    ) -> None:\n        super().__init__(loop=loop)\n\n        self._protocol = protocol\n        self._limit = limit * 2\n\n    def feed_data(self, data: _T, size: int = 0) -> None:\n        super().feed_data(data, size)\n\n        if self._size > self._limit and not self._protocol._reading_paused:\n            self._protocol.pause_reading()\n\n    async def read(self) -> _T:\n        try:\n            return await super().read()\n        finally:\n            if self._size < self._limit and self._protocol._reading_paused:\n                self._protocol.resume_reading()\n",
            "header": {
                "file": {
                    "path": "aiohttp/streams.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "d5f4c2ba",
                "new_commit_hash": "32ec7f14",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/aiohttp/streams.py"
            },
            "plus_file": {
                "path": "b/aiohttp/streams.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 502,
                            "length": 6
                        },
                        "new_range": {
                            "start": 502,
                            "length": 9
                        },
                        "section": "class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    def __init__(self) -> None:",
                                "type": "context"
                            },
                            {
                                "content": "        pass",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def __repr__(self) -> str:",
                                "type": "added"
                            },
                            {
                                "content": "        return \"<%s>\" % self.__class__.__name__",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def exception(self) -> Optional[BaseException]:",
                                "type": "context"
                            },
                            {
                                "content": "        return None",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "aiohttp/streams.py",
                            "type": "class",
                            "name": "EmptyStreamReader",
                            "content": "class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]\n    def __init__(self) -> None:\n        pass\n\n    def __repr__(self) -> str:\n        return \"<%s>\" % self.__class__.__name__\n\n    def exception(self) -> Optional[BaseException]:\n        return None\n\n    def set_exception(self, exc: BaseException) -> None:\n        pass\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        try:\n            callback()\n        except Exception:\n            internal_logger.exception(\"Exception in eof callback\")\n\n    def feed_eof(self) -> None:\n        pass\n\n    def is_eof(self) -> bool:\n        return True\n\n    def at_eof(self) -> bool:\n        return True\n\n    async def wait_eof(self) -> None:\n        return\n\n    def feed_data(self, data: bytes, n: int = 0) -> None:\n        pass\n\n    async def readline(self) -> bytes:\n        return b\"\"\n\n    async def read(self, n: int = -1) -> bytes:\n        return b\"\"\n\n    # TODO add async def readuntil\n\n    async def readany(self) -> bytes:\n        return b\"\"\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        return (b\"\", True)\n\n    async def readexactly(self, n: int) -> bytes:\n        raise asyncio.IncompleteReadError(b\"\", n)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        return b\"\"",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 501,
                            "end_lineno": 553,
                            "parent": null
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "aiohttp/streams.py",
                            "type": "method",
                            "name": "EmptyStreamReader.__repr__",
                            "content": "class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]\n    def __init__(self) -> None:\n        pass\n\n    def __repr__(self) -> str:\n        return \"<%s>\" % self.__class__.__name__\n\n    def exception(self) -> Optional[BaseException]:\n        return None\n\n    def set_exception(self, exc: BaseException) -> None:\n        pass\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        try:\n            callback()\n        except Exception:\n            internal_logger.exception(\"Exception in eof callback\")\n\n    def feed_eof(self) -> None:\n        pass\n\n    def is_eof(self) -> bool:\n        return True\n\n    def at_eof(self) -> bool:\n        return True\n\n    async def wait_eof(self) -> None:\n        return\n\n    def feed_data(self, data: bytes, n: int = 0) -> None:\n        pass\n\n    async def readline(self) -> bytes:\n        return b\"\"\n\n    async def read(self, n: int = -1) -> bytes:\n        return b\"\"\n\n    # TODO add async def readuntil\n\n    async def readany(self) -> bytes:\n        return b\"\"\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        return (b\"\", True)\n\n    async def readexactly(self, n: int) -> bytes:\n        raise asyncio.IncompleteReadError(b\"\", n)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        return b\"\"",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 505,
                            "end_lineno": 506,
                            "parent": {
                                "file_name": "aiohttp/streams.py",
                                "type": "class",
                                "name": "EmptyStreamReader",
                                "content": "class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]\n    def __init__(self) -> None:\n        pass\n\n    def __repr__(self) -> str:\n        return \"<%s>\" % self.__class__.__name__\n\n    def exception(self) -> Optional[BaseException]:\n        return None\n\n    def set_exception(self, exc: BaseException) -> None:\n        pass\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        try:\n            callback()\n        except Exception:\n            internal_logger.exception(\"Exception in eof callback\")\n\n    def feed_eof(self) -> None:\n        pass\n\n    def is_eof(self) -> bool:\n        return True\n\n    def at_eof(self) -> bool:\n        return True\n\n    async def wait_eof(self) -> None:\n        return\n\n    def feed_data(self, data: bytes, n: int = 0) -> None:\n        pass\n\n    async def readline(self) -> bytes:\n        return b\"\"\n\n    async def read(self, n: int = -1) -> bytes:\n        return b\"\"\n\n    # TODO add async def readuntil\n\n    async def readany(self) -> bytes:\n        return b\"\"\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        return (b\"\", True)\n\n    async def readexactly(self, n: int) -> bytes:\n        raise asyncio.IncompleteReadError(b\"\", n)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        return b\"\"",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 501,
                                "end_lineno": 553,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "# Tests for streams.py\n\nimport abc\nimport asyncio\nimport gc\nimport types\nfrom collections import defaultdict\nfrom itertools import groupby\nfrom unittest import mock\n\nimport pytest\nfrom re_assert import Matches\n\nfrom aiohttp import streams\nfrom aiohttp.helpers import PY_310\n\nDATA = b\"line1\\nline2\\nline3\\n\"\n\n\ndef chunkify(seq, n):\n    for i in range(0, len(seq), n):\n        yield seq[i : i + n]\n\n\nasync def create_stream():\n    loop = asyncio.get_event_loop()\n    protocol = mock.Mock(_reading_paused=False)\n    stream = streams.StreamReader(protocol, 2**16, loop=loop)\n    stream.feed_data(DATA)\n    stream.feed_eof()\n    return stream\n\n\n@pytest.fixture\ndef protocol():\n    return mock.Mock(_reading_paused=False)\n\n\nMEMLEAK_SKIP_TYPES = (\n    *(getattr(types, name) for name in types.__all__ if name.endswith(\"Type\")),\n    mock.Mock,\n    abc.ABCMeta,\n)\n\n\ndef get_memory_usage(obj):\n    objs = [obj]\n    # Memory leak may be caused by leaked links to same objects.\n    # Without link counting, [1,2,3] is indistiguishable from [1,2,3,3,3,3,3,3]\n    known = defaultdict(int)\n    known[id(obj)] += 1\n\n    while objs:\n        refs = gc.get_referents(*objs)\n        objs = []\n        for obj in refs:\n            if isinstance(obj, MEMLEAK_SKIP_TYPES):\n                continue\n            i = id(obj)\n            known[i] += 1\n            if known[i] == 1:\n                objs.append(obj)\n\n        # Make list of unhashable objects uniq\n        objs.sort(key=id)\n        objs = [next(g) for (i, g) in groupby(objs, id)]\n\n    return sum(known.values())\n\n\nclass TestStreamReader:\n\n    DATA = b\"line1\\nline2\\nline3\\n\"\n\n    def _make_one(self, *args, **kwargs):\n        kwargs.setdefault(\"limit\", 2**16)\n        return streams.StreamReader(mock.Mock(_reading_paused=False), *args, **kwargs)\n\n    async def test_create_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one(loop=loop)\n        stream._waiter = loop.create_future\n        with pytest.raises(RuntimeError):\n            await stream._wait(\"test\")\n\n    @pytest.mark.xfail(\n        PY_310,\n        reason=\"No idea why ClientRequest() is constructed out of loop but \"\n        \"it calls `asyncio.get_event_loop()`\",\n        raises=DeprecationWarning,\n    )\n    def test_ctor_global_loop(self) -> None:\n        loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(loop)\n        try:\n            stream = streams.StreamReader(mock.Mock(_reading_paused=False), 2**16)\n\n            assert stream._loop is loop\n        finally:  # Otherwise an unstopped/unclosed loop affects the next test\n            # Cleanup, leaks into `test_at_eof` otherwise:\n            loop.stop()\n            loop.run_forever()\n            loop.close()\n            gc.collect()\n\n    async def test_at_eof(self) -> None:\n        stream = self._make_one()\n        assert not stream.at_eof()\n\n        stream.feed_data(b\"some data\\n\")\n        assert not stream.at_eof()\n\n        await stream.readline()\n        assert not stream.at_eof()\n\n        stream.feed_data(b\"some data\\n\")\n        stream.feed_eof()\n        await stream.readline()\n        assert stream.at_eof()\n\n    async def test_wait_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        wait_task = loop.create_task(stream.wait_eof())\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        await wait_task\n        assert stream.is_eof()\n        assert stream._eof_waiter is None\n\n    async def test_wait_eof_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_eof()\n\n        wait_task = loop.create_task(stream.wait_eof())\n        await wait_task\n        assert stream.is_eof()\n\n    async def test_feed_empty_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"\")\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_feed_nonempty_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_read_zero(self) -> None:\n        # Read zero bytes.\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.read(0)\n        assert b\"\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_read(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read bytes.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(30))\n\n        def cb():\n            stream.feed_data(self.DATA)\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert self.DATA == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_line_breaks(self) -> None:\n        # Read bytes without line breaks.\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        data = await stream.read(5)\n        assert b\"line2\" == data\n\n    async def test_read_all(self) -> None:\n        # Read all available buffered bytes\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert b\"line1line2\" == data\n\n    async def test_read_up_to(self) -> None:\n        # Read available buffered bytes up to requested amount\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n\n        data = await stream.read(8)\n        assert b\"line1lin\" == data\n\n        data = await stream.read(8)\n        assert b\"e2\" == data\n\n    async def test_read_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read bytes, stop at eof.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(1024))\n\n        def cb():\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert b\"\" == data\n\n        data = await stream.read()\n        assert data == b\"\"\n\n    async def test_read_eof_infinite(self) -> None:\n        # Read bytes.\n        stream = self._make_one()\n        stream.feed_eof()\n\n        with mock.patch(\"aiohttp.streams.internal_logger\") as internal_logger:\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n        assert internal_logger.warning.called\n\n    async def test_read_eof_unread_data_no_warning(self) -> None:\n        # Read bytes.\n        stream = self._make_one()\n        stream.feed_eof()\n\n        with mock.patch(\"aiohttp.streams.internal_logger\") as internal_logger:\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"data\")\n        await stream.read()\n        await stream.read()\n        assert not internal_logger.warning.called\n\n    async def test_read_until_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read all bytes until eof.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(-1))\n\n        def cb():\n            stream.feed_data(b\"chunk1\\n\")\n            stream.feed_data(b\"chunk2\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert b\"chunk1\\nchunk2\" == data\n\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.read(2)\n        assert b\"li\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.read(2)\n\n    async def test_readline(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one line. 'readline' will need to wait for the data\n        # to come from 'cb'\n        stream = self._make_one()\n        stream.feed_data(b\"chunk1 \")\n        read_task = loop.create_task(stream.readline())\n\n        def cb():\n            stream.feed_data(b\"chunk2 \")\n            stream.feed_data(b\"chunk3 \")\n            stream.feed_data(b\"\\n chunk4\")\n\n        loop.call_soon(cb)\n\n        line = await read_task\n        assert b\"chunk1 chunk2 chunk3 \\n\" == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\" chunk4\" == data\n\n    async def test_readline_limit_with_existing_data(self) -> None:\n        # Read one line. The data is in StreamReader's buffer\n        # before the event loop is run.\n\n        stream = self._make_one(limit=2)\n        stream.feed_data(b\"li\")\n        stream.feed_data(b\"ne1\\nline2\\n\")\n\n        with pytest.raises(ValueError):\n            await stream.readline()\n        # The buffer should contain the remaining data after exception\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\\n\" == data\n\n    async def test_readline_limit(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one line. StreamReaders are fed with data after\n        # their 'readline' methods are called.\n        stream = self._make_one(limit=4)\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\\n\")\n            stream.feed_data(b\"chunk3\\n\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(ValueError):\n            await stream.readline()\n        data = await stream.read()\n        assert b\"chunk3\\n\" == data\n\n    async def test_readline_nolimit_nowait(self) -> None:\n        # All needed data for the first 'readline' call will be\n        # in the buffer.\n        stream = self._make_one()\n        stream.feed_data(self.DATA[:6])\n        stream.feed_data(self.DATA[6:])\n\n        line = await stream.readline()\n        assert b\"line1\\n\" == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\\nline3\\n\" == data\n\n    async def test_readline_eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"some data\")\n        stream.feed_eof()\n\n        line = await stream.readline()\n        assert b\"some data\" == line\n\n    async def test_readline_empty_eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n\n        line = await stream.readline()\n        assert b\"\" == line\n\n    async def test_readline_read_byte_count(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        await stream.readline()\n\n        data = await stream.read(7)\n        assert b\"line2\\nl\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"ine3\\n\" == data\n\n    async def test_readline_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readline()\n        assert b\"line\\n\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readline()\n\n    @pytest.mark.parametrize(\"separator\", [b\"*\", b\"**\"])\n    async def test_readuntil(self, separator: bytes) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one chunk. 'readuntil' will need to wait for the data\n        # to come from 'cb'\n        stream = self._make_one()\n        stream.feed_data(b\"chunk1 \")\n        read_task = loop.create_task(stream.readuntil(separator))\n\n        def cb():\n            stream.feed_data(b\"chunk2 \")\n            stream.feed_data(b\"chunk3 \")\n            stream.feed_data(separator + b\" chunk4\")\n\n        loop.call_soon(cb)\n\n        line = await read_task\n        assert b\"chunk1 chunk2 chunk3 \" + separator == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\" chunk4\" == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"&\", b\"&&\"])\n    async def test_readuntil_limit_with_existing_data(self, separator: bytes) -> None:\n        # Read one chunk. The data is in StreamReader's buffer\n        # before the event loop is run.\n\n        stream = self._make_one(limit=2)\n        stream.feed_data(b\"li\")\n        stream.feed_data(b\"ne1\" + separator + b\"line2\" + separator)\n\n        with pytest.raises(ValueError):\n            await stream.readuntil(separator)\n        # The buffer should contain the remaining data after exception\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"$\", b\"$$\"])\n    async def test_readuntil_limit(self, separator: bytes) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one chunk. StreamReaders are fed with data after\n        # their 'readuntil' methods are called.\n        stream = self._make_one(limit=4)\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\" + separator)\n            stream.feed_data(b\"chunk3#\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(ValueError, match=\"Chunk too big\"):\n            await stream.readuntil(separator)\n        data = await stream.read()\n        assert b\"chunk3#\" == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"!\", b\"!!\"])\n    async def test_readuntil_nolimit_nowait(self, separator: bytes) -> None:\n        # All needed data for the first 'readuntil' call will be\n        # in the buffer.\n        seplen = len(separator)\n        stream = self._make_one()\n        data = b\"line1\" + separator + b\"line2\" + separator + b\"line3\" + separator\n        stream.feed_data(data[: 5 + seplen])\n        stream.feed_data(data[5 + seplen :])\n\n        line = await stream.readuntil(separator)\n        assert b\"line1\" + separator == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\" + separator + b\"line3\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"@\", b\"@@\"])\n    async def test_readuntil_eof(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"some data\")\n        stream.feed_eof()\n\n        line = await stream.readuntil(separator)\n        assert b\"some data\" == line\n\n    @pytest.mark.parametrize(\"separator\", [b\"@\", b\"@@\"])\n    async def test_readuntil_empty_eof(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n\n        line = await stream.readuntil(separator)\n        assert b\"\" == line\n\n    @pytest.mark.parametrize(\"separator\", [b\"!\", b\"!!\"])\n    async def test_readuntil_read_byte_count(self, separator: bytes) -> None:\n        seplen = len(separator)\n        stream = self._make_one()\n        stream.feed_data(\n            b\"line1\" + separator + b\"line2\" + separator + b\"line3\" + separator\n        )\n\n        await stream.readuntil(separator)\n\n        data = await stream.read(6 + seplen)\n        assert b\"line2\" + separator + b\"l\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"ine3\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"#\", b\"##\"])\n    async def test_readuntil_exception(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\" + separator)\n\n        data = await stream.readuntil(separator)\n        assert b\"line\" + separator == data\n\n        stream.set_exception(ValueError(\"Another exception\"))\n        with pytest.raises(ValueError, match=\"Another exception\"):\n            await stream.readuntil(separator)\n\n    async def test_readexactly_zero_or_less(self) -> None:\n        # Read exact number of bytes (zero or less).\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.readexactly(0)\n        assert b\"\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.readexactly(-1)\n        assert b\"\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_readexactly(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read exact number of bytes.\n        stream = self._make_one()\n\n        n = 2 * len(self.DATA)\n        read_task = loop.create_task(stream.readexactly(n))\n\n        def cb():\n            stream.feed_data(self.DATA)\n            stream.feed_data(self.DATA)\n            stream.feed_data(self.DATA)\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert self.DATA + self.DATA == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_readexactly_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read exact number of bytes (eof).\n        stream = self._make_one(loop=loop)\n        n = 2 * len(self.DATA)\n        read_task = loop.create_task(stream.readexactly(n))\n\n        def cb():\n            stream.feed_data(self.DATA)\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(asyncio.IncompleteReadError) as cm:\n            await read_task\n        assert cm.value.partial == self.DATA\n        assert cm.value.expected == n\n        assert str(cm.value) == \"18 bytes read on a total of 36 expected bytes\"\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_readexactly_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readexactly(2)\n        assert b\"li\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readexactly(2)\n\n    async def test_unread_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n        stream.feed_data(b\"onemoreline\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(data)\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        data = await stream.read(4)\n        assert b\"line\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"line1line\")\n\n        data = b\"\"\n        while len(data) < 10:\n            data += await stream.read(10)\n        assert b\"line1line2\" == data\n\n        data = await stream.read(7)\n        assert b\"onemore\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(data)\n\n        data = b\"\"\n        while len(data) < 11:\n            data += await stream.read(11)\n        assert b\"onemoreline\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"line\")\n        data = await stream.read(4)\n        assert b\"line\" == data\n\n        stream.feed_eof()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"at_eof\")\n        data = await stream.read(6)\n        assert b\"at_eof\" == data\n\n    async def test_exception(self) -> None:\n        stream = self._make_one()\n        assert stream.exception() is None\n\n        exc = ValueError()\n        stream.set_exception(exc)\n        assert stream.exception() is exc\n\n    async def test_exception_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def set_err():\n            stream.set_exception(ValueError())\n\n        t1 = loop.create_task(stream.readline())\n        t2 = loop.create_task(set_err())\n\n        await asyncio.wait([t1, t2])\n        with pytest.raises(ValueError):\n            t1.result()\n\n    async def test_exception_cancel(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def read_a_line():\n            await stream.readline()\n\n        t = loop.create_task(read_a_line())\n        await asyncio.sleep(0)\n        t.cancel()\n        await asyncio.sleep(0)\n        # The following line fails if set_exception() isn't careful.\n        stream.set_exception(RuntimeError(\"message\"))\n        await asyncio.sleep(0)\n        assert stream._waiter is None\n\n    async def test_readany_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        read_task = loop.create_task(stream.readany())\n        loop.call_soon(stream.feed_data, b\"chunk1\\n\")\n\n        data = await read_task\n        assert b\"chunk1\\n\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_readany_empty_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_eof()\n        read_task = loop.create_task(stream.readany())\n\n        data = await read_task\n\n        assert b\"\" == data\n\n    async def test_readany_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readany()\n        assert b\"line\\n\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readany()\n\n    async def test_read_nowait(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\\nline2\\n\")\n\n        assert stream.read_nowait() == b\"line1\\nline2\\n\"\n        assert stream.read_nowait() == b\"\"\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_nowait_n(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\\nline2\\n\")\n\n        assert stream.read_nowait(4) == b\"line\"\n        assert stream.read_nowait() == b\"1\\nline2\\n\"\n        assert stream.read_nowait() == b\"\"\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_nowait_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n        stream.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            stream.read_nowait()\n\n    async def test_read_nowait_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n        stream._waiter = loop.create_future()\n\n        with pytest.raises(RuntimeError):\n            stream.read_nowait()\n\n    async def test_readchunk(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"chunk1\" == data\n        assert not end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"chunk2\" == data\n        assert not end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readchunk_wait_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n        assert stream.is_eof()\n\n    async def test_begin_and_end_chunk_receiving(self) -> None:\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part1part2\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part3\" == data\n        assert not end_of_chunk\n\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.feed_eof()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readany_chunk_end_race(self) -> None:\n        stream = self._make_one()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n\n        data = await stream.readany()\n        assert data == b\"part1\"\n\n        loop = asyncio.get_event_loop()\n        task = loop.create_task(stream.readany())\n\n        # Give a chance for task to create waiter and start waiting for it.\n        await asyncio.sleep(0.1)\n        assert stream._waiter is not None\n        assert not task.done()  # Just for sure.\n\n        # This will trigger waiter, but without feeding any data.\n        # The stream should re-create waiter again.\n        stream.end_http_chunk_receiving()\n\n        # Give a chance for task to resolve.\n        # If everything is OK, previous action SHOULD NOT resolve the task.\n        await asyncio.sleep(0.1)\n        assert not task.done()  # The actual test.\n\n        stream.begin_http_chunk_receiving()\n        # This SHOULD unblock the task actually.\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        data = await task\n        assert data == b\"part2\"\n\n    async def test_end_chunk_receiving_without_begin(self) -> None:\n        stream = self._make_one()\n        with pytest.raises(RuntimeError):\n            stream.end_http_chunk_receiving()\n\n    async def test_readchunk_with_unread(self) -> None:\n        # Test that stream.unread does not break controlled chunk receiving.\n        stream = self._make_one()\n\n        # Send 2 chunks\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        # Read only one chunk\n        data, end_of_chunk = await stream.readchunk()\n\n        # Try to unread a part of the first chunk\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"rt1\")\n\n        # The end_of_chunk signal was already received for the first chunk,\n        # so we receive up to the second one\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt1part2\" == data\n        assert end_of_chunk\n\n        # Unread a part of the second chunk\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"rt2\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt2\" == data\n        # end_of_chunk was already received for this chunk\n        assert not end_of_chunk\n\n        stream.feed_eof()\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readchunk_with_other_read_calls(self) -> None:\n        # Test that stream.readchunk works when other read calls are made on\n        # the stream.\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n        stream.end_http_chunk_receiving()\n\n        data = await stream.read(7)\n        assert b\"part1pa\" == data\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt2\" == data\n        assert end_of_chunk\n\n        # Corner case between read/readchunk\n        data = await stream.read(5)\n        assert b\"part3\" == data\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.feed_eof()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_chunksplits_memory_leak(self) -> None:\n        # Test for memory leak on chunksplits\n        stream = self._make_one()\n\n        N = 500\n\n        # Warm-up variables\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"Y\" * N)\n        stream.end_http_chunk_receiving()\n        await stream.read(N)\n\n        N = 300\n\n        before = get_memory_usage(stream)\n        for _ in range(N):\n            stream.begin_http_chunk_receiving()\n            stream.feed_data(b\"X\")\n            stream.end_http_chunk_receiving()\n        await stream.read(N)\n        after = get_memory_usage(stream)\n\n        assert abs(after - before) == 0\n\n    async def test_read_empty_chunks(self) -> None:\n        # Test that feeding empty chunks does not break stream\n        stream = self._make_one()\n\n        # Simulate empty first chunk. This is significant special case\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"ungzipped\")\n        stream.end_http_chunk_receiving()\n\n        # Possible when compression is enabled.\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        # is also possible\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\" data\")\n        stream.end_http_chunk_receiving()\n\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert data == b\"ungzipped data\"\n\n    async def test_readchunk_separate_http_chunk_tail(self) -> None:\n        # Test that stream.readchunk returns (b'', True) when end of\n        # http chunk received after body\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part1\" == data\n        assert not end_of_chunk\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.end_http_chunk_receiving()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part2\" == data\n        assert not end_of_chunk\n\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part3\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part4\")\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part4\" == data\n        assert not end_of_chunk\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.end_http_chunk_receiving()\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test___repr__(self) -> None:\n        stream = self._make_one()\n        assert \"<StreamReader>\" == repr(stream)\n\n    async def test___repr__nondefault_limit(self) -> None:\n        stream = self._make_one(limit=123)\n        assert \"<StreamReader low=123 high=246>\" == repr(stream)\n\n    async def test___repr__eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n        assert \"<StreamReader eof>\" == repr(stream)\n\n    async def test___repr__data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"data\")\n        assert \"<StreamReader 4 bytes>\" == repr(stream)\n\n    async def test___repr__exception(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one(loop=loop)\n        exc = RuntimeError()\n        stream.set_exception(exc)\n        assert \"<StreamReader e=RuntimeError()>\" == repr(stream)\n\n    async def test___repr__waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream._waiter = loop.create_future()\n        assert Matches(r\"<StreamReader w=<Future pending[\\S ]*>>\") == repr(stream)\n        stream._waiter.set_result(None)\n        await stream._waiter\n        stream._waiter = None\n        assert \"<StreamReader>\" == repr(stream)\n\n    async def test_unread_empty(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_eof()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n        assert stream.at_eof()\n\n\nasync def test_empty_stream_reader() -> None:\n    s = streams.EmptyStreamReader()\n    assert s.set_exception(ValueError()) is None\n    assert s.exception() is None\n    assert s.feed_eof() is None\n    assert s.feed_data(b\"data\") is None\n    assert s.at_eof()\n    assert (await s.wait_eof()) is None\n    assert await s.read() == b\"\"\n    assert await s.readline() == b\"\"\n    assert await s.readany() == b\"\"\n    assert await s.readchunk() == (b\"\", True)\n    with pytest.raises(asyncio.IncompleteReadError):\n        await s.readexactly(10)\n    assert s.read_nowait() == b\"\"\n\n\n@pytest.fixture\nasync def buffer(loop):\n    return streams.DataQueue(loop)\n\n\nclass TestDataQueue:\n    def test_is_eof(self, buffer) -> None:\n        assert not buffer.is_eof()\n        buffer.feed_eof()\n        assert buffer.is_eof()\n\n    def test_at_eof(self, buffer) -> None:\n        assert not buffer.at_eof()\n        buffer.feed_eof()\n        assert buffer.at_eof()\n        buffer._buffer.append(object())\n        assert not buffer.at_eof()\n\n    def test_feed_data(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item, 1)\n        assert [(item, 1)] == list(buffer._buffer)\n\n    def test_feed_eof(self, buffer) -> None:\n        buffer.feed_eof()\n        assert buffer._eof\n\n    async def test_read(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        item = object()\n\n        def cb():\n            buffer.feed_data(item, 1)\n\n        loop.call_soon(cb)\n\n        data = await buffer.read()\n        assert item is data\n\n    async def test_read_eof(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n\n        def cb():\n            buffer.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(streams.EofStream):\n            await buffer.read()\n\n    async def test_read_cancelled(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        read_task = loop.create_task(buffer.read())\n        await asyncio.sleep(0)\n        waiter = buffer._waiter\n        assert asyncio.isfuture(waiter)\n\n        read_task.cancel()\n        with pytest.raises(asyncio.CancelledError):\n            await read_task\n        assert waiter.cancelled()\n        assert buffer._waiter is None\n\n        buffer.feed_data(b\"test\", 4)\n        assert buffer._waiter is None\n\n    async def test_read_until_eof(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item, 1)\n        buffer.feed_eof()\n\n        data = await buffer.read()\n        assert data is item\n\n        with pytest.raises(streams.EofStream):\n            await buffer.read()\n\n    async def test_read_exc(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item)\n        buffer.set_exception(ValueError)\n\n        data = await buffer.read()\n        assert item is data\n\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception(self, buffer) -> None:\n        buffer.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception_with_data(self, buffer) -> None:\n        val = object()\n        buffer.feed_data(val, 1)\n        buffer.set_exception(ValueError())\n\n        assert val is (await buffer.read())\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception_on_wait(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        read_task = loop.create_task(buffer.read())\n        await asyncio.sleep(0)\n        assert asyncio.isfuture(buffer._waiter)\n\n        buffer.feed_eof()\n        buffer.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            await read_task\n\n    def test_exception(self, buffer) -> None:\n        assert buffer.exception() is None\n\n        exc = ValueError()\n        buffer.set_exception(exc)\n        assert buffer.exception() is exc\n\n    async def test_exception_waiter(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n\n        async def set_err():\n            buffer.set_exception(ValueError())\n\n        t1 = loop.create_task(buffer.read())\n        t2 = loop.create_task(set_err())\n\n        await asyncio.wait([t1, t2])\n\n        with pytest.raises(ValueError):\n            t1.result()\n\n\nasync def test_feed_data_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    reader.feed_data(b\"1\")\n    assert list(reader._buffer) == [b\"1\"]\n    assert reader._size == 1\n    assert reader.total_bytes == 1\n\n    assert waiter.done()\n    assert not eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is eof_waiter\n\n\nasync def test_feed_data_completed_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n\n    waiter.set_result(1)\n    reader.feed_data(b\"1\")\n\n    assert reader._waiter is None\n\n\nasync def test_feed_eof_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    reader.feed_eof()\n    assert reader._eof\n\n    assert waiter.done()\n    assert eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_feed_eof_cancelled(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    waiter.set_result(1)\n    eof_waiter.set_result(1)\n\n    reader.feed_eof()\n\n    assert waiter.done()\n    assert eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_on_eof(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    assert not on_eof.called\n    reader.feed_eof()\n    assert on_eof.called\n\n\nasync def test_on_eof_empty_reader() -> None:\n    reader = streams.EmptyStreamReader()\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    assert on_eof.called\n\n\nasync def test_on_eof_exc_in_callback(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert not on_eof.called\n    reader.feed_eof()\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_on_eof_exc_in_callback_empty_stream_reader() -> None:\n    reader = streams.EmptyStreamReader()\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert on_eof.called\n\n\nasync def test_on_eof_eof_is_set(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    reader.feed_eof()\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_on_eof_eof_is_set_exception(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    reader.feed_eof()\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_set_exception(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    exc = ValueError()\n    reader.set_exception(exc)\n\n    assert waiter.exception() is exc\n    assert eof_waiter.exception() is exc\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_set_exception_cancelled(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    waiter.set_result(1)\n    eof_waiter.set_result(1)\n\n    exc = ValueError()\n    reader.set_exception(exc)\n\n    assert waiter.exception() is None\n    assert eof_waiter.exception() is None\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_set_exception_eof_callbacks(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    reader.set_exception(ValueError())\n    assert not on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_stream_reader_lines() -> None:\n    line_iter = iter(DATA.splitlines(keepends=True))\n    async for line in await create_stream():\n        assert line == next(line_iter, None)\n    pytest.raises(StopIteration, next, line_iter)\n\n\nasync def test_stream_reader_chunks_complete() -> None:\n    # Tests if chunked iteration works if the chunking works out\n    # (i.e. the data is divisible by the chunk size)\n    chunk_iter = chunkify(DATA, 9)\n    async for data in (await create_stream()).iter_chunked(9):\n        assert data == next(chunk_iter, None)\n    pytest.raises(StopIteration, next, chunk_iter)\n\n\nasync def test_stream_reader_chunks_incomplete() -> None:\n    # Tests if chunked iteration works if the last chunk is incomplete\n    chunk_iter = chunkify(DATA, 8)\n    async for data in (await create_stream()).iter_chunked(8):\n        assert data == next(chunk_iter, None)\n    pytest.raises(StopIteration, next, chunk_iter)\n\n\nasync def test_data_queue_empty() -> None:\n    # Tests that async looping yields nothing if nothing is there\n    loop = asyncio.get_event_loop()\n    buffer = streams.DataQueue(loop)\n    buffer.feed_eof()\n\n    async for _ in buffer:\n        assert False\n\n\nasync def test_data_queue_items() -> None:\n    # Tests that async looping yields objects identically\n    loop = asyncio.get_event_loop()\n    buffer = streams.DataQueue(loop)\n\n    items = [object(), object()]\n    buffer.feed_data(items[0], 1)\n    buffer.feed_data(items[1], 1)\n    buffer.feed_eof()\n\n    item_iter = iter(items)\n    async for item in buffer:\n        assert item is next(item_iter, None)\n    pytest.raises(StopIteration, next, item_iter)\n\n\nasync def test_stream_reader_iter_any() -> None:\n    it = iter([b\"line1\\nline2\\nline3\\n\"])\n    async for raw in (await create_stream()).iter_any():\n        assert raw == next(it)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter() -> None:\n    it = iter([b\"line1\\n\", b\"line2\\n\", b\"line3\\n\"])\n    async for raw in await create_stream():\n        assert raw == next(it)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter_chunks_no_chunked_encoding() -> None:\n    it = iter([b\"line1\\nline2\\nline3\\n\"])\n    async for data, end_of_chunk in (await create_stream()).iter_chunks():\n        assert (data, end_of_chunk) == (next(it), False)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter_chunks_chunked_encoding(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    stream = streams.StreamReader(protocol, 2**16, loop=loop)\n    for line in DATA.splitlines(keepends=True):\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(line)\n        stream.end_http_chunk_receiving()\n    stream.feed_eof()\n\n    it = iter([b\"line1\\n\", b\"line2\\n\", b\"line3\\n\"])\n    async for data, end_of_chunk in stream.iter_chunks():\n        assert (data, end_of_chunk) == (next(it), True)\n    pytest.raises(StopIteration, next, it)\n\n\ndef test_isinstance_check() -> None:\n    assert isinstance(streams.EMPTY_PAYLOAD, streams.StreamReader)\n",
            "new_file_content": "# Tests for streams.py\n\nimport abc\nimport asyncio\nimport gc\nimport types\nfrom collections import defaultdict\nfrom itertools import groupby\nfrom unittest import mock\n\nimport pytest\nfrom re_assert import Matches\n\nfrom aiohttp import streams\nfrom aiohttp.helpers import PY_310\n\nDATA = b\"line1\\nline2\\nline3\\n\"\n\n\ndef chunkify(seq, n):\n    for i in range(0, len(seq), n):\n        yield seq[i : i + n]\n\n\nasync def create_stream():\n    loop = asyncio.get_event_loop()\n    protocol = mock.Mock(_reading_paused=False)\n    stream = streams.StreamReader(protocol, 2**16, loop=loop)\n    stream.feed_data(DATA)\n    stream.feed_eof()\n    return stream\n\n\n@pytest.fixture\ndef protocol():\n    return mock.Mock(_reading_paused=False)\n\n\nMEMLEAK_SKIP_TYPES = (\n    *(getattr(types, name) for name in types.__all__ if name.endswith(\"Type\")),\n    mock.Mock,\n    abc.ABCMeta,\n)\n\n\ndef get_memory_usage(obj):\n    objs = [obj]\n    # Memory leak may be caused by leaked links to same objects.\n    # Without link counting, [1,2,3] is indistiguishable from [1,2,3,3,3,3,3,3]\n    known = defaultdict(int)\n    known[id(obj)] += 1\n\n    while objs:\n        refs = gc.get_referents(*objs)\n        objs = []\n        for obj in refs:\n            if isinstance(obj, MEMLEAK_SKIP_TYPES):\n                continue\n            i = id(obj)\n            known[i] += 1\n            if known[i] == 1:\n                objs.append(obj)\n\n        # Make list of unhashable objects uniq\n        objs.sort(key=id)\n        objs = [next(g) for (i, g) in groupby(objs, id)]\n\n    return sum(known.values())\n\n\nclass TestStreamReader:\n\n    DATA = b\"line1\\nline2\\nline3\\n\"\n\n    def _make_one(self, *args, **kwargs):\n        kwargs.setdefault(\"limit\", 2**16)\n        return streams.StreamReader(mock.Mock(_reading_paused=False), *args, **kwargs)\n\n    async def test_create_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one(loop=loop)\n        stream._waiter = loop.create_future\n        with pytest.raises(RuntimeError):\n            await stream._wait(\"test\")\n\n    @pytest.mark.xfail(\n        PY_310,\n        reason=\"No idea why ClientRequest() is constructed out of loop but \"\n        \"it calls `asyncio.get_event_loop()`\",\n        raises=DeprecationWarning,\n    )\n    def test_ctor_global_loop(self) -> None:\n        loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(loop)\n        try:\n            stream = streams.StreamReader(mock.Mock(_reading_paused=False), 2**16)\n\n            assert stream._loop is loop\n        finally:  # Otherwise an unstopped/unclosed loop affects the next test\n            # Cleanup, leaks into `test_at_eof` otherwise:\n            loop.stop()\n            loop.run_forever()\n            loop.close()\n            gc.collect()\n\n    async def test_at_eof(self) -> None:\n        stream = self._make_one()\n        assert not stream.at_eof()\n\n        stream.feed_data(b\"some data\\n\")\n        assert not stream.at_eof()\n\n        await stream.readline()\n        assert not stream.at_eof()\n\n        stream.feed_data(b\"some data\\n\")\n        stream.feed_eof()\n        await stream.readline()\n        assert stream.at_eof()\n\n    async def test_wait_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        wait_task = loop.create_task(stream.wait_eof())\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        await wait_task\n        assert stream.is_eof()\n        assert stream._eof_waiter is None\n\n    async def test_wait_eof_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_eof()\n\n        wait_task = loop.create_task(stream.wait_eof())\n        await wait_task\n        assert stream.is_eof()\n\n    async def test_feed_empty_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"\")\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_feed_nonempty_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_read_zero(self) -> None:\n        # Read zero bytes.\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.read(0)\n        assert b\"\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_read(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read bytes.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(30))\n\n        def cb():\n            stream.feed_data(self.DATA)\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert self.DATA == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_line_breaks(self) -> None:\n        # Read bytes without line breaks.\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        data = await stream.read(5)\n        assert b\"line2\" == data\n\n    async def test_read_all(self) -> None:\n        # Read all available buffered bytes\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert b\"line1line2\" == data\n\n    async def test_read_up_to(self) -> None:\n        # Read available buffered bytes up to requested amount\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n\n        data = await stream.read(8)\n        assert b\"line1lin\" == data\n\n        data = await stream.read(8)\n        assert b\"e2\" == data\n\n    async def test_read_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read bytes, stop at eof.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(1024))\n\n        def cb():\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert b\"\" == data\n\n        data = await stream.read()\n        assert data == b\"\"\n\n    async def test_read_eof_infinite(self) -> None:\n        # Read bytes.\n        stream = self._make_one()\n        stream.feed_eof()\n\n        with mock.patch(\"aiohttp.streams.internal_logger\") as internal_logger:\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n        assert internal_logger.warning.called\n\n    async def test_read_eof_unread_data_no_warning(self) -> None:\n        # Read bytes.\n        stream = self._make_one()\n        stream.feed_eof()\n\n        with mock.patch(\"aiohttp.streams.internal_logger\") as internal_logger:\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"data\")\n        await stream.read()\n        await stream.read()\n        assert not internal_logger.warning.called\n\n    async def test_read_until_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read all bytes until eof.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(-1))\n\n        def cb():\n            stream.feed_data(b\"chunk1\\n\")\n            stream.feed_data(b\"chunk2\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert b\"chunk1\\nchunk2\" == data\n\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.read(2)\n        assert b\"li\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.read(2)\n\n    async def test_readline(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one line. 'readline' will need to wait for the data\n        # to come from 'cb'\n        stream = self._make_one()\n        stream.feed_data(b\"chunk1 \")\n        read_task = loop.create_task(stream.readline())\n\n        def cb():\n            stream.feed_data(b\"chunk2 \")\n            stream.feed_data(b\"chunk3 \")\n            stream.feed_data(b\"\\n chunk4\")\n\n        loop.call_soon(cb)\n\n        line = await read_task\n        assert b\"chunk1 chunk2 chunk3 \\n\" == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\" chunk4\" == data\n\n    async def test_readline_limit_with_existing_data(self) -> None:\n        # Read one line. The data is in StreamReader's buffer\n        # before the event loop is run.\n\n        stream = self._make_one(limit=2)\n        stream.feed_data(b\"li\")\n        stream.feed_data(b\"ne1\\nline2\\n\")\n\n        with pytest.raises(ValueError):\n            await stream.readline()\n        # The buffer should contain the remaining data after exception\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\\n\" == data\n\n    async def test_readline_limit(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one line. StreamReaders are fed with data after\n        # their 'readline' methods are called.\n        stream = self._make_one(limit=4)\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\\n\")\n            stream.feed_data(b\"chunk3\\n\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(ValueError):\n            await stream.readline()\n        data = await stream.read()\n        assert b\"chunk3\\n\" == data\n\n    async def test_readline_nolimit_nowait(self) -> None:\n        # All needed data for the first 'readline' call will be\n        # in the buffer.\n        stream = self._make_one()\n        stream.feed_data(self.DATA[:6])\n        stream.feed_data(self.DATA[6:])\n\n        line = await stream.readline()\n        assert b\"line1\\n\" == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\\nline3\\n\" == data\n\n    async def test_readline_eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"some data\")\n        stream.feed_eof()\n\n        line = await stream.readline()\n        assert b\"some data\" == line\n\n    async def test_readline_empty_eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n\n        line = await stream.readline()\n        assert b\"\" == line\n\n    async def test_readline_read_byte_count(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        await stream.readline()\n\n        data = await stream.read(7)\n        assert b\"line2\\nl\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"ine3\\n\" == data\n\n    async def test_readline_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readline()\n        assert b\"line\\n\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readline()\n\n    @pytest.mark.parametrize(\"separator\", [b\"*\", b\"**\"])\n    async def test_readuntil(self, separator: bytes) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one chunk. 'readuntil' will need to wait for the data\n        # to come from 'cb'\n        stream = self._make_one()\n        stream.feed_data(b\"chunk1 \")\n        read_task = loop.create_task(stream.readuntil(separator))\n\n        def cb():\n            stream.feed_data(b\"chunk2 \")\n            stream.feed_data(b\"chunk3 \")\n            stream.feed_data(separator + b\" chunk4\")\n\n        loop.call_soon(cb)\n\n        line = await read_task\n        assert b\"chunk1 chunk2 chunk3 \" + separator == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\" chunk4\" == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"&\", b\"&&\"])\n    async def test_readuntil_limit_with_existing_data(self, separator: bytes) -> None:\n        # Read one chunk. The data is in StreamReader's buffer\n        # before the event loop is run.\n\n        stream = self._make_one(limit=2)\n        stream.feed_data(b\"li\")\n        stream.feed_data(b\"ne1\" + separator + b\"line2\" + separator)\n\n        with pytest.raises(ValueError):\n            await stream.readuntil(separator)\n        # The buffer should contain the remaining data after exception\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"$\", b\"$$\"])\n    async def test_readuntil_limit(self, separator: bytes) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one chunk. StreamReaders are fed with data after\n        # their 'readuntil' methods are called.\n        stream = self._make_one(limit=4)\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\" + separator)\n            stream.feed_data(b\"chunk3#\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(ValueError, match=\"Chunk too big\"):\n            await stream.readuntil(separator)\n        data = await stream.read()\n        assert b\"chunk3#\" == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"!\", b\"!!\"])\n    async def test_readuntil_nolimit_nowait(self, separator: bytes) -> None:\n        # All needed data for the first 'readuntil' call will be\n        # in the buffer.\n        seplen = len(separator)\n        stream = self._make_one()\n        data = b\"line1\" + separator + b\"line2\" + separator + b\"line3\" + separator\n        stream.feed_data(data[: 5 + seplen])\n        stream.feed_data(data[5 + seplen :])\n\n        line = await stream.readuntil(separator)\n        assert b\"line1\" + separator == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\" + separator + b\"line3\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"@\", b\"@@\"])\n    async def test_readuntil_eof(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"some data\")\n        stream.feed_eof()\n\n        line = await stream.readuntil(separator)\n        assert b\"some data\" == line\n\n    @pytest.mark.parametrize(\"separator\", [b\"@\", b\"@@\"])\n    async def test_readuntil_empty_eof(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n\n        line = await stream.readuntil(separator)\n        assert b\"\" == line\n\n    @pytest.mark.parametrize(\"separator\", [b\"!\", b\"!!\"])\n    async def test_readuntil_read_byte_count(self, separator: bytes) -> None:\n        seplen = len(separator)\n        stream = self._make_one()\n        stream.feed_data(\n            b\"line1\" + separator + b\"line2\" + separator + b\"line3\" + separator\n        )\n\n        await stream.readuntil(separator)\n\n        data = await stream.read(6 + seplen)\n        assert b\"line2\" + separator + b\"l\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"ine3\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"#\", b\"##\"])\n    async def test_readuntil_exception(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\" + separator)\n\n        data = await stream.readuntil(separator)\n        assert b\"line\" + separator == data\n\n        stream.set_exception(ValueError(\"Another exception\"))\n        with pytest.raises(ValueError, match=\"Another exception\"):\n            await stream.readuntil(separator)\n\n    async def test_readexactly_zero_or_less(self) -> None:\n        # Read exact number of bytes (zero or less).\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.readexactly(0)\n        assert b\"\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.readexactly(-1)\n        assert b\"\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_readexactly(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read exact number of bytes.\n        stream = self._make_one()\n\n        n = 2 * len(self.DATA)\n        read_task = loop.create_task(stream.readexactly(n))\n\n        def cb():\n            stream.feed_data(self.DATA)\n            stream.feed_data(self.DATA)\n            stream.feed_data(self.DATA)\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert self.DATA + self.DATA == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_readexactly_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read exact number of bytes (eof).\n        stream = self._make_one(loop=loop)\n        n = 2 * len(self.DATA)\n        read_task = loop.create_task(stream.readexactly(n))\n\n        def cb():\n            stream.feed_data(self.DATA)\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(asyncio.IncompleteReadError) as cm:\n            await read_task\n        assert cm.value.partial == self.DATA\n        assert cm.value.expected == n\n        assert str(cm.value) == \"18 bytes read on a total of 36 expected bytes\"\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_readexactly_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readexactly(2)\n        assert b\"li\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readexactly(2)\n\n    async def test_unread_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n        stream.feed_data(b\"onemoreline\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(data)\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        data = await stream.read(4)\n        assert b\"line\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"line1line\")\n\n        data = b\"\"\n        while len(data) < 10:\n            data += await stream.read(10)\n        assert b\"line1line2\" == data\n\n        data = await stream.read(7)\n        assert b\"onemore\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(data)\n\n        data = b\"\"\n        while len(data) < 11:\n            data += await stream.read(11)\n        assert b\"onemoreline\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"line\")\n        data = await stream.read(4)\n        assert b\"line\" == data\n\n        stream.feed_eof()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"at_eof\")\n        data = await stream.read(6)\n        assert b\"at_eof\" == data\n\n    async def test_exception(self) -> None:\n        stream = self._make_one()\n        assert stream.exception() is None\n\n        exc = ValueError()\n        stream.set_exception(exc)\n        assert stream.exception() is exc\n\n    async def test_exception_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def set_err():\n            stream.set_exception(ValueError())\n\n        t1 = loop.create_task(stream.readline())\n        t2 = loop.create_task(set_err())\n\n        await asyncio.wait([t1, t2])\n        with pytest.raises(ValueError):\n            t1.result()\n\n    async def test_exception_cancel(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def read_a_line():\n            await stream.readline()\n\n        t = loop.create_task(read_a_line())\n        await asyncio.sleep(0)\n        t.cancel()\n        await asyncio.sleep(0)\n        # The following line fails if set_exception() isn't careful.\n        stream.set_exception(RuntimeError(\"message\"))\n        await asyncio.sleep(0)\n        assert stream._waiter is None\n\n    async def test_readany_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        read_task = loop.create_task(stream.readany())\n        loop.call_soon(stream.feed_data, b\"chunk1\\n\")\n\n        data = await read_task\n        assert b\"chunk1\\n\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_readany_empty_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_eof()\n        read_task = loop.create_task(stream.readany())\n\n        data = await read_task\n\n        assert b\"\" == data\n\n    async def test_readany_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readany()\n        assert b\"line\\n\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readany()\n\n    async def test_read_nowait(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\\nline2\\n\")\n\n        assert stream.read_nowait() == b\"line1\\nline2\\n\"\n        assert stream.read_nowait() == b\"\"\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_nowait_n(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\\nline2\\n\")\n\n        assert stream.read_nowait(4) == b\"line\"\n        assert stream.read_nowait() == b\"1\\nline2\\n\"\n        assert stream.read_nowait() == b\"\"\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_nowait_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n        stream.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            stream.read_nowait()\n\n    async def test_read_nowait_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n        stream._waiter = loop.create_future()\n\n        with pytest.raises(RuntimeError):\n            stream.read_nowait()\n\n    async def test_readchunk(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"chunk1\" == data\n        assert not end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"chunk2\" == data\n        assert not end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readchunk_wait_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n        assert stream.is_eof()\n\n    async def test_begin_and_end_chunk_receiving(self) -> None:\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part1part2\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part3\" == data\n        assert not end_of_chunk\n\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.feed_eof()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readany_chunk_end_race(self) -> None:\n        stream = self._make_one()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n\n        data = await stream.readany()\n        assert data == b\"part1\"\n\n        loop = asyncio.get_event_loop()\n        task = loop.create_task(stream.readany())\n\n        # Give a chance for task to create waiter and start waiting for it.\n        await asyncio.sleep(0.1)\n        assert stream._waiter is not None\n        assert not task.done()  # Just for sure.\n\n        # This will trigger waiter, but without feeding any data.\n        # The stream should re-create waiter again.\n        stream.end_http_chunk_receiving()\n\n        # Give a chance for task to resolve.\n        # If everything is OK, previous action SHOULD NOT resolve the task.\n        await asyncio.sleep(0.1)\n        assert not task.done()  # The actual test.\n\n        stream.begin_http_chunk_receiving()\n        # This SHOULD unblock the task actually.\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        data = await task\n        assert data == b\"part2\"\n\n    async def test_end_chunk_receiving_without_begin(self) -> None:\n        stream = self._make_one()\n        with pytest.raises(RuntimeError):\n            stream.end_http_chunk_receiving()\n\n    async def test_readchunk_with_unread(self) -> None:\n        # Test that stream.unread does not break controlled chunk receiving.\n        stream = self._make_one()\n\n        # Send 2 chunks\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        # Read only one chunk\n        data, end_of_chunk = await stream.readchunk()\n\n        # Try to unread a part of the first chunk\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"rt1\")\n\n        # The end_of_chunk signal was already received for the first chunk,\n        # so we receive up to the second one\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt1part2\" == data\n        assert end_of_chunk\n\n        # Unread a part of the second chunk\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"rt2\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt2\" == data\n        # end_of_chunk was already received for this chunk\n        assert not end_of_chunk\n\n        stream.feed_eof()\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readchunk_with_other_read_calls(self) -> None:\n        # Test that stream.readchunk works when other read calls are made on\n        # the stream.\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n        stream.end_http_chunk_receiving()\n\n        data = await stream.read(7)\n        assert b\"part1pa\" == data\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt2\" == data\n        assert end_of_chunk\n\n        # Corner case between read/readchunk\n        data = await stream.read(5)\n        assert b\"part3\" == data\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.feed_eof()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_chunksplits_memory_leak(self) -> None:\n        # Test for memory leak on chunksplits\n        stream = self._make_one()\n\n        N = 500\n\n        # Warm-up variables\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"Y\" * N)\n        stream.end_http_chunk_receiving()\n        await stream.read(N)\n\n        N = 300\n\n        before = get_memory_usage(stream)\n        for _ in range(N):\n            stream.begin_http_chunk_receiving()\n            stream.feed_data(b\"X\")\n            stream.end_http_chunk_receiving()\n        await stream.read(N)\n        after = get_memory_usage(stream)\n\n        assert abs(after - before) == 0\n\n    async def test_read_empty_chunks(self) -> None:\n        # Test that feeding empty chunks does not break stream\n        stream = self._make_one()\n\n        # Simulate empty first chunk. This is significant special case\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"ungzipped\")\n        stream.end_http_chunk_receiving()\n\n        # Possible when compression is enabled.\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        # is also possible\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\" data\")\n        stream.end_http_chunk_receiving()\n\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert data == b\"ungzipped data\"\n\n    async def test_readchunk_separate_http_chunk_tail(self) -> None:\n        # Test that stream.readchunk returns (b'', True) when end of\n        # http chunk received after body\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part1\" == data\n        assert not end_of_chunk\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.end_http_chunk_receiving()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part2\" == data\n        assert not end_of_chunk\n\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part3\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part4\")\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part4\" == data\n        assert not end_of_chunk\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.end_http_chunk_receiving()\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test___repr__(self) -> None:\n        stream = self._make_one()\n        assert \"<StreamReader>\" == repr(stream)\n\n    async def test___repr__nondefault_limit(self) -> None:\n        stream = self._make_one(limit=123)\n        assert \"<StreamReader low=123 high=246>\" == repr(stream)\n\n    async def test___repr__eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n        assert \"<StreamReader eof>\" == repr(stream)\n\n    async def test___repr__data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"data\")\n        assert \"<StreamReader 4 bytes>\" == repr(stream)\n\n    async def test___repr__exception(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one(loop=loop)\n        exc = RuntimeError()\n        stream.set_exception(exc)\n        assert \"<StreamReader e=RuntimeError()>\" == repr(stream)\n\n    async def test___repr__waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream._waiter = loop.create_future()\n        assert Matches(r\"<StreamReader w=<Future pending[\\S ]*>>\") == repr(stream)\n        stream._waiter.set_result(None)\n        await stream._waiter\n        stream._waiter = None\n        assert \"<StreamReader>\" == repr(stream)\n\n    async def test_unread_empty(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_eof()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n        assert stream.at_eof()\n\n\nasync def test_empty_stream_reader() -> None:\n    s = streams.EmptyStreamReader()\n    assert str(s) is not None\n    assert s.set_exception(ValueError()) is None\n    assert s.exception() is None\n    assert s.feed_eof() is None\n    assert s.feed_data(b\"data\") is None\n    assert s.at_eof()\n    assert (await s.wait_eof()) is None\n    assert await s.read() == b\"\"\n    assert await s.readline() == b\"\"\n    assert await s.readany() == b\"\"\n    assert await s.readchunk() == (b\"\", True)\n    with pytest.raises(asyncio.IncompleteReadError):\n        await s.readexactly(10)\n    assert s.read_nowait() == b\"\"\n\n\n@pytest.fixture\nasync def buffer(loop):\n    return streams.DataQueue(loop)\n\n\nclass TestDataQueue:\n    def test_is_eof(self, buffer) -> None:\n        assert not buffer.is_eof()\n        buffer.feed_eof()\n        assert buffer.is_eof()\n\n    def test_at_eof(self, buffer) -> None:\n        assert not buffer.at_eof()\n        buffer.feed_eof()\n        assert buffer.at_eof()\n        buffer._buffer.append(object())\n        assert not buffer.at_eof()\n\n    def test_feed_data(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item, 1)\n        assert [(item, 1)] == list(buffer._buffer)\n\n    def test_feed_eof(self, buffer) -> None:\n        buffer.feed_eof()\n        assert buffer._eof\n\n    async def test_read(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        item = object()\n\n        def cb():\n            buffer.feed_data(item, 1)\n\n        loop.call_soon(cb)\n\n        data = await buffer.read()\n        assert item is data\n\n    async def test_read_eof(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n\n        def cb():\n            buffer.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(streams.EofStream):\n            await buffer.read()\n\n    async def test_read_cancelled(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        read_task = loop.create_task(buffer.read())\n        await asyncio.sleep(0)\n        waiter = buffer._waiter\n        assert asyncio.isfuture(waiter)\n\n        read_task.cancel()\n        with pytest.raises(asyncio.CancelledError):\n            await read_task\n        assert waiter.cancelled()\n        assert buffer._waiter is None\n\n        buffer.feed_data(b\"test\", 4)\n        assert buffer._waiter is None\n\n    async def test_read_until_eof(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item, 1)\n        buffer.feed_eof()\n\n        data = await buffer.read()\n        assert data is item\n\n        with pytest.raises(streams.EofStream):\n            await buffer.read()\n\n    async def test_read_exc(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item)\n        buffer.set_exception(ValueError)\n\n        data = await buffer.read()\n        assert item is data\n\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception(self, buffer) -> None:\n        buffer.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception_with_data(self, buffer) -> None:\n        val = object()\n        buffer.feed_data(val, 1)\n        buffer.set_exception(ValueError())\n\n        assert val is (await buffer.read())\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception_on_wait(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        read_task = loop.create_task(buffer.read())\n        await asyncio.sleep(0)\n        assert asyncio.isfuture(buffer._waiter)\n\n        buffer.feed_eof()\n        buffer.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            await read_task\n\n    def test_exception(self, buffer) -> None:\n        assert buffer.exception() is None\n\n        exc = ValueError()\n        buffer.set_exception(exc)\n        assert buffer.exception() is exc\n\n    async def test_exception_waiter(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n\n        async def set_err():\n            buffer.set_exception(ValueError())\n\n        t1 = loop.create_task(buffer.read())\n        t2 = loop.create_task(set_err())\n\n        await asyncio.wait([t1, t2])\n\n        with pytest.raises(ValueError):\n            t1.result()\n\n\nasync def test_feed_data_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    reader.feed_data(b\"1\")\n    assert list(reader._buffer) == [b\"1\"]\n    assert reader._size == 1\n    assert reader.total_bytes == 1\n\n    assert waiter.done()\n    assert not eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is eof_waiter\n\n\nasync def test_feed_data_completed_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n\n    waiter.set_result(1)\n    reader.feed_data(b\"1\")\n\n    assert reader._waiter is None\n\n\nasync def test_feed_eof_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    reader.feed_eof()\n    assert reader._eof\n\n    assert waiter.done()\n    assert eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_feed_eof_cancelled(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    waiter.set_result(1)\n    eof_waiter.set_result(1)\n\n    reader.feed_eof()\n\n    assert waiter.done()\n    assert eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_on_eof(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    assert not on_eof.called\n    reader.feed_eof()\n    assert on_eof.called\n\n\nasync def test_on_eof_empty_reader() -> None:\n    reader = streams.EmptyStreamReader()\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    assert on_eof.called\n\n\nasync def test_on_eof_exc_in_callback(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert not on_eof.called\n    reader.feed_eof()\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_on_eof_exc_in_callback_empty_stream_reader() -> None:\n    reader = streams.EmptyStreamReader()\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert on_eof.called\n\n\nasync def test_on_eof_eof_is_set(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    reader.feed_eof()\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_on_eof_eof_is_set_exception(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    reader.feed_eof()\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_set_exception(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    exc = ValueError()\n    reader.set_exception(exc)\n\n    assert waiter.exception() is exc\n    assert eof_waiter.exception() is exc\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_set_exception_cancelled(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    waiter.set_result(1)\n    eof_waiter.set_result(1)\n\n    exc = ValueError()\n    reader.set_exception(exc)\n\n    assert waiter.exception() is None\n    assert eof_waiter.exception() is None\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_set_exception_eof_callbacks(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    reader.set_exception(ValueError())\n    assert not on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_stream_reader_lines() -> None:\n    line_iter = iter(DATA.splitlines(keepends=True))\n    async for line in await create_stream():\n        assert line == next(line_iter, None)\n    pytest.raises(StopIteration, next, line_iter)\n\n\nasync def test_stream_reader_chunks_complete() -> None:\n    # Tests if chunked iteration works if the chunking works out\n    # (i.e. the data is divisible by the chunk size)\n    chunk_iter = chunkify(DATA, 9)\n    async for data in (await create_stream()).iter_chunked(9):\n        assert data == next(chunk_iter, None)\n    pytest.raises(StopIteration, next, chunk_iter)\n\n\nasync def test_stream_reader_chunks_incomplete() -> None:\n    # Tests if chunked iteration works if the last chunk is incomplete\n    chunk_iter = chunkify(DATA, 8)\n    async for data in (await create_stream()).iter_chunked(8):\n        assert data == next(chunk_iter, None)\n    pytest.raises(StopIteration, next, chunk_iter)\n\n\nasync def test_data_queue_empty() -> None:\n    # Tests that async looping yields nothing if nothing is there\n    loop = asyncio.get_event_loop()\n    buffer = streams.DataQueue(loop)\n    buffer.feed_eof()\n\n    async for _ in buffer:\n        assert False\n\n\nasync def test_data_queue_items() -> None:\n    # Tests that async looping yields objects identically\n    loop = asyncio.get_event_loop()\n    buffer = streams.DataQueue(loop)\n\n    items = [object(), object()]\n    buffer.feed_data(items[0], 1)\n    buffer.feed_data(items[1], 1)\n    buffer.feed_eof()\n\n    item_iter = iter(items)\n    async for item in buffer:\n        assert item is next(item_iter, None)\n    pytest.raises(StopIteration, next, item_iter)\n\n\nasync def test_stream_reader_iter_any() -> None:\n    it = iter([b\"line1\\nline2\\nline3\\n\"])\n    async for raw in (await create_stream()).iter_any():\n        assert raw == next(it)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter() -> None:\n    it = iter([b\"line1\\n\", b\"line2\\n\", b\"line3\\n\"])\n    async for raw in await create_stream():\n        assert raw == next(it)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter_chunks_no_chunked_encoding() -> None:\n    it = iter([b\"line1\\nline2\\nline3\\n\"])\n    async for data, end_of_chunk in (await create_stream()).iter_chunks():\n        assert (data, end_of_chunk) == (next(it), False)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter_chunks_chunked_encoding(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    stream = streams.StreamReader(protocol, 2**16, loop=loop)\n    for line in DATA.splitlines(keepends=True):\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(line)\n        stream.end_http_chunk_receiving()\n    stream.feed_eof()\n\n    it = iter([b\"line1\\n\", b\"line2\\n\", b\"line3\\n\"])\n    async for data, end_of_chunk in stream.iter_chunks():\n        assert (data, end_of_chunk) == (next(it), True)\n    pytest.raises(StopIteration, next, it)\n\n\ndef test_isinstance_check() -> None:\n    assert isinstance(streams.EMPTY_PAYLOAD, streams.StreamReader)\n",
            "header": {
                "file": {
                    "path": "tests/test_streams.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "a16f7ebf",
                "new_commit_hash": "29eab256",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/tests/test_streams.py"
            },
            "plus_file": {
                "path": "b/tests/test_streams.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 1132,
                            "length": 6
                        },
                        "new_range": {
                            "start": 1132,
                            "length": 7
                        },
                        "section": "class TestStreamReader:"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "async def test_empty_stream_reader() -> None:",
                                "type": "context"
                            },
                            {
                                "content": "    s = streams.EmptyStreamReader()",
                                "type": "context"
                            },
                            {
                                "content": "    assert str(s) is not None",
                                "type": "added"
                            },
                            {
                                "content": "    assert s.set_exception(ValueError()) is None",
                                "type": "context"
                            },
                            {
                                "content": "    assert s.exception() is None",
                                "type": "context"
                            },
                            {
                                "content": "    assert s.feed_eof() is None",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "tests/test_streams.py",
                            "type": "function",
                            "name": "test_empty_stream_reader",
                            "content": "async def test_empty_stream_reader() -> None:\n    s = streams.EmptyStreamReader()\n    assert str(s) is not None\n    assert s.set_exception(ValueError()) is None\n    assert s.exception() is None\n    assert s.feed_eof() is None\n    assert s.feed_data(b\"data\") is None\n    assert s.at_eof()\n    assert (await s.wait_eof()) is None\n    assert await s.read() == b\"\"\n    assert await s.readline() == b\"\"\n    assert await s.readany() == b\"\"\n    assert await s.readchunk() == (b\"\", True)\n    with pytest.raises(asyncio.IncompleteReadError):\n        await s.readexactly(10)\n    assert s.read_nowait() == b\"\"",
                            "ast_type_str": "AsyncFunctionDef",
                            "start_lineno": 1133,
                            "end_lineno": 1148,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "f7e4246114ce48335f224f36c2d4b058b02bea7b^",
    "new_commit_hash": "f7e4246114ce48335f224f36c2d4b058b02bea7b",
    "commit_message": "[PR #6916/abafcdac backport][3.9] Add missing __repr__ to streams.EmptyStreamReader (#7106)\n\n**This is a backport of PR #6916 as merged into master\r\n(abafcdac6cbef06bc555cb77b1ebe724d2a098ec).**\r\n\r\n**EmptyStreamReader** currently inherits `__repr__` from\r\n**StreamReader** , which then tries to access non-existing fields,\r\ncausing AttributeErrors. The bug causes issues like this in upstream\r\ncode: https://github.com/miguelgrinberg/python-socketio/issues/1032\r\n\r\nThis PR adds a custom `__repr__` to EmptyStreamReader to fix the\r\nproblem.\r\n\r\nCo-authored-by: elonen <elonen@iki.fi>",
    "commit_date": "2022-11-28T20:29:16Z",
    "metadata": {}
}
{
    "repo_name": "aiohttp",
    "new_commit_hash": "f7e4246114ce48335f224f36c2d4b058b02bea7b",
    "test_file_codes": [
        "# Tests for streams.py\n\nimport abc\nimport asyncio\nimport gc\nimport types\nfrom collections import defaultdict\nfrom itertools import groupby\nfrom unittest import mock\n\nimport pytest\nfrom re_assert import Matches\n\nfrom aiohttp import streams\nfrom aiohttp.helpers import PY_310\n\nDATA = b\"line1\\nline2\\nline3\\n\"\n\n\ndef chunkify(seq, n):\n    for i in range(0, len(seq), n):\n        yield seq[i : i + n]\n\n\nasync def create_stream():\n    loop = asyncio.get_event_loop()\n    protocol = mock.Mock(_reading_paused=False)\n    stream = streams.StreamReader(protocol, 2**16, loop=loop)\n    stream.feed_data(DATA)\n    stream.feed_eof()\n    return stream\n\n\n@pytest.fixture\ndef protocol():\n    return mock.Mock(_reading_paused=False)\n\n\nMEMLEAK_SKIP_TYPES = (\n    *(getattr(types, name) for name in types.__all__ if name.endswith(\"Type\")),\n    mock.Mock,\n    abc.ABCMeta,\n)\n\n\ndef get_memory_usage(obj):\n    objs = [obj]\n    # Memory leak may be caused by leaked links to same objects.\n    # Without link counting, [1,2,3] is indistiguishable from [1,2,3,3,3,3,3,3]\n    known = defaultdict(int)\n    known[id(obj)] += 1\n\n    while objs:\n        refs = gc.get_referents(*objs)\n        objs = []\n        for obj in refs:\n            if isinstance(obj, MEMLEAK_SKIP_TYPES):\n                continue\n            i = id(obj)\n            known[i] += 1\n            if known[i] == 1:\n                objs.append(obj)\n\n        # Make list of unhashable objects uniq\n        objs.sort(key=id)\n        objs = [next(g) for (i, g) in groupby(objs, id)]\n\n    return sum(known.values())\n\n\nclass TestStreamReader:\n\n    DATA = b\"line1\\nline2\\nline3\\n\"\n\n    def _make_one(self, *args, **kwargs):\n        kwargs.setdefault(\"limit\", 2**16)\n        return streams.StreamReader(mock.Mock(_reading_paused=False), *args, **kwargs)\n\n    async def test_create_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one(loop=loop)\n        stream._waiter = loop.create_future\n        with pytest.raises(RuntimeError):\n            await stream._wait(\"test\")\n\n    @pytest.mark.xfail(\n        PY_310,\n        reason=\"No idea why ClientRequest() is constructed out of loop but \"\n        \"it calls `asyncio.get_event_loop()`\",\n        raises=DeprecationWarning,\n    )\n    def test_ctor_global_loop(self) -> None:\n        loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(loop)\n        try:\n            stream = streams.StreamReader(mock.Mock(_reading_paused=False), 2**16)\n\n            assert stream._loop is loop\n        finally:  # Otherwise an unstopped/unclosed loop affects the next test\n            # Cleanup, leaks into `test_at_eof` otherwise:\n            loop.stop()\n            loop.run_forever()\n            loop.close()\n            gc.collect()\n\n    async def test_at_eof(self) -> None:\n        stream = self._make_one()\n        assert not stream.at_eof()\n\n        stream.feed_data(b\"some data\\n\")\n        assert not stream.at_eof()\n\n        await stream.readline()\n        assert not stream.at_eof()\n\n        stream.feed_data(b\"some data\\n\")\n        stream.feed_eof()\n        await stream.readline()\n        assert stream.at_eof()\n\n    async def test_wait_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        wait_task = loop.create_task(stream.wait_eof())\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        await wait_task\n        assert stream.is_eof()\n        assert stream._eof_waiter is None\n\n    async def test_wait_eof_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_eof()\n\n        wait_task = loop.create_task(stream.wait_eof())\n        await wait_task\n        assert stream.is_eof()\n\n    async def test_feed_empty_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"\")\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_feed_nonempty_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_read_zero(self) -> None:\n        # Read zero bytes.\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.read(0)\n        assert b\"\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_read(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read bytes.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(30))\n\n        def cb():\n            stream.feed_data(self.DATA)\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert self.DATA == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_line_breaks(self) -> None:\n        # Read bytes without line breaks.\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        data = await stream.read(5)\n        assert b\"line2\" == data\n\n    async def test_read_all(self) -> None:\n        # Read all available buffered bytes\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert b\"line1line2\" == data\n\n    async def test_read_up_to(self) -> None:\n        # Read available buffered bytes up to requested amount\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n\n        data = await stream.read(8)\n        assert b\"line1lin\" == data\n\n        data = await stream.read(8)\n        assert b\"e2\" == data\n\n    async def test_read_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read bytes, stop at eof.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(1024))\n\n        def cb():\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert b\"\" == data\n\n        data = await stream.read()\n        assert data == b\"\"\n\n    async def test_read_eof_infinite(self) -> None:\n        # Read bytes.\n        stream = self._make_one()\n        stream.feed_eof()\n\n        with mock.patch(\"aiohttp.streams.internal_logger\") as internal_logger:\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n        assert internal_logger.warning.called\n\n    async def test_read_eof_unread_data_no_warning(self) -> None:\n        # Read bytes.\n        stream = self._make_one()\n        stream.feed_eof()\n\n        with mock.patch(\"aiohttp.streams.internal_logger\") as internal_logger:\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n            await stream.read()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"data\")\n        await stream.read()\n        await stream.read()\n        assert not internal_logger.warning.called\n\n    async def test_read_until_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read all bytes until eof.\n        stream = self._make_one()\n        read_task = loop.create_task(stream.read(-1))\n\n        def cb():\n            stream.feed_data(b\"chunk1\\n\")\n            stream.feed_data(b\"chunk2\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert b\"chunk1\\nchunk2\" == data\n\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.read(2)\n        assert b\"li\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.read(2)\n\n    async def test_readline(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one line. 'readline' will need to wait for the data\n        # to come from 'cb'\n        stream = self._make_one()\n        stream.feed_data(b\"chunk1 \")\n        read_task = loop.create_task(stream.readline())\n\n        def cb():\n            stream.feed_data(b\"chunk2 \")\n            stream.feed_data(b\"chunk3 \")\n            stream.feed_data(b\"\\n chunk4\")\n\n        loop.call_soon(cb)\n\n        line = await read_task\n        assert b\"chunk1 chunk2 chunk3 \\n\" == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\" chunk4\" == data\n\n    async def test_readline_limit_with_existing_data(self) -> None:\n        # Read one line. The data is in StreamReader's buffer\n        # before the event loop is run.\n\n        stream = self._make_one(limit=2)\n        stream.feed_data(b\"li\")\n        stream.feed_data(b\"ne1\\nline2\\n\")\n\n        with pytest.raises(ValueError):\n            await stream.readline()\n        # The buffer should contain the remaining data after exception\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\\n\" == data\n\n    async def test_readline_limit(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one line. StreamReaders are fed with data after\n        # their 'readline' methods are called.\n        stream = self._make_one(limit=4)\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\\n\")\n            stream.feed_data(b\"chunk3\\n\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(ValueError):\n            await stream.readline()\n        data = await stream.read()\n        assert b\"chunk3\\n\" == data\n\n    async def test_readline_nolimit_nowait(self) -> None:\n        # All needed data for the first 'readline' call will be\n        # in the buffer.\n        stream = self._make_one()\n        stream.feed_data(self.DATA[:6])\n        stream.feed_data(self.DATA[6:])\n\n        line = await stream.readline()\n        assert b\"line1\\n\" == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\\nline3\\n\" == data\n\n    async def test_readline_eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"some data\")\n        stream.feed_eof()\n\n        line = await stream.readline()\n        assert b\"some data\" == line\n\n    async def test_readline_empty_eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n\n        line = await stream.readline()\n        assert b\"\" == line\n\n    async def test_readline_read_byte_count(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        await stream.readline()\n\n        data = await stream.read(7)\n        assert b\"line2\\nl\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"ine3\\n\" == data\n\n    async def test_readline_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readline()\n        assert b\"line\\n\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readline()\n\n    @pytest.mark.parametrize(\"separator\", [b\"*\", b\"**\"])\n    async def test_readuntil(self, separator: bytes) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one chunk. 'readuntil' will need to wait for the data\n        # to come from 'cb'\n        stream = self._make_one()\n        stream.feed_data(b\"chunk1 \")\n        read_task = loop.create_task(stream.readuntil(separator))\n\n        def cb():\n            stream.feed_data(b\"chunk2 \")\n            stream.feed_data(b\"chunk3 \")\n            stream.feed_data(separator + b\" chunk4\")\n\n        loop.call_soon(cb)\n\n        line = await read_task\n        assert b\"chunk1 chunk2 chunk3 \" + separator == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\" chunk4\" == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"&\", b\"&&\"])\n    async def test_readuntil_limit_with_existing_data(self, separator: bytes) -> None:\n        # Read one chunk. The data is in StreamReader's buffer\n        # before the event loop is run.\n\n        stream = self._make_one(limit=2)\n        stream.feed_data(b\"li\")\n        stream.feed_data(b\"ne1\" + separator + b\"line2\" + separator)\n\n        with pytest.raises(ValueError):\n            await stream.readuntil(separator)\n        # The buffer should contain the remaining data after exception\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"$\", b\"$$\"])\n    async def test_readuntil_limit(self, separator: bytes) -> None:\n        loop = asyncio.get_event_loop()\n        # Read one chunk. StreamReaders are fed with data after\n        # their 'readuntil' methods are called.\n        stream = self._make_one(limit=4)\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\" + separator)\n            stream.feed_data(b\"chunk3#\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(ValueError, match=\"Chunk too big\"):\n            await stream.readuntil(separator)\n        data = await stream.read()\n        assert b\"chunk3#\" == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"!\", b\"!!\"])\n    async def test_readuntil_nolimit_nowait(self, separator: bytes) -> None:\n        # All needed data for the first 'readuntil' call will be\n        # in the buffer.\n        seplen = len(separator)\n        stream = self._make_one()\n        data = b\"line1\" + separator + b\"line2\" + separator + b\"line3\" + separator\n        stream.feed_data(data[: 5 + seplen])\n        stream.feed_data(data[5 + seplen :])\n\n        line = await stream.readuntil(separator)\n        assert b\"line1\" + separator == line\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"line2\" + separator + b\"line3\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"@\", b\"@@\"])\n    async def test_readuntil_eof(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"some data\")\n        stream.feed_eof()\n\n        line = await stream.readuntil(separator)\n        assert b\"some data\" == line\n\n    @pytest.mark.parametrize(\"separator\", [b\"@\", b\"@@\"])\n    async def test_readuntil_empty_eof(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n\n        line = await stream.readuntil(separator)\n        assert b\"\" == line\n\n    @pytest.mark.parametrize(\"separator\", [b\"!\", b\"!!\"])\n    async def test_readuntil_read_byte_count(self, separator: bytes) -> None:\n        seplen = len(separator)\n        stream = self._make_one()\n        stream.feed_data(\n            b\"line1\" + separator + b\"line2\" + separator + b\"line3\" + separator\n        )\n\n        await stream.readuntil(separator)\n\n        data = await stream.read(6 + seplen)\n        assert b\"line2\" + separator + b\"l\" == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"ine3\" + separator == data\n\n    @pytest.mark.parametrize(\"separator\", [b\"#\", b\"##\"])\n    async def test_readuntil_exception(self, separator: bytes) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\" + separator)\n\n        data = await stream.readuntil(separator)\n        assert b\"line\" + separator == data\n\n        stream.set_exception(ValueError(\"Another exception\"))\n        with pytest.raises(ValueError, match=\"Another exception\"):\n            await stream.readuntil(separator)\n\n    async def test_readexactly_zero_or_less(self) -> None:\n        # Read exact number of bytes (zero or less).\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.readexactly(0)\n        assert b\"\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n        stream = self._make_one()\n        stream.feed_data(self.DATA)\n\n        data = await stream.readexactly(-1)\n        assert b\"\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_readexactly(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read exact number of bytes.\n        stream = self._make_one()\n\n        n = 2 * len(self.DATA)\n        read_task = loop.create_task(stream.readexactly(n))\n\n        def cb():\n            stream.feed_data(self.DATA)\n            stream.feed_data(self.DATA)\n            stream.feed_data(self.DATA)\n\n        loop.call_soon(cb)\n\n        data = await read_task\n        assert self.DATA + self.DATA == data\n\n        stream.feed_eof()\n        data = await stream.read()\n        assert self.DATA == data\n\n    async def test_readexactly_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        # Read exact number of bytes (eof).\n        stream = self._make_one(loop=loop)\n        n = 2 * len(self.DATA)\n        read_task = loop.create_task(stream.readexactly(n))\n\n        def cb():\n            stream.feed_data(self.DATA)\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(asyncio.IncompleteReadError) as cm:\n            await read_task\n        assert cm.value.partial == self.DATA\n        assert cm.value.expected == n\n        assert str(cm.value) == \"18 bytes read on a total of 36 expected bytes\"\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_readexactly_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readexactly(2)\n        assert b\"li\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readexactly(2)\n\n    async def test_unread_data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_data(b\"line2\")\n        stream.feed_data(b\"onemoreline\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(data)\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n\n        data = await stream.read(4)\n        assert b\"line\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"line1line\")\n\n        data = b\"\"\n        while len(data) < 10:\n            data += await stream.read(10)\n        assert b\"line1line2\" == data\n\n        data = await stream.read(7)\n        assert b\"onemore\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(data)\n\n        data = b\"\"\n        while len(data) < 11:\n            data += await stream.read(11)\n        assert b\"onemoreline\" == data\n\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"line\")\n        data = await stream.read(4)\n        assert b\"line\" == data\n\n        stream.feed_eof()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"at_eof\")\n        data = await stream.read(6)\n        assert b\"at_eof\" == data\n\n    async def test_exception(self) -> None:\n        stream = self._make_one()\n        assert stream.exception() is None\n\n        exc = ValueError()\n        stream.set_exception(exc)\n        assert stream.exception() is exc\n\n    async def test_exception_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def set_err():\n            stream.set_exception(ValueError())\n\n        t1 = loop.create_task(stream.readline())\n        t2 = loop.create_task(set_err())\n\n        await asyncio.wait([t1, t2])\n        with pytest.raises(ValueError):\n            t1.result()\n\n    async def test_exception_cancel(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def read_a_line():\n            await stream.readline()\n\n        t = loop.create_task(read_a_line())\n        await asyncio.sleep(0)\n        t.cancel()\n        await asyncio.sleep(0)\n        # The following line fails if set_exception() isn't careful.\n        stream.set_exception(RuntimeError(\"message\"))\n        await asyncio.sleep(0)\n        assert stream._waiter is None\n\n    async def test_readany_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        read_task = loop.create_task(stream.readany())\n        loop.call_soon(stream.feed_data, b\"chunk1\\n\")\n\n        data = await read_task\n        assert b\"chunk1\\n\" == data\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_readany_empty_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_eof()\n        read_task = loop.create_task(stream.readany())\n\n        data = await read_task\n\n        assert b\"\" == data\n\n    async def test_readany_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n\n        data = await stream.readany()\n        assert b\"line\\n\" == data\n\n        stream.set_exception(ValueError())\n        with pytest.raises(ValueError):\n            await stream.readany()\n\n    async def test_read_nowait(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\\nline2\\n\")\n\n        assert stream.read_nowait() == b\"line1\\nline2\\n\"\n        assert stream.read_nowait() == b\"\"\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_nowait_n(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\\nline2\\n\")\n\n        assert stream.read_nowait(4) == b\"line\"\n        assert stream.read_nowait() == b\"1\\nline2\\n\"\n        assert stream.read_nowait() == b\"\"\n        stream.feed_eof()\n        data = await stream.read()\n        assert b\"\" == data\n\n    async def test_read_nowait_exception(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n        stream.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            stream.read_nowait()\n\n    async def test_read_nowait_waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream.feed_data(b\"line\\n\")\n        stream._waiter = loop.create_future()\n\n        with pytest.raises(RuntimeError):\n            stream.read_nowait()\n\n    async def test_readchunk(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        def cb():\n            stream.feed_data(b\"chunk1\")\n            stream.feed_data(b\"chunk2\")\n            stream.feed_eof()\n\n        loop.call_soon(cb)\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"chunk1\" == data\n        assert not end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"chunk2\" == data\n        assert not end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readchunk_wait_eof(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n        assert stream.is_eof()\n\n    async def test_begin_and_end_chunk_receiving(self) -> None:\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part1part2\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part3\" == data\n        assert not end_of_chunk\n\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.feed_eof()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readany_chunk_end_race(self) -> None:\n        stream = self._make_one()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n\n        data = await stream.readany()\n        assert data == b\"part1\"\n\n        loop = asyncio.get_event_loop()\n        task = loop.create_task(stream.readany())\n\n        # Give a chance for task to create waiter and start waiting for it.\n        await asyncio.sleep(0.1)\n        assert stream._waiter is not None\n        assert not task.done()  # Just for sure.\n\n        # This will trigger waiter, but without feeding any data.\n        # The stream should re-create waiter again.\n        stream.end_http_chunk_receiving()\n\n        # Give a chance for task to resolve.\n        # If everything is OK, previous action SHOULD NOT resolve the task.\n        await asyncio.sleep(0.1)\n        assert not task.done()  # The actual test.\n\n        stream.begin_http_chunk_receiving()\n        # This SHOULD unblock the task actually.\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        data = await task\n        assert data == b\"part2\"\n\n    async def test_end_chunk_receiving_without_begin(self) -> None:\n        stream = self._make_one()\n        with pytest.raises(RuntimeError):\n            stream.end_http_chunk_receiving()\n\n    async def test_readchunk_with_unread(self) -> None:\n        # Test that stream.unread does not break controlled chunk receiving.\n        stream = self._make_one()\n\n        # Send 2 chunks\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n\n        # Read only one chunk\n        data, end_of_chunk = await stream.readchunk()\n\n        # Try to unread a part of the first chunk\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"rt1\")\n\n        # The end_of_chunk signal was already received for the first chunk,\n        # so we receive up to the second one\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt1part2\" == data\n        assert end_of_chunk\n\n        # Unread a part of the second chunk\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"rt2\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt2\" == data\n        # end_of_chunk was already received for this chunk\n        assert not end_of_chunk\n\n        stream.feed_eof()\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_readchunk_with_other_read_calls(self) -> None:\n        # Test that stream.readchunk works when other read calls are made on\n        # the stream.\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n        stream.end_http_chunk_receiving()\n\n        data = await stream.read(7)\n        assert b\"part1pa\" == data\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"rt2\" == data\n        assert end_of_chunk\n\n        # Corner case between read/readchunk\n        data = await stream.read(5)\n        assert b\"part3\" == data\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.feed_eof()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test_chunksplits_memory_leak(self) -> None:\n        # Test for memory leak on chunksplits\n        stream = self._make_one()\n\n        N = 500\n\n        # Warm-up variables\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"Y\" * N)\n        stream.end_http_chunk_receiving()\n        await stream.read(N)\n\n        N = 300\n\n        before = get_memory_usage(stream)\n        for _ in range(N):\n            stream.begin_http_chunk_receiving()\n            stream.feed_data(b\"X\")\n            stream.end_http_chunk_receiving()\n        await stream.read(N)\n        after = get_memory_usage(stream)\n\n        assert abs(after - before) == 0\n\n    async def test_read_empty_chunks(self) -> None:\n        # Test that feeding empty chunks does not break stream\n        stream = self._make_one()\n\n        # Simulate empty first chunk. This is significant special case\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"ungzipped\")\n        stream.end_http_chunk_receiving()\n\n        # Possible when compression is enabled.\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        # is also possible\n        stream.begin_http_chunk_receiving()\n        stream.end_http_chunk_receiving()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\" data\")\n        stream.end_http_chunk_receiving()\n\n        stream.feed_eof()\n\n        data = await stream.read()\n        assert data == b\"ungzipped data\"\n\n    async def test_readchunk_separate_http_chunk_tail(self) -> None:\n        # Test that stream.readchunk returns (b'', True) when end of\n        # http chunk received after body\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part1\")\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part1\" == data\n        assert not end_of_chunk\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.end_http_chunk_receiving()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part2\")\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part2\" == data\n        assert not end_of_chunk\n\n        stream.end_http_chunk_receiving()\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part3\")\n        stream.end_http_chunk_receiving()\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part3\" == data\n        assert end_of_chunk\n\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(b\"part4\")\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"part4\" == data\n        assert not end_of_chunk\n\n        async def cb():\n            await asyncio.sleep(0.1)\n            stream.end_http_chunk_receiving()\n            stream.feed_eof()\n\n        loop.create_task(cb())\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert end_of_chunk\n\n        data, end_of_chunk = await stream.readchunk()\n        assert b\"\" == data\n        assert not end_of_chunk\n\n    async def test___repr__(self) -> None:\n        stream = self._make_one()\n        assert \"<StreamReader>\" == repr(stream)\n\n    async def test___repr__nondefault_limit(self) -> None:\n        stream = self._make_one(limit=123)\n        assert \"<StreamReader low=123 high=246>\" == repr(stream)\n\n    async def test___repr__eof(self) -> None:\n        stream = self._make_one()\n        stream.feed_eof()\n        assert \"<StreamReader eof>\" == repr(stream)\n\n    async def test___repr__data(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"data\")\n        assert \"<StreamReader 4 bytes>\" == repr(stream)\n\n    async def test___repr__exception(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one(loop=loop)\n        exc = RuntimeError()\n        stream.set_exception(exc)\n        assert \"<StreamReader e=RuntimeError()>\" == repr(stream)\n\n    async def test___repr__waiter(self) -> None:\n        loop = asyncio.get_event_loop()\n        stream = self._make_one()\n        stream._waiter = loop.create_future()\n        assert Matches(r\"<StreamReader w=<Future pending[\\S ]*>>\") == repr(stream)\n        stream._waiter.set_result(None)\n        await stream._waiter\n        stream._waiter = None\n        assert \"<StreamReader>\" == repr(stream)\n\n    async def test_unread_empty(self) -> None:\n        stream = self._make_one()\n        stream.feed_data(b\"line1\")\n        stream.feed_eof()\n        with pytest.deprecated_call(\n            match=r\"^unread_data\\(\\) is deprecated and will be \"\n            r\"removed in future releases \\(#3260\\)$\",\n        ):\n            stream.unread_data(b\"\")\n\n        data = await stream.read(5)\n        assert b\"line1\" == data\n        assert stream.at_eof()\n\n\nasync def test_empty_stream_reader() -> None:\n    s = streams.EmptyStreamReader()\n    assert str(s) is not None\n    assert s.set_exception(ValueError()) is None\n    assert s.exception() is None\n    assert s.feed_eof() is None\n    assert s.feed_data(b\"data\") is None\n    assert s.at_eof()\n    assert (await s.wait_eof()) is None\n    assert await s.read() == b\"\"\n    assert await s.readline() == b\"\"\n    assert await s.readany() == b\"\"\n    assert await s.readchunk() == (b\"\", True)\n    with pytest.raises(asyncio.IncompleteReadError):\n        await s.readexactly(10)\n    assert s.read_nowait() == b\"\"\n\n\n@pytest.fixture\nasync def buffer(loop):\n    return streams.DataQueue(loop)\n\n\nclass TestDataQueue:\n    def test_is_eof(self, buffer) -> None:\n        assert not buffer.is_eof()\n        buffer.feed_eof()\n        assert buffer.is_eof()\n\n    def test_at_eof(self, buffer) -> None:\n        assert not buffer.at_eof()\n        buffer.feed_eof()\n        assert buffer.at_eof()\n        buffer._buffer.append(object())\n        assert not buffer.at_eof()\n\n    def test_feed_data(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item, 1)\n        assert [(item, 1)] == list(buffer._buffer)\n\n    def test_feed_eof(self, buffer) -> None:\n        buffer.feed_eof()\n        assert buffer._eof\n\n    async def test_read(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        item = object()\n\n        def cb():\n            buffer.feed_data(item, 1)\n\n        loop.call_soon(cb)\n\n        data = await buffer.read()\n        assert item is data\n\n    async def test_read_eof(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n\n        def cb():\n            buffer.feed_eof()\n\n        loop.call_soon(cb)\n\n        with pytest.raises(streams.EofStream):\n            await buffer.read()\n\n    async def test_read_cancelled(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        read_task = loop.create_task(buffer.read())\n        await asyncio.sleep(0)\n        waiter = buffer._waiter\n        assert asyncio.isfuture(waiter)\n\n        read_task.cancel()\n        with pytest.raises(asyncio.CancelledError):\n            await read_task\n        assert waiter.cancelled()\n        assert buffer._waiter is None\n\n        buffer.feed_data(b\"test\", 4)\n        assert buffer._waiter is None\n\n    async def test_read_until_eof(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item, 1)\n        buffer.feed_eof()\n\n        data = await buffer.read()\n        assert data is item\n\n        with pytest.raises(streams.EofStream):\n            await buffer.read()\n\n    async def test_read_exc(self, buffer) -> None:\n        item = object()\n        buffer.feed_data(item)\n        buffer.set_exception(ValueError)\n\n        data = await buffer.read()\n        assert item is data\n\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception(self, buffer) -> None:\n        buffer.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception_with_data(self, buffer) -> None:\n        val = object()\n        buffer.feed_data(val, 1)\n        buffer.set_exception(ValueError())\n\n        assert val is (await buffer.read())\n        with pytest.raises(ValueError):\n            await buffer.read()\n\n    async def test_read_exception_on_wait(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n        read_task = loop.create_task(buffer.read())\n        await asyncio.sleep(0)\n        assert asyncio.isfuture(buffer._waiter)\n\n        buffer.feed_eof()\n        buffer.set_exception(ValueError())\n\n        with pytest.raises(ValueError):\n            await read_task\n\n    def test_exception(self, buffer) -> None:\n        assert buffer.exception() is None\n\n        exc = ValueError()\n        buffer.set_exception(exc)\n        assert buffer.exception() is exc\n\n    async def test_exception_waiter(self, buffer) -> None:\n        loop = asyncio.get_event_loop()\n\n        async def set_err():\n            buffer.set_exception(ValueError())\n\n        t1 = loop.create_task(buffer.read())\n        t2 = loop.create_task(set_err())\n\n        await asyncio.wait([t1, t2])\n\n        with pytest.raises(ValueError):\n            t1.result()\n\n\nasync def test_feed_data_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    reader.feed_data(b\"1\")\n    assert list(reader._buffer) == [b\"1\"]\n    assert reader._size == 1\n    assert reader.total_bytes == 1\n\n    assert waiter.done()\n    assert not eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is eof_waiter\n\n\nasync def test_feed_data_completed_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n\n    waiter.set_result(1)\n    reader.feed_data(b\"1\")\n\n    assert reader._waiter is None\n\n\nasync def test_feed_eof_waiters(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    reader.feed_eof()\n    assert reader._eof\n\n    assert waiter.done()\n    assert eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_feed_eof_cancelled(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    waiter.set_result(1)\n    eof_waiter.set_result(1)\n\n    reader.feed_eof()\n\n    assert waiter.done()\n    assert eof_waiter.done()\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_on_eof(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    assert not on_eof.called\n    reader.feed_eof()\n    assert on_eof.called\n\n\nasync def test_on_eof_empty_reader() -> None:\n    reader = streams.EmptyStreamReader()\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    assert on_eof.called\n\n\nasync def test_on_eof_exc_in_callback(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert not on_eof.called\n    reader.feed_eof()\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_on_eof_exc_in_callback_empty_stream_reader() -> None:\n    reader = streams.EmptyStreamReader()\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert on_eof.called\n\n\nasync def test_on_eof_eof_is_set(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    reader.feed_eof()\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_on_eof_eof_is_set_exception(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    reader.feed_eof()\n\n    on_eof = mock.Mock()\n    on_eof.side_effect = ValueError\n\n    reader.on_eof(on_eof)\n    assert on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_set_exception(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    exc = ValueError()\n    reader.set_exception(exc)\n\n    assert waiter.exception() is exc\n    assert eof_waiter.exception() is exc\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_set_exception_cancelled(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n    waiter = reader._waiter = loop.create_future()\n    eof_waiter = reader._eof_waiter = loop.create_future()\n\n    waiter.set_result(1)\n    eof_waiter.set_result(1)\n\n    exc = ValueError()\n    reader.set_exception(exc)\n\n    assert waiter.exception() is None\n    assert eof_waiter.exception() is None\n    assert reader._waiter is None\n    assert reader._eof_waiter is None\n\n\nasync def test_set_exception_eof_callbacks(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    reader = streams.StreamReader(protocol, 2**16, loop=loop)\n\n    on_eof = mock.Mock()\n    reader.on_eof(on_eof)\n\n    reader.set_exception(ValueError())\n    assert not on_eof.called\n    assert not reader._eof_callbacks\n\n\nasync def test_stream_reader_lines() -> None:\n    line_iter = iter(DATA.splitlines(keepends=True))\n    async for line in await create_stream():\n        assert line == next(line_iter, None)\n    pytest.raises(StopIteration, next, line_iter)\n\n\nasync def test_stream_reader_chunks_complete() -> None:\n    # Tests if chunked iteration works if the chunking works out\n    # (i.e. the data is divisible by the chunk size)\n    chunk_iter = chunkify(DATA, 9)\n    async for data in (await create_stream()).iter_chunked(9):\n        assert data == next(chunk_iter, None)\n    pytest.raises(StopIteration, next, chunk_iter)\n\n\nasync def test_stream_reader_chunks_incomplete() -> None:\n    # Tests if chunked iteration works if the last chunk is incomplete\n    chunk_iter = chunkify(DATA, 8)\n    async for data in (await create_stream()).iter_chunked(8):\n        assert data == next(chunk_iter, None)\n    pytest.raises(StopIteration, next, chunk_iter)\n\n\nasync def test_data_queue_empty() -> None:\n    # Tests that async looping yields nothing if nothing is there\n    loop = asyncio.get_event_loop()\n    buffer = streams.DataQueue(loop)\n    buffer.feed_eof()\n\n    async for _ in buffer:\n        assert False\n\n\nasync def test_data_queue_items() -> None:\n    # Tests that async looping yields objects identically\n    loop = asyncio.get_event_loop()\n    buffer = streams.DataQueue(loop)\n\n    items = [object(), object()]\n    buffer.feed_data(items[0], 1)\n    buffer.feed_data(items[1], 1)\n    buffer.feed_eof()\n\n    item_iter = iter(items)\n    async for item in buffer:\n        assert item is next(item_iter, None)\n    pytest.raises(StopIteration, next, item_iter)\n\n\nasync def test_stream_reader_iter_any() -> None:\n    it = iter([b\"line1\\nline2\\nline3\\n\"])\n    async for raw in (await create_stream()).iter_any():\n        assert raw == next(it)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter() -> None:\n    it = iter([b\"line1\\n\", b\"line2\\n\", b\"line3\\n\"])\n    async for raw in await create_stream():\n        assert raw == next(it)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter_chunks_no_chunked_encoding() -> None:\n    it = iter([b\"line1\\nline2\\nline3\\n\"])\n    async for data, end_of_chunk in (await create_stream()).iter_chunks():\n        assert (data, end_of_chunk) == (next(it), False)\n    pytest.raises(StopIteration, next, it)\n\n\nasync def test_stream_reader_iter_chunks_chunked_encoding(protocol) -> None:\n    loop = asyncio.get_event_loop()\n    stream = streams.StreamReader(protocol, 2**16, loop=loop)\n    for line in DATA.splitlines(keepends=True):\n        stream.begin_http_chunk_receiving()\n        stream.feed_data(line)\n        stream.end_http_chunk_receiving()\n    stream.feed_eof()\n\n    it = iter([b\"line1\\n\", b\"line2\\n\", b\"line3\\n\"])\n    async for data, end_of_chunk in stream.iter_chunks():\n        assert (data, end_of_chunk) == (next(it), True)\n    pytest.raises(StopIteration, next, it)\n\n\ndef test_isinstance_check() -> None:\n    assert isinstance(streams.EMPTY_PAYLOAD, streams.StreamReader)\n",
        "import asyncio\nimport os\nimport socket\nimport ssl\nimport sys\nfrom hashlib import md5, sha256\nfrom pathlib import Path\nfrom tempfile import TemporaryDirectory\nfrom uuid import uuid4\n\nimport pytest\n\nfrom aiohttp.test_utils import loop_context\n\ntry:\n    import trustme\n\n    # Check if the CA is available in runtime, MacOS on Py3.10 fails somehow\n    trustme.CA()\n\n    TRUSTME: bool = True\nexcept ImportError:\n    TRUSTME = False\n\npytest_plugins = [\"aiohttp.pytest_plugin\", \"pytester\"]\n\n\nIS_HPUX = sys.platform.startswith(\"hp-ux\")\n\"\"\"Specifies whether the current runtime is HP-UX.\"\"\"\nIS_LINUX = sys.platform.startswith(\"linux\")\n\"\"\"Specifies whether the current runtime is HP-UX.\"\"\"\nIS_UNIX = hasattr(socket, \"AF_UNIX\")\n\"\"\"Specifies whether the current runtime is *NIX.\"\"\"\n\nneeds_unix = pytest.mark.skipif(not IS_UNIX, reason=\"requires UNIX sockets\")\n\n\n@pytest.fixture\ndef tls_certificate_authority():\n    if not TRUSTME:\n        pytest.xfail(\"trustme is not supported\")\n    return trustme.CA()\n\n\n@pytest.fixture\ndef tls_certificate(tls_certificate_authority):\n    return tls_certificate_authority.issue_cert(\n        \"localhost\",\n        \"127.0.0.1\",\n        \"::1\",\n    )\n\n\n@pytest.fixture\ndef ssl_ctx(tls_certificate):\n    ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)\n    tls_certificate.configure_cert(ssl_ctx)\n    return ssl_ctx\n\n\n@pytest.fixture\ndef client_ssl_ctx(tls_certificate_authority):\n    ssl_ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)\n    tls_certificate_authority.configure_trust(ssl_ctx)\n    return ssl_ctx\n\n\n@pytest.fixture\ndef tls_ca_certificate_pem_path(tls_certificate_authority):\n    with tls_certificate_authority.cert_pem.tempfile() as ca_cert_pem:\n        yield ca_cert_pem\n\n\n@pytest.fixture\ndef tls_certificate_pem_path(tls_certificate):\n    with tls_certificate.private_key_and_cert_chain_pem.tempfile() as cert_pem:\n        yield cert_pem\n\n\n@pytest.fixture\ndef tls_certificate_pem_bytes(tls_certificate):\n    return tls_certificate.cert_chain_pems[0].bytes()\n\n\n@pytest.fixture\ndef tls_certificate_fingerprint_sha256(tls_certificate_pem_bytes):\n    tls_cert_der = ssl.PEM_cert_to_DER_cert(tls_certificate_pem_bytes.decode())\n    return sha256(tls_cert_der).digest()\n\n\n@pytest.fixture\ndef unix_sockname(tmp_path, tmp_path_factory):\n    \"\"\"Generate an fs path to the UNIX domain socket for testing.\n\n    N.B. Different OS kernels have different fs path length limitations\n    for it. For Linux, it's 108, for HP-UX it's 92 (or higher) depending\n    on its version. For for most of the BSDs (Open, Free, macOS) it's\n    mostly 104 but sometimes it can be down to 100.\n\n    Ref: https://github.com/aio-libs/aiohttp/issues/3572\n    \"\"\"\n    if not IS_UNIX:\n        pytest.skip(\"requires UNIX sockets\")\n\n    max_sock_len = 92 if IS_HPUX else 108 if IS_LINUX else 100\n    \"\"\"Amount of bytes allocated for the UNIX socket path by OS kernel.\n\n    Ref: https://unix.stackexchange.com/a/367012/27133\n    \"\"\"\n\n    sock_file_name = \"unix.sock\"\n    unique_prefix = f\"{uuid4()!s}-\"\n    unique_prefix_len = len(unique_prefix.encode())\n\n    root_tmp_dir = Path(\"/tmp\").resolve()\n    os_tmp_dir = Path(os.getenv(\"TMPDIR\", \"/tmp\")).resolve()\n    original_base_tmp_path = Path(\n        str(tmp_path_factory.getbasetemp()),\n    ).resolve()\n\n    original_base_tmp_path_hash = md5(\n        str(original_base_tmp_path).encode(),\n    ).hexdigest()\n\n    def make_tmp_dir(base_tmp_dir):\n        return TemporaryDirectory(\n            dir=str(base_tmp_dir),\n            prefix=\"pt-\",\n            suffix=f\"-{original_base_tmp_path_hash!s}\",\n        )\n\n    def assert_sock_fits(sock_path):\n        sock_path_len = len(sock_path.encode())\n        # exit-check to verify that it's correct and simplify debugging\n        # in the future\n        assert sock_path_len <= max_sock_len, (\n            \"Suggested UNIX socket ({sock_path}) is {sock_path_len} bytes \"\n            \"long but the current kernel only has {max_sock_len} bytes \"\n            \"allocated to hold it so it must be shorter. \"\n            \"See https://github.com/aio-libs/aiohttp/issues/3572 \"\n            \"for more info.\"\n        ).format_map(locals())\n\n    paths = original_base_tmp_path, os_tmp_dir, root_tmp_dir\n    unique_paths = [p for n, p in enumerate(paths) if p not in paths[:n]]\n    paths_num = len(unique_paths)\n\n    for num, tmp_dir_path in enumerate(paths, 1):\n        with make_tmp_dir(tmp_dir_path) as tmpd:\n            tmpd = Path(tmpd).resolve()\n            sock_path = str(tmpd / sock_file_name)\n            sock_path_len = len(sock_path.encode())\n\n            if num >= paths_num:\n                # exit-check to verify that it's correct and simplify\n                # debugging in the future\n                assert_sock_fits(sock_path)\n\n            if sock_path_len <= max_sock_len:\n                if max_sock_len - sock_path_len >= unique_prefix_len:\n                    # If we're lucky to have extra space in the path,\n                    # let's also make it more unique\n                    sock_path = str(tmpd / \"\".join((unique_prefix, sock_file_name)))\n                    # Double-checking it:\n                    assert_sock_fits(sock_path)\n                yield sock_path\n                return\n\n\n@pytest.fixture\ndef pipe_name():\n    name = rf\"\\\\.\\pipe\\{uuid4().hex}\"\n    return name\n\n\n@pytest.fixture\ndef selector_loop():\n    if sys.version_info >= (3, 8):\n        policy = asyncio.WindowsSelectorEventLoopPolicy()\n    else:\n        policy = asyncio.DefaultEventLoopPolicy()\n    asyncio.set_event_loop_policy(policy)\n\n    with loop_context(policy.new_event_loop) as _loop:\n        asyncio.set_event_loop(_loop)\n        yield _loop\n"
    ],
    "test_file_names": [
        "test_1.py",
        "conftest.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "re-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/requirements/cython.txt\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/tools/gen.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/hdrs.py\n./tools/gen.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_helpers.pyx\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_http_parser.pyx\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_http_writer.pyx\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_websocket.pyx\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_helpers.pyi\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_cparser.pxd\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/_find_header.pxd\ncython -3 -o aiohttp/_helpers.c aiohttp/_helpers.pyx -I aiohttp\ncython -3 -o aiohttp/_http_parser.c aiohttp/_http_parser.pyx -I aiohttp\ncython -3 -o aiohttp/_http_writer.c aiohttp/_http_writer.pyx -I aiohttp\ncython -3 -o aiohttp/_websocket.c aiohttp/_websocket.pyx -I aiohttp\ncd vendor/llhttp; npm install\n\n> llhttp@6.0.6 prepare\n> npm run clean && npm run build-ts\n\n\n> llhttp@6.0.6 clean\n> rm -rf lib && rm -rf test/tmp\n\n\n> llhttp@6.0.6 build-ts\n> tsc\n\n\nadded 185 packages, and audited 186 packages in 4s\n\n29 packages are looking for funding\n  run `npm fund` for details\n\n12 vulnerabilities (1 low, 3 moderate, 4 high, 4 critical)\n\nTo address issues that do not require attention, run:\n  npm audit fix\n\nTo address all issues possible (including breaking changes), run:\n  npm audit fix --force\n\nSome issues need review, and may require choosing\na different dependency.\n\nRun `npm audit` for details.\nmake -C vendor/llhttp generate\nmake[1]: Entering directory '/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/vendor/llhttp'\nnpx ts-node bin/generate.ts\nmake[1]: Leaving directory '/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/vendor/llhttp'\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/__init__.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/abc.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/base_protocol.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/client.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/client_exceptions.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/client_proto.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/client_reqrep.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/client_ws.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/connector.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/cookiejar.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/formdata.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/helpers.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/http.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/http_exceptions.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/http_parser.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/http_websocket.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/http_writer.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/locks.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/log.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/multipart.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/payload.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/payload_streamer.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/pytest_plugin.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/resolver.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/tcp_helpers.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/test_utils.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/tracing.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/typedefs.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_app.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_exceptions.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_fileresponse.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_log.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_middlewares.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_protocol.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_request.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_response.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_routedef.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_runner.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_server.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_urldispatcher.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/web_ws.py\nre-hash /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/worker.py\nuv pip install -e . -c requirements/constraints.txt\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 1 package in 41ms\nPrepared 1 package in 0.34ms\nInstalled 1 package in 44ms\n + pip==24.3.1\nResolved 3 packages in 10ms\nInstalled 3 packages in 11ms\n + cython==0.29.32\n + multidict==5.2.0\n + typing-extensions==4.1.1\nResolved 97 packages in 87ms\nUninstalled 1 package in 4ms\nInstalled 95 packages in 79ms\n + aiodns==3.0.0\n + aiohttp-theme==0.1.6\n + aioredis==2.0.1\n + aiosignal==1.2.0\n + alabaster==0.7.12\n + async-generator==1.10\n + async-timeout==4.0.2\n + attrs==21.4.0\n + babel==2.9.1\n + backports-entry-points-selectable==1.1.1\n + blockdiag==2.0.1\n + brotli==1.0.9\n + cchardet==2.1.7\n + certifi==2021.10.8\n + cffi==1.15.0\n + cfgv==3.3.1\n + charset-normalizer==2.0.12\n + cherry-picker==2.1.0\n + click==8.0.3\n + click-default-group==1.2.2\n + coverage==6.4.2\n + cryptography==36.0.1\n + distlib==0.3.3\n + docutils==0.17.1\n + filelock==3.3.2\n + freezegun==1.1.0\n + frozenlist==1.3.1\n + funcparserlib==1.0.0a0\n + gidgethub==5.0.1\n + gunicorn==20.1.0\n + identify==2.3.5\n + idna==3.3\n + imagesize==1.3.0\n + importlib-metadata==5.0.0\n + incremental==21.3.0\n + iniconfig==1.1.1\n + jinja2==3.0.3\n + markupsafe==2.0.1\n + mypy==0.982\n + mypy-extensions==0.4.3\n + nodeenv==1.6.0\n + packaging==21.2\n + pep517==0.12.0\n + pillow==9.2.0\n - pip==24.3.1\n + pip==21.3.1\n + pip-tools==6.4.0\n + platformdirs==2.4.0\n + pluggy==1.0.0\n + pre-commit==2.17.0\n + proxy-py==2.4.4rc3\n + py==1.11.0\n + pycares==4.1.2\n + pycparser==2.21\n + pydantic==1.8.2\n + pygments==2.11.2\n + pyjwt==2.3.0\n + pyparsing==2.4.7\n + pytest==7.1.3\n + pytest-cov==3.0.0\n + pytest-mock==3.6.1\n + python-dateutil==2.8.2\n + python-on-whales==0.36.1\n + pytz==2021.3\n + pyyaml==6.0\n + re-assert==1.1.0\n + regex==2021.11.10\n + requests==2.26.0\n + setuptools==59.1.0\n + setuptools-git==1.2\n + six==1.16.0\n + snowballstemmer==2.1.0\n + sphinx==5.1.1\n + sphinxcontrib-applehelp==1.0.2\n + sphinxcontrib-asyncio==0.3.0\n + sphinxcontrib-blockdiag==3.0.0\n + sphinxcontrib-devhelp==1.0.2\n + sphinxcontrib-htmlhelp==2.0.0\n + sphinxcontrib-jsmath==1.0.1\n + sphinxcontrib-qthelp==1.0.3\n + sphinxcontrib-serializinghtml==1.1.5\n + sphinxcontrib-towncrier==0.3.0a0\n + toml==0.10.2\n + tomli==1.2.2\n + towncrier==22.8.0\n + tqdm==4.62.3\n + trustme==0.9.0\n + typer==0.4.0\n + uritemplate==4.1.1\n + urllib3==1.26.7\n + virtualenv==20.10.0\n + wait-for-it==2.2.1\n + webcolors==1.11.1\n + wheel==0.37.0\n + yarl==1.8.1\n + zipp==3.10.0\nwarning: `setuptools==59.1.0` is yanked (reason: \"https://github.com/pypa/setuptools/issues/2885\")\nnpm warn deprecated debug@3.2.6: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)\nResolved 9 packages in 1.48s\nPrepared 1 package in 11.95s\nInstalled 1 package in 0.52ms\n + aiohttp==3.9.0.dev0 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b)\nResolved 27 packages in 15ms\nInstalled 4 packages in 5ms\n + brotlipy==0.7.0\n + chardet==5.2.0\n + multdict==0.0.5\n + pytest-asyncio==0.23.8\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.9.21, pytest-7.1.3, pluggy-1.0.0 -- /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/.venv/bin/python\ncachedir: .pytest_cache\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b, configfile: setup.cfg\nplugins: mock-3.6.1, cov-3.0.0, asyncio-0.23.8\nasyncio: mode=strict\ncollecting ... collected 111 items\n\nr2e_tests/test_1.py::TestStreamReader::test_create_waiter PASSED         [  0%]\nr2e_tests/test_1.py::TestStreamReader::test_ctor_global_loop PASSED      [  1%]\nr2e_tests/test_1.py::TestStreamReader::test_at_eof PASSED                [  2%]\nr2e_tests/test_1.py::TestStreamReader::test_wait_eof PASSED              [  3%]\nr2e_tests/test_1.py::TestStreamReader::test_wait_eof_eof PASSED          [  4%]\nr2e_tests/test_1.py::TestStreamReader::test_feed_empty_data PASSED       [  5%]\nr2e_tests/test_1.py::TestStreamReader::test_feed_nonempty_data PASSED    [  6%]\nr2e_tests/test_1.py::TestStreamReader::test_read_zero PASSED             [  7%]\nr2e_tests/test_1.py::TestStreamReader::test_read PASSED                  [  8%]\nr2e_tests/test_1.py::TestStreamReader::test_read_line_breaks PASSED      [  9%]\nr2e_tests/test_1.py::TestStreamReader::test_read_all PASSED              [  9%]\nr2e_tests/test_1.py::TestStreamReader::test_read_up_to PASSED            [ 10%]\nr2e_tests/test_1.py::TestStreamReader::test_read_eof PASSED              [ 11%]\nr2e_tests/test_1.py::TestStreamReader::test_read_eof_infinite PASSED     [ 12%]\nr2e_tests/test_1.py::TestStreamReader::test_read_eof_unread_data_no_warning PASSED [ 13%]\nr2e_tests/test_1.py::TestStreamReader::test_read_until_eof PASSED        [ 14%]\nr2e_tests/test_1.py::TestStreamReader::test_read_exception PASSED        [ 15%]\nr2e_tests/test_1.py::TestStreamReader::test_readline PASSED              [ 16%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_limit_with_existing_data PASSED [ 17%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_limit PASSED        [ 18%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_nolimit_nowait PASSED [ 18%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_eof PASSED          [ 19%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_empty_eof PASSED    [ 20%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_read_byte_count PASSED [ 21%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_exception PASSED    [ 22%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil[*] PASSED          [ 23%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil[**] PASSED         [ 24%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&] PASSED [ 25%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&&] PASSED [ 26%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$] PASSED    [ 27%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$$] PASSED   [ 27%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!] PASSED [ 28%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!!] PASSED [ 29%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@] PASSED      [ 30%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@@] PASSED     [ 31%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@] PASSED [ 32%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@@] PASSED [ 33%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!] PASSED [ 34%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!!] PASSED [ 35%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[#] PASSED [ 36%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[##] PASSED [ 36%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly_zero_or_less PASSED [ 37%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly PASSED           [ 38%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly_eof PASSED       [ 39%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly_exception PASSED [ 40%]\nr2e_tests/test_1.py::TestStreamReader::test_unread_data PASSED           [ 41%]\nr2e_tests/test_1.py::TestStreamReader::test_exception PASSED             [ 42%]\nr2e_tests/test_1.py::TestStreamReader::test_exception_waiter PASSED      [ 43%]\nr2e_tests/test_1.py::TestStreamReader::test_exception_cancel PASSED      [ 44%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_eof PASSED           [ 45%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_empty_eof PASSED     [ 45%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_exception PASSED     [ 46%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait PASSED           [ 47%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait_n PASSED         [ 48%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait_exception PASSED [ 49%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait_waiter PASSED    [ 50%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk PASSED             [ 51%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_wait_eof PASSED    [ 52%]\nr2e_tests/test_1.py::TestStreamReader::test_begin_and_end_chunk_receiving PASSED [ 53%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_chunk_end_race PASSED [ 54%]\nr2e_tests/test_1.py::TestStreamReader::test_end_chunk_receiving_without_begin PASSED [ 54%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_with_unread PASSED [ 55%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_with_other_read_calls PASSED [ 56%]\nr2e_tests/test_1.py::TestStreamReader::test_chunksplits_memory_leak PASSED [ 57%]\nr2e_tests/test_1.py::TestStreamReader::test_read_empty_chunks PASSED     [ 58%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_separate_http_chunk_tail PASSED [ 59%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__ PASSED              [ 60%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__nondefault_limit PASSED [ 61%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__eof PASSED           [ 62%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__data PASSED          [ 63%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__exception PASSED     [ 63%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__waiter PASSED        [ 64%]\nr2e_tests/test_1.py::TestStreamReader::test_unread_empty PASSED          [ 65%]\nr2e_tests/test_1.py::test_empty_stream_reader PASSED                     [ 66%]\nr2e_tests/test_1.py::TestDataQueue::test_is_eof[pyloop] PASSED           [ 67%]\nr2e_tests/test_1.py::TestDataQueue::test_at_eof[pyloop] PASSED           [ 68%]\nr2e_tests/test_1.py::TestDataQueue::test_feed_data[pyloop] PASSED        [ 69%]\nr2e_tests/test_1.py::TestDataQueue::test_feed_eof[pyloop] PASSED         [ 70%]\nr2e_tests/test_1.py::TestDataQueue::test_read[pyloop] PASSED             [ 71%]\nr2e_tests/test_1.py::TestDataQueue::test_read_eof[pyloop] PASSED         [ 72%]\nr2e_tests/test_1.py::TestDataQueue::test_read_cancelled[pyloop] PASSED   [ 72%]\nr2e_tests/test_1.py::TestDataQueue::test_read_until_eof[pyloop] PASSED   [ 73%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exc[pyloop] PASSED         [ 74%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exception[pyloop] PASSED   [ 75%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exception_with_data[pyloop] PASSED [ 76%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exception_on_wait[pyloop] PASSED [ 77%]\nr2e_tests/test_1.py::TestDataQueue::test_exception[pyloop] PASSED        [ 78%]\nr2e_tests/test_1.py::TestDataQueue::test_exception_waiter[pyloop] PASSED [ 79%]\nr2e_tests/test_1.py::test_feed_data_waiters PASSED                       [ 80%]\nr2e_tests/test_1.py::test_feed_data_completed_waiters PASSED             [ 81%]\nr2e_tests/test_1.py::test_feed_eof_waiters PASSED                        [ 81%]\nr2e_tests/test_1.py::test_feed_eof_cancelled PASSED                      [ 82%]\nr2e_tests/test_1.py::test_on_eof PASSED                                  [ 83%]\nr2e_tests/test_1.py::test_on_eof_empty_reader PASSED                     [ 84%]\nr2e_tests/test_1.py::test_on_eof_exc_in_callback PASSED                  [ 85%]\nr2e_tests/test_1.py::test_on_eof_exc_in_callback_empty_stream_reader PASSED [ 86%]\nr2e_tests/test_1.py::test_on_eof_eof_is_set PASSED                       [ 87%]\nr2e_tests/test_1.py::test_on_eof_eof_is_set_exception PASSED             [ 88%]\nr2e_tests/test_1.py::test_set_exception PASSED                           [ 89%]\nr2e_tests/test_1.py::test_set_exception_cancelled PASSED                 [ 90%]\nr2e_tests/test_1.py::test_set_exception_eof_callbacks PASSED             [ 90%]\nr2e_tests/test_1.py::test_stream_reader_lines PASSED                     [ 91%]\nr2e_tests/test_1.py::test_stream_reader_chunks_complete PASSED           [ 92%]\nr2e_tests/test_1.py::test_stream_reader_chunks_incomplete PASSED         [ 93%]\nr2e_tests/test_1.py::test_data_queue_empty PASSED                        [ 94%]\nr2e_tests/test_1.py::test_data_queue_items PASSED                        [ 95%]\nr2e_tests/test_1.py::test_stream_reader_iter_any PASSED                  [ 96%]\nr2e_tests/test_1.py::test_stream_reader_iter PASSED                      [ 97%]\nr2e_tests/test_1.py::test_stream_reader_iter_chunks_no_chunked_encoding PASSED [ 98%]\nr2e_tests/test_1.py::test_stream_reader_iter_chunks_chunked_encoding PASSED [ 99%]\nr2e_tests/test_1.py::test_isinstance_check PASSED                        [100%]\n\n==================================== PASSES ====================================\n_________________________ test_on_eof_exc_in_callback __________________________\n------------------------------ Captured log call -------------------------------\nERROR    aiohttp.internal:streams.py:182 Exception in eof callback\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\", line 180, in feed_eof\n    cb()\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1092, in __call__\n    return self._mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1096, in _mock_call\n    return self._execute_mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1151, in _execute_mock_call\n    raise effect\nValueError\n_______________ test_on_eof_exc_in_callback_empty_stream_reader ________________\n------------------------------ Captured log call -------------------------------\nERROR    aiohttp.internal:streams.py:518 Exception in eof callback\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\", line 516, in on_eof\n    callback()\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1092, in __call__\n    return self._mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1096, in _mock_call\n    return self._execute_mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1151, in _execute_mock_call\n    raise effect\nValueError\n_______________________ test_on_eof_eof_is_set_exception _______________________\n------------------------------ Captured log call -------------------------------\nERROR    aiohttp.internal:streams.py:161 Exception in eof callback\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\", line 159, in on_eof\n    callback()\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1092, in __call__\n    return self._mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1096, in _mock_call\n    return self._execute_mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1151, in _execute_mock_call\n    raise effect\nValueError\n\n---------- coverage: platform linux, python 3.9.21-final-0 -----------\nName                                     Stmts   Miss Branch BrPart  Cover\n--------------------------------------------------------------------------\naiohttp/__init__.py                         29     11      4      1    58%\naiohttp/abc.py                              90      8     12      0    92%\naiohttp/base_protocol.py                    65     52     24      0    17%\naiohttp/client.py                          482    361    184      1    20%\naiohttp/client_exceptions.py               135     61     56      0    60%\naiohttp/client_proto.py                    148    120     56      0    15%\naiohttp/client_reqrep.py                   645    485    286      0    18%\naiohttp/client_ws.py                       206    166     66      0    15%\naiohttp/connector.py                       711    588    327      0    13%\naiohttp/cookiejar.py                       256    207    120      0    14%\naiohttp/formdata.py                         93     76     48      0    13%\naiohttp/hdrs.py                             94      1      2      1    98%\naiohttp/helpers.py                         510    316    198      4    33%\naiohttp/http.py                             11      0      2      0   100%\naiohttp/http_exceptions.py                  49     20     28      0    66%\naiohttp/http_parser.py                     482    393    200      1    16%\naiohttp/http_websocket.py                  383    284    168      0    21%\naiohttp/http_writer.py                     119     83     54      1    24%\naiohttp/locks.py                            24     16      6      0    33%\naiohttp/log.py                               7      0      0      0   100%\naiohttp/multipart.py                       564    458    248      0    15%\naiohttp/payload.py                         221    109     86      1    47%\naiohttp/payload_streamer.py                 29     10      8      0    73%\naiohttp/pytest_plugin.py                   168     66     44      7    59%\naiohttp/resolver.py                         68     48     26      0    26%\naiohttp/streams.py                         395     20    160      6    94%\naiohttp/tcp_helpers.py                      19     11      6      0    32%\naiohttp/test_utils.py                      333    202     70      4    36%\naiohttp/tracing.py                         191     69     36      0    70%\naiohttp/typedefs.py                         27      1      2      1    93%\naiohttp/web.py                             118     84     54      0    21%\naiohttp/web_app.py                         301    196     78      0    29%\naiohttp/web_exceptions.py                  151     22    122      0    90%\naiohttp/web_fileresponse.py                143    120     54      0    13%\naiohttp/web_log.py                          98     55     20      0    38%\naiohttp/web_middlewares.py                  55     42     20      0    17%\naiohttp/web_protocol.py                    340    280    161      0    14%\naiohttp/web_request.py                     435    285    132      1    28%\naiohttp/web_response.py                    486    371    218      1    17%\naiohttp/web_routedef.py                    106     46     14      0    57%\naiohttp/web_runner.py                      210    128     52      0    38%\naiohttp/web_server.py                       37     19      8      0    44%\naiohttp/web_urldispatcher.py               710    453    205      0    33%\naiohttp/web_ws.py                          316    254    108      0    16%\naiohttp/worker.py                          129    129     36      0     0%\ntests/conftest.py                          101    101     16      0     0%\ntests/test_base_protocol.py                152    152      2      0     0%\ntests/test_circular_imports.py              31     31     15      0     0%\ntests/test_classbasedview.py                39     39      6      0     0%\ntests/test_client_connection.py             94     94      2      0     0%\ntests/test_client_exceptions.py            183    183     26      0     0%\ntests/test_client_fingerprint.py            59     59      0      0     0%\ntests/test_client_functional.py           2094   2094     76      0     0%\ntests/test_client_proto.py                  88     88      0      0     0%\ntests/test_client_request.py               755    755     24      0     0%\ntests/test_client_response.py              469    469      2      0     0%\ntests/test_client_session.py               496    496     33      0     0%\ntests/test_client_ws.py                    415    415      4      0     0%\ntests/test_client_ws_functional.py         585    585     14      0     0%\ntests/test_connector.py                   1509   1509     86      0     0%\ntests/test_cookiejar.py                    325    325     26      0     0%\ntests/test_flowcontrol_streams.py          100    100      4      0     0%\ntests/test_formdata.py                      72     72      6      0     0%\ntests/test_helpers.py                      403    403     30      0     0%\ntests/test_http_exceptions.py              107    107     20      0     0%\ntests/test_http_parser.py                  766    766     40      0     0%\ntests/test_http_writer.py                  176    176     10      0     0%\ntests/test_imports.py                       31     31      6      0     0%\ntests/test_locks.py                         39     39      2      0     0%\ntests/test_loop.py                          39     39      2      0     0%\ntests/test_multipart.py                    754    754     42      0     0%\ntests/test_multipart_helpers.py            446    446      4      0     0%\ntests/test_payload.py                       94     94      6      0     0%\ntests/test_proxy.py                        266    266      2      0     0%\ntests/test_proxy_functional.py             487    487     22      0     0%\ntests/test_pytest_plugin.py                 30     30      0      0     0%\ntests/test_resolver.py                     176    176     16      0     0%\ntests/test_route_def.py                    210    210      0      0     0%\ntests/test_run_app.py                      337    337     24      0     0%\ntests/test_streams.py                     1073   1073     44      0     0%\ntests/test_tcp_helpers.py                   52     52      2      0     0%\ntests/test_test_utils.py                   242    242      8      0     0%\ntests/test_tracing.py                       48     48      4      0     0%\ntests/test_urldispatch.py                  844    844     24      0     0%\ntests/test_web_app.py                      455    455     12      0     0%\ntests/test_web_cli.py                       75     75      0      0     0%\ntests/test_web_exceptions.py               156    156     22      0     0%\ntests/test_web_functional.py              1520   1520     38      0     0%\ntests/test_web_log.py                      110    110      6      0     0%\ntests/test_web_middleware.py               266    266     18      0     0%\ntests/test_web_request.py                  490    490      8      0     0%\ntests/test_web_request_handler.py           40     40      0      0     0%\ntests/test_web_response.py                 818    818      6      0     0%\ntests/test_web_runner.py                   148    148      4      0     0%\ntests/test_web_sendfile.py                  84     84      0      0     0%\ntests/test_web_sendfile_functional.py      634    634     18      0     0%\ntests/test_web_server.py                   110    110      0      0     0%\ntests/test_web_urldispatcher.py            307    307     22      0     0%\ntests/test_web_websocket.py                304    304      4      0     0%\ntests/test_web_websocket_functional.py     542    542     16      0     0%\ntests/test_websocket_handshake.py          152    152     12      0     0%\ntests/test_websocket_parser.py             300    300     14      0     0%\ntests/test_websocket_writer.py              68     68      0      0     0%\ntests/test_worker.py                       197    197     10      0     0%\n--------------------------------------------------------------------------\nTOTAL                                    31152  27689   4669     30    12%\n\n============================= slowest 10 durations =============================\n0.22s call     r2e_tests/test_1.py::TestStreamReader::test_readany_chunk_end_race\n0.22s call     r2e_tests/test_1.py::TestStreamReader::test_readchunk_separate_http_chunk_tail\n0.12s call     r2e_tests/test_1.py::TestStreamReader::test_readchunk_wait_eof\n0.12s call     r2e_tests/test_1.py::TestStreamReader::test_wait_eof\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_end_chunk_receiving_without_begin\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_create_waiter\n0.02s call     r2e_tests/test_1.py::test_stream_reader_chunks_complete\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_chunksplits_memory_leak\n0.02s call     r2e_tests/test_1.py::test_stream_reader_lines\n0.02s call     r2e_tests/test_1.py::test_stream_reader_iter\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::TestStreamReader::test_create_waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_ctor_global_loop\nPASSED r2e_tests/test_1.py::TestStreamReader::test_at_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_wait_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_wait_eof_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_feed_empty_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_feed_nonempty_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_zero\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_line_breaks\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_all\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_up_to\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_eof_infinite\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_eof_unread_data_no_warning\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_until_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_limit_with_existing_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_limit\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_nolimit_nowait\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_empty_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_read_byte_count\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil[*]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil[**]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&&]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$$]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[#]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[##]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly_zero_or_less\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_unread_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_exception_waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_exception_cancel\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_empty_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait_n\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait_waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_wait_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_begin_and_end_chunk_receiving\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_chunk_end_race\nPASSED r2e_tests/test_1.py::TestStreamReader::test_end_chunk_receiving_without_begin\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_with_unread\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_with_other_read_calls\nPASSED r2e_tests/test_1.py::TestStreamReader::test_chunksplits_memory_leak\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_empty_chunks\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_separate_http_chunk_tail\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__nondefault_limit\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__data\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_unread_empty\nPASSED r2e_tests/test_1.py::test_empty_stream_reader\nPASSED r2e_tests/test_1.py::TestDataQueue::test_is_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_at_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_feed_data[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_feed_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_cancelled[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_until_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exc[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exception[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exception_with_data[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exception_on_wait[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_exception[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_exception_waiter[pyloop]\nPASSED r2e_tests/test_1.py::test_feed_data_waiters\nPASSED r2e_tests/test_1.py::test_feed_data_completed_waiters\nPASSED r2e_tests/test_1.py::test_feed_eof_waiters\nPASSED r2e_tests/test_1.py::test_feed_eof_cancelled\nPASSED r2e_tests/test_1.py::test_on_eof\nPASSED r2e_tests/test_1.py::test_on_eof_empty_reader\nPASSED r2e_tests/test_1.py::test_on_eof_exc_in_callback\nPASSED r2e_tests/test_1.py::test_on_eof_exc_in_callback_empty_stream_reader\nPASSED r2e_tests/test_1.py::test_on_eof_eof_is_set\nPASSED r2e_tests/test_1.py::test_on_eof_eof_is_set_exception\nPASSED r2e_tests/test_1.py::test_set_exception\nPASSED r2e_tests/test_1.py::test_set_exception_cancelled\nPASSED r2e_tests/test_1.py::test_set_exception_eof_callbacks\nPASSED r2e_tests/test_1.py::test_stream_reader_lines\nPASSED r2e_tests/test_1.py::test_stream_reader_chunks_complete\nPASSED r2e_tests/test_1.py::test_stream_reader_chunks_incomplete\nPASSED r2e_tests/test_1.py::test_data_queue_empty\nPASSED r2e_tests/test_1.py::test_data_queue_items\nPASSED r2e_tests/test_1.py::test_stream_reader_iter_any\nPASSED r2e_tests/test_1.py::test_stream_reader_iter\nPASSED r2e_tests/test_1.py::test_stream_reader_iter_chunks_no_chunked_encoding\nPASSED r2e_tests/test_1.py::test_stream_reader_iter_chunks_chunked_encoding\nPASSED r2e_tests/test_1.py::test_isinstance_check\n============================= 111 passed in 5.57s ==============================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.9.21, pytest-7.1.3, pluggy-1.0.0 -- /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/.venv/bin/python\ncachedir: .pytest_cache\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b, configfile: setup.cfg\nplugins: mock-3.6.1, cov-3.0.0, asyncio-0.23.8\nasyncio: mode=strict\ncollecting ... collected 111 items\n\nr2e_tests/test_1.py::TestStreamReader::test_create_waiter PASSED         [  0%]\nr2e_tests/test_1.py::TestStreamReader::test_ctor_global_loop PASSED      [  1%]\nr2e_tests/test_1.py::TestStreamReader::test_at_eof PASSED                [  2%]\nr2e_tests/test_1.py::TestStreamReader::test_wait_eof PASSED              [  3%]\nr2e_tests/test_1.py::TestStreamReader::test_wait_eof_eof PASSED          [  4%]\nr2e_tests/test_1.py::TestStreamReader::test_feed_empty_data PASSED       [  5%]\nr2e_tests/test_1.py::TestStreamReader::test_feed_nonempty_data PASSED    [  6%]\nr2e_tests/test_1.py::TestStreamReader::test_read_zero PASSED             [  7%]\nr2e_tests/test_1.py::TestStreamReader::test_read PASSED                  [  8%]\nr2e_tests/test_1.py::TestStreamReader::test_read_line_breaks PASSED      [  9%]\nr2e_tests/test_1.py::TestStreamReader::test_read_all PASSED              [  9%]\nr2e_tests/test_1.py::TestStreamReader::test_read_up_to PASSED            [ 10%]\nr2e_tests/test_1.py::TestStreamReader::test_read_eof PASSED              [ 11%]\nr2e_tests/test_1.py::TestStreamReader::test_read_eof_infinite PASSED     [ 12%]\nr2e_tests/test_1.py::TestStreamReader::test_read_eof_unread_data_no_warning PASSED [ 13%]\nr2e_tests/test_1.py::TestStreamReader::test_read_until_eof PASSED        [ 14%]\nr2e_tests/test_1.py::TestStreamReader::test_read_exception PASSED        [ 15%]\nr2e_tests/test_1.py::TestStreamReader::test_readline PASSED              [ 16%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_limit_with_existing_data PASSED [ 17%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_limit PASSED        [ 18%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_nolimit_nowait PASSED [ 18%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_eof PASSED          [ 19%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_empty_eof PASSED    [ 20%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_read_byte_count PASSED [ 21%]\nr2e_tests/test_1.py::TestStreamReader::test_readline_exception PASSED    [ 22%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil[*] PASSED          [ 23%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil[**] PASSED         [ 24%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&] PASSED [ 25%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&&] PASSED [ 26%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$] PASSED    [ 27%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$$] PASSED   [ 27%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!] PASSED [ 28%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!!] PASSED [ 29%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@] PASSED      [ 30%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@@] PASSED     [ 31%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@] PASSED [ 32%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@@] PASSED [ 33%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!] PASSED [ 34%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!!] PASSED [ 35%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[#] PASSED [ 36%]\nr2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[##] PASSED [ 36%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly_zero_or_less PASSED [ 37%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly PASSED           [ 38%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly_eof PASSED       [ 39%]\nr2e_tests/test_1.py::TestStreamReader::test_readexactly_exception PASSED [ 40%]\nr2e_tests/test_1.py::TestStreamReader::test_unread_data PASSED           [ 41%]\nr2e_tests/test_1.py::TestStreamReader::test_exception PASSED             [ 42%]\nr2e_tests/test_1.py::TestStreamReader::test_exception_waiter PASSED      [ 43%]\nr2e_tests/test_1.py::TestStreamReader::test_exception_cancel PASSED      [ 44%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_eof PASSED           [ 45%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_empty_eof PASSED     [ 45%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_exception PASSED     [ 46%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait PASSED           [ 47%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait_n PASSED         [ 48%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait_exception PASSED [ 49%]\nr2e_tests/test_1.py::TestStreamReader::test_read_nowait_waiter PASSED    [ 50%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk PASSED             [ 51%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_wait_eof PASSED    [ 52%]\nr2e_tests/test_1.py::TestStreamReader::test_begin_and_end_chunk_receiving PASSED [ 53%]\nr2e_tests/test_1.py::TestStreamReader::test_readany_chunk_end_race PASSED [ 54%]\nr2e_tests/test_1.py::TestStreamReader::test_end_chunk_receiving_without_begin PASSED [ 54%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_with_unread PASSED [ 55%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_with_other_read_calls PASSED [ 56%]\nr2e_tests/test_1.py::TestStreamReader::test_chunksplits_memory_leak PASSED [ 57%]\nr2e_tests/test_1.py::TestStreamReader::test_read_empty_chunks PASSED     [ 58%]\nr2e_tests/test_1.py::TestStreamReader::test_readchunk_separate_http_chunk_tail PASSED [ 59%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__ PASSED              [ 60%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__nondefault_limit PASSED [ 61%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__eof PASSED           [ 62%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__data PASSED          [ 63%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__exception PASSED     [ 63%]\nr2e_tests/test_1.py::TestStreamReader::test___repr__waiter PASSED        [ 64%]\nr2e_tests/test_1.py::TestStreamReader::test_unread_empty PASSED          [ 65%]\nr2e_tests/test_1.py::test_empty_stream_reader FAILED                     [ 66%]\nr2e_tests/test_1.py::TestDataQueue::test_is_eof[pyloop] PASSED           [ 67%]\nr2e_tests/test_1.py::TestDataQueue::test_at_eof[pyloop] PASSED           [ 68%]\nr2e_tests/test_1.py::TestDataQueue::test_feed_data[pyloop] PASSED        [ 69%]\nr2e_tests/test_1.py::TestDataQueue::test_feed_eof[pyloop] PASSED         [ 70%]\nr2e_tests/test_1.py::TestDataQueue::test_read[pyloop] PASSED             [ 71%]\nr2e_tests/test_1.py::TestDataQueue::test_read_eof[pyloop] PASSED         [ 72%]\nr2e_tests/test_1.py::TestDataQueue::test_read_cancelled[pyloop] PASSED   [ 72%]\nr2e_tests/test_1.py::TestDataQueue::test_read_until_eof[pyloop] PASSED   [ 73%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exc[pyloop] PASSED         [ 74%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exception[pyloop] PASSED   [ 75%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exception_with_data[pyloop] PASSED [ 76%]\nr2e_tests/test_1.py::TestDataQueue::test_read_exception_on_wait[pyloop] PASSED [ 77%]\nr2e_tests/test_1.py::TestDataQueue::test_exception[pyloop] PASSED        [ 78%]\nr2e_tests/test_1.py::TestDataQueue::test_exception_waiter[pyloop] PASSED [ 79%]\nr2e_tests/test_1.py::test_feed_data_waiters PASSED                       [ 80%]\nr2e_tests/test_1.py::test_feed_data_completed_waiters PASSED             [ 81%]\nr2e_tests/test_1.py::test_feed_eof_waiters PASSED                        [ 81%]\nr2e_tests/test_1.py::test_feed_eof_cancelled PASSED                      [ 82%]\nr2e_tests/test_1.py::test_on_eof PASSED                                  [ 83%]\nr2e_tests/test_1.py::test_on_eof_empty_reader PASSED                     [ 84%]\nr2e_tests/test_1.py::test_on_eof_exc_in_callback PASSED                  [ 85%]\nr2e_tests/test_1.py::test_on_eof_exc_in_callback_empty_stream_reader PASSED [ 86%]\nr2e_tests/test_1.py::test_on_eof_eof_is_set PASSED                       [ 87%]\nr2e_tests/test_1.py::test_on_eof_eof_is_set_exception PASSED             [ 88%]\nr2e_tests/test_1.py::test_set_exception PASSED                           [ 89%]\nr2e_tests/test_1.py::test_set_exception_cancelled PASSED                 [ 90%]\nr2e_tests/test_1.py::test_set_exception_eof_callbacks PASSED             [ 90%]\nr2e_tests/test_1.py::test_stream_reader_lines PASSED                     [ 91%]\nr2e_tests/test_1.py::test_stream_reader_chunks_complete PASSED           [ 92%]\nr2e_tests/test_1.py::test_stream_reader_chunks_incomplete PASSED         [ 93%]\nr2e_tests/test_1.py::test_data_queue_empty PASSED                        [ 94%]\nr2e_tests/test_1.py::test_data_queue_items PASSED                        [ 95%]\nr2e_tests/test_1.py::test_stream_reader_iter_any PASSED                  [ 96%]\nr2e_tests/test_1.py::test_stream_reader_iter PASSED                      [ 97%]\nr2e_tests/test_1.py::test_stream_reader_iter_chunks_no_chunked_encoding PASSED [ 98%]\nr2e_tests/test_1.py::test_stream_reader_iter_chunks_chunked_encoding PASSED [ 99%]\nr2e_tests/test_1.py::test_isinstance_check PASSED                        [100%]\n\n=================================== FAILURES ===================================\n___________________________ test_empty_stream_reader ___________________________\n\n    async def test_empty_stream_reader() -> None:\n        s = streams.EmptyStreamReader()\n>       assert str(s) is not None\n\ns          = <[AttributeError(\"'EmptyStreamReader' object has no attribute '_size'\") raised in repr()] EmptyStreamReader object at 0x7f2a0577eeb0>\n\nr2e_tests/test_1.py:1135: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <[AttributeError(\"'EmptyStreamReader' object has no attribute '_size'\") raised in repr()] EmptyStreamReader object at 0x7f2a0577eeb0>\n\n    def __repr__(self) -> str:\n        info = [self.__class__.__name__]\n>       if self._size:\nE       AttributeError: 'EmptyStreamReader' object has no attribute '_size'\n\ninfo       = ['EmptyStreamReader']\nself       = <[AttributeError(\"'EmptyStreamReader' object has no attribute '_size'\") raised in repr()] EmptyStreamReader object at 0x7f2a0577eeb0>\n\naiohttp/streams.py:124: AttributeError\n==================================== PASSES ====================================\n_________________________ test_on_eof_exc_in_callback __________________________\n------------------------------ Captured log call -------------------------------\nERROR    aiohttp.internal:streams.py:182 Exception in eof callback\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\", line 180, in feed_eof\n    cb()\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1092, in __call__\n    return self._mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1096, in _mock_call\n    return self._execute_mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1151, in _execute_mock_call\n    raise effect\nValueError\n_______________ test_on_eof_exc_in_callback_empty_stream_reader ________________\n------------------------------ Captured log call -------------------------------\nERROR    aiohttp.internal:streams.py:515 Exception in eof callback\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\", line 513, in on_eof\n    callback()\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1092, in __call__\n    return self._mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1096, in _mock_call\n    return self._execute_mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1151, in _execute_mock_call\n    raise effect\nValueError\n_______________________ test_on_eof_eof_is_set_exception _______________________\n------------------------------ Captured log call -------------------------------\nERROR    aiohttp.internal:streams.py:161 Exception in eof callback\nTraceback (most recent call last):\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_f7e4246114ce48335f224f36c2d4b058b02bea7b/aiohttp/streams.py\", line 159, in on_eof\n    callback()\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1092, in __call__\n    return self._mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1096, in _mock_call\n    return self._execute_mock_call(*args, **kwargs)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/mock.py\", line 1151, in _execute_mock_call\n    raise effect\nValueError\n\n---------- coverage: platform linux, python 3.9.21-final-0 -----------\nName                                     Stmts   Miss Branch BrPart  Cover\n--------------------------------------------------------------------------\naiohttp/__init__.py                         29     11      4      1    58%\naiohttp/abc.py                              90      8     12      0    92%\naiohttp/base_protocol.py                    65     52     24      0    17%\naiohttp/client.py                          482    361    184      1    20%\naiohttp/client_exceptions.py               135     61     56      0    60%\naiohttp/client_proto.py                    148    120     56      0    15%\naiohttp/client_reqrep.py                   645    485    286      0    18%\naiohttp/client_ws.py                       206    166     66      0    15%\naiohttp/connector.py                       711    588    327      0    13%\naiohttp/cookiejar.py                       256    207    120      0    14%\naiohttp/formdata.py                         93     76     48      0    13%\naiohttp/hdrs.py                             94      1      2      1    98%\naiohttp/helpers.py                         510    316    198      4    33%\naiohttp/http.py                             11      0      2      0   100%\naiohttp/http_exceptions.py                  49     20     28      0    66%\naiohttp/http_parser.py                     482    393    200      1    16%\naiohttp/http_websocket.py                  383    284    168      0    21%\naiohttp/http_writer.py                     119     83     54      1    24%\naiohttp/locks.py                            24     16      6      0    33%\naiohttp/log.py                               7      0      0      0   100%\naiohttp/multipart.py                       564    458    248      0    15%\naiohttp/payload.py                         221    109     86      1    47%\naiohttp/payload_streamer.py                 29     10      8      0    73%\naiohttp/pytest_plugin.py                   168     65     44      7    59%\naiohttp/resolver.py                         68     48     26      0    26%\naiohttp/streams.py                         393     32    160      6    92%\naiohttp/tcp_helpers.py                      19     11      6      0    32%\naiohttp/test_utils.py                      333    202     70      4    36%\naiohttp/tracing.py                         191     69     36      0    70%\naiohttp/typedefs.py                         27      1      2      1    93%\naiohttp/web.py                             118     84     54      0    21%\naiohttp/web_app.py                         301    196     78      0    29%\naiohttp/web_exceptions.py                  151     22    122      0    90%\naiohttp/web_fileresponse.py                143    120     54      0    13%\naiohttp/web_log.py                          98     55     20      0    38%\naiohttp/web_middlewares.py                  55     42     20      0    17%\naiohttp/web_protocol.py                    340    280    161      0    14%\naiohttp/web_request.py                     435    285    132      1    28%\naiohttp/web_response.py                    486    371    218      1    17%\naiohttp/web_routedef.py                    106     46     14      0    57%\naiohttp/web_runner.py                      210    128     52      0    38%\naiohttp/web_server.py                       37     19      8      0    44%\naiohttp/web_urldispatcher.py               710    453    205      0    33%\naiohttp/web_ws.py                          316    254    108      0    16%\naiohttp/worker.py                          129    129     36      0     0%\ntests/conftest.py                          101    101     16      0     0%\ntests/test_base_protocol.py                152    152      2      0     0%\ntests/test_circular_imports.py              31     31     15      0     0%\ntests/test_classbasedview.py                39     39      6      0     0%\ntests/test_client_connection.py             94     94      2      0     0%\ntests/test_client_exceptions.py            183    183     26      0     0%\ntests/test_client_fingerprint.py            59     59      0      0     0%\ntests/test_client_functional.py           2094   2094     76      0     0%\ntests/test_client_proto.py                  88     88      0      0     0%\ntests/test_client_request.py               755    755     24      0     0%\ntests/test_client_response.py              469    469      2      0     0%\ntests/test_client_session.py               496    496     33      0     0%\ntests/test_client_ws.py                    415    415      4      0     0%\ntests/test_client_ws_functional.py         585    585     14      0     0%\ntests/test_connector.py                   1509   1509     86      0     0%\ntests/test_cookiejar.py                    325    325     26      0     0%\ntests/test_flowcontrol_streams.py          100    100      4      0     0%\ntests/test_formdata.py                      72     72      6      0     0%\ntests/test_helpers.py                      403    403     30      0     0%\ntests/test_http_exceptions.py              107    107     20      0     0%\ntests/test_http_parser.py                  766    766     40      0     0%\ntests/test_http_writer.py                  176    176     10      0     0%\ntests/test_imports.py                       31     31      6      0     0%\ntests/test_locks.py                         39     39      2      0     0%\ntests/test_loop.py                          39     39      2      0     0%\ntests/test_multipart.py                    754    754     42      0     0%\ntests/test_multipart_helpers.py            446    446      4      0     0%\ntests/test_payload.py                       94     94      6      0     0%\ntests/test_proxy.py                        266    266      2      0     0%\ntests/test_proxy_functional.py             487    487     22      0     0%\ntests/test_pytest_plugin.py                 30     30      0      0     0%\ntests/test_resolver.py                     176    176     16      0     0%\ntests/test_route_def.py                    210    210      0      0     0%\ntests/test_run_app.py                      337    337     24      0     0%\ntests/test_streams.py                     1072   1072     44      0     0%\ntests/test_tcp_helpers.py                   52     52      2      0     0%\ntests/test_test_utils.py                   242    242      8      0     0%\ntests/test_tracing.py                       48     48      4      0     0%\ntests/test_urldispatch.py                  844    844     24      0     0%\ntests/test_web_app.py                      455    455     12      0     0%\ntests/test_web_cli.py                       75     75      0      0     0%\ntests/test_web_exceptions.py               156    156     22      0     0%\ntests/test_web_functional.py              1520   1520     38      0     0%\ntests/test_web_log.py                      110    110      6      0     0%\ntests/test_web_middleware.py               266    266     18      0     0%\ntests/test_web_request.py                  490    490      8      0     0%\ntests/test_web_request_handler.py           40     40      0      0     0%\ntests/test_web_response.py                 818    818      6      0     0%\ntests/test_web_runner.py                   148    148      4      0     0%\ntests/test_web_sendfile.py                  84     84      0      0     0%\ntests/test_web_sendfile_functional.py      634    634     18      0     0%\ntests/test_web_server.py                   110    110      0      0     0%\ntests/test_web_urldispatcher.py            307    307     22      0     0%\ntests/test_web_websocket.py                304    304      4      0     0%\ntests/test_web_websocket_functional.py     542    542     16      0     0%\ntests/test_websocket_handshake.py          152    152     12      0     0%\ntests/test_websocket_parser.py             300    300     14      0     0%\ntests/test_websocket_writer.py              68     68      0      0     0%\ntests/test_worker.py                       197    197     10      0     0%\n--------------------------------------------------------------------------\nTOTAL                                    31149  27699   4669     30    12%\n\n============================= slowest 10 durations =============================\n0.22s call     r2e_tests/test_1.py::TestStreamReader::test_readchunk_separate_http_chunk_tail\n0.22s call     r2e_tests/test_1.py::TestStreamReader::test_readany_chunk_end_race\n0.13s call     r2e_tests/test_1.py::TestStreamReader::test_readchunk_wait_eof\n0.12s call     r2e_tests/test_1.py::TestStreamReader::test_wait_eof\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_create_waiter\n0.02s teardown r2e_tests/test_1.py::TestDataQueue::test_is_eof[pyloop]\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_exception_waiter\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_ctor_global_loop\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_exception_cancel\n0.02s call     r2e_tests/test_1.py::TestStreamReader::test_readline_nolimit_nowait\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::TestStreamReader::test_create_waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_ctor_global_loop\nPASSED r2e_tests/test_1.py::TestStreamReader::test_at_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_wait_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_wait_eof_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_feed_empty_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_feed_nonempty_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_zero\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_line_breaks\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_all\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_up_to\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_eof_infinite\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_eof_unread_data_no_warning\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_until_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_limit_with_existing_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_limit\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_nolimit_nowait\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_empty_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_read_byte_count\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readline_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil[*]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil[**]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit_with_existing_data[&&]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_limit[$$]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_nolimit_nowait[!!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_eof[@@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_empty_eof[@@]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_read_byte_count[!!]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[#]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readuntil_exception[##]\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly_zero_or_less\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readexactly_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_unread_data\nPASSED r2e_tests/test_1.py::TestStreamReader::test_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_exception_waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_exception_cancel\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_empty_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait_n\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait_exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_nowait_waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_wait_eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test_begin_and_end_chunk_receiving\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readany_chunk_end_race\nPASSED r2e_tests/test_1.py::TestStreamReader::test_end_chunk_receiving_without_begin\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_with_unread\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_with_other_read_calls\nPASSED r2e_tests/test_1.py::TestStreamReader::test_chunksplits_memory_leak\nPASSED r2e_tests/test_1.py::TestStreamReader::test_read_empty_chunks\nPASSED r2e_tests/test_1.py::TestStreamReader::test_readchunk_separate_http_chunk_tail\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__nondefault_limit\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__eof\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__data\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__exception\nPASSED r2e_tests/test_1.py::TestStreamReader::test___repr__waiter\nPASSED r2e_tests/test_1.py::TestStreamReader::test_unread_empty\nPASSED r2e_tests/test_1.py::TestDataQueue::test_is_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_at_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_feed_data[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_feed_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_cancelled[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_until_eof[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exc[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exception[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exception_with_data[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_read_exception_on_wait[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_exception[pyloop]\nPASSED r2e_tests/test_1.py::TestDataQueue::test_exception_waiter[pyloop]\nPASSED r2e_tests/test_1.py::test_feed_data_waiters\nPASSED r2e_tests/test_1.py::test_feed_data_completed_waiters\nPASSED r2e_tests/test_1.py::test_feed_eof_waiters\nPASSED r2e_tests/test_1.py::test_feed_eof_cancelled\nPASSED r2e_tests/test_1.py::test_on_eof\nPASSED r2e_tests/test_1.py::test_on_eof_empty_reader\nPASSED r2e_tests/test_1.py::test_on_eof_exc_in_callback\nPASSED r2e_tests/test_1.py::test_on_eof_exc_in_callback_empty_stream_reader\nPASSED r2e_tests/test_1.py::test_on_eof_eof_is_set\nPASSED r2e_tests/test_1.py::test_on_eof_eof_is_set_exception\nPASSED r2e_tests/test_1.py::test_set_exception\nPASSED r2e_tests/test_1.py::test_set_exception_cancelled\nPASSED r2e_tests/test_1.py::test_set_exception_eof_callbacks\nPASSED r2e_tests/test_1.py::test_stream_reader_lines\nPASSED r2e_tests/test_1.py::test_stream_reader_chunks_complete\nPASSED r2e_tests/test_1.py::test_stream_reader_chunks_incomplete\nPASSED r2e_tests/test_1.py::test_data_queue_empty\nPASSED r2e_tests/test_1.py::test_data_queue_items\nPASSED r2e_tests/test_1.py::test_stream_reader_iter_any\nPASSED r2e_tests/test_1.py::test_stream_reader_iter\nPASSED r2e_tests/test_1.py::test_stream_reader_iter_chunks_no_chunked_encoding\nPASSED r2e_tests/test_1.py::test_stream_reader_iter_chunks_chunked_encoding\nPASSED r2e_tests/test_1.py::test_isinstance_check\nFAILED r2e_tests/test_1.py::test_empty_stream_reader - AttributeError: 'Empty...\n======================== 1 failed, 110 passed in 5.26s =========================\n",
    "old_commit_res_stderr": ""
}
CHANGES/6916.bugfix CONTRIBUTORS.txt aiohttp/streams.py tests/test_streams.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** EmptyStreamReader's String Representation Raises AttributeError

**Description:**
When using `EmptyStreamReader`, converting it to a string results in an `AttributeError`. This happens because `EmptyStreamReader` inherits the `__repr__` method from `StreamReader`, which expects certain attributes that `EmptyStreamReader` does not have.

**Example Code:**
```python
from aiohttp import streams

def example_representation():
    reader = streams.EmptyStreamReader()
    print(str(reader))
```

**Expected Behavior:**
Converting `EmptyStreamReader` to a string should return a simple representation of the object, such as `"<EmptyStreamReader>"`, without raising any errors.

**Actual Behavior:**
An `AttributeError` is raised because the inherited `__repr__` method tries to access the `_size` attribute, which does not exist in `EmptyStreamReader`.

**Error Message:**
```
AttributeError: 'EmptyStreamReader' object has no attribute '_size'
```
[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### aiohttp/streams.py
import asyncio
import collections
import warnings
from typing import Awaitable, Callable, Deque, Generic, List, Optional, Tuple, TypeVar

from .base_protocol import BaseProtocol
from .helpers import BaseTimerContext, set_exception, set_result
from .log import internal_logger
from .typedefs import Final

__all__ = (
    "EMPTY_PAYLOAD",
    "EofStream",
    "StreamReader",
    "DataQueue",
    "FlowControlDataQueue",
)

_T = TypeVar("_T")


class EofStream(Exception):
    """eof stream indication."""


class AsyncStreamIterator(Generic[_T]):
    def __init__(self, read_func: Callable[[], Awaitable[_T]]) -> None:
        self.read_func = read_func

    def __aiter__(self) -> "AsyncStreamIterator[_T]":
        return self

    async def __anext__(self) -> _T:
        try:
            rv = await self.read_func()
        except EofStream:
            raise StopAsyncIteration
        if rv == b"":
            raise StopAsyncIteration
        return rv


class ChunkTupleAsyncStreamIterator:
    def __init__(self, stream: "StreamReader") -> None:
        self._stream = stream

    def __aiter__(self) -> "ChunkTupleAsyncStreamIterator":
        return self

    async def __anext__(self) -> Tuple[bytes, bool]:
        rv = await self._stream.readchunk()
        if rv == (b"", False):
            raise StopAsyncIteration
        return rv


class AsyncStreamReaderMixin:
    def __aiter__(self) -> AsyncStreamIterator[bytes]:
        return AsyncStreamIterator(self.readline)  # type: ignore[attr-defined]

    def iter_chunked(self, n: int) -> AsyncStreamIterator[bytes]:
        """Returns an asynchronous iterator that yields chunks of size n."""
        return AsyncStreamIterator(
            lambda: self.read(n)  # type: ignore[attr-defined,no-any-return]
        )

    def iter_any(self) -> AsyncStreamIterator[bytes]:
        """Yield all available data as soon as it is received."""
        return AsyncStreamIterator(self.readany)  # type: ignore[attr-defined]

    def iter_chunks(self) -> ChunkTupleAsyncStreamIterator:
        """Yield chunks of data as they are received by the server.

        The yielded objects are tuples
        of (bytes, bool) as returned by the StreamReader.readchunk method.
        """
        return ChunkTupleAsyncStreamIterator(self)  # type: ignore[arg-type]


class StreamReader(AsyncStreamReaderMixin):
    """An enhancement of asyncio.StreamReader.

    Supports asynchronous iteration by line, chunk or as available::

        async for line in reader:
            ...
        async for chunk in reader.iter_chunked(1024):
            ...
        async for slice in reader.iter_any():
            ...

    """

    total_bytes = 0

    def __init__(
        self,
        protocol: BaseProtocol,
        limit: int,
        *,
        timer: Optional[BaseTimerContext] = None,
        loop: Optional[asyncio.AbstractEventLoop] = None,
    ) -> None:
        self._protocol = protocol
        self._low_water = limit
        self._high_water = limit * 2
        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self._size = 0
        self._cursor = 0
        self._http_chunk_splits: Optional[List[int]] = None
        self._buffer: Deque[bytes] = collections.deque()
        self._buffer_offset = 0
        self._eof = False
        self._waiter: Optional[asyncio.Future[None]] = None
        self._eof_waiter: Optional[asyncio.Future[None]] = None
        self._exception: Optional[BaseException] = None
        self._timer = timer
        self._eof_callbacks: List[Callable[[], None]] = []

    def __repr__(self) -> str:
        info = [self.__class__.__name__]
        if self._size:
            info.append("%d bytes" % self._size)
        if self._eof:
            info.append("eof")
        if self._low_water != 2**16:  # default limit
            info.append("low=%d high=%d" % (self._low_water, self._high_water))
        if self._waiter:
            info.append("w=%r" % self._waiter)
        if self._exception:
            info.append("e=%r" % self._exception)
        return "<%s>" % " ".join(info)

    def get_read_buffer_limits(self) -> Tuple[int, int]:
        return (self._low_water, self._high_water)

    def exception(self) -> Optional[BaseException]:
        return self._exception

    def set_exception(self, exc: BaseException) -> None:
        self._exception = exc
        self._eof_callbacks.clear()

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_exception(waiter, exc)

        waiter = self._eof_waiter
        if waiter is not None:
            self._eof_waiter = None
            set_exception(waiter, exc)

    def on_eof(self, callback: Callable[[], None]) -> None:
        if self._eof:
            try:
                callback()
            except Exception:
                internal_logger.exception("Exception in eof callback")
        else:
            self._eof_callbacks.append(callback)

    def feed_eof(self) -> None:
        self._eof = True

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

        waiter = self._eof_waiter
        if waiter is not None:
            self._eof_waiter = None
            set_result(waiter, None)

        for cb in self._eof_callbacks:
            try:
                cb()
            except Exception:
                internal_logger.exception("Exception in eof callback")

        self._eof_callbacks.clear()

    def is_eof(self) -> bool:
        """Return True if  'feed_eof' was called."""
        return self._eof

    def at_eof(self) -> bool:
        """Return True if the buffer is empty and 'feed_eof' was called."""
        return self._eof and not self._buffer

    async def wait_eof(self) -> None:
        if self._eof:
            return

        assert self._eof_waiter is None
        self._eof_waiter = self._loop.create_future()
        try:
            await self._eof_waiter
        finally:
            self._eof_waiter = None

    def unread_data(self, data: bytes) -> None:
        """rollback reading some data from stream, inserting it to buffer head."""
        warnings.warn(
            "unread_data() is deprecated "
            "and will be removed in future releases (#3260)",
            DeprecationWarning,
            stacklevel=2,
        )
        if not data:
            return

        if self._buffer_offset:
            self._buffer[0] = self._buffer[0][self._buffer_offset :]
            self._buffer_offset = 0
        self._size += len(data)
        self._cursor -= len(data)
        self._buffer.appendleft(data)
        self._eof_counter = 0

    # TODO: size is ignored, remove the param later
    def feed_data(self, data: bytes, size: int = 0) -> None:
        assert not self._eof, "feed_data after feed_eof"

        if not data:
            return

        self._size += len(data)
        self._buffer.append(data)
        self.total_bytes += len(data)

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

        if self._size > self._high_water and not self._protocol._reading_paused:
            self._protocol.pause_reading()

    def begin_http_chunk_receiving(self) -> None:
        if self._http_chunk_splits is None:
            if self.total_bytes:
                raise RuntimeError(
                    "Called begin_http_chunk_receiving when" "some data was already fed"
                )
            self._http_chunk_splits = []

    def end_http_chunk_receiving(self) -> None:
        if self._http_chunk_splits is None:
            raise RuntimeError(
                "Called end_chunk_receiving without calling "
                "begin_chunk_receiving first"
            )

        # self._http_chunk_splits contains logical byte offsets from start of
        # the body transfer. Each offset is the offset of the end of a chunk.
        # "Logical" means bytes, accessible for a user.
        # If no chunks containig logical data were received, current position
        # is difinitely zero.
        pos = self._http_chunk_splits[-1] if self._http_chunk_splits else 0

        if self.total_bytes == pos:
            # We should not add empty chunks here. So we check for that.
            # Note, when chunked + gzip is used, we can receive a chunk
            # of compressed data, but that data may not be enough for gzip FSM
            # to yield any uncompressed data. That's why current position may
            # not change after receiving a chunk.
            return

        self._http_chunk_splits.append(self.total_bytes)

        # wake up readchunk when end of http chunk received
        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

    async def _wait(self, func_name: str) -> None:
        # StreamReader uses a future to link the protocol feed_data() method
        # to a read coroutine. Running two read coroutines at the same time
        # would have an unexpected behaviour. It would not possible to know
        # which coroutine would get the next data.
        if self._waiter is not None:
            raise RuntimeError(
                "%s() called while another coroutine is "
                "already waiting for incoming data" % func_name
            )

        waiter = self._waiter = self._loop.create_future()
        try:
            if self._timer:
                with self._timer:
                    await waiter
            else:
                await waiter
        finally:
            self._waiter = None

    async def readline(self) -> bytes:
        return await self.readuntil()

    async def readuntil(self, separator: bytes = b"\n") -> bytes:
        seplen = len(separator)
        if seplen == 0:
            raise ValueError("Separator should be at least one-byte string")

        if self._exception is not None:
            raise self._exception

        chunk = b""
        chunk_size = 0
        not_enough = True

        while not_enough:
            while self._buffer and not_enough:
                offset = self._buffer_offset
                ichar = self._buffer[0].find(separator, offset) + 1
                # Read from current offset to found separator or to the end.
                data = self._read_nowait_chunk(
                    ichar - offset + seplen - 1 if ichar else -1
                )
                chunk += data
                chunk_size += len(data)
                if ichar:
                    not_enough = False

                if chunk_size > self._high_water:
                    raise ValueError("Chunk too big")

            if self._eof:
                break

            if not_enough:
                await self._wait("readuntil")

        return chunk

    async def read(self, n: int = -1) -> bytes:
        if self._exception is not None:
            raise self._exception

        # migration problem; with DataQueue you have to catch
        # EofStream exception, so common way is to run payload.read() inside
        # infinite loop. what can cause real infinite loop with StreamReader
        # lets keep this code one major release.
        if __debug__:
            if self._eof and not self._buffer:
                self._eof_counter = getattr(self, "_eof_counter", 0) + 1
                if self._eof_counter > 5:
                    internal_logger.warning(
                        "Multiple access to StreamReader in eof state, "
                        "might be infinite loop.",
                        stack_info=True,
                    )

        if not n:
            return b""

        if n < 0:
            # This used to just loop creating a new waiter hoping to
            # collect everything in self._buffer, but that would
            # deadlock if the subprocess sends more than self.limit
            # bytes.  So just call self.readany() until EOF.
            blocks = []
            while True:
                block = await self.readany()
                if not block:
                    break
                blocks.append(block)
            return b"".join(blocks)

        # TODO: should be `if` instead of `while`
        # because waiter maybe triggered on chunk end,
        # without feeding any data
        while not self._buffer and not self._eof:
            await self._wait("read")

        return self._read_nowait(n)

    async def readany(self) -> bytes:
        if self._exception is not None:
            raise self._exception

        # TODO: should be `if` instead of `while`
        # because waiter maybe triggered on chunk end,
        # without feeding any data
        while not self._buffer and not self._eof:
            await self._wait("readany")

        return self._read_nowait(-1)

    async def readchunk(self) -> Tuple[bytes, bool]:
        """Returns a tuple of (data, end_of_http_chunk).

        When chunked transfer
        encoding is used, end_of_http_chunk is a boolean indicating if the end
        of the data corresponds to the end of a HTTP chunk , otherwise it is
        always False.
        """
        while True:
            if self._exception is not None:
                raise self._exception

            while self._http_chunk_splits:
                pos = self._http_chunk_splits.pop(0)
                if pos == self._cursor:
                    return (b"", True)
                if pos > self._cursor:
                    return (self._read_nowait(pos - self._cursor), True)
                internal_logger.warning(
                    "Skipping HTTP chunk end due to data "
                    "consumption beyond chunk boundary"
                )

            if self._buffer:
                return (self._read_nowait_chunk(-1), False)
                # return (self._read_nowait(-1), False)

            if self._eof:
                # Special case for signifying EOF.
                # (b'', True) is not a final return value actually.
                return (b"", False)

            await self._wait("readchunk")

    async def readexactly(self, n: int) -> bytes:
        if self._exception is not None:
            raise self._exception

        blocks: List[bytes] = []
        while n > 0:
            block = await self.read(n)
            if not block:
                partial = b"".join(blocks)
                raise asyncio.IncompleteReadError(partial, len(partial) + n)
            blocks.append(block)
            n -= len(block)

        return b"".join(blocks)

    def read_nowait(self, n: int = -1) -> bytes:
        # default was changed to be consistent with .read(-1)
        #
        # I believe the most users don't know about the method and
        # they are not affected.
        if self._exception is not None:
            raise self._exception

        if self._waiter and not self._waiter.done():
            raise RuntimeError(
                "Called while some coroutine is waiting for incoming data."
            )

        return self._read_nowait(n)

    def _read_nowait_chunk(self, n: int) -> bytes:
        first_buffer = self._buffer[0]
        offset = self._buffer_offset
        if n != -1 and len(first_buffer) - offset > n:
            data = first_buffer[offset : offset + n]
            self._buffer_offset += n

        elif offset:
            self._buffer.popleft()
            data = first_buffer[offset:]
            self._buffer_offset = 0

        else:
            data = self._buffer.popleft()

        self._size -= len(data)
        self._cursor += len(data)

        chunk_splits = self._http_chunk_splits
        # Prevent memory leak: drop useless chunk splits
        while chunk_splits and chunk_splits[0] < self._cursor:
            chunk_splits.pop(0)

        if self._size < self._low_water and self._protocol._reading_paused:
            self._protocol.resume_reading()
        return data

    def _read_nowait(self, n: int) -> bytes:
        """Read not more than n bytes, or whole buffer if n == -1"""
        chunks = []

        while self._buffer:
            chunk = self._read_nowait_chunk(n)
            chunks.append(chunk)
            if n != -1:
                n -= len(chunk)
                if n == 0:
                    break

        return b"".join(chunks) if chunks else b""


class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]
    def __init__(self) -> None:
        pass

    def exception(self) -> Optional[BaseException]:
        return None

    def set_exception(self, exc: BaseException) -> None:
        pass

    def on_eof(self, callback: Callable[[], None]) -> None:
        try:
            callback()
        except Exception:
            internal_logger.exception("Exception in eof callback")

    def feed_eof(self) -> None:
        pass

    def is_eof(self) -> bool:
        return True

    def at_eof(self) -> bool:
        return True

    async def wait_eof(self) -> None:
        return

    def feed_data(self, data: bytes, n: int = 0) -> None:
        pass

    async def readline(self) -> bytes:
        return b""

    async def read(self, n: int = -1) -> bytes:
        return b""

    # TODO add async def readuntil

    async def readany(self) -> bytes:
        return b""

    async def readchunk(self) -> Tuple[bytes, bool]:
        return (b"", True)

    async def readexactly(self, n: int) -> bytes:
        raise asyncio.IncompleteReadError(b"", n)

    def read_nowait(self, n: int = -1) -> bytes:
        return b""


EMPTY_PAYLOAD: Final[StreamReader] = EmptyStreamReader()


class DataQueue(Generic[_T]):
    """DataQueue is a general-purpose blocking queue with one reader."""

    def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
        self._loop = loop
        self._eof = False
        self._waiter: Optional[asyncio.Future[None]] = None
        self._exception: Optional[BaseException] = None
        self._size = 0
        self._buffer: Deque[Tuple[_T, int]] = collections.deque()

    def __len__(self) -> int:
        return len(self._buffer)

    def is_eof(self) -> bool:
        return self._eof

    def at_eof(self) -> bool:
        return self._eof and not self._buffer

    def exception(self) -> Optional[BaseException]:
        return self._exception

    def set_exception(self, exc: BaseException) -> None:
        self._eof = True
        self._exception = exc

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_exception(waiter, exc)

    def feed_data(self, data: _T, size: int = 0) -> None:
        self._size += size
        self._buffer.append((data, size))

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

    def feed_eof(self) -> None:
        self._eof = True

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

    async def read(self) -> _T:
        if not self._buffer and not self._eof:
            assert not self._waiter
            self._waiter = self._loop.create_future()
            try:
                await self._waiter
            except (asyncio.CancelledError, asyncio.TimeoutError):
                self._waiter = None
                raise

        if self._buffer:
            data, size = self._buffer.popleft()
            self._size -= size
            return data
        else:
            if self._exception is not None:
                raise self._exception
            else:
                raise EofStream

    def __aiter__(self) -> AsyncStreamIterator[_T]:
        return AsyncStreamIterator(self.read)


class FlowControlDataQueue(DataQueue[_T]):
    """FlowControlDataQueue resumes and pauses an underlying stream.

    It is a destination for parsed data.
    """

    def __init__(
        self, protocol: BaseProtocol, limit: int, *, loop: asyncio.AbstractEventLoop
    ) -> None:
        super().__init__(loop=loop)

        self._protocol = protocol
        self._limit = limit * 2

    def feed_data(self, data: _T, size: int = 0) -> None:
        super().feed_data(data, size)

        if self._size > self._limit and not self._protocol._reading_paused:
            self._protocol.pause_reading()

    async def read(self) -> _T:
        try:
            return await super().read()
        finally:
            if self._size < self._limit and self._protocol._reading_paused:
                self._protocol.resume_reading()

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** EmptyStreamReader's String Representation Raises AttributeError

**Description:**
When using `EmptyStreamReader`, converting it to a string results in an `AttributeError`. This happens because `EmptyStreamReader` inherits the `__repr__` method from `StreamReader`, which expects certain attributes that `EmptyStreamReader` does not have.

**Example Code:**
```python
from aiohttp import streams

def example_representation():
    reader = streams.EmptyStreamReader()
    print(str(reader))
```

**Expected Behavior:**
Converting `EmptyStreamReader` to a string should return a simple representation of the object, such as `"<EmptyStreamReader>"`, without raising any errors.

**Actual Behavior:**
An `AttributeError` is raised because the inherited `__repr__` method tries to access the `_size` attribute, which does not exist in `EmptyStreamReader`.

**Error Message:**
```
AttributeError: 'EmptyStreamReader' object has no attribute '_size'
```
[/ISSUE]
{
    "TestStreamReader.test_create_waiter": "PASSED",
    "TestStreamReader.test_ctor_global_loop": "PASSED",
    "TestStreamReader.test_at_eof": "PASSED",
    "TestStreamReader.test_wait_eof": "PASSED",
    "TestStreamReader.test_wait_eof_eof": "PASSED",
    "TestStreamReader.test_feed_empty_data": "PASSED",
    "TestStreamReader.test_feed_nonempty_data": "PASSED",
    "TestStreamReader.test_read_zero": "PASSED",
    "TestStreamReader.test_read": "PASSED",
    "TestStreamReader.test_read_line_breaks": "PASSED",
    "TestStreamReader.test_read_all": "PASSED",
    "TestStreamReader.test_read_up_to": "PASSED",
    "TestStreamReader.test_read_eof": "PASSED",
    "TestStreamReader.test_read_eof_infinite": "PASSED",
    "TestStreamReader.test_read_eof_unread_data_no_warning": "PASSED",
    "TestStreamReader.test_read_until_eof": "PASSED",
    "TestStreamReader.test_read_exception": "PASSED",
    "TestStreamReader.test_readline": "PASSED",
    "TestStreamReader.test_readline_limit_with_existing_data": "PASSED",
    "TestStreamReader.test_readline_limit": "PASSED",
    "TestStreamReader.test_readline_nolimit_nowait": "PASSED",
    "TestStreamReader.test_readline_eof": "PASSED",
    "TestStreamReader.test_readline_empty_eof": "PASSED",
    "TestStreamReader.test_readline_read_byte_count": "PASSED",
    "TestStreamReader.test_readline_exception": "PASSED",
    "TestStreamReader.test_readuntil[*]": "PASSED",
    "TestStreamReader.test_readuntil[**]": "PASSED",
    "TestStreamReader.test_readuntil_limit_with_existing_data[&]": "PASSED",
    "TestStreamReader.test_readuntil_limit_with_existing_data[&&]": "PASSED",
    "TestStreamReader.test_readuntil_limit[$]": "PASSED",
    "TestStreamReader.test_readuntil_limit[$$]": "PASSED",
    "TestStreamReader.test_readuntil_nolimit_nowait[!]": "PASSED",
    "TestStreamReader.test_readuntil_nolimit_nowait[!!]": "PASSED",
    "TestStreamReader.test_readuntil_eof[@]": "PASSED",
    "TestStreamReader.test_readuntil_eof[@@]": "PASSED",
    "TestStreamReader.test_readuntil_empty_eof[@]": "PASSED",
    "TestStreamReader.test_readuntil_empty_eof[@@]": "PASSED",
    "TestStreamReader.test_readuntil_read_byte_count[!]": "PASSED",
    "TestStreamReader.test_readuntil_read_byte_count[!!]": "PASSED",
    "TestStreamReader.test_readuntil_exception[#]": "PASSED",
    "TestStreamReader.test_readuntil_exception[##]": "PASSED",
    "TestStreamReader.test_readexactly_zero_or_less": "PASSED",
    "TestStreamReader.test_readexactly": "PASSED",
    "TestStreamReader.test_readexactly_eof": "PASSED",
    "TestStreamReader.test_readexactly_exception": "PASSED",
    "TestStreamReader.test_unread_data": "PASSED",
    "TestStreamReader.test_exception": "PASSED",
    "TestStreamReader.test_exception_waiter": "PASSED",
    "TestStreamReader.test_exception_cancel": "PASSED",
    "TestStreamReader.test_readany_eof": "PASSED",
    "TestStreamReader.test_readany_empty_eof": "PASSED",
    "TestStreamReader.test_readany_exception": "PASSED",
    "TestStreamReader.test_read_nowait": "PASSED",
    "TestStreamReader.test_read_nowait_n": "PASSED",
    "TestStreamReader.test_read_nowait_exception": "PASSED",
    "TestStreamReader.test_read_nowait_waiter": "PASSED",
    "TestStreamReader.test_readchunk": "PASSED",
    "TestStreamReader.test_readchunk_wait_eof": "PASSED",
    "TestStreamReader.test_begin_and_end_chunk_receiving": "PASSED",
    "TestStreamReader.test_readany_chunk_end_race": "PASSED",
    "TestStreamReader.test_end_chunk_receiving_without_begin": "PASSED",
    "TestStreamReader.test_readchunk_with_unread": "PASSED",
    "TestStreamReader.test_readchunk_with_other_read_calls": "PASSED",
    "TestStreamReader.test_chunksplits_memory_leak": "PASSED",
    "TestStreamReader.test_read_empty_chunks": "PASSED",
    "TestStreamReader.test_readchunk_separate_http_chunk_tail": "PASSED",
    "TestStreamReader.test___repr__": "PASSED",
    "TestStreamReader.test___repr__nondefault_limit": "PASSED",
    "TestStreamReader.test___repr__eof": "PASSED",
    "TestStreamReader.test___repr__data": "PASSED",
    "TestStreamReader.test___repr__exception": "PASSED",
    "TestStreamReader.test___repr__waiter": "PASSED",
    "TestStreamReader.test_unread_empty": "PASSED",
    "test_empty_stream_reader": "PASSED",
    "TestDataQueue.test_is_eof[pyloop]": "PASSED",
    "TestDataQueue.test_at_eof[pyloop]": "PASSED",
    "TestDataQueue.test_feed_data[pyloop]": "PASSED",
    "TestDataQueue.test_feed_eof[pyloop]": "PASSED",
    "TestDataQueue.test_read[pyloop]": "PASSED",
    "TestDataQueue.test_read_eof[pyloop]": "PASSED",
    "TestDataQueue.test_read_cancelled[pyloop]": "PASSED",
    "TestDataQueue.test_read_until_eof[pyloop]": "PASSED",
    "TestDataQueue.test_read_exc[pyloop]": "PASSED",
    "TestDataQueue.test_read_exception[pyloop]": "PASSED",
    "TestDataQueue.test_read_exception_with_data[pyloop]": "PASSED",
    "TestDataQueue.test_read_exception_on_wait[pyloop]": "PASSED",
    "TestDataQueue.test_exception[pyloop]": "PASSED",
    "TestDataQueue.test_exception_waiter[pyloop]": "PASSED",
    "test_feed_data_waiters": "PASSED",
    "test_feed_data_completed_waiters": "PASSED",
    "test_feed_eof_waiters": "PASSED",
    "test_feed_eof_cancelled": "PASSED",
    "test_on_eof": "PASSED",
    "test_on_eof_empty_reader": "PASSED",
    "test_on_eof_exc_in_callback": "PASSED",
    "test_on_eof_exc_in_callback_empty_stream_reader": "PASSED",
    "test_on_eof_eof_is_set": "PASSED",
    "test_on_eof_eof_is_set_exception": "PASSED",
    "test_set_exception": "PASSED",
    "test_set_exception_cancelled": "PASSED",
    "test_set_exception_eof_callbacks": "PASSED",
    "test_stream_reader_lines": "PASSED",
    "test_stream_reader_chunks_complete": "PASSED",
    "test_stream_reader_chunks_incomplete": "PASSED",
    "test_data_queue_empty": "PASSED",
    "test_data_queue_items": "PASSED",
    "test_stream_reader_iter_any": "PASSED",
    "test_stream_reader_iter": "PASSED",
    "test_stream_reader_iter_chunks_no_chunked_encoding": "PASSED",
    "test_stream_reader_iter_chunks_chunked_encoding": "PASSED",
    "test_isinstance_check": "PASSED"
}
diff --git a/aiohttp/streams.py b/aiohttp/streams.py
index d5f4c2ba..32ec7f14 100644
--- a/aiohttp/streams.py
+++ b/aiohttp/streams.py
@@ -502,6 +502,9 @@ class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]
     def __init__(self) -> None:
         pass
 
+    def __repr__(self) -> str:
+        return "<%s>" % self.__class__.__name__
+
     def exception(self) -> Optional[BaseException]:
         return None
 

{"aiohttp/streams.py": "import asyncio\nimport collections\nimport warnings\nfrom typing import Awaitable, Callable, Deque, Generic, List, Optional, Tuple, TypeVar\n\nfrom .base_protocol import BaseProtocol\nfrom .helpers import BaseTimerContext, set_exception, set_result\nfrom .log import internal_logger\nfrom .typedefs import Final\n\n__all__ = (\n    \"EMPTY_PAYLOAD\",\n    \"EofStream\",\n    \"StreamReader\",\n    \"DataQueue\",\n    \"FlowControlDataQueue\",\n)\n\n_T = TypeVar(\"_T\")\n\n\nclass EofStream(Exception):\n    \"\"\"eof stream indication.\"\"\"\n\n\nclass AsyncStreamIterator(Generic[_T]):\n    def __init__(self, read_func: Callable[[], Awaitable[_T]]) -> None:\n        self.read_func = read_func\n\n    def __aiter__(self) -> \"AsyncStreamIterator[_T]\":\n        return self\n\n    async def __anext__(self) -> _T:\n        try:\n            rv = await self.read_func()\n        except EofStream:\n            raise StopAsyncIteration\n        if rv == b\"\":\n            raise StopAsyncIteration\n        return rv\n\n\nclass ChunkTupleAsyncStreamIterator:\n    def __init__(self, stream: \"StreamReader\") -> None:\n        self._stream = stream\n\n    def __aiter__(self) -> \"ChunkTupleAsyncStreamIterator\":\n        return self\n\n    async def __anext__(self) -> Tuple[bytes, bool]:\n        rv = await self._stream.readchunk()\n        if rv == (b\"\", False):\n            raise StopAsyncIteration\n        return rv\n\n\nclass AsyncStreamReaderMixin:\n    def __aiter__(self) -> AsyncStreamIterator[bytes]:\n        return AsyncStreamIterator(self.readline)  # type: ignore[attr-defined]\n\n    def iter_chunked(self, n: int) -> AsyncStreamIterator[bytes]:\n        \"\"\"Returns an asynchronous iterator that yields chunks of size n.\"\"\"\n        return AsyncStreamIterator(\n            lambda: self.read(n)  # type: ignore[attr-defined,no-any-return]\n        )\n\n    def iter_any(self) -> AsyncStreamIterator[bytes]:\n        \"\"\"Yield all available data as soon as it is received.\"\"\"\n        return AsyncStreamIterator(self.readany)  # type: ignore[attr-defined]\n\n    def iter_chunks(self) -> ChunkTupleAsyncStreamIterator:\n        \"\"\"Yield chunks of data as they are received by the server.\n\n        The yielded objects are tuples\n        of (bytes, bool) as returned by the StreamReader.readchunk method.\n        \"\"\"\n        return ChunkTupleAsyncStreamIterator(self)  # type: ignore[arg-type]\n\n\nclass StreamReader(AsyncStreamReaderMixin):\n    \"\"\"An enhancement of asyncio.StreamReader.\n\n    Supports asynchronous iteration by line, chunk or as available::\n\n        async for line in reader:\n            ...\n        async for chunk in reader.iter_chunked(1024):\n            ...\n        async for slice in reader.iter_any():\n            ...\n\n    \"\"\"\n\n    total_bytes = 0\n\n    def __init__(\n        self,\n        protocol: BaseProtocol,\n        limit: int,\n        *,\n        timer: Optional[BaseTimerContext] = None,\n        loop: Optional[asyncio.AbstractEventLoop] = None,\n    ) -> None:\n        self._protocol = protocol\n        self._low_water = limit\n        self._high_water = limit * 2\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n        self._size = 0\n        self._cursor = 0\n        self._http_chunk_splits: Optional[List[int]] = None\n        self._buffer: Deque[bytes] = collections.deque()\n        self._buffer_offset = 0\n        self._eof = False\n        self._waiter: Optional[asyncio.Future[None]] = None\n        self._eof_waiter: Optional[asyncio.Future[None]] = None\n        self._exception: Optional[BaseException] = None\n        self._timer = timer\n        self._eof_callbacks: List[Callable[[], None]] = []\n\n    def __repr__(self) -> str:\n        info = [self.__class__.__name__]\n        if self._size:\n            info.append(\"%d bytes\" % self._size)\n        if self._eof:\n            info.append(\"eof\")\n        if self._low_water != 2**16:  # default limit\n            info.append(\"low=%d high=%d\" % (self._low_water, self._high_water))\n        if self._waiter:\n            info.append(\"w=%r\" % self._waiter)\n        if self._exception:\n            info.append(\"e=%r\" % self._exception)\n        return \"<%s>\" % \" \".join(info)\n\n    def get_read_buffer_limits(self) -> Tuple[int, int]:\n        return (self._low_water, self._high_water)\n\n    def exception(self) -> Optional[BaseException]:\n        return self._exception\n\n    def set_exception(self, exc: BaseException) -> None:\n        self._exception = exc\n        self._eof_callbacks.clear()\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_exception(waiter, exc)\n\n        waiter = self._eof_waiter\n        if waiter is not None:\n            self._eof_waiter = None\n            set_exception(waiter, exc)\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        if self._eof:\n            try:\n                callback()\n            except Exception:\n                internal_logger.exception(\"Exception in eof callback\")\n        else:\n            self._eof_callbacks.append(callback)\n\n    def feed_eof(self) -> None:\n        self._eof = True\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n        waiter = self._eof_waiter\n        if waiter is not None:\n            self._eof_waiter = None\n            set_result(waiter, None)\n\n        for cb in self._eof_callbacks:\n            try:\n                cb()\n            except Exception:\n                internal_logger.exception(\"Exception in eof callback\")\n\n        self._eof_callbacks.clear()\n\n    def is_eof(self) -> bool:\n        \"\"\"Return True if  'feed_eof' was called.\"\"\"\n        return self._eof\n\n    def at_eof(self) -> bool:\n        \"\"\"Return True if the buffer is empty and 'feed_eof' was called.\"\"\"\n        return self._eof and not self._buffer\n\n    async def wait_eof(self) -> None:\n        if self._eof:\n            return\n\n        assert self._eof_waiter is None\n        self._eof_waiter = self._loop.create_future()\n        try:\n            await self._eof_waiter\n        finally:\n            self._eof_waiter = None\n\n    def unread_data(self, data: bytes) -> None:\n        \"\"\"rollback reading some data from stream, inserting it to buffer head.\"\"\"\n        warnings.warn(\n            \"unread_data() is deprecated \"\n            \"and will be removed in future releases (#3260)\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        if not data:\n            return\n\n        if self._buffer_offset:\n            self._buffer[0] = self._buffer[0][self._buffer_offset :]\n            self._buffer_offset = 0\n        self._size += len(data)\n        self._cursor -= len(data)\n        self._buffer.appendleft(data)\n        self._eof_counter = 0\n\n    # TODO: size is ignored, remove the param later\n    def feed_data(self, data: bytes, size: int = 0) -> None:\n        assert not self._eof, \"feed_data after feed_eof\"\n\n        if not data:\n            return\n\n        self._size += len(data)\n        self._buffer.append(data)\n        self.total_bytes += len(data)\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n        if self._size > self._high_water and not self._protocol._reading_paused:\n            self._protocol.pause_reading()\n\n    def begin_http_chunk_receiving(self) -> None:\n        if self._http_chunk_splits is None:\n            if self.total_bytes:\n                raise RuntimeError(\n                    \"Called begin_http_chunk_receiving when\" \"some data was already fed\"\n                )\n            self._http_chunk_splits = []\n\n    def end_http_chunk_receiving(self) -> None:\n        if self._http_chunk_splits is None:\n            raise RuntimeError(\n                \"Called end_chunk_receiving without calling \"\n                \"begin_chunk_receiving first\"\n            )\n\n        # self._http_chunk_splits contains logical byte offsets from start of\n        # the body transfer. Each offset is the offset of the end of a chunk.\n        # \"Logical\" means bytes, accessible for a user.\n        # If no chunks containig logical data were received, current position\n        # is difinitely zero.\n        pos = self._http_chunk_splits[-1] if self._http_chunk_splits else 0\n\n        if self.total_bytes == pos:\n            # We should not add empty chunks here. So we check for that.\n            # Note, when chunked + gzip is used, we can receive a chunk\n            # of compressed data, but that data may not be enough for gzip FSM\n            # to yield any uncompressed data. That's why current position may\n            # not change after receiving a chunk.\n            return\n\n        self._http_chunk_splits.append(self.total_bytes)\n\n        # wake up readchunk when end of http chunk received\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    async def _wait(self, func_name: str) -> None:\n        # StreamReader uses a future to link the protocol feed_data() method\n        # to a read coroutine. Running two read coroutines at the same time\n        # would have an unexpected behaviour. It would not possible to know\n        # which coroutine would get the next data.\n        if self._waiter is not None:\n            raise RuntimeError(\n                \"%s() called while another coroutine is \"\n                \"already waiting for incoming data\" % func_name\n            )\n\n        waiter = self._waiter = self._loop.create_future()\n        try:\n            if self._timer:\n                with self._timer:\n                    await waiter\n            else:\n                await waiter\n        finally:\n            self._waiter = None\n\n    async def readline(self) -> bytes:\n        return await self.readuntil()\n\n    async def readuntil(self, separator: bytes = b\"\\n\") -> bytes:\n        seplen = len(separator)\n        if seplen == 0:\n            raise ValueError(\"Separator should be at least one-byte string\")\n\n        if self._exception is not None:\n            raise self._exception\n\n        chunk = b\"\"\n        chunk_size = 0\n        not_enough = True\n\n        while not_enough:\n            while self._buffer and not_enough:\n                offset = self._buffer_offset\n                ichar = self._buffer[0].find(separator, offset) + 1\n                # Read from current offset to found separator or to the end.\n                data = self._read_nowait_chunk(\n                    ichar - offset + seplen - 1 if ichar else -1\n                )\n                chunk += data\n                chunk_size += len(data)\n                if ichar:\n                    not_enough = False\n\n                if chunk_size > self._high_water:\n                    raise ValueError(\"Chunk too big\")\n\n            if self._eof:\n                break\n\n            if not_enough:\n                await self._wait(\"readuntil\")\n\n        return chunk\n\n    async def read(self, n: int = -1) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        # migration problem; with DataQueue you have to catch\n        # EofStream exception, so common way is to run payload.read() inside\n        # infinite loop. what can cause real infinite loop with StreamReader\n        # lets keep this code one major release.\n        if __debug__:\n            if self._eof and not self._buffer:\n                self._eof_counter = getattr(self, \"_eof_counter\", 0) + 1\n                if self._eof_counter > 5:\n                    internal_logger.warning(\n                        \"Multiple access to StreamReader in eof state, \"\n                        \"might be infinite loop.\",\n                        stack_info=True,\n                    )\n\n        if not n:\n            return b\"\"\n\n        if n < 0:\n            # This used to just loop creating a new waiter hoping to\n            # collect everything in self._buffer, but that would\n            # deadlock if the subprocess sends more than self.limit\n            # bytes.  So just call self.readany() until EOF.\n            blocks = []\n            while True:\n                block = await self.readany()\n                if not block:\n                    break\n                blocks.append(block)\n            return b\"\".join(blocks)\n\n        # TODO: should be `if` instead of `while`\n        # because waiter maybe triggered on chunk end,\n        # without feeding any data\n        while not self._buffer and not self._eof:\n            await self._wait(\"read\")\n\n        return self._read_nowait(n)\n\n    async def readany(self) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        # TODO: should be `if` instead of `while`\n        # because waiter maybe triggered on chunk end,\n        # without feeding any data\n        while not self._buffer and not self._eof:\n            await self._wait(\"readany\")\n\n        return self._read_nowait(-1)\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        \"\"\"Returns a tuple of (data, end_of_http_chunk).\n\n        When chunked transfer\n        encoding is used, end_of_http_chunk is a boolean indicating if the end\n        of the data corresponds to the end of a HTTP chunk , otherwise it is\n        always False.\n        \"\"\"\n        while True:\n            if self._exception is not None:\n                raise self._exception\n\n            while self._http_chunk_splits:\n                pos = self._http_chunk_splits.pop(0)\n                if pos == self._cursor:\n                    return (b\"\", True)\n                if pos > self._cursor:\n                    return (self._read_nowait(pos - self._cursor), True)\n                internal_logger.warning(\n                    \"Skipping HTTP chunk end due to data \"\n                    \"consumption beyond chunk boundary\"\n                )\n\n            if self._buffer:\n                return (self._read_nowait_chunk(-1), False)\n                # return (self._read_nowait(-1), False)\n\n            if self._eof:\n                # Special case for signifying EOF.\n                # (b'', True) is not a final return value actually.\n                return (b\"\", False)\n\n            await self._wait(\"readchunk\")\n\n    async def readexactly(self, n: int) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        blocks: List[bytes] = []\n        while n > 0:\n            block = await self.read(n)\n            if not block:\n                partial = b\"\".join(blocks)\n                raise asyncio.IncompleteReadError(partial, len(partial) + n)\n            blocks.append(block)\n            n -= len(block)\n\n        return b\"\".join(blocks)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        # default was changed to be consistent with .read(-1)\n        #\n        # I believe the most users don't know about the method and\n        # they are not affected.\n        if self._exception is not None:\n            raise self._exception\n\n        if self._waiter and not self._waiter.done():\n            raise RuntimeError(\n                \"Called while some coroutine is waiting for incoming data.\"\n            )\n\n        return self._read_nowait(n)\n\n    def _read_nowait_chunk(self, n: int) -> bytes:\n        first_buffer = self._buffer[0]\n        offset = self._buffer_offset\n        if n != -1 and len(first_buffer) - offset > n:\n            data = first_buffer[offset : offset + n]\n            self._buffer_offset += n\n\n        elif offset:\n            self._buffer.popleft()\n            data = first_buffer[offset:]\n            self._buffer_offset = 0\n\n        else:\n            data = self._buffer.popleft()\n\n        self._size -= len(data)\n        self._cursor += len(data)\n\n        chunk_splits = self._http_chunk_splits\n        # Prevent memory leak: drop useless chunk splits\n        while chunk_splits and chunk_splits[0] < self._cursor:\n            chunk_splits.pop(0)\n\n        if self._size < self._low_water and self._protocol._reading_paused:\n            self._protocol.resume_reading()\n        return data\n\n    def _read_nowait(self, n: int) -> bytes:\n        \"\"\"Read not more than n bytes, or whole buffer if n == -1\"\"\"\n        chunks = []\n\n        while self._buffer:\n            chunk = self._read_nowait_chunk(n)\n            chunks.append(chunk)\n            if n != -1:\n                n -= len(chunk)\n                if n == 0:\n                    break\n\n        return b\"\".join(chunks) if chunks else b\"\"\n\n\nclass EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]\n    def __init__(self) -> None:\n        pass\n\n    def exception(self) -> Optional[BaseException]:\n        return None\n\n    def set_exception(self, exc: BaseException) -> None:\n        pass\n\n    def on_eof(self, callback: Callable[[], None]) -> None:\n        try:\n            callback()\n        except Exception:\n            internal_logger.exception(\"Exception in eof callback\")\n\n    def feed_eof(self) -> None:\n        pass\n\n    def is_eof(self) -> bool:\n        return True\n\n    def at_eof(self) -> bool:\n        return True\n\n    async def wait_eof(self) -> None:\n        return\n\n    def feed_data(self, data: bytes, n: int = 0) -> None:\n        pass\n\n    async def readline(self) -> bytes:\n        return b\"\"\n\n    async def read(self, n: int = -1) -> bytes:\n        return b\"\"\n\n    # TODO add async def readuntil\n\n    async def readany(self) -> bytes:\n        return b\"\"\n\n    async def readchunk(self) -> Tuple[bytes, bool]:\n        return (b\"\", True)\n\n    async def readexactly(self, n: int) -> bytes:\n        raise asyncio.IncompleteReadError(b\"\", n)\n\n    def read_nowait(self, n: int = -1) -> bytes:\n        return b\"\"\n\n\nEMPTY_PAYLOAD: Final[StreamReader] = EmptyStreamReader()\n\n\nclass DataQueue(Generic[_T]):\n    \"\"\"DataQueue is a general-purpose blocking queue with one reader.\"\"\"\n\n    def __init__(self, loop: asyncio.AbstractEventLoop) -> None:\n        self._loop = loop\n        self._eof = False\n        self._waiter: Optional[asyncio.Future[None]] = None\n        self._exception: Optional[BaseException] = None\n        self._size = 0\n        self._buffer: Deque[Tuple[_T, int]] = collections.deque()\n\n    def __len__(self) -> int:\n        return len(self._buffer)\n\n    def is_eof(self) -> bool:\n        return self._eof\n\n    def at_eof(self) -> bool:\n        return self._eof and not self._buffer\n\n    def exception(self) -> Optional[BaseException]:\n        return self._exception\n\n    def set_exception(self, exc: BaseException) -> None:\n        self._eof = True\n        self._exception = exc\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_exception(waiter, exc)\n\n    def feed_data(self, data: _T, size: int = 0) -> None:\n        self._size += size\n        self._buffer.append((data, size))\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    def feed_eof(self) -> None:\n        self._eof = True\n\n        waiter = self._waiter\n        if waiter is not None:\n            self._waiter = None\n            set_result(waiter, None)\n\n    async def read(self) -> _T:\n        if not self._buffer and not self._eof:\n            assert not self._waiter\n            self._waiter = self._loop.create_future()\n            try:\n                await self._waiter\n            except (asyncio.CancelledError, asyncio.TimeoutError):\n                self._waiter = None\n                raise\n\n        if self._buffer:\n            data, size = self._buffer.popleft()\n            self._size -= size\n            return data\n        else:\n            if self._exception is not None:\n                raise self._exception\n            else:\n                raise EofStream\n\n    def __aiter__(self) -> AsyncStreamIterator[_T]:\n        return AsyncStreamIterator(self.read)\n\n\nclass FlowControlDataQueue(DataQueue[_T]):\n    \"\"\"FlowControlDataQueue resumes and pauses an underlying stream.\n\n    It is a destination for parsed data.\n    \"\"\"\n\n    def __init__(\n        self, protocol: BaseProtocol, limit: int, *, loop: asyncio.AbstractEventLoop\n    ) -> None:\n        super().__init__(loop=loop)\n\n        self._protocol = protocol\n        self._limit = limit * 2\n\n    def feed_data(self, data: _T, size: int = 0) -> None:\n        super().feed_data(data, size)\n\n        if self._size > self._limit and not self._protocol._reading_paused:\n            self._protocol.pause_reading()\n\n    async def read(self) -> _T:\n        try:\n            return await super().read()\n        finally:\n            if self._size < self._limit and self._protocol._reading_paused:\n                self._protocol.resume_reading()\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** EmptyStreamReader's String Representation Raises AttributeError

**Description:**
When using `EmptyStreamReader`, converting it to a string results in an `AttributeError`. This happens because `EmptyStreamReader` inherits the `__repr__` method from `StreamReader`, which expects certain attributes that `EmptyStreamReader` does not have.

**Example Code:**
```python
from aiohttp import streams

def example_representation():
    reader = streams.EmptyStreamReader()
    print(str(reader))
```

**Expected Behavior:**
Converting `EmptyStreamReader` to a string should return a simple representation of the object, such as `"<EmptyStreamReader>"`, without raising any errors.

**Actual Behavior:**
An `AttributeError` is raised because the inherited `__repr__` method tries to access the `_size` attribute, which does not exist in `EmptyStreamReader`.

**Error Message:**
```
AttributeError: 'EmptyStreamReader' object has no attribute '_size'
```
[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### aiohttp/streams.py
import asyncio
import collections
import warnings
from typing import Awaitable, Callable, Deque, Generic, List, Optional, Tuple, TypeVar

from .base_protocol import BaseProtocol
from .helpers import BaseTimerContext, set_exception, set_result
from .log import internal_logger
from .typedefs import Final

__all__ = (
    "EMPTY_PAYLOAD",
    "EofStream",
    "StreamReader",
    "DataQueue",
    "FlowControlDataQueue",
)

_T = TypeVar("_T")


class EofStream(Exception):
    """eof stream indication."""


class AsyncStreamIterator(Generic[_T]):
    def __init__(self, read_func: Callable[[], Awaitable[_T]]) -> None:
        self.read_func = read_func

    def __aiter__(self) -> "AsyncStreamIterator[_T]":
        return self

    async def __anext__(self) -> _T:
        try:
            rv = await self.read_func()
        except EofStream:
            raise StopAsyncIteration
        if rv == b"":
            raise StopAsyncIteration
        return rv


class ChunkTupleAsyncStreamIterator:
    def __init__(self, stream: "StreamReader") -> None:
        self._stream = stream

    def __aiter__(self) -> "ChunkTupleAsyncStreamIterator":
        return self

    async def __anext__(self) -> Tuple[bytes, bool]:
        rv = await self._stream.readchunk()
        if rv == (b"", False):
            raise StopAsyncIteration
        return rv


class AsyncStreamReaderMixin:
    def __aiter__(self) -> AsyncStreamIterator[bytes]:
        return AsyncStreamIterator(self.readline)  # type: ignore[attr-defined]

    def iter_chunked(self, n: int) -> AsyncStreamIterator[bytes]:
        """Returns an asynchronous iterator that yields chunks of size n."""
        return AsyncStreamIterator(
            lambda: self.read(n)  # type: ignore[attr-defined,no-any-return]
        )

    def iter_any(self) -> AsyncStreamIterator[bytes]:
        """Yield all available data as soon as it is received."""
        return AsyncStreamIterator(self.readany)  # type: ignore[attr-defined]

    def iter_chunks(self) -> ChunkTupleAsyncStreamIterator:
        """Yield chunks of data as they are received by the server.

        The yielded objects are tuples
        of (bytes, bool) as returned by the StreamReader.readchunk method.
        """
        return ChunkTupleAsyncStreamIterator(self)  # type: ignore[arg-type]


class StreamReader(AsyncStreamReaderMixin):
    """An enhancement of asyncio.StreamReader.

    Supports asynchronous iteration by line, chunk or as available::

        async for line in reader:
            ...
        async for chunk in reader.iter_chunked(1024):
            ...
        async for slice in reader.iter_any():
            ...

    """

    total_bytes = 0

    def __init__(
        self,
        protocol: BaseProtocol,
        limit: int,
        *,
        timer: Optional[BaseTimerContext] = None,
        loop: Optional[asyncio.AbstractEventLoop] = None,
    ) -> None:
        self._protocol = protocol
        self._low_water = limit
        self._high_water = limit * 2
        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self._size = 0
        self._cursor = 0
        self._http_chunk_splits: Optional[List[int]] = None
        self._buffer: Deque[bytes] = collections.deque()
        self._buffer_offset = 0
        self._eof = False
        self._waiter: Optional[asyncio.Future[None]] = None
        self._eof_waiter: Optional[asyncio.Future[None]] = None
        self._exception: Optional[BaseException] = None
        self._timer = timer
        self._eof_callbacks: List[Callable[[], None]] = []

    def __repr__(self) -> str:
        info = [self.__class__.__name__]
        if self._size:
            info.append("%d bytes" % self._size)
        if self._eof:
            info.append("eof")
        if self._low_water != 2**16:  # default limit
            info.append("low=%d high=%d" % (self._low_water, self._high_water))
        if self._waiter:
            info.append("w=%r" % self._waiter)
        if self._exception:
            info.append("e=%r" % self._exception)
        return "<%s>" % " ".join(info)

    def get_read_buffer_limits(self) -> Tuple[int, int]:
        return (self._low_water, self._high_water)

    def exception(self) -> Optional[BaseException]:
        return self._exception

    def set_exception(self, exc: BaseException) -> None:
        self._exception = exc
        self._eof_callbacks.clear()

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_exception(waiter, exc)

        waiter = self._eof_waiter
        if waiter is not None:
            self._eof_waiter = None
            set_exception(waiter, exc)

    def on_eof(self, callback: Callable[[], None]) -> None:
        if self._eof:
            try:
                callback()
            except Exception:
                internal_logger.exception("Exception in eof callback")
        else:
            self._eof_callbacks.append(callback)

    def feed_eof(self) -> None:
        self._eof = True

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

        waiter = self._eof_waiter
        if waiter is not None:
            self._eof_waiter = None
            set_result(waiter, None)

        for cb in self._eof_callbacks:
            try:
                cb()
            except Exception:
                internal_logger.exception("Exception in eof callback")

        self._eof_callbacks.clear()

    def is_eof(self) -> bool:
        """Return True if  'feed_eof' was called."""
        return self._eof

    def at_eof(self) -> bool:
        """Return True if the buffer is empty and 'feed_eof' was called."""
        return self._eof and not self._buffer

    async def wait_eof(self) -> None:
        if self._eof:
            return

        assert self._eof_waiter is None
        self._eof_waiter = self._loop.create_future()
        try:
            await self._eof_waiter
        finally:
            self._eof_waiter = None

    def unread_data(self, data: bytes) -> None:
        """rollback reading some data from stream, inserting it to buffer head."""
        warnings.warn(
            "unread_data() is deprecated "
            "and will be removed in future releases (#3260)",
            DeprecationWarning,
            stacklevel=2,
        )
        if not data:
            return

        if self._buffer_offset:
            self._buffer[0] = self._buffer[0][self._buffer_offset :]
            self._buffer_offset = 0
        self._size += len(data)
        self._cursor -= len(data)
        self._buffer.appendleft(data)
        self._eof_counter = 0

    # TODO: size is ignored, remove the param later
    def feed_data(self, data: bytes, size: int = 0) -> None:
        assert not self._eof, "feed_data after feed_eof"

        if not data:
            return

        self._size += len(data)
        self._buffer.append(data)
        self.total_bytes += len(data)

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

        if self._size > self._high_water and not self._protocol._reading_paused:
            self._protocol.pause_reading()

    def begin_http_chunk_receiving(self) -> None:
        if self._http_chunk_splits is None:
            if self.total_bytes:
                raise RuntimeError(
                    "Called begin_http_chunk_receiving when" "some data was already fed"
                )
            self._http_chunk_splits = []

    def end_http_chunk_receiving(self) -> None:
        if self._http_chunk_splits is None:
            raise RuntimeError(
                "Called end_chunk_receiving without calling "
                "begin_chunk_receiving first"
            )

        # self._http_chunk_splits contains logical byte offsets from start of
        # the body transfer. Each offset is the offset of the end of a chunk.
        # "Logical" means bytes, accessible for a user.
        # If no chunks containig logical data were received, current position
        # is difinitely zero.
        pos = self._http_chunk_splits[-1] if self._http_chunk_splits else 0

        if self.total_bytes == pos:
            # We should not add empty chunks here. So we check for that.
            # Note, when chunked + gzip is used, we can receive a chunk
            # of compressed data, but that data may not be enough for gzip FSM
            # to yield any uncompressed data. That's why current position may
            # not change after receiving a chunk.
            return

        self._http_chunk_splits.append(self.total_bytes)

        # wake up readchunk when end of http chunk received
        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

    async def _wait(self, func_name: str) -> None:
        # StreamReader uses a future to link the protocol feed_data() method
        # to a read coroutine. Running two read coroutines at the same time
        # would have an unexpected behaviour. It would not possible to know
        # which coroutine would get the next data.
        if self._waiter is not None:
            raise RuntimeError(
                "%s() called while another coroutine is "
                "already waiting for incoming data" % func_name
            )

        waiter = self._waiter = self._loop.create_future()
        try:
            if self._timer:
                with self._timer:
                    await waiter
            else:
                await waiter
        finally:
            self._waiter = None

    async def readline(self) -> bytes:
        return await self.readuntil()

    async def readuntil(self, separator: bytes = b"\n") -> bytes:
        seplen = len(separator)
        if seplen == 0:
            raise ValueError("Separator should be at least one-byte string")

        if self._exception is not None:
            raise self._exception

        chunk = b""
        chunk_size = 0
        not_enough = True

        while not_enough:
            while self._buffer and not_enough:
                offset = self._buffer_offset
                ichar = self._buffer[0].find(separator, offset) + 1
                # Read from current offset to found separator or to the end.
                data = self._read_nowait_chunk(
                    ichar - offset + seplen - 1 if ichar else -1
                )
                chunk += data
                chunk_size += len(data)
                if ichar:
                    not_enough = False

                if chunk_size > self._high_water:
                    raise ValueError("Chunk too big")

            if self._eof:
                break

            if not_enough:
                await self._wait("readuntil")

        return chunk

    async def read(self, n: int = -1) -> bytes:
        if self._exception is not None:
            raise self._exception

        # migration problem; with DataQueue you have to catch
        # EofStream exception, so common way is to run payload.read() inside
        # infinite loop. what can cause real infinite loop with StreamReader
        # lets keep this code one major release.
        if __debug__:
            if self._eof and not self._buffer:
                self._eof_counter = getattr(self, "_eof_counter", 0) + 1
                if self._eof_counter > 5:
                    internal_logger.warning(
                        "Multiple access to StreamReader in eof state, "
                        "might be infinite loop.",
                        stack_info=True,
                    )

        if not n:
            return b""

        if n < 0:
            # This used to just loop creating a new waiter hoping to
            # collect everything in self._buffer, but that would
            # deadlock if the subprocess sends more than self.limit
            # bytes.  So just call self.readany() until EOF.
            blocks = []
            while True:
                block = await self.readany()
                if not block:
                    break
                blocks.append(block)
            return b"".join(blocks)

        # TODO: should be `if` instead of `while`
        # because waiter maybe triggered on chunk end,
        # without feeding any data
        while not self._buffer and not self._eof:
            await self._wait("read")

        return self._read_nowait(n)

    async def readany(self) -> bytes:
        if self._exception is not None:
            raise self._exception

        # TODO: should be `if` instead of `while`
        # because waiter maybe triggered on chunk end,
        # without feeding any data
        while not self._buffer and not self._eof:
            await self._wait("readany")

        return self._read_nowait(-1)

    async def readchunk(self) -> Tuple[bytes, bool]:
        """Returns a tuple of (data, end_of_http_chunk).

        When chunked transfer
        encoding is used, end_of_http_chunk is a boolean indicating if the end
        of the data corresponds to the end of a HTTP chunk , otherwise it is
        always False.
        """
        while True:
            if self._exception is not None:
                raise self._exception

            while self._http_chunk_splits:
                pos = self._http_chunk_splits.pop(0)
                if pos == self._cursor:
                    return (b"", True)
                if pos > self._cursor:
                    return (self._read_nowait(pos - self._cursor), True)
                internal_logger.warning(
                    "Skipping HTTP chunk end due to data "
                    "consumption beyond chunk boundary"
                )

            if self._buffer:
                return (self._read_nowait_chunk(-1), False)
                # return (self._read_nowait(-1), False)

            if self._eof:
                # Special case for signifying EOF.
                # (b'', True) is not a final return value actually.
                return (b"", False)

            await self._wait("readchunk")

    async def readexactly(self, n: int) -> bytes:
        if self._exception is not None:
            raise self._exception

        blocks: List[bytes] = []
        while n > 0:
            block = await self.read(n)
            if not block:
                partial = b"".join(blocks)
                raise asyncio.IncompleteReadError(partial, len(partial) + n)
            blocks.append(block)
            n -= len(block)

        return b"".join(blocks)

    def read_nowait(self, n: int = -1) -> bytes:
        # default was changed to be consistent with .read(-1)
        #
        # I believe the most users don't know about the method and
        # they are not affected.
        if self._exception is not None:
            raise self._exception

        if self._waiter and not self._waiter.done():
            raise RuntimeError(
                "Called while some coroutine is waiting for incoming data."
            )

        return self._read_nowait(n)

    def _read_nowait_chunk(self, n: int) -> bytes:
        first_buffer = self._buffer[0]
        offset = self._buffer_offset
        if n != -1 and len(first_buffer) - offset > n:
            data = first_buffer[offset : offset + n]
            self._buffer_offset += n

        elif offset:
            self._buffer.popleft()
            data = first_buffer[offset:]
            self._buffer_offset = 0

        else:
            data = self._buffer.popleft()

        self._size -= len(data)
        self._cursor += len(data)

        chunk_splits = self._http_chunk_splits
        # Prevent memory leak: drop useless chunk splits
        while chunk_splits and chunk_splits[0] < self._cursor:
            chunk_splits.pop(0)

        if self._size < self._low_water and self._protocol._reading_paused:
            self._protocol.resume_reading()
        return data

    def _read_nowait(self, n: int) -> bytes:
        """Read not more than n bytes, or whole buffer if n == -1"""
        chunks = []

        while self._buffer:
            chunk = self._read_nowait_chunk(n)
            chunks.append(chunk)
            if n != -1:
                n -= len(chunk)
                if n == 0:
                    break

        return b"".join(chunks) if chunks else b""


class EmptyStreamReader(StreamReader):  # lgtm [py/missing-call-to-init]
    def __init__(self) -> None:
        pass

    def exception(self) -> Optional[BaseException]:
        return None

    def set_exception(self, exc: BaseException) -> None:
        pass

    def on_eof(self, callback: Callable[[], None]) -> None:
        try:
            callback()
        except Exception:
            internal_logger.exception("Exception in eof callback")

    def feed_eof(self) -> None:
        pass

    def is_eof(self) -> bool:
        return True

    def at_eof(self) -> bool:
        return True

    async def wait_eof(self) -> None:
        return

    def feed_data(self, data: bytes, n: int = 0) -> None:
        pass

    async def readline(self) -> bytes:
        return b""

    async def read(self, n: int = -1) -> bytes:
        return b""

    # TODO add async def readuntil

    async def readany(self) -> bytes:
        return b""

    async def readchunk(self) -> Tuple[bytes, bool]:
        return (b"", True)

    async def readexactly(self, n: int) -> bytes:
        raise asyncio.IncompleteReadError(b"", n)

    def read_nowait(self, n: int = -1) -> bytes:
        return b""


EMPTY_PAYLOAD: Final[StreamReader] = EmptyStreamReader()


class DataQueue(Generic[_T]):
    """DataQueue is a general-purpose blocking queue with one reader."""

    def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
        self._loop = loop
        self._eof = False
        self._waiter: Optional[asyncio.Future[None]] = None
        self._exception: Optional[BaseException] = None
        self._size = 0
        self._buffer: Deque[Tuple[_T, int]] = collections.deque()

    def __len__(self) -> int:
        return len(self._buffer)

    def is_eof(self) -> bool:
        return self._eof

    def at_eof(self) -> bool:
        return self._eof and not self._buffer

    def exception(self) -> Optional[BaseException]:
        return self._exception

    def set_exception(self, exc: BaseException) -> None:
        self._eof = True
        self._exception = exc

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_exception(waiter, exc)

    def feed_data(self, data: _T, size: int = 0) -> None:
        self._size += size
        self._buffer.append((data, size))

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

    def feed_eof(self) -> None:
        self._eof = True

        waiter = self._waiter
        if waiter is not None:
            self._waiter = None
            set_result(waiter, None)

    async def read(self) -> _T:
        if not self._buffer and not self._eof:
            assert not self._waiter
            self._waiter = self._loop.create_future()
            try:
                await self._waiter
            except (asyncio.CancelledError, asyncio.TimeoutError):
                self._waiter = None
                raise

        if self._buffer:
            data, size = self._buffer.popleft()
            self._size -= size
            return data
        else:
            if self._exception is not None:
                raise self._exception
            else:
                raise EofStream

    def __aiter__(self) -> AsyncStreamIterator[_T]:
        return AsyncStreamIterator(self.read)


class FlowControlDataQueue(DataQueue[_T]):
    """FlowControlDataQueue resumes and pauses an underlying stream.

    It is a destination for parsed data.
    """

    def __init__(
        self, protocol: BaseProtocol, limit: int, *, loop: asyncio.AbstractEventLoop
    ) -> None:
        super().__init__(loop=loop)

        self._protocol = protocol
        self._limit = limit * 2

    def feed_data(self, data: _T, size: int = 0) -> None:
        super().feed_data(data, size)

        if self._size > self._limit and not self._protocol._reading_paused:
            self._protocol.pause_reading()

    async def read(self) -> _T:
        try:
            return await super().read()
        finally:
            if self._size < self._limit and self._protocol._reading_paused:
                self._protocol.resume_reading()

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user