Utilities

class file_config.utils.Types[source]

An enum which keeps a record of top-level type grouping names.

Note

Specifically implemented for ease of use with the TYPE_MAPPINGS and helps reduce the use of magic strings used throughout the is_x_type methods.

ARRAY = 'array'
BOOL = 'bool'
BYTES = 'bytes'
ENUM = 'enum'
INTEGER = 'integer'
NULL = 'null'
NUMBER = 'number'
OBJECT = 'object'
STRING = 'string'
UNION = 'union'
file_config.utils._get_types(type_)[source]

Gathers all types within the TYPE_MAPPINGS for a specific Types value.

Parameters

type (Types) – The type to retrieve

Returns

All types within the TYPE_MAPPINGS

Return type

list

file_config.utils.decode_bytes(string)[source]

Decodes a given base64 string into bytes.

Parameters

string (str) – The string to decode

Returns

The decoded bytes

Return type

bytes

file_config.utils.encode_bytes(bytes_)[source]

Encodes some given bytes into base64 using utf-8.

Parameters

bytes (bytes) – The bytes to encode

Returns

The bytes encoded base64 string

Return type

str

file_config.utils.is_array_type[source]

Checks if the given type is a array type.

Parameters

type – The type to check

Returns

True if the type is a array type, otherwise False

Return type

bool

file_config.utils.is_bool_type[source]

Checks if the given type is a bool type.

Parameters

type – The type to check

Returns

True if the type is a bool type, otherwise False

Return type

bool

file_config.utils.is_builtin_type[source]

Checks if the given type is a bulitin type.

Parameters

type – The type to check

Returns

True if the type is a bulitin, otherwise False

Return type

bool

file_config.utils.is_bytes_type[source]

Checks if the given type is a bytes type.

Parameters

type – The type to check

Returns

True if the type is a bytes type, otherwise False

Return type

bool

file_config.utils.is_collections_type[source]

Checks if the given type is a collections module type

Parameters

type – The type to check

Returns

True if the type is part of the collections module, otherwise False

Return type

bool

file_config.utils.is_compiled_pattern[source]

Checks if the given value is a compiled regex pattern.

Parameters

compiled_pattern – The value to check

Returns

True if the given value is a compiled regex pattern, otherwise False

Return type

bool

file_config.utils.is_config(config_instance)[source]

Checks if the given value is a file_config.config instance.

Parameters

config_instance – The instance to check

Returns

True if the given instance is a config, otherwise False

Return type

bool

file_config.utils.is_config_type(type_)[source]

Checks if the given type is file_config.config decorated.

Parameters

type – The type to check

Returns

True if the type is config decorated, otherwise False

Return type

bool

file_config.utils.is_config_var(var)[source]

Checks if the given value is a valid file_config.var.

Parameters

var – The value to check

Returns

True if the given value is a var, otherwise False

Return type

bool

file_config.utils.is_enum_type[source]

Checks if the given type is an enum type.

Parameters

type – The type to check

Returns

True if the type is a enum type, otherwise False

Return type

bool

file_config.utils.is_integer_type[source]

Checks if the given type is a integer type.

Parameters

type – The type to check

Returns

True if the type is a integer type, otherwise False

Return type

bool

file_config.utils.is_null_type[source]

Checks if the given type is a null type.

Parameters

type – The type to check

Returns

True if the type is a null type, otherwise False

Return type

bool

file_config.utils.is_number_type[source]

Checks if the given type is a number type.

Parameters

type – The type to check

Returns

True if the type is a number type, otherwise False

Return type

bool

file_config.utils.is_object_type(type_)[source]

Checks if the given type is a object type.

Parameters

type – The type to check

Returns

True if the type is a object type, otherwise False

Return type

bool

file_config.utils.is_regex_type[source]

Checks if the given type is a regex type.

Parameters

type – The type to check

Returns

True if the type is a regex type, otherwise False

Return type

bool

file_config.utils.is_string_type[source]

Checks if the given type is a string type.

Parameters

type – The type to check

Returns

True if the type is a string type, otherwise False

Return type

bool

file_config.utils.is_typing_type[source]

Checks if the given type is a typing module type.

Parameters

type – The type to check

Returns

True if the type is part of the typing module, otherwise False

Return type

bool

file_config.utils.is_union_type[source]

Checks if the given type is a union type.

Parameters

type – The type to check

Returns

True if the type is a union type, otherwise False

Return type

bool

file_config.utils.typecast(type_, value)[source]

Tries to smartly typecast the given value with the given type.

Parameters
  • type – The type to try to use for the given value

  • value – The value to try and typecast to the given type

Returns

The typecasted value if possible, otherwise just the original value