# 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

Filters are small functions that can be run against incoming payload telemetry
during the parse phase, either before attempts at callsign extraction, before
the actual parse (but after the callsign has been identified) or after parsing
is complete.

This module contains commonly used filters which are supplied with habitat, but
end users are free to write their own and have :mod:`habitat.loadable_manager`
load them for use.
"""


__all__ = ["semicolons_to_commas", "numeric_scale", "simple_map",
           "invalid_always", "invalid_location_zero", "invalid_gps_lock",
           "zero_pad_coordinates", "zero_pad_times"]


def semicolons_to_commas(config, data):
    """
    Intermediate filter that converts semicolons to commas.

    All semicolons in the string are replaced with colons and the checksum is
    updated; ``crc16-ccitt`` is assumed by default but can be overwritten with
    ``config["checksum"]``.

    >>> semicolons_to_commas({}, '$$testpayload,1,2,3;4;5;6*8A24')
    '$$testpayload,1,2,3,4,5,6*888F'
    """
    data = {"data": data}
    checksum = config['checksum'] if 'checksum' in config else 'crc16-ccitt'

# 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


Filters are small functions that can be run against incoming payload telemetry
during the parse phase, either before attempts at callsign extraction, before
the actual parse (but after the callsign has been identified) or after parsing
is complete.

This module contains commonly used filters which are supplied with habitat, but
end users are free to write their own and have :mod:`habitat.loadable_manager`
load them for use.
"""


__all__ = ["semicolons_to_commas", "numeric_scale", "simple_map",
           "invalid_always", "invalid_location_zero", "invalid_gps_lock",
           "zero_pad_coordinates", "zero_pad_times"]


def semicolons_to_commas(config, data):
    """
    Intermediate filter that converts semicolons to commas.

    All semicolons in the string are replaced with colons and the checksum is
    updated; ``crc16-ccitt`` is assumed by default but can be overwritten with
    ``config["checksum"]``.

    >>> semicolons_to_commas({}, '$$testpayload,1,2,3;4;5;6*8A24')
    '$$testpayload,1,2,3,4,5,6*888F'
    """
    data = {"data": data}
    checksum = config['checksum'] if 'checksum' in config else 'crc16-ccitt'

    with filtertools.UKHASChecksumFixer(checksum, data) as c: