Minor clarity improvements to required_feature logic.
This commit is contained in:
		
							parent
							
								
									e2cf9344c1
								
							
						
					
					
						commit
						df7fbeae0a
					
				
					 1 changed files with 9 additions and 4 deletions
				
			
		|  | @ -28,17 +28,22 @@ def required_feature(features): | ||||||
|             config = photodb.config['enable_feature'] |             config = photodb.config['enable_feature'] | ||||||
| 
 | 
 | ||||||
|             # Using the received string like "photo.new", try to navigate the |             # 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. |             # Allow KeyErrors to raise themselves. | ||||||
|             for feature in features: |             for feature in features: | ||||||
|                 cfg = config |                 cfg = config | ||||||
|                 pieces = feature.split('.') |                 pieces = feature.split('.') | ||||||
|                 for piece in pieces: |                 for piece in pieces: | ||||||
|                     cfg = cfg[piece] |                     cfg = cfg[piece] | ||||||
|                 if cfg is False: | 
 | ||||||
|  |                 if cfg is True: | ||||||
|  |                     pass | ||||||
|  | 
 | ||||||
|  |                 elif cfg is False: | ||||||
|                     raise exceptions.FeatureDisabled(method.__qualname__) |                     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 method(self, *args, **kwargs) | ||||||
|         return wrapped_required_feature |         return wrapped_required_feature | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue