swimlane.utils package

Utility functions

swimlane.utils.get_recursive_subclasses(cls)[source]

Return list of all subclasses for a class, including subclasses of direct subclasses

swimlane.utils.import_submodules(package)[source]

Return list of imported module instances from beneath root_package

swimlane.utils.one_of_keyword_only(*valid_keywords)[source]

Decorator to help make one-and-only-one keyword-only argument functions more reusable

Notes

Decorated function should take 2 arguments, the first for the key, the second the value

Examples

@one_of_keyword_only('a', 'b', 'c')
def func(key, value):
    if key == 'a':
        ...
    elif key == 'b':
        ...
    else:
        # key = 'c'
        ...

...

func(a=1)
func(b=2)
func(c=3)

try:
    func(d=4)
except TypeError:
    ...

try:
    func(a=1, b=2)
except TypeError:
    ...
Parameters:

*valid_keywords (str) – All allowed keyword argument names

Raises:

TypeError – On decorated call, if 0 or 2+ arguments are provided or kwargs contains a key not in valid_keywords

swimlane.utils.random_string(length, source='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')[source]

Return random string of characters from source of specified length

Parameters:
  • length (int) – Length of the returned string

  • source (str) – String of characters to use as options for randomly selected characters. Defaults to alphanumeric

Returns:

String of length number of characters composed of source characters

Return type:

str

swimlane.utils.validate_type(field, value)[source]

Type validation for filters and fields from bulk_modify, bulk_delete and filter

Submodules