]> granicus.if.org Git - python/commitdiff
asyncio: Add set_protocol / get_protocol methods to Transports
authorYury Selivanov <yury@magic.io>
Mon, 12 Sep 2016 01:11:02 +0000 (21:11 -0400)
committerYury Selivanov <yury@magic.io>
Mon, 12 Sep 2016 01:11:02 +0000 (21:11 -0400)
Lib/asyncio/base_subprocess.py
Lib/asyncio/proactor_events.py
Lib/asyncio/selector_events.py
Lib/asyncio/sslproto.py
Lib/asyncio/transports.py
Lib/asyncio/unix_events.py
Lib/test/test_asyncio/test_sslproto.py

index 8fc253c18eb981d1d6079ce374bfdafffed21261..bcc481d20ea54a385d0ff56dbeb9fa7a83a78334 100644 (file)
@@ -87,6 +87,12 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
     def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
         raise NotImplementedError
 
+    def set_protocol(self, protocol):
+        self._protocol = protocol
+
+    def get_protocol(self):
+        return self._protocol
+
     def is_closing(self):
         return self._closed
 
index 3ac314c0cc667d4b8ed82141e1fbf5a482173f73..97ab487f974c3fcb4698a27b64b2249ffb850aa3 100644 (file)
@@ -66,6 +66,12 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
     def _set_extra(self, sock):
         self._extra['pipe'] = sock
 
+    def set_protocol(self, protocol):
+        self._protocol = protocol
+
+    def get_protocol(self):
+        return self._protocol
+
     def is_closing(self):
         return self._closing
 
index ed2b4d756feddec5a4b8846ff8f0e9d8a23ccc36..c57f509a12b444d1b70f9c3a4e0e1ace072b6f9a 100644 (file)
@@ -560,6 +560,12 @@ class _SelectorTransport(transports._FlowControlMixin,
     def abort(self):
         self._force_close(None)
 
+    def set_protocol(self, protocol):
+        self._protocol = protocol
+
+    def get_protocol(self):
+        return self._protocol
+
     def is_closing(self):
         return self._closing
 
index 33d5de2db0ee1ac120f6f8b6f6d84ac81e3291c5..afe85a143870c264e4a2fa4a8b33f4de87d9dacb 100644 (file)
@@ -305,6 +305,12 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
         """Get optional transport information."""
         return self._ssl_protocol._get_extra_info(name, default)
 
+    def set_protocol(self, protocol):
+        self._app_protocol = protocol
+
+    def get_protocol(self):
+        return self._app_protocol
+
     def is_closing(self):
         return self._closed
 
index 9a6d9197d9a0aa350b8f00b8bfe4e1235abe50f5..0db0875715619d04b8c4a2f7a5fdbe934bb03981 100644 (file)
@@ -33,6 +33,14 @@ class BaseTransport:
         """
         raise NotImplementedError
 
+    def set_protocol(self, protocol):
+        """Set a new protocol."""
+        raise NotImplementedError
+
+    def get_protocol(self):
+        """Return the current protocol."""
+        raise NotImplementedError
+
 
 class ReadTransport(BaseTransport):
     """Interface for read-only transports."""
index 18519fc120f5bfe4a3c2f1fa6aaf766f7780208b..f7f9eb2a1dde822deb3858384d1f8f06418ecda2 100644 (file)
@@ -374,6 +374,12 @@ class _UnixReadPipeTransport(transports.ReadTransport):
     def resume_reading(self):
         self._loop.add_reader(self._fileno, self._read_ready)
 
+    def set_protocol(self, protocol):
+        self._protocol = protocol
+
+    def get_protocol(self):
+        return self._protocol
+
     def is_closing(self):
         return self._closing
 
@@ -570,6 +576,12 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
             self._loop.remove_reader(self._fileno)
             self._loop.call_soon(self._call_connection_lost, None)
 
+    def set_protocol(self, protocol):
+        self._protocol = protocol
+
+    def get_protocol(self):
+        return self._protocol
+
     def is_closing(self):
         return self._closing
 
index 8d5233565e4612a518fa10a413f3e4e584a87ce5..7dfa6c2c63b2be27818b08130d194f075f4dd395 100644 (file)
@@ -25,6 +25,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
         sslcontext = test_utils.dummy_ssl_context()
         app_proto = asyncio.Protocol()
         proto = sslproto.SSLProtocol(self.loop, app_proto, sslcontext, waiter)
+        self.assertIs(proto._app_transport.get_protocol(), app_proto)
         self.addCleanup(proto._app_transport.close)
         return proto