Skip to content

Commit 218b7bb

Browse files
committed
fix parsing of USA callsigns--specifically different prefix/suffix counts like 1x2 and 1x3 calls
1 parent 27091b5 commit 218b7bb

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

apprise/utils/parse.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@
107107
re.I,
108108
)
109109

110-
# A simple verification check to make sure the content specified
111-
# rougly conforms to a ham radio call sign before we parse it further
110+
# Quick sanity check - does this look like a valid callsign before we
111+
# bother parsing it
112112
IS_CALL_SIGN = re.compile(
113-
r"^(?P<callsign>[a-z0-9]{2,3}[0-9][a-z0-9]{3})"
114-
r"(?P<ssid>-[a-z0-9]{1,2})?\s*$",
113+
r"^(?P<callsign>[a-z]{1,3}[0-9][a-z]{1,3})"
114+
r"(?P<ssid>-(?:[0-9]|1[0-5]))?\s*$",
115115
re.I,
116116
)
117117

118-
# Regular expression used to destinguish between multiple ham radio call signs
118+
# Regex to split multiple callsigns from a single string
119119
CALL_SIGN_DETECTION_RE = re.compile(
120-
r"\s*([a-z0-9]{2,3}[0-9][a-z0-9]{3}(?:-[a-z0-9]{1,2})?)"
121-
r"(?=$|[\s,]+[a-z0-9]{4,6})",
120+
r"\s*([a-z0-9]{1,2}[0-9][a-z0-9]{1,3}(?:-(?:[0-9]|1[0-5]))?)"
121+
r"(?=\s*$|\s*[,;\s]+)",
122122
re.I,
123123
)
124124

tests/test_apprise_utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,14 +1685,38 @@ def test_is_call_sign_no():
16851685
assert utils.parse.is_call_sign(42) is False
16861686

16871687
# To short or 2 long
1688-
assert utils.parse.is_call_sign("DF1AB") is False
16891688
assert utils.parse.is_call_sign("DF1ABCX") is False
16901689
assert utils.parse.is_call_sign("DF1ABCEFG") is False
16911690
assert utils.parse.is_call_sign("1ABCX") is False
16921691
# 4th character is not an number
16931692
assert utils.parse.is_call_sign("XXXXXX") is False
16941693

16951694
# Some valid checks
1695+
# 1x2
1696+
result = utils.parse.is_call_sign("A0AF")
1697+
assert isinstance(result, dict)
1698+
assert result["callsign"] == "A0AF"
1699+
assert result["ssid"] == ""
1700+
1701+
# 2x1
1702+
result = utils.parse.is_call_sign("AA0A")
1703+
assert isinstance(result, dict)
1704+
assert result["callsign"] == "AA0A"
1705+
assert result["ssid"] == ""
1706+
1707+
# 2x2
1708+
result = utils.parse.is_call_sign("AA0AF")
1709+
assert isinstance(result, dict)
1710+
assert result["callsign"] == "AA0AF"
1711+
assert result["ssid"] == ""
1712+
1713+
# 1x3
1714+
result = utils.parse.is_call_sign("K0ACL")
1715+
assert isinstance(result, dict)
1716+
assert result["callsign"] == "K0ACL"
1717+
assert result["ssid"] == ""
1718+
1719+
# 2x3
16961720
result = utils.parse.is_call_sign("DF1ABC")
16971721
assert isinstance(result, dict)
16981722
assert result["callsign"] == "DF1ABC"

tests/test_plugin_aprs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ def test_plugin_aprs_urls(mock_create_connection):
8080
)
8181
assert instance.notify("test") is True
8282

83+
# 1N3 callsigns
84+
instance = apprise.Apprise.instantiate(
85+
"aprs://D1JSL-15:12345@D1ABC"
86+
)
87+
assert isinstance(instance, NotifyAprs)
88+
8389
instance = apprise.Apprise.instantiate(
8490
"aprs://DF1JSL-15:12345@DF1ABC?delay=3.0"
8591
)

0 commit comments

Comments
 (0)