inihelper 0.1.0__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.
- inihelper-0.1.0/LICENSE +21 -0
- inihelper-0.1.0/PKG-INFO +99 -0
- inihelper-0.1.0/README.md +74 -0
- inihelper-0.1.0/inihandler/__init__.py +38 -0
- inihelper-0.1.0/inihandler/ini.py +665 -0
- inihelper-0.1.0/inihandler/lang/english.py +69 -0
- inihelper-0.1.0/inihandler/tools/LoadFile.py +256 -0
- inihelper-0.1.0/inihandler/tools/vars.py +87 -0
- inihelper-0.1.0/inihelper.egg-info/PKG-INFO +99 -0
- inihelper-0.1.0/inihelper.egg-info/SOURCES.txt +12 -0
- inihelper-0.1.0/inihelper.egg-info/dependency_links.txt +1 -0
- inihelper-0.1.0/inihelper.egg-info/top_level.txt +1 -0
- inihelper-0.1.0/pyproject.toml +35 -0
- inihelper-0.1.0/setup.cfg +4 -0
inihelper-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arjuna S. Erat
|
|
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.
|
inihelper-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: inihelper
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An INI parser that preserves comments, supports custom 'separator' (=) 'rules' and comment styles, incl (wip) multiline.
|
|
5
|
+
Author-email: "Simon Arjuna Erat (sri-arjuna)" <erat.simon@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sri-arjuna/python-ini
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/sri-arjuna/python-ini/issues
|
|
9
|
+
Project-URL: Source, https://github.com/sri-arjuna/python-ini
|
|
10
|
+
Keywords: ini,config,parser,comments
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Topic :: Utilities
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# INI Comments
|
|
27
|
+
This is a ini-file handler that preserves comments.
|
|
28
|
+
|
|
29
|
+
For various projects of mine, I prefer to provide comments within an ini file for others to know their meanings, or other options.
|
|
30
|
+
|
|
31
|
+
While configParser is nice, it always removed any/all comments from the file, so this project solves that issue.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features:
|
|
35
|
+
- Supports: "#", ";" and "//" as line comments
|
|
36
|
+
- Preserve comments
|
|
37
|
+
- Handles "line comment" and "comments behind values"
|
|
38
|
+
- Custom "separator" (default: "=")
|
|
39
|
+
- Allows toggle between: "instant save" or "on purpose"
|
|
40
|
+
- May handle "lazy" (bStrict=False) ini files, that do not have any "[Section]"s (this is required for the saving, wether manual or automatic)
|
|
41
|
+
- Allows for fallback/non-existing config
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# Usage:
|
|
45
|
+
How to handle this class:
|
|
46
|
+
|
|
47
|
+
## Available commands:
|
|
48
|
+
- my_ini.export(args)
|
|
49
|
+
- my_ini.get(args)
|
|
50
|
+
- my_ini.get_simple(args)
|
|
51
|
+
- my_ini.list_sections()
|
|
52
|
+
- my_ini.list_variables(args)
|
|
53
|
+
- my_ini.load_data()
|
|
54
|
+
- my_ini.load_file()
|
|
55
|
+
- my_ini.save()
|
|
56
|
+
- my_ini.set(args)
|
|
57
|
+
- my_ini.set_simple(args)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Import:
|
|
61
|
+
```python
|
|
62
|
+
import inicomments
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Initialize:
|
|
66
|
+
```python
|
|
67
|
+
my_ini = inicomments.handler("/path/to/file")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Working with values:
|
|
71
|
+
```python
|
|
72
|
+
# Get value:
|
|
73
|
+
current_value = my_ini.get("SectionName", "VariableName")
|
|
74
|
+
print(current_value)
|
|
75
|
+
|
|
76
|
+
# Set Value:
|
|
77
|
+
my_ini.set("SectionName", "VariableName", "NewValue")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Special Handling:
|
|
81
|
+
If you have ``bInstantSave=False`` you simply call: ``my_ini.save()`` at whatever point you want/need to save the file.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Example File:
|
|
86
|
+
Here is an example of a - *very chaotic, but still work-able* - ini file:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
# Most used comment
|
|
90
|
+
; But you can apply any comment style
|
|
91
|
+
// that fits your project
|
|
92
|
+
|
|
93
|
+
[section]
|
|
94
|
+
variable = some value
|
|
95
|
+
someting = with a comment // like this
|
|
96
|
+
ofCourse = this would ; work as well
|
|
97
|
+
sooooo = "would this ; if you" ; apply quotes
|
|
98
|
+
|
|
99
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# INI Comments
|
|
2
|
+
This is a ini-file handler that preserves comments.
|
|
3
|
+
|
|
4
|
+
For various projects of mine, I prefer to provide comments within an ini file for others to know their meanings, or other options.
|
|
5
|
+
|
|
6
|
+
While configParser is nice, it always removed any/all comments from the file, so this project solves that issue.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features:
|
|
10
|
+
- Supports: "#", ";" and "//" as line comments
|
|
11
|
+
- Preserve comments
|
|
12
|
+
- Handles "line comment" and "comments behind values"
|
|
13
|
+
- Custom "separator" (default: "=")
|
|
14
|
+
- Allows toggle between: "instant save" or "on purpose"
|
|
15
|
+
- May handle "lazy" (bStrict=False) ini files, that do not have any "[Section]"s (this is required for the saving, wether manual or automatic)
|
|
16
|
+
- Allows for fallback/non-existing config
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Usage:
|
|
20
|
+
How to handle this class:
|
|
21
|
+
|
|
22
|
+
## Available commands:
|
|
23
|
+
- my_ini.export(args)
|
|
24
|
+
- my_ini.get(args)
|
|
25
|
+
- my_ini.get_simple(args)
|
|
26
|
+
- my_ini.list_sections()
|
|
27
|
+
- my_ini.list_variables(args)
|
|
28
|
+
- my_ini.load_data()
|
|
29
|
+
- my_ini.load_file()
|
|
30
|
+
- my_ini.save()
|
|
31
|
+
- my_ini.set(args)
|
|
32
|
+
- my_ini.set_simple(args)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Import:
|
|
36
|
+
```python
|
|
37
|
+
import inicomments
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Initialize:
|
|
41
|
+
```python
|
|
42
|
+
my_ini = inicomments.handler("/path/to/file")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Working with values:
|
|
46
|
+
```python
|
|
47
|
+
# Get value:
|
|
48
|
+
current_value = my_ini.get("SectionName", "VariableName")
|
|
49
|
+
print(current_value)
|
|
50
|
+
|
|
51
|
+
# Set Value:
|
|
52
|
+
my_ini.set("SectionName", "VariableName", "NewValue")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Special Handling:
|
|
56
|
+
If you have ``bInstantSave=False`` you simply call: ``my_ini.save()`` at whatever point you want/need to save the file.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Example File:
|
|
61
|
+
Here is an example of a - *very chaotic, but still work-able* - ini file:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
# Most used comment
|
|
65
|
+
; But you can apply any comment style
|
|
66
|
+
// that fits your project
|
|
67
|
+
|
|
68
|
+
[section]
|
|
69
|
+
variable = some value
|
|
70
|
+
someting = with a comment // like this
|
|
71
|
+
ofCourse = this would ; work as well
|
|
72
|
+
sooooo = "would this ; if you" ; apply quotes
|
|
73
|
+
|
|
74
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from .ini import INIhandler as _INIhandler
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Imports - Official
|
|
5
|
+
#
|
|
6
|
+
import os as _os
|
|
7
|
+
import sys as _sys
|
|
8
|
+
import shutil as _shutil
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Imports - Internals
|
|
12
|
+
#
|
|
13
|
+
from .tools import vars
|
|
14
|
+
from .tools import LoadFile
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def handler(file_path="", bInstantSave=True, bStrict=True, bForcedCommentStyle: vars.NoneOrString=None, bVerbose=False, sVerbosePrefix="", SEP="=", sEncoding="utf-8", sDefaultBackupConfig="", lang: str="english"):
|
|
18
|
+
"""
|
|
19
|
+
Initialize the ini-handler, the one that preserves file comments on normal saves!
|
|
20
|
+
|
|
21
|
+
Errors will always be printed to "stderr".
|
|
22
|
+
|
|
23
|
+
Supported comment-single/on-line styles are: "#", ";", "//", "|"
|
|
24
|
+
|
|
25
|
+
Supported comment-MULTI-line styles are: "*/", "-->", '\"\"\"'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
:param file_path: Path to the .ini **file**, or a **nested dict**: {"Section 1": {"var1": "value1"}, "Section 2": {"variable_name": "its value"}}
|
|
29
|
+
:param bInstantSave: If True, saves to file on every 'set()'.
|
|
30
|
+
:param bStrict: True/Default expects '[Section]', where as 'False' will expect ONLY 'variable = value'
|
|
31
|
+
:param bForcedCommentStyle: If set to a non-None string (e.g., "#"), it enforces that only that specific comment style is accepted for all parsing. Set to None for flexible, multi-style comment handling, incl multi-line comments.
|
|
32
|
+
:param bVerbose: If True, prints basic status messages.
|
|
33
|
+
:param sVerbosePrefix: This will print '[sVerbosePrefix] message' instead of just 'message'
|
|
34
|
+
:param SEP: The separator for key-value pairs (default "=" for cross-platform compatability).
|
|
35
|
+
:param sEncoding: On rare occasions your files might not be "utf-8", here you can handle such cases.
|
|
36
|
+
:param sDefaultBackupConfig: Expects "path/to/file", this will be used if required "file_path" doesnt exist) and/or if/when its config became invalid.
|
|
37
|
+
"""
|
|
38
|
+
return _INIhandler(file_path, bInstantSave=bInstantSave, bStrict=bStrict, bForcedCommentStyle=bForcedCommentStyle, bVerbose=bVerbose, sVerbosePrefix=sVerbosePrefix, SEP=SEP, sEncoding=sEncoding, sDefaultBackupConfig=sDefaultBackupConfig, lang=lang)
|