MapleX 2.2.0a2__tar.gz → 2.2.0b1__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.
- {maplex-2.2.0a2 → maplex-2.2.0b1}/PKG-INFO +119 -80
- maplex-2.2.0a2/src/MapleX.egg-info/PKG-INFO → maplex-2.2.0b1/README.md +116 -98
- {maplex-2.2.0a2 → maplex-2.2.0b1}/pyproject.toml +4 -3
- maplex-2.2.0a2/README.md → maplex-2.2.0b1/src/MapleX.egg-info/PKG-INFO +137 -77
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/maplex/__init__.py +3 -1
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/maplex/mapleColors.py +1 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/maplex/mapleExceptions.py +7 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/maplex/mapleLogger.py +15 -10
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/maplex/mapleTreeEditor.py +49 -14
- {maplex-2.2.0a2 → maplex-2.2.0b1}/LICENSE +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/MANIFEST.in +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/setup.cfg +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/MapleX.egg-info/SOURCES.txt +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/MapleX.egg-info/dependency_links.txt +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/MapleX.egg-info/requires.txt +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/MapleX.egg-info/top_level.txt +0 -0
- {maplex-2.2.0a2 → maplex-2.2.0b1}/src/maplex/utils.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: MapleX
|
|
3
|
-
Version: 2.2.
|
|
4
|
-
Summary:
|
|
5
|
-
Author:
|
|
3
|
+
Version: 2.2.0b1
|
|
4
|
+
Summary: A Python library for Maple file format operations, with logging and console color utilities
|
|
5
|
+
Author: RyujiHazama
|
|
6
6
|
Project-URL: PyPI, https://pypi.org/project/MapleX/
|
|
7
7
|
Project-URL: Homepage, https://github.com/Ryuji-Hazama
|
|
8
8
|
Project-URL: Repository, https://github.com/Ryuji-Hazama/MapleTree
|
|
@@ -26,9 +26,18 @@ Dynamic: license-file
|
|
|
26
26
|
***You can install the package from pip with the following command.***
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
pip install
|
|
29
|
+
pip install MapleX
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## Table of Contents
|
|
33
|
+
|
|
34
|
+
> - [Maple File](#maple-file)
|
|
35
|
+
> - [MapleTree Class](#mapletree-class)
|
|
36
|
+
> - [Logger Class](#logger-class)
|
|
37
|
+
> - [Exceptions](#exceptions)
|
|
38
|
+
> - [Console Colors](#console-colors)
|
|
39
|
+
> - [Install MapleX](#install-maplex)
|
|
40
|
+
|
|
32
41
|
## Maple File
|
|
33
42
|
|
|
34
43
|
Maple is a file system that I created when I was a child. It's like a combination of the INI file and the Jason file. I made this format that is easy to read and write for both humans and machines.
|
|
@@ -314,6 +323,8 @@ EOF
|
|
|
314
323
|
If `encrypt=True`, the instance decrypts data when it is read, and encrypts data when it is saved.
|
|
315
324
|
You need to specify the byte key when you use encryption, and the file must be encrypted.
|
|
316
325
|
|
|
326
|
+
:warning: **The key must be 32 url-safe base64-encoded bytes**
|
|
327
|
+
|
|
317
328
|
```python
|
|
318
329
|
mapleFile = MapleTree("FileName.mpl", encrypt=True, key=key)
|
|
319
330
|
```
|
|
@@ -385,7 +396,32 @@ def saveTagLine(
|
|
|
385
396
|
|**`willSave`**|\*|Save to file flag|
|
|
386
397
|
|**`headers`**||Target headers|
|
|
387
398
|
|
|
388
|
-
 
|
|
399
|
+
Outdated from `v2.2.0`
|
|
400
|
+
|
|
401
|
+
### `saveValue()`
|
|
402
|
+
|
|
403
|
+
`v2.2.0` or newer
|
|
404
|
+
|
|
405
|
+
```python
|
|
406
|
+
def saveValue(
|
|
407
|
+
tag: str,
|
|
408
|
+
valueString: any,
|
|
409
|
+
*headers: str,
|
|
410
|
+
**kwargs
|
|
411
|
+
) -> bool
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
|Property|Required|Value|
|
|
415
|
+
|--------|--------|-----|
|
|
416
|
+
|**`tag`**|\*|Target tag|
|
|
417
|
+
|**`value`**|\*|Value to save|
|
|
418
|
+
|**`headers`**||Target headers|
|
|
419
|
+
|**`kwargs`**||Keyword arguments|
|
|
420
|
+
|
|
421
|
+
`saveValue` saves a value with a tag in a header block specified by the parameter.
|
|
422
|
+
|
|
423
|
+
- Set `save=True` to save changes to the file.
|
|
424
|
+
- Default: `save=False`
|
|
389
425
|
|
|
390
426
|
E.g.:
|
|
391
427
|
|
|
@@ -393,7 +429,7 @@ E.g.:
|
|
|
393
429
|
from maplex import MapleTree
|
|
394
430
|
|
|
395
431
|
mapleFile = MapleTree("SampleData.mpl", createBaseFile=True)
|
|
396
|
-
mapleFile.saveTagLine("TAG", "VALUE",
|
|
432
|
+
mapleFile.saveTagLine("TAG", "VALUE", "FOO", save=True)
|
|
397
433
|
|
|
398
434
|
```
|
|
399
435
|
|
|
@@ -409,12 +445,12 @@ EOF
|
|
|
409
445
|
|
|
410
446
|
#### Update a Buffer Content
|
|
411
447
|
|
|
412
|
-
If `
|
|
448
|
+
If `save=False` (or not specified), the buffer content will be updated, but no update on physical file content.
|
|
413
449
|
|
|
414
450
|
E.g.:
|
|
415
451
|
|
|
416
452
|
```python
|
|
417
|
-
mapleFile.saveTagLine("TAG", "NEW VALUE",
|
|
453
|
+
mapleFile.saveTagLine("TAG", "NEW VALUE", "FOO")
|
|
418
454
|
```
|
|
419
455
|
|
|
420
456
|
This code changes the contents on buffer like:
|
|
@@ -439,10 +475,10 @@ EOF
|
|
|
439
475
|
|
|
440
476
|
#### Update and Save Changes
|
|
441
477
|
|
|
442
|
-
If `
|
|
478
|
+
If `save=True`, all the changes to the buffer will be saved.
|
|
443
479
|
|
|
444
480
|
```python
|
|
445
|
-
mapleFile.saveTagLine("BAR", "ANOTHER VALUE",
|
|
481
|
+
mapleFile.saveTagLine("BAR", "ANOTHER VALUE", "FOO", save=True)
|
|
446
482
|
```
|
|
447
483
|
|
|
448
484
|
This code changes the contents in the file like:
|
|
@@ -461,10 +497,10 @@ EOF
|
|
|
461
497
|
If the block and/or the header(s) specified with the parameters do not exist in the data, the function creates the new header block(s) and the tag and saves the value.
|
|
462
498
|
|
|
463
499
|
```python
|
|
464
|
-
mapleFile.saveTagLine("TAZ", "NEW HEADER AND TAG",
|
|
500
|
+
mapleFile.saveTagLine("TAZ", "NEW HEADER AND TAG", "NEW_HEADER")
|
|
465
501
|
```
|
|
466
502
|
|
|
467
|
-
This code will change the data like:
|
|
503
|
+
This code will change the buffer data like:
|
|
468
504
|
|
|
469
505
|
```text
|
|
470
506
|
MAPLE
|
|
@@ -478,48 +514,47 @@ E
|
|
|
478
514
|
EOF
|
|
479
515
|
```
|
|
480
516
|
|
|
481
|
-
### `
|
|
482
|
-
|
|
483
|
-
`v2.2.0` or newer
|
|
517
|
+
### `deleteTag()`
|
|
484
518
|
|
|
485
519
|
```python
|
|
486
|
-
def
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
*headers: str
|
|
490
|
-
**kwargs
|
|
520
|
+
def deleteTag(
|
|
521
|
+
delTag: str,
|
|
522
|
+
willSave: bool = False,
|
|
523
|
+
*headers: str
|
|
491
524
|
) -> bool
|
|
492
525
|
```
|
|
493
526
|
|
|
494
527
|
|Property|Required|Value|
|
|
495
528
|
|--------|--------|-----|
|
|
496
|
-
|**`
|
|
497
|
-
|**`
|
|
529
|
+
|**`delTag`**|\*|Tag to delete|
|
|
530
|
+
|**`willSave`**||Save to file flag|
|
|
498
531
|
|**`headers`**||Target headers|
|
|
499
|
-
|**`kwargs`**||Keyword arguments|
|
|
500
532
|
|
|
501
|
-
|
|
502
|
-
- Set `save=True` to save changes to the file.
|
|
503
|
-
- Default: `save=False`
|
|
533
|
+
Outdated from `v2.2.0`
|
|
504
534
|
|
|
505
|
-
### `
|
|
535
|
+
### `deleteValue()`
|
|
536
|
+
|
|
537
|
+
`v2.2.0` or newer
|
|
506
538
|
|
|
507
539
|
```python
|
|
508
|
-
def
|
|
540
|
+
def deleteValue(
|
|
509
541
|
delTag: str,
|
|
510
|
-
|
|
511
|
-
|
|
542
|
+
*headers: str,
|
|
543
|
+
**kwargs
|
|
512
544
|
) -> bool
|
|
513
545
|
```
|
|
514
546
|
|
|
515
547
|
|Property|Required|Value|
|
|
516
548
|
|--------|--------|-----|
|
|
517
549
|
|**`delTag`**|\*|Tag to delete|
|
|
518
|
-
|**`willSave`**||Save to file flag|
|
|
519
550
|
|**`headers`**||Target headers|
|
|
551
|
+
|**`kwargs`**||Keyword arguments|
|
|
520
552
|
|
|
521
553
|
Delete a tag and its value.
|
|
522
554
|
|
|
555
|
+
- Set `save=True` to save changes to the file.
|
|
556
|
+
- Default: `save=False`
|
|
557
|
+
|
|
523
558
|
Sample data: `SampleData.mpl`
|
|
524
559
|
|
|
525
560
|
```text
|
|
@@ -539,7 +574,7 @@ E.g.:
|
|
|
539
574
|
from maplex import MapleTree
|
|
540
575
|
|
|
541
576
|
mapleFile = MapleTree("SampleData.mpl")
|
|
542
|
-
mapleFile.deleteTag("BAR",
|
|
577
|
+
mapleFile.deleteTag("BAR", "FOO", save=True)
|
|
543
578
|
```
|
|
544
579
|
|
|
545
580
|
The file data will be changed like:
|
|
@@ -554,28 +589,6 @@ E
|
|
|
554
589
|
EOF
|
|
555
590
|
```
|
|
556
591
|
|
|
557
|
-
### `deleteValue()`
|
|
558
|
-
|
|
559
|
-
`v2.2.0` or newer
|
|
560
|
-
|
|
561
|
-
```python
|
|
562
|
-
def deleteValue(
|
|
563
|
-
delTag: str,
|
|
564
|
-
*headers: str,
|
|
565
|
-
**kwargs
|
|
566
|
-
) -> bool
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
|Property|Required|Value|
|
|
570
|
-
|--------|--------|-----|
|
|
571
|
-
|**`delTag`**|\*|Tag to delete|
|
|
572
|
-
|**`headers`**||Target headers|
|
|
573
|
-
|**`kwargs`**||Keyword arguments|
|
|
574
|
-
|
|
575
|
-
- Same as `deleteTag()`
|
|
576
|
-
- Set `save=True` to save changes to the file.
|
|
577
|
-
- Default: `save=False`
|
|
578
|
-
|
|
579
592
|
### `getTagValueDict()`
|
|
580
593
|
|
|
581
594
|
```python
|
|
@@ -670,8 +683,31 @@ def deleteHeader(
|
|
|
670
683
|
|**`willSave`**||Save to file flag|
|
|
671
684
|
|**`Headers`**||Target headers|
|
|
672
685
|
|
|
686
|
+
Outdated from `v2.2.0`
|
|
687
|
+
|
|
688
|
+
### `removeHeader()`
|
|
689
|
+
|
|
690
|
+
`v2.2.0` or newer
|
|
691
|
+
|
|
692
|
+
```python
|
|
693
|
+
def removeHeader(
|
|
694
|
+
delHead: str,
|
|
695
|
+
*headers: str,
|
|
696
|
+
**kwargs
|
|
697
|
+
) -> bool
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
|Property|Required|Value|
|
|
701
|
+
|--------|--------|-----|
|
|
702
|
+
|**`delHead`**|\*|Deleting header|
|
|
703
|
+
|**`headers`**||Target headers|
|
|
704
|
+
|**`kwargs`**||Keyword arguments|
|
|
705
|
+
|
|
673
706
|
This deletes an entire header block and its associated data, including child blocks.
|
|
674
707
|
|
|
708
|
+
- Set `save=True` for save data to the file.
|
|
709
|
+
- Default: `save=False`
|
|
710
|
+
|
|
675
711
|
Sample data: `SampleData.mpl`
|
|
676
712
|
|
|
677
713
|
```text
|
|
@@ -696,7 +732,7 @@ E.g.:
|
|
|
696
732
|
from maplex import MapleTree
|
|
697
733
|
|
|
698
734
|
mapleTree = MapleTree("SampleData.mpl")
|
|
699
|
-
mapleTree.deleteHeader("FOO", True)
|
|
735
|
+
mapleTree.deleteHeader("FOO", save=True)
|
|
700
736
|
```
|
|
701
737
|
|
|
702
738
|
This code changes the data like:
|
|
@@ -711,28 +747,6 @@ E
|
|
|
711
747
|
EOF
|
|
712
748
|
```
|
|
713
749
|
|
|
714
|
-
### `removeHeader()`
|
|
715
|
-
|
|
716
|
-
`v2.2.0` or newer
|
|
717
|
-
|
|
718
|
-
```python
|
|
719
|
-
def removeHeader(
|
|
720
|
-
delHead: str,
|
|
721
|
-
*headers: str,
|
|
722
|
-
**kwargs
|
|
723
|
-
) -> bool
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
|Property|Required|Value|
|
|
727
|
-
|--------|--------|-----|
|
|
728
|
-
|**`delHead`**|\*|Deleting header|
|
|
729
|
-
|**`headers`**||Target headers|
|
|
730
|
-
|**`kwargs`**||Keyword arguments|
|
|
731
|
-
|
|
732
|
-
- Same as `deleteHeader()`
|
|
733
|
-
- Set `save=True` for save data to the file.
|
|
734
|
-
- Default: `save=False`
|
|
735
|
-
|
|
736
750
|
### `getHeaders()`
|
|
737
751
|
|
|
738
752
|
```python
|
|
@@ -1006,6 +1020,26 @@ E
|
|
|
1006
1020
|
EOF
|
|
1007
1021
|
```
|
|
1008
1022
|
|
|
1023
|
+
### `changeEncryptionKey()`
|
|
1024
|
+
|
|
1025
|
+
`v2.2.0` or newer
|
|
1026
|
+
|
|
1027
|
+
```python
|
|
1028
|
+
def changeEncryptionKey(
|
|
1029
|
+
newKey: bytes,
|
|
1030
|
+
save: bool = False
|
|
1031
|
+
) -> None
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
|Property|Required|Value|
|
|
1035
|
+
|--------|--------|-----|
|
|
1036
|
+
|**`newKey`**|\*|New encryption key|
|
|
1037
|
+
|**`save`**||Save to file flag|
|
|
1038
|
+
|
|
1039
|
+
Changing file encryption key. If `save=True`, encrypt the buffer data with new key and save to the file.
|
|
1040
|
+
|
|
1041
|
+
:warning: **The key must be 32 url-safe base64-encoded bytes**
|
|
1042
|
+
|
|
1009
1043
|
## Logger Class
|
|
1010
1044
|
|
|
1011
1045
|
Logger is a logging object for Python applications. It outputs application logs to log files and to standard output.
|
|
@@ -1088,8 +1122,9 @@ def ShowError(
|
|
|
1088
1122
|
|
|
1089
1123
|
- You can configure log settings with `config.mpl`.
|
|
1090
1124
|
- If `config.mpl` does not exist, the instance auto-generates the file.
|
|
1125
|
+
- Instance uses the parameter values to auto-generate configuration file, or using default value if it was not specified.
|
|
1091
1126
|
|
|
1092
|
-
Auto-generated `config.mpl
|
|
1127
|
+
Auto-generated `config.mpl` (parameters not specified):
|
|
1093
1128
|
|
|
1094
1129
|
```text
|
|
1095
1130
|
MAPLE
|
|
@@ -1136,6 +1171,10 @@ EOF
|
|
|
1136
1171
|
|
|
1137
1172
|
This occurs when the data is not found in the file.
|
|
1138
1173
|
|
|
1174
|
+
### `MapleEncryptionNotEnabledException(MapleException)`
|
|
1175
|
+
|
|
1176
|
+
This occurs when try to encrypt maple data, but the encryption flag is `False`.
|
|
1177
|
+
|
|
1139
1178
|
### `class MapleHeaderNotFoundException(MapleDataNotFoundException)`
|
|
1140
1179
|
|
|
1141
1180
|
This occurs when the header (specified by the user) is not found in the data.
|
|
@@ -1218,12 +1257,12 @@ EOF
|
|
|
1218
1257
|
|`Reversed`|\\033\[7m|Reversed colors|
|
|
1219
1258
|
|`Reset`|\\033\[0m|Reset formatting|
|
|
1220
1259
|
|
|
1221
|
-
## Install
|
|
1260
|
+
## Install MapleX
|
|
1222
1261
|
|
|
1223
1262
|
### From PyPI
|
|
1224
1263
|
|
|
1225
1264
|
```bash
|
|
1226
|
-
[python[3] -m] pip install
|
|
1265
|
+
[python[3] -m] pip install MapleX [--break-system-packages]
|
|
1227
1266
|
```
|
|
1228
1267
|
|
|
1229
1268
|
### Manual Installation
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: MapleX
|
|
3
|
-
Version: 2.2.0a2
|
|
4
|
-
Summary: # MapleX
|
|
5
|
-
Author: Ryuji Hazama
|
|
6
|
-
Project-URL: PyPI, https://pypi.org/project/MapleX/
|
|
7
|
-
Project-URL: Homepage, https://github.com/Ryuji-Hazama
|
|
8
|
-
Project-URL: Repository, https://github.com/Ryuji-Hazama/MapleTree
|
|
9
|
-
Project-URL: Issues, https://github.com/Ryuji-Hazama/MapleTree/issues
|
|
10
|
-
Project-URL: YouTube, https://www.youtube.com/@ryujihazama
|
|
11
|
-
Project-URL: Instagram, https://www.instagram.com/ryujihazama/
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Requires-Python: >=3.12
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
License-File: LICENSE
|
|
18
|
-
Requires-Dist: cryptography>=46.0.3
|
|
19
|
-
Requires-Dist: pydantic>=2.12.5
|
|
20
|
-
Dynamic: license-file
|
|
21
|
-
|
|
22
1
|
# :maple_leaf: MapleX :deciduous_tree:
|
|
23
2
|
|
|
24
3
|
MapleX is a tool set for Maple file format operations, with logging and console color utilities for Python applications.
|
|
@@ -26,9 +5,18 @@ Dynamic: license-file
|
|
|
26
5
|
***You can install the package from pip with the following command.***
|
|
27
6
|
|
|
28
7
|
```bash
|
|
29
|
-
pip install
|
|
8
|
+
pip install MapleX
|
|
30
9
|
```
|
|
31
10
|
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
> - [Maple File](#maple-file)
|
|
14
|
+
> - [MapleTree Class](#mapletree-class)
|
|
15
|
+
> - [Logger Class](#logger-class)
|
|
16
|
+
> - [Exceptions](#exceptions)
|
|
17
|
+
> - [Console Colors](#console-colors)
|
|
18
|
+
> - [Install MapleX](#install-maplex)
|
|
19
|
+
|
|
32
20
|
## Maple File
|
|
33
21
|
|
|
34
22
|
Maple is a file system that I created when I was a child. It's like a combination of the INI file and the Jason file. I made this format that is easy to read and write for both humans and machines.
|
|
@@ -314,6 +302,8 @@ EOF
|
|
|
314
302
|
If `encrypt=True`, the instance decrypts data when it is read, and encrypts data when it is saved.
|
|
315
303
|
You need to specify the byte key when you use encryption, and the file must be encrypted.
|
|
316
304
|
|
|
305
|
+
:warning: **The key must be 32 url-safe base64-encoded bytes**
|
|
306
|
+
|
|
317
307
|
```python
|
|
318
308
|
mapleFile = MapleTree("FileName.mpl", encrypt=True, key=key)
|
|
319
309
|
```
|
|
@@ -385,7 +375,32 @@ def saveTagLine(
|
|
|
385
375
|
|**`willSave`**|\*|Save to file flag|
|
|
386
376
|
|**`headers`**||Target headers|
|
|
387
377
|
|
|
388
|
-
 
|
|
378
|
+
Outdated from `v2.2.0`
|
|
379
|
+
|
|
380
|
+
### `saveValue()`
|
|
381
|
+
|
|
382
|
+
`v2.2.0` or newer
|
|
383
|
+
|
|
384
|
+
```python
|
|
385
|
+
def saveValue(
|
|
386
|
+
tag: str,
|
|
387
|
+
valueString: any,
|
|
388
|
+
*headers: str,
|
|
389
|
+
**kwargs
|
|
390
|
+
) -> bool
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
|Property|Required|Value|
|
|
394
|
+
|--------|--------|-----|
|
|
395
|
+
|**`tag`**|\*|Target tag|
|
|
396
|
+
|**`value`**|\*|Value to save|
|
|
397
|
+
|**`headers`**||Target headers|
|
|
398
|
+
|**`kwargs`**||Keyword arguments|
|
|
399
|
+
|
|
400
|
+
`saveValue` saves a value with a tag in a header block specified by the parameter.
|
|
401
|
+
|
|
402
|
+
- Set `save=True` to save changes to the file.
|
|
403
|
+
- Default: `save=False`
|
|
389
404
|
|
|
390
405
|
E.g.:
|
|
391
406
|
|
|
@@ -393,7 +408,7 @@ E.g.:
|
|
|
393
408
|
from maplex import MapleTree
|
|
394
409
|
|
|
395
410
|
mapleFile = MapleTree("SampleData.mpl", createBaseFile=True)
|
|
396
|
-
mapleFile.saveTagLine("TAG", "VALUE",
|
|
411
|
+
mapleFile.saveTagLine("TAG", "VALUE", "FOO", save=True)
|
|
397
412
|
|
|
398
413
|
```
|
|
399
414
|
|
|
@@ -409,12 +424,12 @@ EOF
|
|
|
409
424
|
|
|
410
425
|
#### Update a Buffer Content
|
|
411
426
|
|
|
412
|
-
If `
|
|
427
|
+
If `save=False` (or not specified), the buffer content will be updated, but no update on physical file content.
|
|
413
428
|
|
|
414
429
|
E.g.:
|
|
415
430
|
|
|
416
431
|
```python
|
|
417
|
-
mapleFile.saveTagLine("TAG", "NEW VALUE",
|
|
432
|
+
mapleFile.saveTagLine("TAG", "NEW VALUE", "FOO")
|
|
418
433
|
```
|
|
419
434
|
|
|
420
435
|
This code changes the contents on buffer like:
|
|
@@ -439,10 +454,10 @@ EOF
|
|
|
439
454
|
|
|
440
455
|
#### Update and Save Changes
|
|
441
456
|
|
|
442
|
-
If `
|
|
457
|
+
If `save=True`, all the changes to the buffer will be saved.
|
|
443
458
|
|
|
444
459
|
```python
|
|
445
|
-
mapleFile.saveTagLine("BAR", "ANOTHER VALUE",
|
|
460
|
+
mapleFile.saveTagLine("BAR", "ANOTHER VALUE", "FOO", save=True)
|
|
446
461
|
```
|
|
447
462
|
|
|
448
463
|
This code changes the contents in the file like:
|
|
@@ -461,10 +476,10 @@ EOF
|
|
|
461
476
|
If the block and/or the header(s) specified with the parameters do not exist in the data, the function creates the new header block(s) and the tag and saves the value.
|
|
462
477
|
|
|
463
478
|
```python
|
|
464
|
-
mapleFile.saveTagLine("TAZ", "NEW HEADER AND TAG",
|
|
479
|
+
mapleFile.saveTagLine("TAZ", "NEW HEADER AND TAG", "NEW_HEADER")
|
|
465
480
|
```
|
|
466
481
|
|
|
467
|
-
This code will change the data like:
|
|
482
|
+
This code will change the buffer data like:
|
|
468
483
|
|
|
469
484
|
```text
|
|
470
485
|
MAPLE
|
|
@@ -478,48 +493,47 @@ E
|
|
|
478
493
|
EOF
|
|
479
494
|
```
|
|
480
495
|
|
|
481
|
-
### `
|
|
482
|
-
|
|
483
|
-
`v2.2.0` or newer
|
|
496
|
+
### `deleteTag()`
|
|
484
497
|
|
|
485
498
|
```python
|
|
486
|
-
def
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
*headers: str
|
|
490
|
-
**kwargs
|
|
499
|
+
def deleteTag(
|
|
500
|
+
delTag: str,
|
|
501
|
+
willSave: bool = False,
|
|
502
|
+
*headers: str
|
|
491
503
|
) -> bool
|
|
492
504
|
```
|
|
493
505
|
|
|
494
506
|
|Property|Required|Value|
|
|
495
507
|
|--------|--------|-----|
|
|
496
|
-
|**`
|
|
497
|
-
|**`
|
|
508
|
+
|**`delTag`**|\*|Tag to delete|
|
|
509
|
+
|**`willSave`**||Save to file flag|
|
|
498
510
|
|**`headers`**||Target headers|
|
|
499
|
-
|**`kwargs`**||Keyword arguments|
|
|
500
511
|
|
|
501
|
-
|
|
502
|
-
- Set `save=True` to save changes to the file.
|
|
503
|
-
- Default: `save=False`
|
|
512
|
+
Outdated from `v2.2.0`
|
|
504
513
|
|
|
505
|
-
### `
|
|
514
|
+
### `deleteValue()`
|
|
515
|
+
|
|
516
|
+
`v2.2.0` or newer
|
|
506
517
|
|
|
507
518
|
```python
|
|
508
|
-
def
|
|
519
|
+
def deleteValue(
|
|
509
520
|
delTag: str,
|
|
510
|
-
|
|
511
|
-
|
|
521
|
+
*headers: str,
|
|
522
|
+
**kwargs
|
|
512
523
|
) -> bool
|
|
513
524
|
```
|
|
514
525
|
|
|
515
526
|
|Property|Required|Value|
|
|
516
527
|
|--------|--------|-----|
|
|
517
528
|
|**`delTag`**|\*|Tag to delete|
|
|
518
|
-
|**`willSave`**||Save to file flag|
|
|
519
529
|
|**`headers`**||Target headers|
|
|
530
|
+
|**`kwargs`**||Keyword arguments|
|
|
520
531
|
|
|
521
532
|
Delete a tag and its value.
|
|
522
533
|
|
|
534
|
+
- Set `save=True` to save changes to the file.
|
|
535
|
+
- Default: `save=False`
|
|
536
|
+
|
|
523
537
|
Sample data: `SampleData.mpl`
|
|
524
538
|
|
|
525
539
|
```text
|
|
@@ -539,7 +553,7 @@ E.g.:
|
|
|
539
553
|
from maplex import MapleTree
|
|
540
554
|
|
|
541
555
|
mapleFile = MapleTree("SampleData.mpl")
|
|
542
|
-
mapleFile.deleteTag("BAR",
|
|
556
|
+
mapleFile.deleteTag("BAR", "FOO", save=True)
|
|
543
557
|
```
|
|
544
558
|
|
|
545
559
|
The file data will be changed like:
|
|
@@ -554,28 +568,6 @@ E
|
|
|
554
568
|
EOF
|
|
555
569
|
```
|
|
556
570
|
|
|
557
|
-
### `deleteValue()`
|
|
558
|
-
|
|
559
|
-
`v2.2.0` or newer
|
|
560
|
-
|
|
561
|
-
```python
|
|
562
|
-
def deleteValue(
|
|
563
|
-
delTag: str,
|
|
564
|
-
*headers: str,
|
|
565
|
-
**kwargs
|
|
566
|
-
) -> bool
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
|Property|Required|Value|
|
|
570
|
-
|--------|--------|-----|
|
|
571
|
-
|**`delTag`**|\*|Tag to delete|
|
|
572
|
-
|**`headers`**||Target headers|
|
|
573
|
-
|**`kwargs`**||Keyword arguments|
|
|
574
|
-
|
|
575
|
-
- Same as `deleteTag()`
|
|
576
|
-
- Set `save=True` to save changes to the file.
|
|
577
|
-
- Default: `save=False`
|
|
578
|
-
|
|
579
571
|
### `getTagValueDict()`
|
|
580
572
|
|
|
581
573
|
```python
|
|
@@ -670,8 +662,31 @@ def deleteHeader(
|
|
|
670
662
|
|**`willSave`**||Save to file flag|
|
|
671
663
|
|**`Headers`**||Target headers|
|
|
672
664
|
|
|
665
|
+
Outdated from `v2.2.0`
|
|
666
|
+
|
|
667
|
+
### `removeHeader()`
|
|
668
|
+
|
|
669
|
+
`v2.2.0` or newer
|
|
670
|
+
|
|
671
|
+
```python
|
|
672
|
+
def removeHeader(
|
|
673
|
+
delHead: str,
|
|
674
|
+
*headers: str,
|
|
675
|
+
**kwargs
|
|
676
|
+
) -> bool
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
|Property|Required|Value|
|
|
680
|
+
|--------|--------|-----|
|
|
681
|
+
|**`delHead`**|\*|Deleting header|
|
|
682
|
+
|**`headers`**||Target headers|
|
|
683
|
+
|**`kwargs`**||Keyword arguments|
|
|
684
|
+
|
|
673
685
|
This deletes an entire header block and its associated data, including child blocks.
|
|
674
686
|
|
|
687
|
+
- Set `save=True` for save data to the file.
|
|
688
|
+
- Default: `save=False`
|
|
689
|
+
|
|
675
690
|
Sample data: `SampleData.mpl`
|
|
676
691
|
|
|
677
692
|
```text
|
|
@@ -696,7 +711,7 @@ E.g.:
|
|
|
696
711
|
from maplex import MapleTree
|
|
697
712
|
|
|
698
713
|
mapleTree = MapleTree("SampleData.mpl")
|
|
699
|
-
mapleTree.deleteHeader("FOO", True)
|
|
714
|
+
mapleTree.deleteHeader("FOO", save=True)
|
|
700
715
|
```
|
|
701
716
|
|
|
702
717
|
This code changes the data like:
|
|
@@ -711,28 +726,6 @@ E
|
|
|
711
726
|
EOF
|
|
712
727
|
```
|
|
713
728
|
|
|
714
|
-
### `removeHeader()`
|
|
715
|
-
|
|
716
|
-
`v2.2.0` or newer
|
|
717
|
-
|
|
718
|
-
```python
|
|
719
|
-
def removeHeader(
|
|
720
|
-
delHead: str,
|
|
721
|
-
*headers: str,
|
|
722
|
-
**kwargs
|
|
723
|
-
) -> bool
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
|Property|Required|Value|
|
|
727
|
-
|--------|--------|-----|
|
|
728
|
-
|**`delHead`**|\*|Deleting header|
|
|
729
|
-
|**`headers`**||Target headers|
|
|
730
|
-
|**`kwargs`**||Keyword arguments|
|
|
731
|
-
|
|
732
|
-
- Same as `deleteHeader()`
|
|
733
|
-
- Set `save=True` for save data to the file.
|
|
734
|
-
- Default: `save=False`
|
|
735
|
-
|
|
736
729
|
### `getHeaders()`
|
|
737
730
|
|
|
738
731
|
```python
|
|
@@ -1006,6 +999,26 @@ E
|
|
|
1006
999
|
EOF
|
|
1007
1000
|
```
|
|
1008
1001
|
|
|
1002
|
+
### `changeEncryptionKey()`
|
|
1003
|
+
|
|
1004
|
+
`v2.2.0` or newer
|
|
1005
|
+
|
|
1006
|
+
```python
|
|
1007
|
+
def changeEncryptionKey(
|
|
1008
|
+
newKey: bytes,
|
|
1009
|
+
save: bool = False
|
|
1010
|
+
) -> None
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
|Property|Required|Value|
|
|
1014
|
+
|--------|--------|-----|
|
|
1015
|
+
|**`newKey`**|\*|New encryption key|
|
|
1016
|
+
|**`save`**||Save to file flag|
|
|
1017
|
+
|
|
1018
|
+
Changing file encryption key. If `save=True`, encrypt the buffer data with new key and save to the file.
|
|
1019
|
+
|
|
1020
|
+
:warning: **The key must be 32 url-safe base64-encoded bytes**
|
|
1021
|
+
|
|
1009
1022
|
## Logger Class
|
|
1010
1023
|
|
|
1011
1024
|
Logger is a logging object for Python applications. It outputs application logs to log files and to standard output.
|
|
@@ -1088,8 +1101,9 @@ def ShowError(
|
|
|
1088
1101
|
|
|
1089
1102
|
- You can configure log settings with `config.mpl`.
|
|
1090
1103
|
- If `config.mpl` does not exist, the instance auto-generates the file.
|
|
1104
|
+
- Instance uses the parameter values to auto-generate configuration file, or using default value if it was not specified.
|
|
1091
1105
|
|
|
1092
|
-
Auto-generated `config.mpl
|
|
1106
|
+
Auto-generated `config.mpl` (parameters not specified):
|
|
1093
1107
|
|
|
1094
1108
|
```text
|
|
1095
1109
|
MAPLE
|
|
@@ -1136,6 +1150,10 @@ EOF
|
|
|
1136
1150
|
|
|
1137
1151
|
This occurs when the data is not found in the file.
|
|
1138
1152
|
|
|
1153
|
+
### `MapleEncryptionNotEnabledException(MapleException)`
|
|
1154
|
+
|
|
1155
|
+
This occurs when try to encrypt maple data, but the encryption flag is `False`.
|
|
1156
|
+
|
|
1139
1157
|
### `class MapleHeaderNotFoundException(MapleDataNotFoundException)`
|
|
1140
1158
|
|
|
1141
1159
|
This occurs when the header (specified by the user) is not found in the data.
|
|
@@ -1218,12 +1236,12 @@ EOF
|
|
|
1218
1236
|
|`Reversed`|\\033\[7m|Reversed colors|
|
|
1219
1237
|
|`Reset`|\\033\[0m|Reset formatting|
|
|
1220
1238
|
|
|
1221
|
-
## Install
|
|
1239
|
+
## Install MapleX
|
|
1222
1240
|
|
|
1223
1241
|
### From PyPI
|
|
1224
1242
|
|
|
1225
1243
|
```bash
|
|
1226
|
-
[python[3] -m] pip install
|
|
1244
|
+
[python[3] -m] pip install MapleX [--break-system-packages]
|
|
1227
1245
|
```
|
|
1228
1246
|
|
|
1229
1247
|
### Manual Installation
|
|
@@ -4,8 +4,9 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "MapleX"
|
|
7
|
-
version = "2.2.
|
|
8
|
-
description = """
|
|
7
|
+
version = "2.2.0b1"
|
|
8
|
+
description = """A Python library for Maple file format operations, with logging and console color utilities
|
|
9
|
+
|
|
9
10
|
# MapleX
|
|
10
11
|
|
|
11
12
|
A Python library for Maple file format operations, with logging and console color utilities
|
|
@@ -21,7 +22,7 @@ Logger is a versatile logging utility that allows developers to log messages wit
|
|
|
21
22
|
readme = "README.md"
|
|
22
23
|
license-files = ["LICENSE"]
|
|
23
24
|
authors = [
|
|
24
|
-
{name = "
|
|
25
|
+
{name = "RyujiHazama"}
|
|
25
26
|
]
|
|
26
27
|
dependencies = [
|
|
27
28
|
"cryptography>=46.0.3",
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: MapleX
|
|
3
|
+
Version: 2.2.0b1
|
|
4
|
+
Summary: A Python library for Maple file format operations, with logging and console color utilities
|
|
5
|
+
Author: RyujiHazama
|
|
6
|
+
Project-URL: PyPI, https://pypi.org/project/MapleX/
|
|
7
|
+
Project-URL: Homepage, https://github.com/Ryuji-Hazama
|
|
8
|
+
Project-URL: Repository, https://github.com/Ryuji-Hazama/MapleTree
|
|
9
|
+
Project-URL: Issues, https://github.com/Ryuji-Hazama/MapleTree/issues
|
|
10
|
+
Project-URL: YouTube, https://www.youtube.com/@ryujihazama
|
|
11
|
+
Project-URL: Instagram, https://www.instagram.com/ryujihazama/
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: cryptography>=46.0.3
|
|
19
|
+
Requires-Dist: pydantic>=2.12.5
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
1
22
|
# :maple_leaf: MapleX :deciduous_tree:
|
|
2
23
|
|
|
3
24
|
MapleX is a tool set for Maple file format operations, with logging and console color utilities for Python applications.
|
|
@@ -5,9 +26,18 @@
|
|
|
5
26
|
***You can install the package from pip with the following command.***
|
|
6
27
|
|
|
7
28
|
```bash
|
|
8
|
-
pip install
|
|
29
|
+
pip install MapleX
|
|
9
30
|
```
|
|
10
31
|
|
|
32
|
+
## Table of Contents
|
|
33
|
+
|
|
34
|
+
> - [Maple File](#maple-file)
|
|
35
|
+
> - [MapleTree Class](#mapletree-class)
|
|
36
|
+
> - [Logger Class](#logger-class)
|
|
37
|
+
> - [Exceptions](#exceptions)
|
|
38
|
+
> - [Console Colors](#console-colors)
|
|
39
|
+
> - [Install MapleX](#install-maplex)
|
|
40
|
+
|
|
11
41
|
## Maple File
|
|
12
42
|
|
|
13
43
|
Maple is a file system that I created when I was a child. It's like a combination of the INI file and the Jason file. I made this format that is easy to read and write for both humans and machines.
|
|
@@ -293,6 +323,8 @@ EOF
|
|
|
293
323
|
If `encrypt=True`, the instance decrypts data when it is read, and encrypts data when it is saved.
|
|
294
324
|
You need to specify the byte key when you use encryption, and the file must be encrypted.
|
|
295
325
|
|
|
326
|
+
:warning: **The key must be 32 url-safe base64-encoded bytes**
|
|
327
|
+
|
|
296
328
|
```python
|
|
297
329
|
mapleFile = MapleTree("FileName.mpl", encrypt=True, key=key)
|
|
298
330
|
```
|
|
@@ -364,7 +396,32 @@ def saveTagLine(
|
|
|
364
396
|
|**`willSave`**|\*|Save to file flag|
|
|
365
397
|
|**`headers`**||Target headers|
|
|
366
398
|
|
|
367
|
-
 
|
|
399
|
+
Outdated from `v2.2.0`
|
|
400
|
+
|
|
401
|
+
### `saveValue()`
|
|
402
|
+
|
|
403
|
+
`v2.2.0` or newer
|
|
404
|
+
|
|
405
|
+
```python
|
|
406
|
+
def saveValue(
|
|
407
|
+
tag: str,
|
|
408
|
+
valueString: any,
|
|
409
|
+
*headers: str,
|
|
410
|
+
**kwargs
|
|
411
|
+
) -> bool
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
|Property|Required|Value|
|
|
415
|
+
|--------|--------|-----|
|
|
416
|
+
|**`tag`**|\*|Target tag|
|
|
417
|
+
|**`value`**|\*|Value to save|
|
|
418
|
+
|**`headers`**||Target headers|
|
|
419
|
+
|**`kwargs`**||Keyword arguments|
|
|
420
|
+
|
|
421
|
+
`saveValue` saves a value with a tag in a header block specified by the parameter.
|
|
422
|
+
|
|
423
|
+
- Set `save=True` to save changes to the file.
|
|
424
|
+
- Default: `save=False`
|
|
368
425
|
|
|
369
426
|
E.g.:
|
|
370
427
|
|
|
@@ -372,7 +429,7 @@ E.g.:
|
|
|
372
429
|
from maplex import MapleTree
|
|
373
430
|
|
|
374
431
|
mapleFile = MapleTree("SampleData.mpl", createBaseFile=True)
|
|
375
|
-
mapleFile.saveTagLine("TAG", "VALUE",
|
|
432
|
+
mapleFile.saveTagLine("TAG", "VALUE", "FOO", save=True)
|
|
376
433
|
|
|
377
434
|
```
|
|
378
435
|
|
|
@@ -388,12 +445,12 @@ EOF
|
|
|
388
445
|
|
|
389
446
|
#### Update a Buffer Content
|
|
390
447
|
|
|
391
|
-
If `
|
|
448
|
+
If `save=False` (or not specified), the buffer content will be updated, but no update on physical file content.
|
|
392
449
|
|
|
393
450
|
E.g.:
|
|
394
451
|
|
|
395
452
|
```python
|
|
396
|
-
mapleFile.saveTagLine("TAG", "NEW VALUE",
|
|
453
|
+
mapleFile.saveTagLine("TAG", "NEW VALUE", "FOO")
|
|
397
454
|
```
|
|
398
455
|
|
|
399
456
|
This code changes the contents on buffer like:
|
|
@@ -418,10 +475,10 @@ EOF
|
|
|
418
475
|
|
|
419
476
|
#### Update and Save Changes
|
|
420
477
|
|
|
421
|
-
If `
|
|
478
|
+
If `save=True`, all the changes to the buffer will be saved.
|
|
422
479
|
|
|
423
480
|
```python
|
|
424
|
-
mapleFile.saveTagLine("BAR", "ANOTHER VALUE",
|
|
481
|
+
mapleFile.saveTagLine("BAR", "ANOTHER VALUE", "FOO", save=True)
|
|
425
482
|
```
|
|
426
483
|
|
|
427
484
|
This code changes the contents in the file like:
|
|
@@ -440,10 +497,10 @@ EOF
|
|
|
440
497
|
If the block and/or the header(s) specified with the parameters do not exist in the data, the function creates the new header block(s) and the tag and saves the value.
|
|
441
498
|
|
|
442
499
|
```python
|
|
443
|
-
mapleFile.saveTagLine("TAZ", "NEW HEADER AND TAG",
|
|
500
|
+
mapleFile.saveTagLine("TAZ", "NEW HEADER AND TAG", "NEW_HEADER")
|
|
444
501
|
```
|
|
445
502
|
|
|
446
|
-
This code will change the data like:
|
|
503
|
+
This code will change the buffer data like:
|
|
447
504
|
|
|
448
505
|
```text
|
|
449
506
|
MAPLE
|
|
@@ -457,48 +514,47 @@ E
|
|
|
457
514
|
EOF
|
|
458
515
|
```
|
|
459
516
|
|
|
460
|
-
### `
|
|
461
|
-
|
|
462
|
-
`v2.2.0` or newer
|
|
517
|
+
### `deleteTag()`
|
|
463
518
|
|
|
464
519
|
```python
|
|
465
|
-
def
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
*headers: str
|
|
469
|
-
**kwargs
|
|
520
|
+
def deleteTag(
|
|
521
|
+
delTag: str,
|
|
522
|
+
willSave: bool = False,
|
|
523
|
+
*headers: str
|
|
470
524
|
) -> bool
|
|
471
525
|
```
|
|
472
526
|
|
|
473
527
|
|Property|Required|Value|
|
|
474
528
|
|--------|--------|-----|
|
|
475
|
-
|**`
|
|
476
|
-
|**`
|
|
529
|
+
|**`delTag`**|\*|Tag to delete|
|
|
530
|
+
|**`willSave`**||Save to file flag|
|
|
477
531
|
|**`headers`**||Target headers|
|
|
478
|
-
|**`kwargs`**||Keyword arguments|
|
|
479
532
|
|
|
480
|
-
|
|
481
|
-
- Set `save=True` to save changes to the file.
|
|
482
|
-
- Default: `save=False`
|
|
533
|
+
Outdated from `v2.2.0`
|
|
483
534
|
|
|
484
|
-
### `
|
|
535
|
+
### `deleteValue()`
|
|
536
|
+
|
|
537
|
+
`v2.2.0` or newer
|
|
485
538
|
|
|
486
539
|
```python
|
|
487
|
-
def
|
|
540
|
+
def deleteValue(
|
|
488
541
|
delTag: str,
|
|
489
|
-
|
|
490
|
-
|
|
542
|
+
*headers: str,
|
|
543
|
+
**kwargs
|
|
491
544
|
) -> bool
|
|
492
545
|
```
|
|
493
546
|
|
|
494
547
|
|Property|Required|Value|
|
|
495
548
|
|--------|--------|-----|
|
|
496
549
|
|**`delTag`**|\*|Tag to delete|
|
|
497
|
-
|**`willSave`**||Save to file flag|
|
|
498
550
|
|**`headers`**||Target headers|
|
|
551
|
+
|**`kwargs`**||Keyword arguments|
|
|
499
552
|
|
|
500
553
|
Delete a tag and its value.
|
|
501
554
|
|
|
555
|
+
- Set `save=True` to save changes to the file.
|
|
556
|
+
- Default: `save=False`
|
|
557
|
+
|
|
502
558
|
Sample data: `SampleData.mpl`
|
|
503
559
|
|
|
504
560
|
```text
|
|
@@ -518,7 +574,7 @@ E.g.:
|
|
|
518
574
|
from maplex import MapleTree
|
|
519
575
|
|
|
520
576
|
mapleFile = MapleTree("SampleData.mpl")
|
|
521
|
-
mapleFile.deleteTag("BAR",
|
|
577
|
+
mapleFile.deleteTag("BAR", "FOO", save=True)
|
|
522
578
|
```
|
|
523
579
|
|
|
524
580
|
The file data will be changed like:
|
|
@@ -533,28 +589,6 @@ E
|
|
|
533
589
|
EOF
|
|
534
590
|
```
|
|
535
591
|
|
|
536
|
-
### `deleteValue()`
|
|
537
|
-
|
|
538
|
-
`v2.2.0` or newer
|
|
539
|
-
|
|
540
|
-
```python
|
|
541
|
-
def deleteValue(
|
|
542
|
-
delTag: str,
|
|
543
|
-
*headers: str,
|
|
544
|
-
**kwargs
|
|
545
|
-
) -> bool
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
|Property|Required|Value|
|
|
549
|
-
|--------|--------|-----|
|
|
550
|
-
|**`delTag`**|\*|Tag to delete|
|
|
551
|
-
|**`headers`**||Target headers|
|
|
552
|
-
|**`kwargs`**||Keyword arguments|
|
|
553
|
-
|
|
554
|
-
- Same as `deleteTag()`
|
|
555
|
-
- Set `save=True` to save changes to the file.
|
|
556
|
-
- Default: `save=False`
|
|
557
|
-
|
|
558
592
|
### `getTagValueDict()`
|
|
559
593
|
|
|
560
594
|
```python
|
|
@@ -649,8 +683,31 @@ def deleteHeader(
|
|
|
649
683
|
|**`willSave`**||Save to file flag|
|
|
650
684
|
|**`Headers`**||Target headers|
|
|
651
685
|
|
|
686
|
+
Outdated from `v2.2.0`
|
|
687
|
+
|
|
688
|
+
### `removeHeader()`
|
|
689
|
+
|
|
690
|
+
`v2.2.0` or newer
|
|
691
|
+
|
|
692
|
+
```python
|
|
693
|
+
def removeHeader(
|
|
694
|
+
delHead: str,
|
|
695
|
+
*headers: str,
|
|
696
|
+
**kwargs
|
|
697
|
+
) -> bool
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
|Property|Required|Value|
|
|
701
|
+
|--------|--------|-----|
|
|
702
|
+
|**`delHead`**|\*|Deleting header|
|
|
703
|
+
|**`headers`**||Target headers|
|
|
704
|
+
|**`kwargs`**||Keyword arguments|
|
|
705
|
+
|
|
652
706
|
This deletes an entire header block and its associated data, including child blocks.
|
|
653
707
|
|
|
708
|
+
- Set `save=True` for save data to the file.
|
|
709
|
+
- Default: `save=False`
|
|
710
|
+
|
|
654
711
|
Sample data: `SampleData.mpl`
|
|
655
712
|
|
|
656
713
|
```text
|
|
@@ -675,7 +732,7 @@ E.g.:
|
|
|
675
732
|
from maplex import MapleTree
|
|
676
733
|
|
|
677
734
|
mapleTree = MapleTree("SampleData.mpl")
|
|
678
|
-
mapleTree.deleteHeader("FOO", True)
|
|
735
|
+
mapleTree.deleteHeader("FOO", save=True)
|
|
679
736
|
```
|
|
680
737
|
|
|
681
738
|
This code changes the data like:
|
|
@@ -690,28 +747,6 @@ E
|
|
|
690
747
|
EOF
|
|
691
748
|
```
|
|
692
749
|
|
|
693
|
-
### `removeHeader()`
|
|
694
|
-
|
|
695
|
-
`v2.2.0` or newer
|
|
696
|
-
|
|
697
|
-
```python
|
|
698
|
-
def removeHeader(
|
|
699
|
-
delHead: str,
|
|
700
|
-
*headers: str,
|
|
701
|
-
**kwargs
|
|
702
|
-
) -> bool
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
|Property|Required|Value|
|
|
706
|
-
|--------|--------|-----|
|
|
707
|
-
|**`delHead`**|\*|Deleting header|
|
|
708
|
-
|**`headers`**||Target headers|
|
|
709
|
-
|**`kwargs`**||Keyword arguments|
|
|
710
|
-
|
|
711
|
-
- Same as `deleteHeader()`
|
|
712
|
-
- Set `save=True` for save data to the file.
|
|
713
|
-
- Default: `save=False`
|
|
714
|
-
|
|
715
750
|
### `getHeaders()`
|
|
716
751
|
|
|
717
752
|
```python
|
|
@@ -985,6 +1020,26 @@ E
|
|
|
985
1020
|
EOF
|
|
986
1021
|
```
|
|
987
1022
|
|
|
1023
|
+
### `changeEncryptionKey()`
|
|
1024
|
+
|
|
1025
|
+
`v2.2.0` or newer
|
|
1026
|
+
|
|
1027
|
+
```python
|
|
1028
|
+
def changeEncryptionKey(
|
|
1029
|
+
newKey: bytes,
|
|
1030
|
+
save: bool = False
|
|
1031
|
+
) -> None
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
|Property|Required|Value|
|
|
1035
|
+
|--------|--------|-----|
|
|
1036
|
+
|**`newKey`**|\*|New encryption key|
|
|
1037
|
+
|**`save`**||Save to file flag|
|
|
1038
|
+
|
|
1039
|
+
Changing file encryption key. If `save=True`, encrypt the buffer data with new key and save to the file.
|
|
1040
|
+
|
|
1041
|
+
:warning: **The key must be 32 url-safe base64-encoded bytes**
|
|
1042
|
+
|
|
988
1043
|
## Logger Class
|
|
989
1044
|
|
|
990
1045
|
Logger is a logging object for Python applications. It outputs application logs to log files and to standard output.
|
|
@@ -1067,8 +1122,9 @@ def ShowError(
|
|
|
1067
1122
|
|
|
1068
1123
|
- You can configure log settings with `config.mpl`.
|
|
1069
1124
|
- If `config.mpl` does not exist, the instance auto-generates the file.
|
|
1125
|
+
- Instance uses the parameter values to auto-generate configuration file, or using default value if it was not specified.
|
|
1070
1126
|
|
|
1071
|
-
Auto-generated `config.mpl
|
|
1127
|
+
Auto-generated `config.mpl` (parameters not specified):
|
|
1072
1128
|
|
|
1073
1129
|
```text
|
|
1074
1130
|
MAPLE
|
|
@@ -1115,6 +1171,10 @@ EOF
|
|
|
1115
1171
|
|
|
1116
1172
|
This occurs when the data is not found in the file.
|
|
1117
1173
|
|
|
1174
|
+
### `MapleEncryptionNotEnabledException(MapleException)`
|
|
1175
|
+
|
|
1176
|
+
This occurs when try to encrypt maple data, but the encryption flag is `False`.
|
|
1177
|
+
|
|
1118
1178
|
### `class MapleHeaderNotFoundException(MapleDataNotFoundException)`
|
|
1119
1179
|
|
|
1120
1180
|
This occurs when the header (specified by the user) is not found in the data.
|
|
@@ -1197,12 +1257,12 @@ EOF
|
|
|
1197
1257
|
|`Reversed`|\\033\[7m|Reversed colors|
|
|
1198
1258
|
|`Reset`|\\033\[0m|Reset formatting|
|
|
1199
1259
|
|
|
1200
|
-
## Install
|
|
1260
|
+
## Install MapleX
|
|
1201
1261
|
|
|
1202
1262
|
### From PyPI
|
|
1203
1263
|
|
|
1204
1264
|
```bash
|
|
1205
|
-
[python[3] -m] pip install
|
|
1265
|
+
[python[3] -m] pip install MapleX [--break-system-packages]
|
|
1206
1266
|
```
|
|
1207
1267
|
|
|
1208
1268
|
### Manual Installation
|
|
@@ -10,6 +10,7 @@ from .mapleExceptions import (
|
|
|
10
10
|
KeyEmptyException,
|
|
11
11
|
MapleDataNotFoundException,
|
|
12
12
|
MapleException,
|
|
13
|
+
MapleEncryptionNotEnabledException,
|
|
13
14
|
MapleFileEmptyException,
|
|
14
15
|
MapleFileLockedException,
|
|
15
16
|
MapleFileNotFoundException,
|
|
@@ -27,6 +28,7 @@ __all__ = [
|
|
|
27
28
|
'InvalidMapleFileFormatException',
|
|
28
29
|
'KeyEmptyException',
|
|
29
30
|
'MapleDataNotFoundException',
|
|
31
|
+
'MapleEncryptionNotEnabledException',
|
|
30
32
|
'MapleException',
|
|
31
33
|
'MapleFileEmptyException',
|
|
32
34
|
'MapleFileLockedException',
|
|
@@ -42,6 +44,6 @@ __all__ = [
|
|
|
42
44
|
'winUnHide'
|
|
43
45
|
]
|
|
44
46
|
|
|
45
|
-
__version__ = "2.2.
|
|
47
|
+
__version__ = "2.2.0b1"
|
|
46
48
|
__author__ = "Ryuji Hazama"
|
|
47
49
|
__license__ = "MIT"
|
|
@@ -54,6 +54,13 @@ class MapleDataNotFoundException(MapleException):
|
|
|
54
54
|
|
|
55
55
|
super().__init__(self.message)
|
|
56
56
|
|
|
57
|
+
class MapleEncryptionNotEnabledException(MapleException):
|
|
58
|
+
|
|
59
|
+
def __init__(self, mapleFile: str = "", message: str = "File encryption is not enabled"):
|
|
60
|
+
|
|
61
|
+
self.message = f"{message}: {mapleFile}"
|
|
62
|
+
super().__init__(self.message)
|
|
63
|
+
|
|
57
64
|
class MapleHeaderNotFoundException(MapleDataNotFoundException):
|
|
58
65
|
|
|
59
66
|
def __init__(self, fileName = "", header: str = "", preHeader: str = "", message = ""):
|
|
@@ -52,15 +52,15 @@ class Logger:
|
|
|
52
52
|
|
|
53
53
|
with open(configFile, "w") as f:
|
|
54
54
|
|
|
55
|
-
f.write("MAPLE\n"
|
|
56
|
-
"H *LOG_SETTINGS\n"
|
|
57
|
-
" CMD INFO\n"
|
|
58
|
-
" FLE INFO\n"
|
|
59
|
-
" # TRACE, DEBUG, INFO, WARN,\n"
|
|
60
|
-
" # ERROR, FATAL, NONE\n"
|
|
61
|
-
" MAX 3\n"
|
|
62
|
-
" OUT logs\n"
|
|
63
|
-
"E\nEOF")
|
|
55
|
+
f.write(f"MAPLE\n"
|
|
56
|
+
f"H *LOG_SETTINGS\n"
|
|
57
|
+
f" CMD {cmdLogLevel if cmdLogLevel is not None else 'INFO'}\n"
|
|
58
|
+
f" FLE {fileLogLevel if fileLogLevel is not None else 'INFO'}\n"
|
|
59
|
+
f" # TRACE, DEBUG, INFO, WARN,\n"
|
|
60
|
+
f" # ERROR, FATAL, NONE\n"
|
|
61
|
+
f" MAX {maxLogSize if maxLogSize is not None else 3}\n"
|
|
62
|
+
f" OUT {workingDirectory if workingDirectory is not None else 'logs'}\n"
|
|
63
|
+
f"E\nEOF")
|
|
64
64
|
|
|
65
65
|
maple = MapleTree(configFile)
|
|
66
66
|
|
|
@@ -225,6 +225,7 @@ class Logger:
|
|
|
225
225
|
Green = self.consoleColors.Green
|
|
226
226
|
bLightBlue = self.consoleColors.bLightBlue
|
|
227
227
|
Bold = self.consoleColors.Bold
|
|
228
|
+
Italic = self.consoleColors.Italic
|
|
228
229
|
Reset = self.consoleColors.Reset
|
|
229
230
|
|
|
230
231
|
try:
|
|
@@ -265,7 +266,7 @@ class Logger:
|
|
|
265
266
|
|
|
266
267
|
case self.LogLevel.NONE:
|
|
267
268
|
|
|
268
|
-
col = Bold + Black
|
|
269
|
+
col = Bold + Italic + Black
|
|
269
270
|
|
|
270
271
|
case _:
|
|
271
272
|
|
|
@@ -406,6 +407,10 @@ ToDo list:
|
|
|
406
407
|
|
|
407
408
|
* Logger *
|
|
408
409
|
|
|
410
|
+
- Create getLogger function
|
|
411
|
+
- Add option to file output mode (append/overwrite/daily)
|
|
412
|
+
- Add option to set date format
|
|
413
|
+
- Add set* functions
|
|
409
414
|
- Configure log format in config file
|
|
410
415
|
|
|
411
416
|
"""
|
|
@@ -32,9 +32,9 @@ class MapleTree:
|
|
|
32
32
|
|
|
33
33
|
# Encrypt data
|
|
34
34
|
|
|
35
|
-
mapleBaseString = Fernet(key).encrypt(mapleBaseString.encode())
|
|
35
|
+
mapleBaseString = Fernet(key).encrypt(mapleBaseString.encode())
|
|
36
36
|
|
|
37
|
-
with open(fileName, "
|
|
37
|
+
with open(fileName, "wb") as f:
|
|
38
38
|
|
|
39
39
|
f.write(mapleBaseString)
|
|
40
40
|
|
|
@@ -44,24 +44,26 @@ class MapleTree:
|
|
|
44
44
|
|
|
45
45
|
try:
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if encrypt:
|
|
47
|
+
if encrypt:
|
|
50
48
|
|
|
49
|
+
with open(fileName, "rb") as f:
|
|
50
|
+
|
|
51
51
|
# Decode encryption
|
|
52
52
|
|
|
53
53
|
fileData = f.read()
|
|
54
|
-
fileData = Fernet(key).decrypt(fileData
|
|
54
|
+
fileData = Fernet(key).decrypt(fileData).decode()
|
|
55
55
|
self.fileStream = fileData.split("\n")
|
|
56
56
|
|
|
57
|
-
# Add \
|
|
57
|
+
# Add \n at the end of each line
|
|
58
58
|
|
|
59
59
|
for i, fileLine in enumerate(self.fileStream):
|
|
60
60
|
|
|
61
61
|
self.fileStream[i] = f"{fileLine}\n"
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
else:
|
|
64
|
+
|
|
65
|
+
with open(fileName, "r") as f:
|
|
66
|
+
|
|
65
67
|
self.fileStream = f.readlines()
|
|
66
68
|
|
|
67
69
|
# If the file is empty
|
|
@@ -117,18 +119,39 @@ class MapleTree:
|
|
|
117
119
|
##############################
|
|
118
120
|
# Read file
|
|
119
121
|
|
|
122
|
+
#
|
|
123
|
+
##############################
|
|
124
|
+
# Change encryption key
|
|
125
|
+
|
|
126
|
+
def changeEncryptionKey(self, newKey: bytes, save: bool = False) -> None:
|
|
127
|
+
|
|
128
|
+
"""
|
|
129
|
+
Change encryption key to newKey.
|
|
130
|
+
If save is True, overwrite the file with new encryption.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
if not self.ENCRYPT:
|
|
134
|
+
|
|
135
|
+
raise mExc.MapleEncryptionNotEnabledException(self.fileName)
|
|
136
|
+
|
|
137
|
+
self.KEY = newKey
|
|
138
|
+
|
|
139
|
+
if save:
|
|
140
|
+
|
|
141
|
+
self._saveToFile()
|
|
142
|
+
|
|
120
143
|
#
|
|
121
144
|
##############################
|
|
122
145
|
# Encrypt data
|
|
123
146
|
|
|
124
|
-
def __encryptData(self) ->
|
|
147
|
+
def __encryptData(self) -> bytes:
|
|
125
148
|
|
|
126
149
|
"""
|
|
127
150
|
Return encrypted base_64 string
|
|
128
151
|
"""
|
|
129
152
|
|
|
130
153
|
fileData = "".join(self.fileStream).encode()
|
|
131
|
-
fileData = Fernet(self.KEY).encrypt(fileData)
|
|
154
|
+
fileData = Fernet(self.KEY).encrypt(fileData)
|
|
132
155
|
|
|
133
156
|
return fileData
|
|
134
157
|
|
|
@@ -149,15 +172,21 @@ class MapleTree:
|
|
|
149
172
|
|
|
150
173
|
fileData = self.__encryptData()
|
|
151
174
|
|
|
175
|
+
# Save to file
|
|
176
|
+
|
|
177
|
+
with open(self.fileName, "wb") as f:
|
|
178
|
+
|
|
179
|
+
f.write(fileData)
|
|
180
|
+
|
|
152
181
|
else:
|
|
153
182
|
|
|
154
183
|
fileData = "".join(self.fileStream)
|
|
155
184
|
|
|
156
|
-
|
|
185
|
+
# Save to file
|
|
157
186
|
|
|
158
|
-
|
|
187
|
+
with open(self.fileName, "w") as f:
|
|
159
188
|
|
|
160
|
-
|
|
189
|
+
f.writelines(fileData)
|
|
161
190
|
|
|
162
191
|
except Exception as e:
|
|
163
192
|
|
|
@@ -1117,5 +1146,11 @@ ToDo list:
|
|
|
1117
1146
|
|
|
1118
1147
|
* MapleTree *
|
|
1119
1148
|
|
|
1149
|
+
- In changeEncryptionKey, if encrypt is False, force to encrypt the file with new key.
|
|
1150
|
+
- In changeEncryptionKey, if newKey is None, save file without encryption.
|
|
1151
|
+
- Add parameter to control this behavior. (changeEncryptionState: bool = False)
|
|
1152
|
+
- Add auto-generate key function.
|
|
1153
|
+
- Add function to get current key.
|
|
1154
|
+
|
|
1120
1155
|
"""
|
|
1121
1156
|
""" * * * * * * * * * * * * * """
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|