Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def method(
self: "Env", name: str, default: typing.Any = ma.missing, subcast: typing.Type = None, **kwargs
):
if self._sealed:
raise EnvSealedError("Env has already been sealed. New values cannot be parsed.")
parsed_key, raw_value, proxied_key = self._get_from_environ(name, default)
if raw_value is ma.missing:
raise EnvError('Environment variable "{}" not set'.format(proxied_key or parsed_key))
value = func(raw_value, **kwargs)
self._fields[parsed_key] = ma.fields.Field(**kwargs)
self._values[parsed_key] = value
return value
FieldType = typing.Type[ma.fields.Field]
FieldOrFactory = typing.Union[FieldType, FieldFactory]
ParserMethod = typing.Callable[..., _T]
class EnvError(ValueError):
"""Raised when an environment variable or if a required environment variable is unset."""
class EnvValidationError(EnvError):
def __init__(self, message: str, error_messages: typing.Union[ErrorList, ErrorMapping]):
self.error_messages = error_messages
super().__init__(message)
class EnvSealedError(TypeError, EnvError):
pass
class ParserConflictError(ValueError):
"""Raised when adding a custom parser that conflicts with a built-in parser method."""
def _field2method(
field_or_factory: FieldOrFactory, method_name: str, *, preprocess: typing.Callable = None
) -> ParserMethod:
def method(
self: "Env", name: str, default: typing.Any = ma.missing, subcast: Subcast = None, **kwargs
) -> _T:
if self._sealed:
raise EnvSealedError("Env has already been sealed. New values cannot be parsed.")
missing = kwargs.pop("missing", None) or default
_IntType = int
ErrorMapping = typing.Mapping[str, typing.List[str]]
ErrorList = typing.List[str]
FieldFactory = typing.Callable[..., ma.fields.Field]
Subcast = typing.Union[typing.Type, typing.Callable[..., _T]]
FieldType = typing.Type[ma.fields.Field]
FieldOrFactory = typing.Union[FieldType, FieldFactory]
ParserMethod = typing.Callable[..., _T]
class EnvError(ValueError):
"""Raised when an environment variable or if a required environment variable is unset."""
class EnvValidationError(EnvError):
def __init__(self, message: str, error_messages: typing.Union[ErrorList, ErrorMapping]):
self.error_messages = error_messages
super().__init__(message)
class EnvSealedError(TypeError, EnvError):
pass
class ParserConflictError(ValueError):
"""Raised when adding a custom parser that conflicts with a built-in parser method."""
def _field2method(
field_or_factory: FieldOrFactory, method_name: str, *, preprocess: typing.Callable = None
) -> ParserMethod: