Skip to content

Commit eaa4813

Browse files
v1.0.8 fixing __dic_2_obj, limiting symbols wich may be used in json keys
1 parent 75fe445 commit eaa4813

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

jsonconfigparser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import re
12
import json
23
from os import path
34
from typing import Any
45
from schema import Schema, SchemaError
56

67
class Config(object):
7-
8+
ENTITY_NAME_PATTERN = "^[\w\d_]+$"
9+
810
__instance = None
911

1012
def __new__(cls, schema:dict = None, path_file:str = "config.json"):
@@ -45,6 +47,8 @@ def __dict_2_obj(cls, data: Any):
4547
if _type is dict:
4648
obj = object.__new__(cls)
4749
for key, value in data.items():
50+
if re.search(cls.ENTITY_NAME_PATTERN, key) is None:
51+
raise ConfigEntitiesWithWrongNameError("The json keys only must have words, number and underscores")
4852
setattr(obj, key, cls.__dict_2_obj(value))
4953
return obj
5054
if _type in (list, set, tuple):
@@ -70,3 +74,6 @@ class ConfigFileOpenReadError(ConfigError):
7074

7175
class ConfigFileNotFoundError(ConfigError):
7276
pass
77+
78+
class ConfigEntitiesWithWrongNameError(ConfigError):
79+
pass

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="python-json-config-parser",
8-
version="1.0.7",
8+
version="1.0.8",
99
author="Bruno Silva de Andrade",
1010
author_email="brunojf.andrade@gmail.com",
1111
description="Project created to given the possibility of create dynamics Json config files",

test_jsonconfigparser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ def test_access_fake_attr(self):
2222
config = Config(SIMPLE_SCHEMA_CONFIG)
2323
self.assertRaises(AttributeError, lambda:config.fake_attr)
2424

25+
if(__name__ == '__main__'):
26+
unittest.main()

0 commit comments

Comments
 (0)