Skip to content

Commit fe142f4

Browse files
committed
allow trailing = in METAR code
closes #84
1 parent b4f8e19 commit fe142f4

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

metar/Metar.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ def xlate_loc(loc):
269269

270270
# Helper functions
271271

272+
def _sanitize(code):
273+
"""Some string prep to improve parsing fidelity."""
274+
# Remove extraneous whitespace, any trailing =, then add trailing
275+
# whitespace as regex matches need that.
276+
return "%s " % (code.strip().rstrip("="), )
277+
278+
272279
def _report_match(handler, match):
273280
"""Report success or failure of the given handler function. (DEBUG)"""
274281
if match:
@@ -366,7 +373,8 @@ def __init__(self, metarcode, month=None, year=None, utcdelta=None,
366373
self._month = month
367374
self._year = year
368375

369-
code = self.code+" " # (the regexps all expect trailing spaces...)
376+
# Do some string prep before parsing
377+
code = _sanitize(self.code)
370378
try:
371379
ngroup = len(self.handlers)
372380
igroup = 0

test/test_metar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ def test_module():
3939
assert hasattr(metar, "__version__")
4040

4141

42+
@pytest.mark.parametrize("trailstr", ["", "=", "= "])
43+
def test_issue84_trimequals(trailstr):
44+
"""A trailing = in METAR should not trip up the ingest."""
45+
code = (
46+
"KABI 031752Z 30010KT 6SM BR FEW009 OVC036 02/01 A3003 RMK AO2 "
47+
"SLP176 60001 I%i003 T00170006 10017 21006 56017"
48+
)
49+
assert Metar.Metar("%s%s" % (code, trailstr)).decode_completed
50+
51+
4252
@pytest.mark.parametrize("hours", [1, 3, 6])
4353
def test_issue77_ice_accretion(hours):
4454
"""Metar parser supports ice accretion data."""

0 commit comments

Comments
 (0)