From 2384dbc9048b0fc17624490b7c648c25d384e7a6 Mon Sep 17 00:00:00 2001 From: Bill Mitchell Date: Fri, 6 Apr 2018 00:34:04 -0500 Subject: [PATCH] Cleaned up remove_WIDEn_N function, moved to aprslib.util --- aprslib/parsing/common.py | 16 ---------------- aprslib/util/__init__.py | 8 ++++++++ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/aprslib/parsing/common.py b/aprslib/parsing/common.py index d25dc96..dd8d9cd 100644 --- a/aprslib/parsing/common.py +++ b/aprslib/parsing/common.py @@ -13,7 +13,6 @@ __all__ = [ 'parse_data_extentions', 'parse_comment_altitude', 'parse_dao', - 'remove_WIDEn_N', ] def validate_callsign(callsign, prefix=""): @@ -74,21 +73,6 @@ def parse_header(head): return parsed -def remove_WIDEn_N(path): - """ - Remove WIDEn-N entries and * markers from path, leaving only digi names - path: path of parsed packet (list of strings) - returns: list of digipeaters that digipeated packet, in order - """ - digipath = [] - for digi in path: - digi = re.sub('\*','',digi) # Get rid of * markers - if not re.match('WIDE[0-9]-*[0-9]*',digi): # check for not WIDEn-N - digipath.append(digi) - - return digipath - - def parse_timestamp(body, packet_type=''): parsed = {} diff --git a/aprslib/util/__init__.py b/aprslib/util/__init__.py index df8a9a4..16507b2 100644 --- a/aprslib/util/__init__.py +++ b/aprslib/util/__init__.py @@ -34,3 +34,11 @@ def comment_altitude(altitude): return "/A={0:06.0f}".format(altitude) +def remove_WIDEn_N(path): + """ + Remove WIDEn-N entries and asterisks from path, leaving only digi names + path: path of parsed packet (list of strings) + returns: list of digipeaters that digipeated packet, in order + """ + path = map(lambda x: re.sub('*$', '', x), path) # Remove asterisks + return(path = list(filter(lambda x: not re.match(r'WIDE[0-9\-\*]+$', x), path)))