cowbird.constants

Constant settings for Cowbird application.

Constants defined with format COWBIRD_[VARIABLE_NAME] can be matched with corresponding settings formatted as cowbird.[variable_name] in the cowbird.ini configuration file.

Note

Since the cowbird.ini file has to be loaded by the application to retrieve various configuration settings, constant COWBIRD_INI_FILE_PATH (or any other path variable defined before it - see below) has to be defined by environment variable if the default location is not desired (ie: if you want to provide your own configuration).

Module Contents

Functions

_get_default_log_level()

Get logging level from INI configuration file or fallback to default INFO if it cannot be retrieved.

get_constant_setting_name(name)

Find the equivalent setting name of the provided environment variable name.

get_constant(constant_name: Ellipsis, settings_container: Optional[cowbird.typedefs.AnySettingsContainer] = None, settings_name: Optional[str] = None, default_value: Optional[cowbird.typedefs.SettingValue] = None, raise_missing: bool = True, print_missing: bool = False, raise_not_set: bool = True) → cowbird.typedefs.SettingValue

Search in order for matched value of constant_name:

validate_required(container: cowbird.typedefs.AnySettingsContainer) → None

Validates that some value is provided for every mandatory configuration setting.

Attributes

COWBIRD_MODULE_DIR

COWBIRD_ROOT

COWBIRD_CONFIG_DIR

COWBIRD_CONFIG_PATH

COWBIRD_INI_FILE_PATH

COWBIRD_URL

COWBIRD_LOG_LEVEL

COWBIRD_LOG_PRINT

COWBIRD_LOG_REQUEST

COWBIRD_LOG_EXCEPTION

COWBIRD_ADMIN_PERMISSION

COWBIRD_CONSTANTS

_REGEX_ASCII_ONLY

_SETTING_SECTION_PREFIXES

_SETTINGS_REQUIRED

cowbird.constants.COWBIRD_MODULE_DIR[source]
cowbird.constants.COWBIRD_ROOT[source]
cowbird.constants.COWBIRD_CONFIG_DIR[source]
cowbird.constants.COWBIRD_CONFIG_PATH[source]
cowbird.constants.COWBIRD_INI_FILE_PATH[source]
cowbird.constants._get_default_log_level()[source]

Get logging level from INI configuration file or fallback to default INFO if it cannot be retrieved.

cowbird.constants.COWBIRD_URL[source]
cowbird.constants.COWBIRD_LOG_LEVEL[source]
cowbird.constants.COWBIRD_LOG_PRINT[source]
cowbird.constants.COWBIRD_LOG_REQUEST[source]
cowbird.constants.COWBIRD_LOG_EXCEPTION[source]
cowbird.constants.COWBIRD_ADMIN_PERMISSION = admin[source]
cowbird.constants.COWBIRD_CONSTANTS = ['COWBIRD_CONSTANTS', 'COWBIRD_MODULE_DIR', 'COWBIRD_ROOT', 'COWBIRD_ADMIN_PERMISSION'][source]
cowbird.constants._REGEX_ASCII_ONLY[source]
cowbird.constants._SETTING_SECTION_PREFIXES = ['cowbird'][source]
cowbird.constants._SETTINGS_REQUIRED = ['COWBIRD_URL'][source]
cowbird.constants.get_constant_setting_name(name)[source]

Find the equivalent setting name of the provided environment variable name.

Lower-case name and replace all non-ascii chars by _. Then, convert known prefixes with their dotted name.

cowbird.constants.get_constant(constant_name: Ellipsis, settings_container: Optional[cowbird.typedefs.AnySettingsContainer] = None, settings_name: Optional[str] = None, default_value: Optional[cowbird.typedefs.SettingValue] = None, raise_missing: bool = True, print_missing: bool = False, raise_not_set: bool = True)cowbird.typedefs.SettingValue[source]
Search in order for matched value of constant_name:
  1. search in COWBIRD_CONSTANTS

  2. search in settings if specified

  3. search alternative setting names (see below)

  4. search in cowbird.constants definitions

  5. search in environment variables

Parameter constant_name is expected to have the format COWBIRD_[VARIABLE_NAME] although any value can be passed to retrieve generic settings from all above mentioned search locations.

If settings_name is provided as alternative name, it is used as is to search for results if constant_name was not found. Otherwise, cowbird.[variable_name] is used for additional search when the format COWBIRD_[VARIABLE_NAME] was used for constant_name (i.e.: COWBIRD_ADMIN_USER will also search for cowbird.admin_user and so on for corresponding constants).

Parameters
  • constant_name – key to search for a value

  • settings_container – WSGI application settings container (if not provided, uses found one in current thread)

  • settings_name – alternative name for settings if specified

  • default_value – default value to be returned if not found anywhere, and exception raises are disabled.

  • raise_missing – raise exception if key is not found anywhere

  • print_missing – print message if key is not found anywhere, return None

  • raise_not_set – raise an exception if the found key is None, search until last case if others are None

Returns

found value or default_value

Raises
  • ValueError – if resulting value is invalid based on options (by default raise missing/None value)

  • LookupError – if no appropriate value could be found from all search locations (according to options)

cowbird.constants.validate_required(container: cowbird.typedefs.AnySettingsContainer)None[source]

Validates that some value is provided for every mandatory configuration setting.

Raises

when any of the requirements are missing a definition.