The ironicclient.openstack.common.strutils Module

System-level utilities and helper functions.

ironicclient.openstack.common.strutils.bool_from_string(subject, strict=False, default=False)[source]

Interpret a string as a boolean.

A case-insensitive match is performed such that strings matching ‘t’, ‘true’, ‘on’, ‘y’, ‘yes’, or ‘1’ are considered True and, when strict=False, anything else returns the value specified by ‘default’.

Useful for JSON-decoded stuff and config file parsing.

If strict=True, unrecognized values, including None, will raise a ValueError which is useful when parsing values passed in from an API call. Strings yielding False are ‘f’, ‘false’, ‘off’, ‘n’, ‘no’, or ‘0’.

ironicclient.openstack.common.strutils.int_from_bool_as_string(subject)[source]

Interpret a string as a boolean and return either 1 or 0.

Any string value in:

(‘True’, ‘true’, ‘On’, ‘on’, ‘1’)

is interpreted as a boolean True.

Useful for JSON-decoded stuff and config file parsing

ironicclient.openstack.common.strutils.safe_decode(text, incoming=None, errors='strict')[source]

Decodes incoming str using incoming if they’re not already unicode.

Parameters:
Returns:

text or a unicode incoming encoded representation of it.

Raises TypeError:
 

If text is not an instance of str

ironicclient.openstack.common.strutils.safe_encode(text, incoming=None, encoding='utf-8', errors='strict')[source]

Encodes incoming str/unicode using encoding.

If incoming is not specified, text is expected to be encoded with current python’s default encoding. (sys.getdefaultencoding)

Parameters:
Returns:

text or a bytestring encoding encoded representation of it.

Raises TypeError:
 

If text is not an instance of str

ironicclient.openstack.common.strutils.to_bytes(text, default=0)[source]

Converts a string into an integer of bytes.

Looks at the last characters of the text to determine what conversion is needed to turn the input text into a byte number. Supports “B, K(B), M(B), G(B), and T(B)”. (case insensitive)

Parameters:
  • text – String input for bytes size conversion.
  • default – Default return value when text is blank.
ironicclient.openstack.common.strutils.to_slug(value, incoming=None, errors='strict')[source]

Normalize string.

Convert to lowercase, remove non-word characters, and convert spaces to hyphens.

Inspired by Django’s slugify filter.

Parameters:
Returns:

slugified unicode representation of value

Raises TypeError:
 

If text is not an instance of str

Previous topic

The ironicclient.openstack.common.importutils Module

Next topic

The ironicclient.openstack.common.uuidutils Module

This Page