Rewrite unnecessary importlib dependency in DynamoDB (#4035)
This commit is contained in:
		
							parent
							
								
									4778377e8e
								
							
						
					
					
						commit
						21a77510b3
					
				| @ -1,3 +1,7 @@ | ||||
| from moto.utilities.utils import load_resource | ||||
| from pkg_resources import resource_filename | ||||
| 
 | ||||
| 
 | ||||
| class ReservedKeywords(list): | ||||
|     """ | ||||
|     DynamoDB has an extensive list of keywords. Keywords are considered when validating the expression Tree. | ||||
| @ -18,12 +22,7 @@ class ReservedKeywords(list): | ||||
|         """ | ||||
|         Get a list of reserved keywords of DynamoDB | ||||
|         """ | ||||
|         try: | ||||
|             import importlib.resources as pkg_resources | ||||
|         except ImportError: | ||||
|             import importlib_resources as pkg_resources | ||||
| 
 | ||||
|         reserved_keywords = pkg_resources.read_text( | ||||
|             "moto.dynamodb2.parsing", "reserved_keywords.txt" | ||||
|         reserved_keywords = load_resource( | ||||
|             resource_filename(__name__, "reserved_keywords.txt"), as_json=False | ||||
|         ) | ||||
|         return reserved_keywords.split() | ||||
|  | ||||
| @ -15,7 +15,7 @@ def random_string(length=None): | ||||
|     return random_str | ||||
| 
 | ||||
| 
 | ||||
| def load_resource(filename): | ||||
| def load_resource(filename, as_json=True): | ||||
|     """ | ||||
|     Open a file, and return the contents as JSON. | ||||
|     Usage: | ||||
| @ -23,4 +23,4 @@ def load_resource(filename): | ||||
|     load_resource(resource_filename(__name__, "resources/file.json")) | ||||
|     """ | ||||
|     with open(filename, "r", encoding="utf-8") as f: | ||||
|         return json.load(f) | ||||
|         return json.load(f) if as_json else f.read() | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user