Add user-defined exception AmbigousTimeError

pull/24/head
Fabian P. Schmidt 2015-12-10 17:25:43 +01:00
rodzic a0a84fb6e4
commit 2e224a16b5
1 zmienionych plików z 19 dodań i 5 usunięć

Wyświetl plik

@ -1,20 +1,34 @@
"""
exception definitions
"""
from datetime import datetime
class AprsParseError(Exception):
"""Parse error while parsing an aprs packet."""
def __init__(self, aprs_string):
self.message = "This is not a valid APRS string: %s" % aprs_string
super(AprsParseError, self).__init__(self.message)
self.aprs_string = aprs_string
self.message = "This is not a valid APRS string: {}".format(aprs_string)
super(AprsParseError, self).__init__(self.message)
class OgnParseError(Exception):
"""Parse error while parsing an aprs packet substring"""
"""Parse error while parsing an aprs packet substring."""
def __init__(self, substring, expected_type):
self.message = "For type %s this is not a valid token: %s" % (expected_type, substring)
super(OgnParseError, self).__init__(self.message)
self.substring = substring
self.expected_type = expected_type
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)