From 6285051c3979a7e326ab92d47de351e5b2313149 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sat, 18 Jul 2015 06:51:30 +0100 Subject: [PATCH 1/4] added bdist_wheel to Makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a3bad69..52c6407 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ clean: dist: clean python setup.py sdist + python setup.py bdist_wheel --universal upload: dist python setup.py register -r pypi From 347410db37e1ab7a3ecec624564c4593b1388cec Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sat, 18 Jul 2015 07:54:54 +0100 Subject: [PATCH 2/4] fix UnicodeDecodeError raise when detect encoding --- aprslib/parsing.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/aprslib/parsing.py b/aprslib/parsing.py index 37223b4..fbe9596 100644 --- a/aprslib/parsing.py +++ b/aprslib/parsing.py @@ -65,6 +65,25 @@ MTYPE_TABLE_CUSTOM = { } +def _unicode_packet(packet): + # attempt utf-8 + try: + return packet.decode('utf-8') + except UnicodeDecodeError: + pass + + # attempt to detect encoding + res = chardet.detect(packet.split(b':', 1)[-1]) + if res['confidence'] > 0.7: + try: + return packet.decode(res['encoding']) + except UnicodeDecodeError: + pass + + # if everything fails + return packet.decode('latin-1') + + def parse(packet): """ Parses an APRS packet and returns a dict with decoded data @@ -83,15 +102,7 @@ def parse(packet): # attempt to detect encoding if isinstance(packet, bytes): - try: - packet = packet.decode('utf-8') - except UnicodeDecodeError: - res = chardet.detect(packet.split(b':', 1)[-1]) - - if res['confidence'] > 0.7: - packet = packet.decode(res['encoding']) - else: - packet = packet.decode('latin-1') + packet = _unicode_packet(packet) packet = packet.rstrip("\r\n") logger.debug("Parsing: %s", packet) From c8ba854eb46764c355ceed2da48e2641ee1c4da1 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sun, 19 Jul 2015 19:26:10 +0100 Subject: [PATCH 3/4] fix #5 regex bug in mice telemetry parsing --- aprslib/parsing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aprslib/parsing.py b/aprslib/parsing.py index fbe9596..beacc1b 100644 --- a/aprslib/parsing.py +++ b/aprslib/parsing.py @@ -629,7 +629,7 @@ def _parse_mice(dstcall, body): body = body[8:] # check for optional 2 or 5 channel telemetry - match = re.findall(r"^('[0-9a-f]{10}|`[0-9-af]{4})(.*)$", body) + match = re.findall(r"^('[0-9a-f]{10}|`[0-9a-f]{4})(.*)$", body) if match: hexdata, body = match[0] From 7f9c7816b1ed0cd16d9a0b7f067d6258add044b2 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sun, 19 Jul 2015 19:29:00 +0100 Subject: [PATCH 4/4] bump to v0.6.39 --- aprslib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aprslib/__init__.py b/aprslib/__init__.py index 477a038..d7120b2 100644 --- a/aprslib/__init__.py +++ b/aprslib/__init__.py @@ -50,7 +50,7 @@ from datetime import date as _date __date__ = str(_date.today()) del _date -__version__ = "0.6.38" +__version__ = "0.6.39" __author__ = "Rossen Georgiev" __all__ = ['IS', 'parse', 'passcode']