Kaydet (Commit) 57497ad1 authored tarafından Guido van Rossum's avatar Guido van Rossum

Rename Transport.pause/resume to pause_reading/pause_writing. Also relax timeout…

Rename Transport.pause/resume to pause_reading/pause_writing. Also relax timeout in test_call_later().
üst 40b22d06
......@@ -94,12 +94,12 @@ class _ProactorReadPipeTransport(_ProactorBasePipeTransport,
self._paused = False
self._loop.call_soon(self._loop_reading)
def pause(self):
assert not self._closing, 'Cannot pause() when closing'
def pause_reading(self):
assert not self._closing, 'Cannot pause_reading() when closing'
assert not self._paused, 'Already paused'
self._paused = True
def resume(self):
def resume_reading(self):
assert self._paused, 'Not paused'
self._paused = False
if self._closing:
......
......@@ -406,13 +406,13 @@ class _SelectorSocketTransport(_SelectorTransport):
if waiter is not None:
self._loop.call_soon(waiter.set_result, None)
def pause(self):
assert not self._closing, 'Cannot pause() when closing'
def pause_reading(self):
assert not self._closing, 'Cannot pause_reading() when closing'
assert not self._paused, 'Already paused'
self._paused = True
self._loop.remove_reader(self._sock_fd)
def resume(self):
def resume_reading(self):
assert self._paused, 'Not paused'
self._paused = False
if self._closing:
......@@ -590,19 +590,19 @@ class _SelectorSslTransport(_SelectorTransport):
if self._waiter is not None:
self._loop.call_soon(self._waiter.set_result, None)
def pause(self):
def pause_reading(self):
# XXX This is a bit icky, given the comment at the top of
# _on_ready(). Is it possible to evoke a deadlock? I don't
# know, although it doesn't look like it; write() will still
# accept more data for the buffer and eventually the app will
# call resume() again, and things will flow again.
# call resume_reading() again, and things will flow again.
assert not self._closing, 'Cannot pause() when closing'
assert not self._closing, 'Cannot pause_reading() when closing'
assert not self._paused, 'Already paused'
self._paused = True
self._loop.remove_reader(self._sock_fd)
def resume(self):
def resume_reading(self):
assert self._paused, 'Not paused'
self._paused = False
if self._closing:
......
......@@ -106,7 +106,7 @@ class StreamReader:
def _maybe_resume_transport(self):
if self._paused and self.byte_count <= self.limit:
self._paused = False
self._transport.resume()
self._transport.resume_reading()
def feed_eof(self):
self.eof = True
......@@ -133,7 +133,7 @@ class StreamReader:
not self._paused and
self.byte_count > 2*self.limit):
try:
self._transport.pause()
self._transport.pause_reading()
except NotImplementedError:
# The transport can't be paused.
# We'll just have to buffer all data.
......
......@@ -29,15 +29,15 @@ class BaseTransport:
class ReadTransport(BaseTransport):
"""ABC for read-only transports."""
def pause(self):
def pause_reading(self):
"""Pause the receiving end.
No data will be passed to the protocol's data_received()
method until resume() is called.
method until resume_reading() is called.
"""
raise NotImplementedError
def resume(self):
def resume_reading(self):
"""Resume the receiving end.
Data received will once again be passed to the protocol's
......
......@@ -232,10 +232,10 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self._loop.call_soon(self._protocol.eof_received)
self._loop.call_soon(self._call_connection_lost, None)
def pause(self):
def pause_reading(self):
self._loop.remove_reader(self._fileno)
def resume(self):
def resume_reading(self):
self._loop.add_reader(self._fileno, self._read_ready)
def close(self):
......
......@@ -238,7 +238,7 @@ class EventLoopTestsMixin:
self.loop.run_forever()
t1 = time.monotonic()
self.assertEqual(results, ['hello world'])
self.assertTrue(0.09 <= t1-t0 <= 0.12, t1-t0)
self.assertTrue(0.08 <= t1-t0 <= 0.2, t1-t0)
def test_call_soon(self):
results = []
......
......@@ -308,7 +308,7 @@ class ProactorSocketTransportTests(unittest.TestCase):
tr.write_eof()
tr.close()
def test_pause_resume(self):
def test_pause_resume_reading(self):
tr = _ProactorSocketTransport(
self.loop, self.sock, self.protocol)
futures = []
......@@ -323,12 +323,12 @@ class ProactorSocketTransportTests(unittest.TestCase):
self.protocol.data_received.assert_called_with(b'data1')
self.loop._run_once()
self.protocol.data_received.assert_called_with(b'data2')
tr.pause()
tr.pause_reading()
self.assertTrue(tr._paused)
for i in range(10):
self.loop._run_once()
self.protocol.data_received.assert_called_with(b'data2')
tr.resume()
tr.resume_reading()
self.assertFalse(tr._paused)
self.loop._run_once()
self.protocol.data_received.assert_called_with(b'data3')
......
......@@ -676,15 +676,15 @@ class SelectorSocketTransportTests(unittest.TestCase):
test_utils.run_briefly(self.loop)
self.assertIsNone(fut.result())
def test_pause_resume(self):
def test_pause_resume_reading(self):
tr = _SelectorSocketTransport(
self.loop, self.sock, self.protocol)
self.assertFalse(tr._paused)
self.loop.assert_reader(7, tr._read_ready)
tr.pause()
tr.pause_reading()
self.assertTrue(tr._paused)
self.assertFalse(7 in self.loop.readers)
tr.resume()
tr.resume_reading()
self.assertFalse(tr._paused)
self.loop.assert_reader(7, tr._read_ready)
......@@ -1044,14 +1044,14 @@ class SelectorSslTransportTests(unittest.TestCase):
self.assertTrue(transport._waiter.done())
self.assertIs(exc, transport._waiter.exception())
def test_pause_resume(self):
def test_pause_resume_reading(self):
tr = self._make_one()
self.assertFalse(tr._paused)
self.loop.assert_reader(1, tr._on_ready)
tr.pause()
tr.pause_reading()
self.assertTrue(tr._paused)
self.assertFalse(1 in self.loop.readers)
tr.resume()
tr.resume_reading()
self.assertFalse(tr._paused)
self.loop.assert_reader(1, tr._on_ready)
......
......@@ -33,8 +33,8 @@ class TransportTests(unittest.TestCase):
self.assertRaises(NotImplementedError, transport.write, 'data')
self.assertRaises(NotImplementedError, transport.write_eof)
self.assertRaises(NotImplementedError, transport.can_write_eof)
self.assertRaises(NotImplementedError, transport.pause)
self.assertRaises(NotImplementedError, transport.resume)
self.assertRaises(NotImplementedError, transport.pause_reading)
self.assertRaises(NotImplementedError, transport.resume_reading)
self.assertRaises(NotImplementedError, transport.close)
self.assertRaises(NotImplementedError, transport.abort)
......
......@@ -375,21 +375,21 @@ class UnixReadPipeTransportTests(unittest.TestCase):
m_logexc.assert_called_with('Fatal error for %s', tr)
@unittest.mock.patch('os.read')
def test_pause(self, m_read):
def test_pause_reading(self, m_read):
tr = unix_events._UnixReadPipeTransport(
self.loop, self.pipe, self.protocol)
m = unittest.mock.Mock()
self.loop.add_reader(5, m)
tr.pause()
tr.pause_reading()
self.assertFalse(self.loop.readers)
@unittest.mock.patch('os.read')
def test_resume(self, m_read):
def test_resume_reading(self, m_read):
tr = unix_events._UnixReadPipeTransport(
self.loop, self.pipe, self.protocol)
tr.resume()
tr.resume_reading()
self.loop.assert_reader(5, tr._read_ready)
@unittest.mock.patch('os.read')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment