Merge 3.4

This commit is contained in:
Yury Selivanov 2015-11-16 12:43:35 -05:00
commit 1334f83de2
11 changed files with 36 additions and 14 deletions

View File

@ -87,6 +87,9 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
raise NotImplementedError
def is_closing(self):
return self._closed
def close(self):
if self._closed:
return

View File

@ -65,6 +65,9 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
def _set_extra(self, sock):
self._extra['pipe'] = sock
def is_closing(self):
return self._closing
def close(self):
if self._closing:
return

View File

@ -556,6 +556,9 @@ class _SelectorTransport(transports._FlowControlMixin,
def abort(self):
self._force_close(None)
def is_closing(self):
return self._closing
def close(self):
if self._closing:
return

View File

@ -304,6 +304,9 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
"""Get optional transport information."""
return self._ssl_protocol._get_extra_info(name, default)
def is_closing(self):
return self._closed
def close(self):
"""Close the transport.

View File

@ -302,7 +302,7 @@ class StreamWriter:
if exc is not None:
raise exc
if self._transport is not None:
if self._transport._closing:
if self._transport.is_closing():
# Yield to the event loop so connection_lost() may be
# called. Without this, _drain_helper() would return
# immediately, and code that calls

View File

@ -19,6 +19,10 @@ class BaseTransport:
"""Get optional transport information."""
return self._extra.get(name, default)
def is_closing(self):
"""Return True if the transport is closing or closed."""
raise NotImplementedError
def close(self):
"""Close the transport.

View File

@ -364,6 +364,9 @@ class _UnixReadPipeTransport(transports.ReadTransport):
def resume_reading(self):
self._loop.add_reader(self._fileno, self._read_ready)
def is_closing(self):
return self._closing
def close(self):
if not self._closing:
self._close(None)
@ -548,6 +551,9 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
self._loop.remove_reader(self._fileno)
self._loop.call_soon(self._call_connection_lost, None)
def is_closing(self):
return self._closing
def close(self):
if self._pipe is not None and not self._closing:
# write_eof is all what we needed to close the write pipe

View File

@ -204,7 +204,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr.close()
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertEqual(tr._conn_lost, 1)
self.protocol.connection_lost.reset_mock()
@ -298,7 +298,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
self.loop, self.sock, self.protocol)
self.assertTrue(tr.can_write_eof())
tr.write_eof()
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.loop._run_once()
self.assertTrue(self.sock.close.called)
tr.close()
@ -309,7 +309,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
tr._loop._proactor.send.return_value = f
tr.write(b'data')
tr.write_eof()
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertFalse(self.sock.shutdown.called)
tr._loop._proactor.send.assert_called_with(self.sock, b'data')
f.set_result(4)

View File

@ -698,7 +698,7 @@ class SelectorTransportTests(test_utils.TestCase):
tr = self.create_transport()
tr.close()
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertEqual(1, self.loop.remove_reader_count[7])
self.protocol.connection_lost(None)
self.assertEqual(tr._conn_lost, 1)
@ -723,7 +723,7 @@ class SelectorTransportTests(test_utils.TestCase):
self.loop.add_writer(7, mock.sentinel)
tr._force_close(None)
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertEqual(tr._buffer, list_to_buffer())
self.assertFalse(self.loop.readers)
self.assertFalse(self.loop.writers)
@ -1436,7 +1436,7 @@ class SelectorSslTransportTests(test_utils.TestCase):
tr = self._make_one()
tr.close()
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertEqual(1, self.loop.remove_reader_count[1])
self.assertEqual(tr._conn_lost, 1)

View File

@ -61,7 +61,7 @@ class SubprocessTransportTests(test_utils.TestCase):
self.assertTrue(protocol.connection_lost.called)
self.assertEqual(protocol.connection_lost.call_args[0], (None,))
self.assertFalse(transport._closed)
self.assertFalse(transport.is_closing())
self.assertIsNone(transport._loop)
self.assertIsNone(transport._proc)
self.assertIsNone(transport._protocol)

View File

@ -440,7 +440,7 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
tr = self.read_pipe_transport()
err = object()
tr._close(err)
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertFalse(self.loop.readers)
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(err)
@ -598,7 +598,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
tr._read_ready()
self.assertFalse(self.loop.readers)
self.assertFalse(self.loop.writers)
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
@ -658,7 +658,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self.assertFalse(self.loop.writers)
self.assertFalse(self.loop.readers)
self.assertEqual([], tr._buffer)
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
m_logexc.assert_called_with(
test_utils.MockPattern(
'Fatal write error on pipe transport'
@ -694,7 +694,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self.assertFalse(self.loop.readers)
self.assertFalse(self.loop.writers)
self.assertEqual([], tr._buffer)
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
@ -743,7 +743,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
def test_write_eof(self):
tr = self.write_pipe_transport()
tr.write_eof()
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertFalse(self.loop.readers)
test_utils.run_briefly(self.loop)
self.protocol.connection_lost.assert_called_with(None)
@ -752,7 +752,7 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
tr = self.write_pipe_transport()
tr._buffer = [b'data']
tr.write_eof()
self.assertTrue(tr._closing)
self.assertTrue(tr.is_closing())
self.assertFalse(self.protocol.connection_lost.called)