Skip to content

Commit

Permalink
ignore messages that contain non printable characters
Browse files Browse the repository at this point in the history
  • Loading branch information
M0r13n committed Nov 12, 2022
1 parent 9755fba commit 43e5010
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
====================
pyais CHANGELOG
====================
-------------------------------------------------------------------------------
Version 2.2.4 11 Nov 2022
-------------------------------------------------------------------------------
* ignores `NonPrintableCharacterException` exceptions when using stream readers
* such messages are simply skipped
-------------------------------------------------------------------------------
Version 2.2.3 04 Nov 2022
-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyais/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pyais.decode import decode

__license__ = 'MIT'
__version__ = '2.2.3'
__version__ = '2.2.4'
__author__ = 'Leon Morten Richter'

__all__ = (
Expand Down
10 changes: 4 additions & 6 deletions pyais/stream.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import typing
from abc import ABC, abstractmethod
from socket import AF_INET, SOCK_DGRAM, SOCK_STREAM, socket
from typing import (
BinaryIO, Generator, Generic, Iterable, List, TypeVar, cast
)
from typing import BinaryIO, Generator, Generic, Iterable, List, TypeVar, cast

from pyais.exceptions import InvalidNMEAMessageException
from pyais.exceptions import InvalidNMEAMessageException, NonPrintableCharacterException
from pyais.messages import NMEAMessage

F = TypeVar("F", BinaryIO, socket, None)
Expand Down Expand Up @@ -52,12 +50,12 @@ def _assemble_messages(self) -> Generator[NMEAMessage, None, None]:

try:
msg: NMEAMessage = NMEAMessage(line)
except InvalidNMEAMessageException:
except (InvalidNMEAMessageException, NonPrintableCharacterException):
# Be gentle and just skip invalid messages
continue

if msg.is_single:
yield msg
yield msg
else:
# Instead of None use -1 as a seq_id
seq_id = msg.seq_id
Expand Down

0 comments on commit 43e5010

Please sign in to comment.