gemseo / utils

string_tools module

Pretty string utils

Classes:

MessageLine(str_format, level, args, kwargs)

Create new instance of MessageLine(str_format, level, args, kwargs)

MultiLineString([lines])

Multi-line string lazy evaluator.

Functions:

pretty_repr(obj, **kwargs)

String representation of an object.

class gemseo.utils.string_tools.MessageLine(str_format, level, args, kwargs)

Bases: tuple

Create new instance of MessageLine(str_format, level, args, kwargs)

Attributes:

args

Alias for field number 2

kwargs

Alias for field number 3

level

Alias for field number 1

str_format

Alias for field number 0

Methods:

count(value, /)

Return number of occurrences of value.

index(value[, start, stop])

Return first index of value.

args

Alias for field number 2

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

kwargs

Alias for field number 3

level

Alias for field number 1

str_format

Alias for field number 0

class gemseo.utils.string_tools.MultiLineString(lines=None)[source]

Bases: object

Multi-line string lazy evaluator.

The creation of the string is postponed to when an instance is stringified through the __repr__ method. This is mainly used for logging complex strings or objects where the string evaluation cost may be avoided when the logging level dismisses a logging message.

A __add__ method is defined to allow the “+” operator between two instances, that implements the concatenation of two MultiLineString. If the other instance is not MultiLineString, it is first converted to string using its __str__ method and then added as a new line in the result.

Attributes:

DEFAULT_LEVEL

INDENTATION

lines

The strings composing the lines.

Methods:

add(str_format, *args, **kwargs)

Add a line.

dedent()

Decrease the indentation.

indent()

Increase the indentation.

offset()

replace(old, new)

Return a new MultiLineString with all occurrences of old replaced by new.

reset()

Reset the indentation.

Parameters

lines (Optional[Iterable[MessageLine]]) –

By default it is set to None.

Return type

None

DEFAULT_LEVEL = 0
INDENTATION = '   '
add(str_format, *args, **kwargs)[source]

Add a line.

Parameters
  • str_format (str) – The string to be process by the format() method.

  • args – The args passed to the format() method.

  • kwargs – The kwargs passed to the format() method.

  • *args (Any) –

  • **kwargs (Any) –

Return type

None

dedent()[source]

Decrease the indentation.

Return type

None

indent()[source]

Increase the indentation.

Return type

None

property lines

The strings composing the lines.

classmethod offset()[source]
Return type

None

replace(old, new)[source]

Return a new MultiLineString with all occurrences of old replaced by new.

Parameters
  • old (str) – The sub-string to be replaced.

  • new (str) – The sub-string to be replaced with.

Returns

The MultiLineString copy with replaced occurences.

Return type

gemseo.utils.string_tools.MultiLineString

reset()[source]

Reset the indentation.

Return type

None

gemseo.utils.string_tools.pretty_repr(obj, **kwargs)[source]

String representation of an object.

Parameters
  • obj (Any) – The object to represent.

  • **kwargs (Any) –

Returns

A pretty string representation.

Return type

str