Add set_protocol and get_protocol to uvloop Transports (issue #42)

This commit is contained in:
Yury Selivanov 2016-10-21 16:04:37 -04:00
parent b2d34939a1
commit ad7d2b3821
3 changed files with 19 additions and 0 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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