From 13b71a16ee9d5af4939a7e214e92fa89cb96f6a3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jul 2015 17:18:59 +0200 Subject: Add closing read-only property to transports * Disallow write() on closing transports * Disallow aslo calling pause_writing() and resume_writing() on StreamReaderProtocol if the transport is closing --- asyncio/streams.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'asyncio/streams.py') diff --git a/asyncio/streams.py b/asyncio/streams.py index 6484c43..409b2f9 100644 --- a/asyncio/streams.py +++ b/asyncio/streams.py @@ -153,15 +153,25 @@ class FlowControlMixin(protocols.Protocol): self._paused = False self._drain_waiter = None self._connection_lost = False + self._transport = None + + def connection_made(self, transport): + self._transport = transport def pause_writing(self): assert not self._paused + if self._transport is not None and self._transport.closing: + raise RuntimeError('Cannot call pause_writing() ' + 'on closing or closed transport') self._paused = True if self._loop.get_debug(): logger.debug("%r pauses writing", self) def resume_writing(self): assert self._paused + if self._transport is not None and self._transport.closing: + raise RuntimeError('Cannot call resume_writing() ' + 'on closing or closed transport') self._paused = False if self._loop.get_debug(): logger.debug("%r resumes writing", self) @@ -217,6 +227,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol): self._client_connected_cb = client_connected_cb def connection_made(self, transport): + super().connection_made(transport) self._stream_reader.set_transport(transport) if self._client_connected_cb is not None: self._stream_writer = StreamWriter(transport, self, -- cgit v1.2.1