From ad7d2b382133dbbeaa60b7c5dccbc1166394aa70 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 21 Oct 2016 16:04:37 -0400 Subject: [PATCH] Add set_protocol and get_protocol to uvloop Transports (issue #42) --- tests/test_tcp.py | 7 +++++++ uvloop/handles/basetransport.pyx | 6 ++++++ uvloop/handles/process.pyx | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/tests/test_tcp.py b/tests/test_tcp.py index 4feead2..8a91f97 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -490,6 +490,13 @@ class _TestTCP: t, p = await self.loop.create_connection( lambda: asyncio.Protocol(), *addr) + if hasattr(t, 'get_protocol'): + p2 = asyncio.Protocol() + self.assertIs(t.get_protocol(), p) + t.set_protocol(p2) + self.assertIs(t.get_protocol(), p2) + t.set_protocol(p) + self.assertFalse(t._paused) t.pause_reading() self.assertTrue(t._paused) diff --git a/uvloop/handles/basetransport.pyx b/uvloop/handles/basetransport.pyx index 167f56f..7c63bcb 100644 --- a/uvloop/handles/basetransport.pyx +++ b/uvloop/handles/basetransport.pyx @@ -241,6 +241,12 @@ cdef class UVBaseTransport(UVSocketHandle): def __get__(self): return bool(not self._is_reading()) + def get_protocol(self): + return self._protocol + + def set_protocol(self, protocol): + self._set_protocol(protocol) + def _force_close(self, exc): # Used by SSLProto. Might be removed in the future. if self._conn_lost or self._closed: diff --git a/uvloop/handles/process.pyx b/uvloop/handles/process.pyx index bb921ce..4f556c8 100644 --- a/uvloop/handles/process.pyx +++ b/uvloop/handles/process.pyx @@ -570,6 +570,12 @@ cdef class UVProcessTransport(UVProcess): return handle + def get_protocol(self): + return self._protocol + + def set_protocol(self, protocol): + self._protocol = protocol + def get_pid(self): return self._pid