コード例 #1
0
 def handle_message(self, message):
     # self.print(Exchange.iso8601(Exchange.milliseconds()), message)
     if message.type == WSMsgType.TEXT:
         self.handle_text_or_binary_message(message.data)
     elif message.type == WSMsgType.BINARY:
         data = message.data
         if self.gunzip:
             data = gunzip(data)
         elif self.inflate:
             data = inflate(data)
         self.handle_text_or_binary_message(data)
     # autoping is responsible for automatically replying with pong
     # to a ping incoming from a server, we have to disable autoping
     # with aiohttp's websockets and respond with pong manually
     # otherwise aiohttp's websockets client won't trigger WSMsgType.PONG
     elif message.type == WSMsgType.PING:
         if self.verbose:
             self.print(Exchange.iso8601(Exchange.milliseconds()), 'ping',
                        message)
         ensure_future(self.connection.pong())
     elif message.type == WSMsgType.PONG:
         self.lastPong = Exchange.milliseconds()
         if self.verbose:
             self.print(Exchange.iso8601(Exchange.milliseconds()), 'pong',
                        message)
         pass
     elif message.type == WSMsgType.CLOSE:
         if self.verbose:
             self.print(Exchange.iso8601(Exchange.milliseconds()), 'close',
                        self.closed(), message)
         self.on_close(message.data)
     elif message.type == WSMsgType.CLOSED:
         if self.verbose:
             self.print(Exchange.iso8601(Exchange.milliseconds()), 'closed',
                        self.closed(), message)
         self.on_close(1000)
     elif message.type == WSMsgType.ERROR:
         if self.verbose:
             self.print(Exchange.iso8601(Exchange.milliseconds()), 'error',
                        message)
         error = NetworkError(str(message))
         self.on_error(error)
コード例 #2
0
ファイル: exchange.py プロジェクト: mickymartin/exchange_01
 def inflate(data):
     return inflate(data)