rics.translation.offline.parse_format_string#

Utility module for parsing raw Format input strings.

Functions

get_elements(fmt)

Split a format string into elements.

Classes

Element(part, placeholders, required)

Information about a single block in a Format specification.

Exceptions

BadDelimiterError(format_string, open_idx, idx)

Errors raised due to mismatched delimiters.

MalformedOptionalBlockError

Error raised for improper optional blocks.

UnusedOptionalBlockError(format_string, ...)

Errors raised when optional blocks do not use any placeholders.

exception MalformedOptionalBlockError[source]#

Bases: ValueError

Error raised for improper optional blocks.

static get_marker_row(format_string: str, open_idx: int = -1, idx: int = -1) str[source]#

Get a string of length equal to format_string which marks problem locations.

exception UnusedOptionalBlockError(format_string: str, open_idx: int, idx: int)[source]#

Bases: MalformedOptionalBlockError

Errors raised when optional blocks do not use any placeholders.

exception BadDelimiterError(format_string: str, open_idx: int, idx: int)[source]#

Bases: MalformedOptionalBlockError

Errors raised due to mismatched delimiters.

class Element(part: str, placeholders: List[str], required: bool)[source]#

Bases: object

Information about a single block in a Format specification.

part: str#

String literal.

placeholders: List[str]#

Placeholder names in part, if any.

required: bool#

Flag indicating whether the element may be excluded.

property positional_part: str#

Return a positional version of the part attribute.

static make(s: str, in_optional_block: bool) Element[source]#

Create an Element from an input string s.

Parameters:
  • s – Input data.

  • in_optional_block – Flag indicating whether s was found inside an optional block.

Returns:

A new Element.

get_elements(fmt: str) List[Element][source]#

Split a format string into elements.

Parameters:

fmt – User input string.

Returns:

A list of parsed elements.

Raises: