# Path: habitat/parser.py
# class ParserModule(object):
#     """
#     Base class for real ParserModules to inherit from.
# 
#     **ParserModules** are classes which turn radio strings into useful data.
#     They do not have to inherit from :class:`ParserModule`, but can if they
#     want. They must implement :meth:`pre_parse` and :meth:`parse` as described
#     below.
#     """
#     def __init__(self, parser):
#         self.parser = parser
#         self.loadable_manager = parser.loadable_manager
# 
#     def pre_parse(self, string):
#         """
#         Go though *string* and attempt to extract a callsign, returning
#         it as a string. If *string* is not parseable by this module, raise
#         :py:class:`CantParse`. If *string* might be parseable but no callsign
#         could be extracted, raise :py:class:`CantExtractCallsign`.
#         """
#         raise ValueError()
# 
#     def parse(self, string, config):
#         """
#         Go through *string* which has been identified as the format this
#         parser module should be able to parse, extracting the data as per
#         the information in *config*, which is the ``sentence`` dictionary
#         extracted from the payload's configuration document.
#         """
#         raise ValueError()
# 
# class CantParse(Exception):
#     """Parser module cannot parse the given sentence."""
#     pass
# 
# Path: habitat/utils/checksums.py
# def crc16_ccitt(data):
# def xor(data):
# def fletcher_16(data, modulus=255):


import re
from ..parser import ParserModule, CantParse
from ..utils import checksums
        :py:exc:`ValueError <exceptions.ValueError>` is raised in invalid
        inputs.
        """

        name = config["name"]
        sensor = 'sensors.' + config["sensor"]

        try:
            data = self.loadable_manager.run(sensor, config, field)
        except (ValueError, KeyError) as e:
            # Annotate error with the field name.
            error_type = type(e)
            raise error_type("(field {f}): {e!s}".format(f=name, e=e))

        return name, data

    def pre_parse(self, string):
        """
        Check if *string* is parsable by this module.

        If it is, :meth:`pre_parse` extracts the payload
        name and return it. Otherwise, a
        :exc:`ValueError <exceptions.ValueError>` is raised.
        """

        try:
            string, checksum = self._split_basic_format(string)
            fields = self._extract_fields(string)
            self._verify_callsign(fields[0])
        except (ValueError, KeyError):

# Path: habitat/parser.py
# class ParserModule(object):
#     """
#     Base class for real ParserModules to inherit from.
# 
#     **ParserModules** are classes which turn radio strings into useful data.
#     They do not have to inherit from :class:`ParserModule`, but can if they
#     want. They must implement :meth:`pre_parse` and :meth:`parse` as described
#     below.
#     """
#     def __init__(self, parser):
#         self.parser = parser
#         self.loadable_manager = parser.loadable_manager
# 
#     def pre_parse(self, string):
#         """
#         Go though *string* and attempt to extract a callsign, returning
#         it as a string. If *string* is not parseable by this module, raise
#         :py:class:`CantParse`. If *string* might be parseable but no callsign
#         could be extracted, raise :py:class:`CantExtractCallsign`.
#         """
#         raise ValueError()
# 
#     def parse(self, string, config):
#         """
#         Go through *string* which has been identified as the format this
#         parser module should be able to parse, extracting the data as per
#         the information in *config*, which is the ``sentence`` dictionary
#         extracted from the payload's configuration document.
#         """
#         raise ValueError()
# 
# class CantParse(Exception):
#     """Parser module cannot parse the given sentence."""
#     pass
# 
# Path: habitat/utils/checksums.py
# def crc16_ccitt(data):
# def xor(data):
# def fletcher_16(data, modulus=255):


# Path: habitat/parser_modules/ukhas_parser.py
import re
from ..parser import ParserModule, CantParse
from ..utils import checksums

        :py:exc:`ValueError <exceptions.ValueError>` is raised in invalid
        inputs.
        """

        name = config["name"]
        sensor = 'sensors.' + config["sensor"]

        try:
            data = self.loadable_manager.run(sensor, config, field)
        except (ValueError, KeyError) as e:
            # Annotate error with the field name.
            error_type = type(e)
            raise error_type("(field {f}): {e!s}".format(f=name, e=e))

        return name, data

    def pre_parse(self, string):
        """
        Check if *string* is parsable by this module.

        If it is, :meth:`pre_parse` extracts the payload
        name and return it. Otherwise, a
        :exc:`ValueError <exceptions.ValueError>` is raised.
        """

        try:
            string, checksum = self._split_basic_format(string)
            fields = self._extract_fields(string)
            self._verify_callsign(fields[0])
        except (ValueError, KeyError):

            raise CantParse