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).
Module Contents¶
Functions¶
Get default configurations from ini file. |
|
Lower-case name and replace all non-ascii chars by _. |
|
|
Search in order for matched value of |
-
magpie.constants.
MAGPIE_CONSTANTS
= ['MAGPIE_CONSTANTS', 'MAGPIE_ADMIN_PERMISSION', 'MAGPIE_LOGGED_PERMISSION', 'MAGPIE_CONTEXT_PERMISSION', 'MAGPIE_LOGGED_USER', 'MAGPIE_DEFAULT_PROVIDER', 'MAGPIE_USER_NAME_MAX_LENGTH', 'MAGPIE_GROUP_NAME_MAX_LENGTH'][source]¶
-
magpie.constants.
get_constant_setting_name
(name)[source]¶ Lower-case name and replace all non-ascii chars by _.
-
magpie.constants.
get_constant
(constant_name: Str, settings_container: Optional[AnySettingsContainer] = None, settings_name: Optional[Str] = None, default_value: Optional[SettingValue] = None, raise_missing: bool = True, print_missing: bool = False, raise_not_set: bool = True) → 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 app settings container
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 areNone
- 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)
- Search in order for matched value of