summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@gmail.com>2017-03-12 21:06:16 (GMT)
committerGitHub <noreply@github.com>2017-03-12 21:06:16 (GMT)
commit99f8d33a94c8951fd6b2d5f079d20be698150993 (patch)
tree7acd7af9e67bb75ab3c1458464bc8305d71dcb6b /Lib
parentfa448de97de85d242491d7ad259ade0732f05db8 (diff)
downloadcpython-99f8d33a94c8951fd6b2d5f079d20be698150993.zip
cpython-99f8d33a94c8951fd6b2d5f079d20be698150993.tar.gz
cpython-99f8d33a94c8951fd6b2d5f079d20be698150993.tar.bz2
bpo-29742: asyncio get_extra_info() throws exception (#525) (#645)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/sslproto.py4
-rw-r--r--Lib/test/test_asyncio/test_sslproto.py12
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 7ad28d6..ab7ff0b 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -543,8 +543,10 @@ class SSLProtocol(protocols.Protocol):
def _get_extra_info(self, name, default=None):
if name in self._extra:
return self._extra[name]
- else:
+ elif self._transport is not None:
return self._transport.get_extra_info(name, default)
+ else:
+ return default
def _start_shutdown(self):
if self._in_shutdown:
diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py
index 59ff0f6..f1771c5 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -95,5 +95,17 @@ class SslProtoHandshakeTests(test_utils.TestCase):
test_utils.run_briefly(self.loop)
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)
+ def test_get_extra_info_on_closed_connection(self):
+ waiter = asyncio.Future(loop=self.loop)
+ ssl_proto = self.ssl_protocol(waiter)
+ self.assertIsNone(ssl_proto._get_extra_info('socket'))
+ default = object()
+ self.assertIs(ssl_proto._get_extra_info('socket', default), default)
+ self.connection_made(ssl_proto)
+ self.assertIsNotNone(ssl_proto._get_extra_info('socket'))
+ ssl_proto.connection_lost(None)
+ self.assertIsNone(ssl_proto._get_extra_info('socket'))
+
+
if __name__ == '__main__':
unittest.main()