nistbeacon/nistbeaconvalue.py
def from_xml(cls, input_xml: str) -> 'NistBeaconValue':
        """
        Convert a string of XML which represents a NIST Randomness Beacon value
        into a 'NistBeaconValue' object.

        :param input_xml: XML to build a 'NistBeaconValue' from
        :return: A 'NistBeaconValue' object, 'None' otherwise
        """

        invalid_result = None

        understood_namespaces = {
            'nist-0.1': 'http://beacon.nist.gov/record/0.1/',
        }

        # Our required values are "must haves". This makes it simple
        # to verify we loaded everything out of XML correctly.
        required_values = {
            cls._KEY_FREQUENCY: None,
            cls._KEY_OUTPUT_VALUE: None,
            cls._KEY_PREVIOUS_OUTPUT_VALUE: None,
            cls._KEY_SEED_VALUE: None,
            cls._KEY_SIGNATURE_VALUE: None,
            cls._KEY_STATUS_CODE: None,
            cls._KEY_TIMESTAMP: None,
            cls._KEY_VERSION: None,
        }

        # First attempt to load the xml, return 'None' on ParseError
        try:
            tree = ElementTree.ElementTree(ElementTree.fromstring(input_xml))
        except ElementTree.ParseError:
            return invalid_result

        # Using the required values, let's load the xml values in
        for key in required_values:
            discovered_element = tree.find(
                "{0}:{1}".format('nist-0.1', key),
                namespaces=understood_namespaces,
            )

            if not isinstance(discovered_element, ElementTree.Element):
                continue

            # Bad pylint message - https://github.com/PyCQA/pylint/issues/476
            # pylint: disable=no-member
            required_values[key] = discovered_element.text

        # Confirm that the required values are set, and not 'None'
        if None in required_values.values():
            return invalid_result

        # We have all the required values, return a node object
        return cls(
            version=required_values[cls._KEY_VERSION],
            frequency=int(required_values[cls._KEY_FREQUENCY]),
            timestamp=int(required_values[cls._KEY_TIMESTAMP]),
            seed_value=required_values[cls._KEY_SEED_VALUE],
            previous_output_value=required_values[
                cls._KEY_PREVIOUS_OUTPUT_VALUE
            ],
            signature_value=required_values[cls._KEY_SIGNATURE_VALUE],
            output_value=required_values[cls._KEY_OUTPUT_VALUE],
            status_code=required_values[cls._KEY_STATUS_CODE],
        )
def from_xml(cls, input_xml: str) -> 'NistBeaconValue':
        """
        Convert a string of XML which represents a NIST Randomness Beacon value
        into a 'NistBeaconValue' object.

        :param input_xml: XML to build a 'NistBeaconValue' from
        :return: A 'NistBeaconValue' object, 'None' otherwise
        """

        invalid_result = None

        understood_namespaces = {
            'nist-0.1': 'http://beacon.nist.gov/record/0.1/',
        }

        # Our required values are "must haves". This makes it simple
        # to verify we loaded everything out of XML correctly.
        required_values = {
            cls._KEY_FREQUENCY: None,
            cls._KEY_OUTPUT_VALUE: None,
            cls._KEY_PREVIOUS_OUTPUT_VALUE: None,
            cls._KEY_SEED_VALUE: None,
            cls._KEY_SIGNATURE_VALUE: None,
            cls._KEY_STATUS_CODE: None,
            cls._KEY_TIMESTAMP: None,
            cls._KEY_VERSION: None,
        }

        # First attempt to load the xml, return 'None' on ParseError
        try:
            tree = ElementTree.ElementTree(ElementTree.fromstring(input_xml))
        except ElementTree.ParseError:
            return invalid_result

        # Using the required values, let's load the xml values in
        for key in required_values:
            discovered_element = tree.find(
                "{0}:{1}".format('nist-0.1', key),
                namespaces=understood_namespaces,
            )

            if not isinstance(discovered_element, ElementTree.Element):
                continue

            # Bad pylint message - https://github.com/PyCQA/pylint/issues/476
            # pylint: disable=no-member
            required_values[key] = discovered_element.text

        # Confirm that the required values are set, and not 'None'
        if None in required_values.values():
            return invalid_result

        # We have all the required values, return a node object
        return cls(
            version=required_values[cls._KEY_VERSION],
            frequency=int(required_values[cls._KEY_FREQUENCY]),
            timestamp=int(required_values[cls._KEY_TIMESTAMP]),
            seed_value=required_values[cls._KEY_SEED_VALUE],
            previous_output_value=required_values[
                cls._KEY_PREVIOUS_OUTPUT_VALUE
            ],
            signature_value=required_values[cls._KEY_SIGNATURE_VALUE],
            output_value=required_values[cls._KEY_OUTPUT_VALUE],
            status_code=required_values[cls._KEY_STATUS_CODE],
        )
Convert a string of XML which represents a NIST Randomness Beacon value
        into a 'NistBeaconValue' object.

        :param input_xml: XML to build a 'NistBeaconValue' from
        :return: A 'NistBeaconValue' object, 'None' otherwise