magpie.constants¶
Constant settings for Magpie application.
Constants defined with format MAGPIE_[VARIABLE_NAME]
can be matched with corresponding
settings formatted as magpie.[variable_name]
in the magpie.ini
configuration file.
Note
Since the magpie.ini
file has to be loaded by the application to retrieve various configuration settings,
constant MAGPIE_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).
Attributes¶
Functions¶
|
Get logging level from INI configuration file or fallback to default |
|
Find the equivalent setting name of the provided environment variable name. |
|
Search in order for matched value of |
Module Contents¶
- magpie.constants._get_default_log_level() magpie.typedefs.Str [source]¶
Get logging level from INI configuration file or fallback to default
INFO
if it cannot be retrieved.
- magpie.constants.MAGPIE_CONSTANTS = ['MAGPIE_CONSTANTS', 'MAGPIE_ADMIN_PERMISSION', 'MAGPIE_LOGGED_PERMISSION',...[source]¶
- magpie.constants.get_constant_setting_name(name: magpie.typedefs.Str) magpie.typedefs.Str [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.
- magpie.constants.get_constant(constant_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None, settings_name: magpie.typedefs.Str | None = None, default_value: magpie.typedefs.SettingValue | None = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) magpie.typedefs.SettingValue [source]¶
- Search in order for matched value of
constant_name
: search in
MAGPIE_CONSTANTS
search in settings if specified
search alternative setting names (see below)
search in
magpie.constants
definitionssearch in environment variables
Parameter
constant_name
is expected to have the formatMAGPIE_[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 ifconstant_name
was not found. Otherwise,magpie.[variable_name]
is used for additional search when the formatMAGPIE_[VARIABLE_NAME]
was used forconstant_name
(i.e.:MAGPIE_ADMIN_USER
will also search formagpie.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_not_set – raise an exception if the found key is
None
, search until last case if others areNone
raise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
None
empty_missing – consider an empty value for an existing key as if it was missing (i.e.: as if not set).
- Returns:
found value or default_value
- Raises:
ValueError – if resulting value is invalid based on options (by default raise missing/empty/
None
value)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of