mirror of
https://github.com/caronc/apprise.git
synced 2025-12-15 10:04:06 +08:00
fix parsing of USA callsigns--specifically different prefix/suffix counts like 1x2 and 1x3 calls (#1418)
This commit is contained in:
@@ -107,18 +107,18 @@ PHONE_NO_WPREFIX_DETECTION_RE = re.compile(
|
||||
re.I,
|
||||
)
|
||||
|
||||
# A simple verification check to make sure the content specified
|
||||
# rougly conforms to a ham radio call sign before we parse it further
|
||||
# Quick sanity check - does this look like a valid callsign before we
|
||||
# bother parsing it
|
||||
IS_CALL_SIGN = re.compile(
|
||||
r"^(?P<callsign>[a-z0-9]{2,3}[0-9][a-z0-9]{3})"
|
||||
r"(?P<ssid>-[a-z0-9]{1,2})?\s*$",
|
||||
r"^(?P<callsign>[0-9a-z]{1,2}[0-9][a-z0-9]{1,3})"
|
||||
r"(-(?P<ssid>[0-9]{1,2}))?\s*$",
|
||||
re.I,
|
||||
)
|
||||
|
||||
# Regular expression used to destinguish between multiple ham radio call signs
|
||||
# Regex to split multiple callsigns from a single string
|
||||
CALL_SIGN_DETECTION_RE = re.compile(
|
||||
r"\s*([a-z0-9]{2,3}[0-9][a-z0-9]{3}(?:-[a-z0-9]{1,2})?)"
|
||||
r"(?=$|[\s,]+[a-z0-9]{4,6})",
|
||||
r"\s*([0-9a-z]{1,2}[0-9][a-z0-9]{1,3}(?:-(?:[0-9]{1,2}))?)"
|
||||
r"(?=\s*$|\s*[,;\s]+)",
|
||||
re.I,
|
||||
)
|
||||
|
||||
|
||||
@@ -1685,7 +1685,6 @@ def test_is_call_sign_no():
|
||||
assert utils.parse.is_call_sign(42) is False
|
||||
|
||||
# To short or 2 long
|
||||
assert utils.parse.is_call_sign("DF1AB") is False
|
||||
assert utils.parse.is_call_sign("DF1ABCX") is False
|
||||
assert utils.parse.is_call_sign("DF1ABCEFG") is False
|
||||
assert utils.parse.is_call_sign("1ABCX") is False
|
||||
@@ -1693,6 +1692,36 @@ def test_is_call_sign_no():
|
||||
assert utils.parse.is_call_sign("XXXXXX") is False
|
||||
|
||||
# Some valid checks
|
||||
# 1x2
|
||||
result = utils.parse.is_call_sign("A0AF")
|
||||
assert isinstance(result, dict)
|
||||
assert result["callsign"] == "A0AF"
|
||||
assert result["ssid"] == ""
|
||||
|
||||
# 2x1
|
||||
result = utils.parse.is_call_sign("AA0A")
|
||||
assert isinstance(result, dict)
|
||||
assert result["callsign"] == "AA0A"
|
||||
assert result["ssid"] == ""
|
||||
|
||||
# 2x2
|
||||
result = utils.parse.is_call_sign("AA0AF")
|
||||
assert isinstance(result, dict)
|
||||
assert result["callsign"] == "AA0AF"
|
||||
assert result["ssid"] == ""
|
||||
|
||||
result = utils.parse.is_call_sign("AA0AF-23")
|
||||
assert isinstance(result, dict)
|
||||
assert result["callsign"] == "AA0AF"
|
||||
assert result["ssid"] == "23"
|
||||
|
||||
# 1x3
|
||||
result = utils.parse.is_call_sign("K0ACL")
|
||||
assert isinstance(result, dict)
|
||||
assert result["callsign"] == "K0ACL"
|
||||
assert result["ssid"] == ""
|
||||
|
||||
# 2x3
|
||||
result = utils.parse.is_call_sign("DF1ABC")
|
||||
assert isinstance(result, dict)
|
||||
assert result["callsign"] == "DF1ABC"
|
||||
@@ -1701,7 +1730,7 @@ def test_is_call_sign_no():
|
||||
# Get our SSID
|
||||
result = utils.parse.is_call_sign("DF1ABC-14")
|
||||
assert result["callsign"] == "DF1ABC"
|
||||
assert result["ssid"] == "-14"
|
||||
assert result["ssid"] == "14"
|
||||
|
||||
|
||||
def test_is_phone_no():
|
||||
@@ -1858,6 +1887,12 @@ def test_parse_call_sign():
|
||||
assert "0A1DEF" in results
|
||||
assert "DF1ABC" in results
|
||||
|
||||
results = utils.parse.parse_call_sign("AA0A, A0AF-12, GARBAGE")
|
||||
assert isinstance(results, list)
|
||||
assert len(results) == 2
|
||||
assert "AA0A" in results
|
||||
assert "A0AF-12" in results
|
||||
|
||||
|
||||
def test_parse_phone_no():
|
||||
"""utils: parse_phone_no() testing"""
|
||||
|
||||
@@ -80,6 +80,12 @@ def test_plugin_aprs_urls(mock_create_connection):
|
||||
)
|
||||
assert instance.notify("test") is True
|
||||
|
||||
# 1N3 callsigns
|
||||
instance = apprise.Apprise.instantiate(
|
||||
"aprs://D1JSL-15:12345@D1ABC"
|
||||
)
|
||||
assert isinstance(instance, NotifyAprs)
|
||||
|
||||
instance = apprise.Apprise.instantiate(
|
||||
"aprs://DF1JSL-15:12345@DF1ABC?delay=3.0"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user