kopia lustrzana https://github.com/glidernet/python-ogn-client
Merge pull request #45 from Meisterschueler/fix/UnicodeDecodeError
Fix for fortyfour #44pull/47/head
commit
483b25d4fa
|
@ -1,5 +1,8 @@
|
|||
# CHANGELOG
|
||||
|
||||
## Unreleased
|
||||
- client: Ignore messages other than UTF-8
|
||||
|
||||
## 0.8.0 - 2017-10-02
|
||||
- parser: Merged function 'parse_aprs' and 'parse_ogn_beacon' to 'parse'
|
||||
- parser: Added support for OGNSDR (receiver), OGNTRK (ogn tracker), OGNFLR (flarm) and OGNAV (Naviter) beacons
|
||||
|
|
|
@ -76,6 +76,8 @@ class AprsClient:
|
|||
self.logger.error('BrokenPipeError', exc_info=True)
|
||||
except socket.error:
|
||||
self.logger.error('socket.error', exc_info=True)
|
||||
except UnicodeDecodeError:
|
||||
self.logger.error('UnicodeDecodeError', exc_info=True)
|
||||
|
||||
if autoreconnect and not self._kill:
|
||||
self.connect()
|
||||
|
|
|
@ -44,6 +44,32 @@ class AprsClientTest(unittest.TestCase):
|
|||
client.sock.close.assert_called_once_with()
|
||||
self.assertTrue(client._kill)
|
||||
|
||||
@mock.patch('ogn.client.client.socket')
|
||||
def test_run(self, mock_socket):
|
||||
import socket
|
||||
mock_socket.error = socket.error
|
||||
|
||||
client = AprsClient(aprs_user='testuser', aprs_filter='')
|
||||
client.connect()
|
||||
|
||||
client.sock_file.readline = mock.MagicMock()
|
||||
client.sock_file.readline.side_effect = ['Normal text blabla',
|
||||
'my weird character ¥',
|
||||
UnicodeDecodeError('funnycodec', b'\x00\x00', 1, 2, 'This is just a fake reason!'),
|
||||
'... show must go on',
|
||||
BrokenPipeError(),
|
||||
'... and on',
|
||||
socket.error(),
|
||||
'... and on',
|
||||
KeyboardInterrupt()]
|
||||
|
||||
try:
|
||||
client.run(callback=lambda msg: print("got: {}".format(msg)), autoreconnect=True)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
client.disconnect()
|
||||
|
||||
def test_reset_kill_reconnect(self):
|
||||
client = AprsClient(aprs_user='testuser', aprs_filter='')
|
||||
client.connect()
|
||||
|
|
Ładowanie…
Reference in New Issue