module documentation

Core utilities

Most common function which are needed everywhere. These function are exported in gws and can be used as gws.function().

Class cached_property Decorator for a cached property.
Function action_url_path Undocumented
Function app_lock Undocumented
Function collect Undocumented
Function compact Remove all None values from a collection.
Function deep_merge Deeply merge dicts/Datas into a nested dict/Data. Latter vales overwrite former ones unless None.
Function delete_app_global Undocumented
Function dirname Undocumented
Function ensure_dir Check if a (possibly nested) directory exists and create if it does not.
Function ensure_system_dirs Undocumented
Function exit Exit the application.
Function first Undocumented
Function format_map Undocumented
Function get Get a nested value/attribute from a structure.
Function get_app_global Undocumented
Function get_cached_object Undocumented
Function get_server_global Undocumented
Function has True if a nested value/attribute exists in a structure.
Function is_atom Undocumented
Function is_bytes Undocumented
Function is_dict Undocumented
Function is_dir Undocumented
Function is_empty Check if the value is empty (None, empty list/dict/object).
Function is_file Undocumented
Function is_list Undocumented
Function join_uid Undocumented
Function merge Create a new dict/Data object by merging values from dicts/Datas or kwargs. Latter vales overwrite former ones unless None.
Function omit Undocumented
Function parse_acl Parse an ACL config into an ACL.
Function pick Undocumented
Function pop Undocumented
Function printtemp Return a transient path name in the print directory.
Function random_string Generate a random string of length size.
Function read_file Undocumented
Function read_file_b Undocumented
Function serialize_to_path Undocumented
Function server_lock Undocumented
Function set_app_global Undocumented
Function sha256 Undocumented
Function split_uid Undocumented
Function strip Strip all strings and remove empty values from a collection.
Function to_bytes Convert a value to bytes by converting it to string and encoding.
Function to_data Convert a value to a Data. If the argument is a Data object, return it.
Function to_dict Convert a value to a dict. If the argument is an object, return its dict.
Function to_float Convert a value to a float or 0.0 if this fails.
Function to_int Convert a value to an int or 0 if this fails.
Function to_lines Convert a multiline string into a list of strings.
Function to_list Convert a value to a list.
Function to_lower_dict Undocumented
Function to_rounded_int Round and convert a value to an int or 0 if this fails.
Function to_str Convert a value to a string.
Function to_uid Convert a value to an uid (alphanumeric string).
Function to_upper_dict Undocumented
Function uniq Remove duplicate elements from a collection.
Function unserialize_from_path Undocumented
Function write_file Undocumented
Function write_file_b Undocumented
Constant UID_DELIMITER Undocumented
Class _FileLock Undocumented
Class _FormatMapDefault Undocumented
Function _chown Undocumented
Function _get Undocumented
Constant _UID_DE_TRANS Undocumented
Variable _app_globals Undocumented
Variable _app_lock Undocumented
Variable _server_globals Undocumented
def action_url_path(name: str, **kwargs) -> str: (source)

Undocumented

def app_lock(name=''): (source)

Undocumented

def collect(pairs): (source)

Undocumented

def compact(x): (source)

Remove all None values from a collection.

def deep_merge(x, y, concat_lists=True): (source)

Deeply merge dicts/Datas into a nested dict/Data. Latter vales overwrite former ones unless None.

Parameters
xdict or Data.
ydict or Data.
concat_listsif true, list will be concatenated, otherwise merged
Returns
A new object (dict or Data).
def delete_app_global(name): (source)

Undocumented

def dirname(path): (source)

Undocumented

def ensure_dir(dir_path: str, base_dir: str = None, mode: int = 493, user: int = None, group: int = None) -> str: (source)

Check if a (possibly nested) directory exists and create if it does not.

Parameters
dir_path:strPath to a directory.
base_dir:strBase directory.
mode:intDirectory creation mode.
user:intDirectory user (defaults to gws.UID)
group:intDirectory group (defaults to gws.GID)
Returns
strThe absolute path to the directory.
def ensure_system_dirs(): (source)

Undocumented

def exit(code: int = 255): (source)

Exit the application.

Parameters
code:intExit code.
def first(it): (source)

Undocumented

def format_map(fmt: str, x: dict|Data, default: str = '') -> str: (source)

Undocumented

def get(x, key, default=None): (source)

Get a nested value/attribute from a structure.

Parameters
xA dict, list or Data.
keyA list or a dot separated string of nested keys.
defaultThe default value.
Returns
The value if it exists and the default otherwise.
def get_app_global(name, init_fn): (source)

Undocumented

def get_cached_object(name: str, life_time: int, init_fn): (source)

Undocumented

def get_server_global(name: str, init_fn): (source)

Undocumented

def has(x, key) -> bool: (source)

True if a nested value/attribute exists in a structure.

Parameters
xA dict, list or Data.
keyA list or a dot separated string of nested keys.
Returns
boolTrue if a key exists
def is_atom(x): (source)

Undocumented

def is_bytes(x): (source)

Undocumented

def is_dict(x): (source)

Undocumented

def is_dir(path): (source)

Undocumented

def is_empty(x) -> bool: (source)

Check if the value is empty (None, empty list/dict/object).

def is_file(path): (source)

Undocumented

def is_list(x): (source)

Undocumented

def join_uid(parent_uid, object_uid): (source)

Undocumented

def merge(*args, **kwargs) -> dict|Data: (source)

Create a new dict/Data object by merging values from dicts/Datas or kwargs. Latter vales overwrite former ones unless None.

Parameters
*argsdicts or Datas.
**kwargsKeyword args.
Returns
dict|DataA new object (dict or Data).
def omit(x, *keys): (source)

Undocumented

def parse_acl(acl) -> types.Acl: (source)

Parse an ACL config into an ACL.

Parameters
aclan ACL config. Can be given as a string allow X, allow Y, deny Z, or as a list of dicts { role X type allow }, { role Y type deny }, or it can already be an ACL [1 X], [0 Y], or it can be None.
Returns
types.AclAccess list.
def pick(x, *keys): (source)

Undocumented

def pop(x, key, default=None): (source)

Undocumented

def printtemp(name: str) -> str: (source)

Return a transient path name in the print directory.

def random_string(size: int) -> str: (source)

Generate a random string of length size.

def read_file(path: str) -> str: (source)

Undocumented

def read_file_b(path: str) -> bytes: (source)

Undocumented

def serialize_to_path(obj, path): (source)

Undocumented

def server_lock(uid): (source)

Undocumented

def set_app_global(name, value): (source)

Undocumented

def sha256(x): (source)

Undocumented

def split_uid(joined_uid: str) -> tuple[str, str]: (source)

Undocumented

def strip(x): (source)

Strip all strings and remove empty values from a collection.

def to_bytes(x, encoding='utf8') -> bytes: (source)

Convert a value to bytes by converting it to string and encoding.

def to_data(x) -> Data: (source)

Convert a value to a Data. If the argument is a Data object, return it.

def to_dict(x) -> dict: (source)

Convert a value to a dict. If the argument is an object, return its dict.

def to_float(x) -> float: (source)

Convert a value to a float or 0.0 if this fails.

def to_int(x) -> int: (source)

Convert a value to an int or 0 if this fails.

def to_lines(txt: str, comment: str = None) -> list[str]: (source)

Convert a multiline string into a list of strings.

Strip each line, skip empty lines, if comment is given, also remove lines starting with it.

def to_list(x, delimiter: str = ',') -> list: (source)

Convert a value to a list.

Parameters
xA value. Is it's a string, split it by the delimiter
delimiter:str
Returns
listA list.
def to_lower_dict(x) -> dict: (source)

Undocumented

def to_rounded_int(x) -> int: (source)

Round and convert a value to an int or 0 if this fails.

def to_str(x, encodings: list[str] = None) -> str: (source)

Convert a value to a string.

Parameters
xValue.
encodings:list[str]A list of acceptable encodings. If the value is bytes, try each encoding, and return the first one which passes without errors.
Returns
strA string.
def to_uid(x) -> str: (source)

Convert a value to an uid (alphanumeric string).

def to_upper_dict(x) -> dict: (source)

Undocumented

def uniq(x): (source)

Remove duplicate elements from a collection.

def unserialize_from_path(path): (source)

Undocumented

def write_file(path: str, s: str, user: int = None, group: int = None): (source)

Undocumented

def write_file_b(path: str, s: bytes, user: int = None, group: int = None): (source)

Undocumented

UID_DELIMITER: str = (source)

Undocumented

Value
'::'
def _chown(path, user, group): (source)

Undocumented

def _get(x, keys): (source)

Undocumented

_UID_DE_TRANS = (source)

Undocumented

Value
{ord('ä'): 'ae', ord('ö'): 'oe', ord('ü'): 'ue', ord('ß'): 'ss'}
_app_globals: dict = (source)

Undocumented

_app_lock = (source)

Undocumented

_server_globals: dict = (source)

Undocumented