hexss 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hexss-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 hexs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
hexss-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.1
2
+ Name: hexss
3
+ Version: 0.0.1
4
+ License-File: LICENSE
@@ -0,0 +1 @@
1
+ from .json.json_utils import json_load, json_dump, json_update
File without changes
@@ -0,0 +1,11 @@
1
+ BLACK = '\033[90m'
2
+ RED = '\033[91m'
3
+ GREEN = '\033[92m'
4
+ YELLOW = '\033[93m'
5
+ BLUE = '\033[94m'
6
+ PINK = '\033[95m'
7
+ CYAN = '\033[96m'
8
+ ENDC = '\033[0m'
9
+ BOLD = '\033[1m'
10
+ ITALICIZED = '\033[3m'
11
+ UNDERLINE = '\033[4m'
File without changes
@@ -0,0 +1,6 @@
1
+ from hexss import json_load, json_update
2
+ from hexss.constants import cml
3
+
4
+ data = json_load("example.json", {'value': 1})
5
+ json_update("example.json", data)
6
+ print(cml.BLUE, data, cml.ENDC, sep='')
@@ -0,0 +1 @@
1
+ from .json_utils import json_load, json_dump, json_update
@@ -0,0 +1,63 @@
1
+ import os
2
+ import json
3
+ from typing import Dict, Any
4
+
5
+
6
+ def json_load(file_path: str, default: Dict[str, Any] | None = None) -> Dict[str, Any]:
7
+ if not file_path.lower().endswith('.json'):
8
+ raise ValueError("File extension must be .json")
9
+
10
+ data = default if default is not None else {}
11
+
12
+ if os.path.exists(file_path):
13
+ with open(file_path, 'r', encoding='utf-8') as f:
14
+ try:
15
+ data.update(json.load(f))
16
+ except json.JSONDecodeError as e:
17
+ raise json.JSONDecodeError(f"Invalid JSON in {file_path}: {str(e)}", e.doc, e.pos) from e
18
+
19
+ return data
20
+
21
+
22
+ def json_dump(file_path: str, data: Dict[str, Any], indent: int = 4) -> None:
23
+ if not file_path.lower().endswith('.json'):
24
+ raise ValueError("File extension must be .json")
25
+
26
+ directory = os.path.dirname(file_path)
27
+ if directory:
28
+ os.makedirs(directory, exist_ok=True)
29
+
30
+ try:
31
+ with open(file_path, 'w', encoding='utf-8') as f:
32
+ json.dump(data, f, indent=indent, ensure_ascii=False)
33
+ except OSError as e:
34
+ raise OSError(f"Error writing to {file_path}: {str(e)}") from e
35
+
36
+
37
+ def json_update(file_path: str, new_data: Dict[str, Any], indent: int = 4) -> Dict[str, Any]:
38
+ if not file_path.lower().endswith('.json'):
39
+ raise ValueError("File extension must be .json")
40
+
41
+ try:
42
+ data = json_load(file_path, default={})
43
+ except json.JSONDecodeError as e:
44
+ raise json.JSONDecodeError(f"Invalid JSON in existing file {file_path}: {str(e)}", e.doc, e.pos) from e
45
+
46
+ data.update(new_data)
47
+
48
+ try:
49
+ json_dump(file_path, data, indent)
50
+ except OSError as e:
51
+ raise OSError(f"Error updating {file_path}: {str(e)}") from e
52
+
53
+ return data
54
+
55
+
56
+ if __name__ == '__main__':
57
+ config = json_load('config.json', default={
58
+ 'device': 'PC',
59
+ 'model_name': '-',
60
+ '2': '1'
61
+ })
62
+ json_update('config.json', config)
63
+ print(config)
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.1
2
+ Name: hexss
3
+ Version: 0.0.1
4
+ License-File: LICENSE
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ setup.py
3
+ hexss/__init__.py
4
+ hexss.egg-info/PKG-INFO
5
+ hexss.egg-info/SOURCES.txt
6
+ hexss.egg-info/dependency_links.txt
7
+ hexss.egg-info/top_level.txt
8
+ hexss/constants/__init__.py
9
+ hexss/constants/cml.py
10
+ hexss/example/__init__.py
11
+ hexss/example/example.py
12
+ hexss/json/__init__.py
13
+ hexss/json/json_utils.py
@@ -0,0 +1 @@
1
+ hexss
hexss-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
hexss-0.0.1/setup.py ADDED
@@ -0,0 +1,8 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name='hexss',
5
+ version='0.0.1',
6
+ packages=find_packages(),
7
+ install_requires=[],
8
+ )