From 3659faa50952a916acd68e584559f1528a63b19e Mon Sep 17 00:00:00 2001 From: Bill Mitchell Date: Thu, 1 Mar 2018 23:54:54 -0600 Subject: [PATCH 1/4] Added third-party packet support --- aprslib/parsing/__init__.py | 8 +++++++- aprslib/parsing/thirdparty.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 aprslib/parsing/thirdparty.py diff --git a/aprslib/parsing/__init__.py b/aprslib/parsing/__init__.py index 43e9766..0da37a5 100644 --- a/aprslib/parsing/__init__.py +++ b/aprslib/parsing/__init__.py @@ -41,6 +41,7 @@ from aprslib.parsing.position import * from aprslib.parsing.mice import * from aprslib.parsing.message import * from aprslib.parsing.telemetry import * +from aprslib.parsing.thirdparty import * from aprslib.parsing.weather import * @@ -158,9 +159,14 @@ def _try_toparse_body(packet_type, body, parsed): # ] - unused # ^ - unused # } - 3rd party traffic - if packet_type in '#$%)* Date: Tue, 1 May 2018 12:03:18 -0500 Subject: [PATCH 2/4] Updated testing to include third-party packets --- tests/test_parse.py | 2 +- tests/test_thirdparty.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/test_thirdparty.py diff --git a/tests/test_parse.py b/tests/test_parse.py index 4974f8d..62ce882 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -66,7 +66,7 @@ class ParseTestCase(unittest.TestCase): def test_unsupported_formats_raising(self): with self.assertRaises(UnknownFormat): - for packet_type in '#$%)*,B:%saaa" % packet_type try: diff --git a/tests/test_thirdparty.py b/tests/test_thirdparty.py new file mode 100644 index 0000000..80a9342 --- /dev/null +++ b/tests/test_thirdparty.py @@ -0,0 +1,58 @@ + +import unittest2 as unittest + +from aprslib import parse +from aprslib.exceptions import ParseError, UnknownFormat + + +class thirdpartyTC(unittest.TestCase): + def test_empty_subpacket(self): + self.assertRaises(ParseError, parse, "A>B:}") + + def test_no_body(self): + self.assertRaises(ParseError, parse, "A>B:}C>D") + + def test_empty_body(self): + self.assertRaises(ParseError, parse, "A>B:}C>D:") + + def testparse_header_exception(self): + self.assertRaises(ParseError, parse, "A>B:}C:asd") + + def test_empty_body_of_format_that_is_not_status(self): + self.assertRaises(ParseError, parse, "A>B:}C>D:!") + + try: + parse("A>B:}C>D:>") + except: + self.fail("empty status packet shouldn't raise exception") + + def test_unsupported_formats_raising(self): + with self.assertRaises(UnknownFormat): + for packet_type in '#$%)*,B:}C>D:%saaa" % packet_type + + try: + parse(packet) + except UnknownFormat as exp: + self.assertEqual(exp.packet, packet) + raise + + def test_valid_thirdparty_msg(self): + packet = "A-1>APRS,B-2,WIDE1*:}C>APU25N,TCPIP,A-1*::DEF :ack56" + result = parse(packet) + self.assertEqual(result['via'],'') + self.assertEqual(result['to'],'APRS') + self.assertEqual(result['from'],'A-1') + self.assertEqual(result['format'],'thirdparty') + self.assertEqual(result['raw'],packet) + self.assertEqual(result['path'],['B-2', 'WIDE1*']) + self.assertEqual(result['subpacket']['raw'],packet[21:]) + self.assertEqual(result['subpacket']['via'],'') + self.assertEqual(result['subpacket']['msgNo'],'56') + self.assertEqual(result['subpacket']['from'],'C') + self.assertEqual(result['subpacket']['path'],['TCPIP', 'A-1*']) + self.assertEqual(result['subpacket']['response'],'ack') + self.assertEqual(result['subpacket']['format'],'message') + self.assertEqual(result['subpacket']['to'],'APU25N') + self.assertEqual(result['subpacket']['addresse'],'DEF') + From 6b96f01db2e9ea0cc0eb42118cce94ca6f5a0d84 Mon Sep 17 00:00:00 2001 From: Bill Mitchell Date: Tue, 1 May 2018 12:03:57 -0500 Subject: [PATCH 3/4] Added ParseError to third-party packet error handling --- aprslib/parsing/thirdparty.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aprslib/parsing/thirdparty.py b/aprslib/parsing/thirdparty.py index ef15a30..58226ea 100644 --- a/aprslib/parsing/thirdparty.py +++ b/aprslib/parsing/thirdparty.py @@ -13,7 +13,7 @@ def parse_thirdparty(body): # Parse sub-packet try: subpacket = parse(body) - except (UnknownFormat) as ukf: + except (UnknownFormat,ParseError) as ukf: raise parsed.update({'subpacket':subpacket}) From e1eda0e53aa447ac151d8f9fa728790872000add Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sat, 27 Nov 2021 12:57:23 +0000 Subject: [PATCH 4/4] fix unittest import in test_thirdparty --- tests/test_thirdparty.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_thirdparty.py b/tests/test_thirdparty.py index 80a9342..f4b0f22 100644 --- a/tests/test_thirdparty.py +++ b/tests/test_thirdparty.py @@ -1,5 +1,5 @@ -import unittest2 as unittest +import unittest from aprslib import parse from aprslib.exceptions import ParseError, UnknownFormat