11import logging
22
33import asyncio
4+ from collections .abc import AsyncIterator
5+ from abc import abstractmethod , abstractproperty
46
57from ..messages .envelope import FramedBuffer
68
79logger = logging .getLogger (__name__ )
810
911
10- class Transport :
11- def __aiter__ (self ):
12- return self
13-
14- async def __anext__ (self ):
15- raise NotImplementedError ("subclasses should implement this" )
12+ class Transport (AsyncIterator ):
1613
14+ @abstractmethod
1715 async def close (self ):
18- raise NotImplementedError ( "subclasses should implement this" )
16+ pass
1917
20- @property
18+ @abstractproperty
2119 def closed (self ):
22- raise NotImplementedError ( "subclasses should implement this" )
20+ pass
2321
22+ @abstractmethod
2423 async def send (self , bytes_ ):
25- raise NotImplementedError ( "subclasses should implement this" )
24+ pass
2625
2726
2827async def watch_queue (conn , buf ):
@@ -41,7 +40,6 @@ async def watch_queue(conn, buf):
4140 logger .exception ("watch_queue: error received trying to write" )
4241 await buf .put (msg )
4342 return await conn .close ()
44- logger .debug ("watch_queue: ws is now closed" )
4543
4644
4745class Worker :
@@ -56,7 +54,6 @@ def __init__(self, receptor, loop):
5654 self .write_task = None
5755
5856 def start_receiving (self ):
59- logger .debug ("starting recv" )
6057 self .read_task = self .loop .create_task (self .receive ())
6158
6259 async def receive (self ):
@@ -98,7 +95,7 @@ async def start_processing(self):
9895 return await self .write_task
9996
10097 async def _wait_handshake (self ):
101- logger .debug ("serve: waiting for HI" )
98+ logger .debug ("waiting for HI" )
10299 response = await self .buf .get () # TODO: deal with timeout
103100 self .remote_id = response .header ["id" ]
104101 self .register ()
@@ -110,7 +107,7 @@ async def client(self, transport):
110107 await self .hello ()
111108 await self ._wait_handshake ()
112109 await self .start_processing ()
113- logger .debug ("connect: normal exit" )
110+ logger .debug ("normal exit" )
114111 finally :
115112 self .unregister ()
116113
0 commit comments