Пример #1
0
 def received_message(self, message):
     if isinstance(message, TextMessage):
         # Data is always returned in bytes through the websocket, so convert it first to unicode
         message_dict = from_json(b2u(message.data))
         self.handle_message(message_dict)
     else:
         log.warning('Unsupported message received on websocket server: %r', message)
Пример #2
0
 def _log_process_output(self, message, output, log_level):
     # Process output is always in bytes
     # We expect the encoding of the output to be the same as the encoding we used
     try:
         output_u = safe_trim(b2u(output, encoding=self._encoding))
         log.log(log_level, '%s%s', message, output_u)
     except Exception:
         log.exception('Unable to log process output')
Пример #3
0
def test_b2u():
    assert b2u(b'\xc3\xa9l\xc3\xa0') == u'élà'
Пример #4
0
def test_b2u_exception_fallback_ignore():
    assert b2u(b'\xc3\xa9l\xc3\xa0', 'ascii', 'ignore') == u'l'
Пример #5
0
def test_b2u_exception_fallback_replace():
    assert b2u(b'\xc3\xa9l\xc3\xa0', 'ascii') == u'��l��'