Base Parser¶
-
class
django_docker_helpers.config.backends.base.BaseParser(scope=None, config=None, nested_delimiter='__', path_separator='.', env=None)[source]¶ Bases:
objectBase class to inherit from in custom parsers.
All
__init__arguments MUST be optional if you needfrom_env()automatic parser initializer (it initializes parsers likeparser_class(**parser_options)).Since
ConfigLoadercan initialize parsers from environment variables it’s recommended to annotate argument types to provide a correct auto typecast.BaseParsercreates aloggerwith name__class__.__name__.BaseParserimplements generic copying of following arguments without any backend-specific logic inside.Parameters: - scope (
Optional[str]) – a global prefix to all underlying values - config (
Optional[str]) – optional config - nested_delimiter (
str) – optional delimiter for environment backend - path_separator (
str) – specifies which character separates nested variables, default is'.' - env (
Optional[Dict[str,str]]) – a dict with environment variables, default isos.environ
-
client¶ Helper property to lazy initialize and cache client. Runs
get_client().Returns: an instance of backend-specific client
-
static
coerce(val, coerce_type=None, coercer=None)[source]¶ Casts a type of
valtocoerce_typewithcoercer.If
coerce_typeis bool and nocoercerspecified it usescoerce_str_to_bool()by default.Parameters: - val (
Any) – a value of any type - coerce_type (
Optional[Type[+CT_co]]) – any type - coercer (
Optional[Callable]) – provide a callback that takesvaland returns a value with desired type
Return type: AnyReturns: type casted value
- val (
-
get(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]¶ Inherited method should take all specified arguments.
Parameters: - variable_path (
str) – a delimiter-separated path to a nested value - default (
Optional[Any]) – default value if there’s no object by specified path - coerce_type (
Optional[Type[+CT_co]]) – cast a type of a value to a specified one - coercer (
Optional[Callable]) – perform a type casting with specified callback - kwargs – additional arguments inherited parser may need
Returns: value or default
- variable_path (
- scope (