From 9c23b173b823b5e6da01d85c570c7ae2ab07b38b Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Thu, 19 Oct 2017 11:12:44 -0700 Subject: [PATCH] bpo-31632: fix set_protocol() in _SSLProtocolTransport (GH-3817) (GH-3817) (#4052) (cherry picked from commit ea2ef5d0ca869d4550820ed53bdf56013dbb9546) --- Lib/asyncio/sslproto.py | 10 ++++------ Lib/test/test_asyncio/test_sslproto.py | 8 ++++++++ Misc/ACKS | 1 + .../Library/2017-10-04-11-37-14.bpo-31632.LiOC3C.rst | 2 ++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2017-10-04-11-37-14.bpo-31632.LiOC3C.rst diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 7948c4c3b4..f4d8a48418 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -294,11 +294,10 @@ class _SSLPipe(object): class _SSLProtocolTransport(transports._FlowControlMixin, transports.Transport): - def __init__(self, loop, ssl_protocol, app_protocol): + def __init__(self, loop, ssl_protocol): self._loop = loop # SSLProtocol instance self._ssl_protocol = ssl_protocol - self._app_protocol = app_protocol self._closed = False def get_extra_info(self, name, default=None): @@ -306,10 +305,10 @@ class _SSLProtocolTransport(transports._FlowControlMixin, return self._ssl_protocol._get_extra_info(name, default) def set_protocol(self, protocol): - self._app_protocol = protocol + self._ssl_protocol._app_protocol = protocol def get_protocol(self): - return self._app_protocol + return self._ssl_protocol._app_protocol def is_closing(self): return self._closed @@ -436,8 +435,7 @@ class SSLProtocol(protocols.Protocol): self._waiter = waiter self._loop = loop self._app_protocol = app_protocol - self._app_transport = _SSLProtocolTransport(self._loop, - self, self._app_protocol) + self._app_transport = _SSLProtocolTransport(self._loop, self) # _SSLPipe instance (None until the connection is made) self._sslpipe = None self._session_established = False diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py index bcd236ea26..f573ae8fe7 100644 --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -121,6 +121,14 @@ class SslProtoHandshakeTests(test_utils.TestCase): ssl_proto.connection_lost(None) self.assertIsNone(ssl_proto._get_extra_info('socket')) + def test_set_new_app_protocol(self): + waiter = asyncio.Future(loop=self.loop) + ssl_proto = self.ssl_protocol(waiter) + new_app_proto = asyncio.Protocol() + ssl_proto._app_transport.set_protocol(new_app_proto) + self.assertIs(ssl_proto._app_transport.get_protocol(), new_app_proto) + self.assertIs(ssl_proto._app_protocol, new_app_proto) + if __name__ == '__main__': unittest.main() diff --git a/Misc/ACKS b/Misc/ACKS index a956acd6ec..667f447bc5 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -849,6 +849,7 @@ Vladimir Kushnir Erno Kuusela Ross Lagerwall Cameron Laird +Loïc Lajeanne David Lam Thomas Lamb Valerie Lambert diff --git a/Misc/NEWS.d/next/Library/2017-10-04-11-37-14.bpo-31632.LiOC3C.rst b/Misc/NEWS.d/next/Library/2017-10-04-11-37-14.bpo-31632.LiOC3C.rst new file mode 100644 index 0000000000..6178d0633e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-10-04-11-37-14.bpo-31632.LiOC3C.rst @@ -0,0 +1,2 @@ +Fix method set_protocol() of class _SSLProtocolTransport in asyncio module. +This method was previously modifying a wrong reference to the protocol. -- 2.40.0