1+ from parsers import ParseException , json_parser , yaml_parser
12from schema import Schema , SchemaError
23from typing import Any
34from os import path
4- import json
5- import yaml
65import os
76import re
87
9-
10- def json_parser (file_buff ):
11- try :
12- return json .loads (file_buff )
13- except json .JSONDecodeError as e :
14- raise ConfigFileDecodeError (f'Unable to decode config file using json' , e )
15-
16-
17- def yaml_parser (file_buff ):
18- try :
19- return yaml .safe_load (file_buff )
20- except yaml .YAMLError as e :
21- raise ConfigFileDecodeError (f'Unable to decode config file using yaml' , e )
22-
23-
248LINUX_KEY_VARIABLE_PATTERN = r'\$([a-zA-Z][\w]+|\{[a-zA-Z][\w]+\})$'
259DEFAULT_CONFIG_FILES = ('config.json' , 'config.yaml' , 'config.yml' )
2610ENTITY_NAME_PATTERN = r'^[a-zA-Z][\w]+$'
27-
2811SUPPORTED_EXTENSIONS = {
2912 'json' : json_parser ,
3013 'yaml' : yaml_parser ,
3114 'yml' : yaml_parser
3215}
3316
3417
18+ class ConfigError (Exception ):
19+ pass
20+
21+
22+ class ConfigFileNotFoundError (ConfigError ):
23+ pass
24+
25+
3526class ConfigValue :
3627
3728 def __getitem__ (self , item ):
@@ -40,6 +31,15 @@ def __getitem__(self, item):
4031 def __iter__ (self ):
4132 return self .__dict__ .keys ().__iter__ ()
4233
34+ def __len__ (self ):
35+ return len (self .__dict__ )
36+
37+ def keys (self ):
38+ return self .__dict__ .keys ()
39+
40+ def values (self ):
41+ return self .__dict__ .values ()
42+
4343
4444class Config :
4545 __instance = None
@@ -147,15 +147,3 @@ def extract_env_variable_key(cls, variable):
147147 if variable [0 ] == '{' :
148148 return variable [1 :- 1 ]
149149 return variable
150-
151-
152- class ConfigError (Exception ):
153- pass
154-
155-
156- class ConfigFileDecodeError (ConfigError ):
157- pass
158-
159-
160- class ConfigFileNotFoundError (ConfigError ):
161- pass
0 commit comments