2015-11-15 18:21:19 +00:00
|
|
|
"""
|
|
|
|
exception definitions
|
|
|
|
"""
|
2015-12-10 16:25:43 +00:00
|
|
|
from datetime import datetime
|
2015-11-15 18:21:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AprsParseError(Exception):
|
2015-11-19 22:17:12 +00:00
|
|
|
"""Parse error while parsing an aprs packet."""
|
|
|
|
def __init__(self, aprs_string):
|
|
|
|
self.aprs_string = aprs_string
|
|
|
|
|
2015-12-10 16:25:43 +00:00
|
|
|
self.message = "This is not a valid APRS string: {}".format(aprs_string)
|
|
|
|
super(AprsParseError, self).__init__(self.message)
|
|
|
|
|
2015-11-19 22:17:12 +00:00
|
|
|
|
|
|
|
class OgnParseError(Exception):
|
2015-12-10 16:25:43 +00:00
|
|
|
"""Parse error while parsing an aprs packet substring."""
|
2015-11-19 22:17:12 +00:00
|
|
|
def __init__(self, substring, expected_type):
|
2015-11-15 18:21:19 +00:00
|
|
|
self.substring = substring
|
|
|
|
self.expected_type = expected_type
|
2015-12-10 16:25:43 +00:00
|
|
|
|
|
|
|
self.message = "For type {} this is not a valid token: {}".format(expected_type, substring)
|
|
|
|
super(OgnParseError, self).__init__(self.message)
|
|
|
|
|
|
|
|
|
|
|
|
class AmbigousTimeError(Exception):
|
|
|
|
"""Timstamp from the past/future, can't fully reconstruct datetime from timestamp."""
|
|
|
|
def __init__(self, reference, packet_time):
|
|
|
|
self.reference = reference
|
|
|
|
self.packet_time = packet_time
|
|
|
|
self.timedelta = reference - datetime.combine(reference, packet_time)
|
|
|
|
|
|
|
|
self.message = "Can't reconstruct timstamp, {:.0f}s from past.".format(self.timedelta.total_seconds())
|
|
|
|
super(AmbigousTimeError, self).__init__(self.message)
|