UnitValueValidator

class UnitValueValidator(modern_allowed_char_rules=False, value_validators=None)[source]

Validates units.

Methods

UnitValueValidator.__init__([...])

Validates the unit and value classes on a given tag.

UnitValueValidator.check_tag_unit_class_units_are_valid(...)

Report incorrect unit class or units.

UnitValueValidator.check_tag_value_class_valid(...)

Report an invalid value portion.

UnitValueValidator.report_value_char_errors(...)

UnitValueValidator.report_value_errors(...)

UnitValueValidator.validate_value_class_type(...)

Report invalid unit or valid class values.

Attributes

UnitValueValidator.DATE_TIME_VALUE_CLASS

UnitValueValidator.DIGIT_OR_POUND_EXPRESSION

UnitValueValidator.NAME_VALUE_CLASS

UnitValueValidator.NUMERIC_VALUE_CLASS

UnitValueValidator.TEXT_VALUE_CLASS

UnitValueValidator.__init__(modern_allowed_char_rules=False, value_validators=None)[source]

Validates the unit and value classes on a given tag.

Parameters:

value_validators (dict or None) – Override or add value class validators

UnitValueValidator.check_tag_unit_class_units_are_valid(original_tag, validate_text, report_as=None, error_code=None, index_offset=0)[source]

Report incorrect unit class or units.

Parameters:
  • original_tag (HedTag) – The original tag that is used to report the error.

  • validate_text (str) – The text to validate.

  • report_as (HedTag) – Report errors as coming from this tag, rather than original_tag.

  • error_code (str) – Override error codes.

  • index_offset (int) – Offset into the extension validate_text starts at.

Returns:

Validation issues. Each issue is a dictionary.

Return type:

list

UnitValueValidator.check_tag_value_class_valid(original_tag, validate_text, report_as=None, error_code=None, index_offset=0)[source]

Report an invalid value portion.

Parameters:
  • original_tag (HedTag) – The original tag that is used to report the error.

  • validate_text (str) – The text to validate.

  • report_as (HedTag) – Report errors as coming from this tag, rather than original_tag.

  • error_code (str) – Override error codes.

  • index_offset (int) – Offset into the extension validate_text starts at.

Returns:

Validation issues.

Return type:

list

static UnitValueValidator.report_value_char_errors(class_name, errors, report_as, index_adj)[source]
static UnitValueValidator.report_value_errors(error_dict, class_valid, report_as, index_adj)[source]
UnitValueValidator.validate_value_class_type(unit_or_value_portion, valid_types)[source]

Report invalid unit or valid class values.

Parameters:
  • unit_or_value_portion (str) – The value portion to validate.

  • valid_types (list) – The names of value class or unit class types (e.g. dateTime or dateTimeClass).

Returns:

True if this is one of the valid_types validators.

Return type:

type_valid (bool)

UnitValueValidator.DATE_TIME_VALUE_CLASS = 'dateTimeClass'
UnitValueValidator.DIGIT_OR_POUND_EXPRESSION = '^(-?[\\d.]+(?:e-?\\d+)?|#)$'
UnitValueValidator.NAME_VALUE_CLASS = 'nameClass'
UnitValueValidator.NUMERIC_VALUE_CLASS = 'numericClass'
UnitValueValidator.TEXT_VALUE_CLASS = 'textClass'