You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSafeConfig(Config):
"""Subclass of starlette.config.Config, but it will urlencode values if requested."""def__call__(self,
key: str,
cast: type=None,
default: typing.Any=undefined,
encode: bool=False) ->typing.Any:
returnself.get(key, cast=cast, default=default, encode=encode)
defget(self,
key: str,
cast: type=None,
default: typing.Any=undefined,
encode: bool=False) ->typing.Any:
value=Noneifkeyinself.environ:
value=self.environ[key]
elifkeyinself.file_values:
value=self.file_values[key]
elifdefaultisnotundefined:
value=defaultifvalue:
ifencode:
value=quote(value)
returnself._perform_cast(key, value, cast)
raiseKeyError(f"Config '{key}' is missing, and has no default.")
I'd prefer to have the function arguments be def __call__(self, key, *, cast, default, encode), but that breaks from the superclass arguments. It seems safer though as all of them except key are optional.
The text was updated successfully, but these errors were encountered:
Not a bad idea, but going to close this off as stale.
If we get other user feedback along these lines in the future perhaps we could reconsider if it's worth prioritising or not.
(Passing thought: we might consider if Starlette really needs it's own config parsing code or not.)
I found this helpful for working around encode/databases#145
I'd prefer to have the function arguments be
def __call__(self, key, *, cast, default, encode)
, but that breaks from the superclass arguments. It seems safer though as all of them exceptkey
are optional.The text was updated successfully, but these errors were encountered: