# Path: habitat/utils/filtertools.py
# class UKHASChecksumFixer(object):
#     def __init__(self, protocol, data):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def fix(cls, protocol, old_data, new_data):
#     def _sum(cls, protocol, data):
#     def _sum_length(cls, protocol):
#     def _split_str(cls, protocol, data):


from .utils import filtertools
import math
        config["checksum"] = "crc16-ccitt"

    # get at individual fields, removing newline and checksum
    fields = data.split(",")
    checksum = ""
    fields[-1] = fields[-1].strip()
    if '*' in fields[-1]:
        fields[-1], checksum = fields[-1].split("*")
        checksum = "*{0}".format(checksum)

    # check field exists
    if len(fields) <= config["field"]:
        raise ValueError("Configured field index is not in sentence.")

    # must use colons
    timefield = fields[config["field"]]
    if ":" not in timefield:
        raise ValueError("Can only zero pad times that use a colon delimiter")

    # reformat the time
    timeparts = [int(x) for x in timefield.split(":")]
    timefield = "{0:02n}:{1:02n}".format(timeparts[0], timeparts[1])
    if len(timeparts) == 3:
        timefield = "{0}:{1:02n}".format(timefield, timeparts[2])
    fields[config["field"]] = timefield

    # add checksum and newline back
    fields[-1] = "{0}{1}\n".format(fields[-1], checksum)
    new = ",".join(fields)
    # fix checksum

# Path: habitat/utils/filtertools.py
# class UKHASChecksumFixer(object):
#     def __init__(self, protocol, data):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def fix(cls, protocol, old_data, new_data):
#     def _sum(cls, protocol, data):
#     def _sum_length(cls, protocol):
#     def _split_str(cls, protocol, data):


# Path: habitat/filters.py
from .utils import filtertools
import math

        config["checksum"] = "crc16-ccitt"

    # get at individual fields, removing newline and checksum
    fields = data.split(",")
    checksum = ""
    fields[-1] = fields[-1].strip()
    if '*' in fields[-1]:
        fields[-1], checksum = fields[-1].split("*")
        checksum = "*{0}".format(checksum)

    # check field exists
    if len(fields) <= config["field"]:
        raise ValueError("Configured field index is not in sentence.")

    # must use colons
    timefield = fields[config["field"]]
    if ":" not in timefield:
        raise ValueError("Can only zero pad times that use a colon delimiter")

    # reformat the time
    timeparts = [int(x) for x in timefield.split(":")]
    timefield = "{0:02n}:{1:02n}".format(timeparts[0], timeparts[1])
    if len(timeparts) == 3:
        timefield = "{0}:{1:02n}".format(timefield, timeparts[2])
    fields[config["field"]] = timefield

    # add checksum and newline back
    fields[-1] = "{0}{1}\n".format(fields[-1], checksum)
    new = ",".join(fields)
    # fix checksum

    return filtertools.UKHASChecksumFixer.fix(config["checksum"], data, new)