Minor clarity improvements to required_feature logic.

master
voussoir 2018-04-27 19:59:44 -07:00
parent e2cf9344c1
commit df7fbeae0a
1 changed files with 9 additions and 4 deletions

View File

@ -28,17 +28,22 @@ def required_feature(features):
config = photodb.config['enable_feature']
# Using the received string like "photo.new", try to navigate the
# config and wind up at a True.
# config and wind up at a True or False. All other values invalid.
# Allow KeyErrors to raise themselves.
for feature in features:
cfg = config
pieces = feature.split('.')
for piece in pieces:
cfg = cfg[piece]
if cfg is False:
if cfg is True:
pass
elif cfg is False:
raise exceptions.FeatureDisabled(method.__qualname__)
if cfg is not True:
raise ValueError('Bad required_feature "%s" led to %s' % (feature, cfg))
else:
raise ValueError(f'Bad required_feature: "{feature}" led to {cfg}')
return method(self, *args, **kwargs)
return wrapped_required_feature