Configurations

Functions to manage the configuration of py-linq-sql.

is_read_only()

Verify if the library configuration is read only or not.

Returns:
  • bool – True if we want denied write to database, False otherwise.

Source code in py_linq_sql/config/config.py
def is_read_only() -> bool:
    """
    Verify if the library configuration is read only or not.

    Returns:
        True if we want denied write to database, False otherwise.
    """
    config = _get_config()
    return cast(bool, config["readonly"])

is_valid_table_name_with_white_and_black_list(table_name)

Verify if the table name is not in the black list and in the white list.

If no (or empty) white and/or black list we treat the specific cases according to: black list white list.

See the documentation to learn more proposed specific cases.

Parameters:
  • table_name (str) – The name of the table to validate.

Returns:
  • bool – True is the table name is valid, False otherwise.

Source code in py_linq_sql/config/config.py
def is_valid_table_name_with_white_and_black_list(  # type: ignore[return]
    table_name: str,
) -> bool:
    """
    Verify if the table name is not in the black list and in the white list.

    If no (or empty) white and/or black list we treat the specific cases according to:
    black list  white list.

    See the documentation to learn more proposed specific cases.

    Args:
        table_name: The name of the table to validate.

    Returns:
        True is the table name is valid, False otherwise.
    """
    config = _get_config()

    w_list = (
        None
        if config["whitelist"] is None
        else set(cast(Iterable, config["whitelist"]))
    )
    b_list = (
        None
        if config["blacklist"] is None
        else set(cast(Iterable, config["blacklist"]))
    )

    match (w_list, b_list):
        case (None, None):
            return True
        case (None, set()) if not b_list:
            return True
        case (set(), _) if not w_list:
            return False
        case (None, _):
            return table_name not in b_list  # type: ignore[operator]
        case (_, None):
            return table_name in w_list  # type: ignore[operator]
        case _:
            return table_name in w_list - b_list  # type: ignore[operator]