dictature 0.9.5__tar.gz → 0.9.7__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.
Files changed (24) hide show
  1. {dictature-0.9.5/src/dictature.egg-info → dictature-0.9.7}/PKG-INFO +2 -1
  2. {dictature-0.9.5 → dictature-0.9.7}/README.md +1 -0
  3. {dictature-0.9.5 → dictature-0.9.7}/pyproject.toml +1 -1
  4. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/backend/directory.py +8 -6
  5. dictature-0.9.7/src/dictature/transformer/gzip.py +53 -0
  6. {dictature-0.9.5 → dictature-0.9.7/src/dictature.egg-info}/PKG-INFO +2 -1
  7. {dictature-0.9.5 → dictature-0.9.7}/src/dictature.egg-info/SOURCES.txt +1 -0
  8. {dictature-0.9.5 → dictature-0.9.7}/tests/test_operations.py +2 -0
  9. {dictature-0.9.5 → dictature-0.9.7}/LICENSE +0 -0
  10. {dictature-0.9.5 → dictature-0.9.7}/setup.cfg +0 -0
  11. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/__init__.py +0 -0
  12. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/backend/__init__.py +0 -0
  13. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/backend/misp.py +0 -0
  14. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/backend/mock.py +0 -0
  15. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/backend/sqlite.py +0 -0
  16. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/dictature.py +0 -0
  17. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/transformer/__init__.py +0 -0
  18. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/transformer/aes.py +0 -0
  19. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/transformer/hmac.py +0 -0
  20. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/transformer/mock.py +0 -0
  21. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/transformer/passthrough.py +0 -0
  22. {dictature-0.9.5 → dictature-0.9.7}/src/dictature/transformer/pipeline.py +0 -0
  23. {dictature-0.9.5 → dictature-0.9.7}/src/dictature.egg-info/dependency_links.txt +0 -0
  24. {dictature-0.9.5 → dictature-0.9.7}/src/dictature.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dictature
3
- Version: 0.9.5
3
+ Version: 0.9.7
4
4
  Summary: dictature -- A generic wrapper around dict-like interface with mulitple backends
5
5
  Author-email: Adam Hlavacek <git@adamhlavacek.com>
6
6
  Project-URL: Homepage, https://github.com/esoadamo/dictature
@@ -78,5 +78,6 @@ dictionary = Dictature(
78
78
  Currently, the following transformers are supported:
79
79
  - `AESTransformer`: encrypts/decrypts the data using AES
80
80
  - `HmacTransformer`: signs the data using HMAC or performs hash integrity checks
81
+ - `GzipTransformer`: compresses given data
81
82
  - `PassthroughTransformer`: does nothing
82
83
  - `PipelineTransformer`: chains multiple transformers
@@ -65,5 +65,6 @@ dictionary = Dictature(
65
65
  Currently, the following transformers are supported:
66
66
  - `AESTransformer`: encrypts/decrypts the data using AES
67
67
  - `HmacTransformer`: signs the data using HMAC or performs hash integrity checks
68
+ - `GzipTransformer`: compresses given data
68
69
  - `PassthroughTransformer`: does nothing
69
70
  - `PipelineTransformer`: chains multiple transformers
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dictature"
7
- version = "0.9.5"
7
+ version = "0.9.7"
8
8
  description = "dictature -- A generic wrapper around dict-like interface with mulitple backends"
9
9
  authors = [
10
10
  { name = "Adam Hlavacek", email = "git@adamhlavacek.com" }
@@ -6,7 +6,7 @@ from .mock import DictatureTableMock, DictatureBackendMock, Value, ValueMode, Va
6
6
 
7
7
 
8
8
  class DictatureBackendDirectory(DictatureBackendMock):
9
- def __init__(self, directory: Union[Path, str], dir_prefix: str = 'db_') -> None:
9
+ def __init__(self, directory: Union[Path, str], dir_prefix: str = 'db_', item_prefix: str = 'item_') -> None:
10
10
  """
11
11
  Create a new directory backend
12
12
  :param directory: directory to store the data
@@ -16,6 +16,7 @@ class DictatureBackendDirectory(DictatureBackendMock):
16
16
  directory = Path(directory)
17
17
  self.__directory = directory
18
18
  self.__dir_prefix = dir_prefix
19
+ self.__item_prefix = item_prefix
19
20
 
20
21
  def keys(self) -> Iterable[str]:
21
22
  for child in self.__directory.iterdir():
@@ -24,14 +25,15 @@ class DictatureBackendDirectory(DictatureBackendMock):
24
25
  yield DictatureTableDirectory._filename_decode(child.name[len(self.__dir_prefix):], suffix='')
25
26
 
26
27
  def table(self, name: str) -> 'DictatureTableMock':
27
- return DictatureTableDirectory(self.__directory, name, self.__dir_prefix)
28
+ return DictatureTableDirectory(self.__directory, name, self.__dir_prefix, self.__item_prefix)
28
29
 
29
30
 
30
31
  class DictatureTableDirectory(DictatureTableMock):
31
- def __init__(self, path_root: Path, name: str, db_prefix: str, prefix: str = 'item_') -> None:
32
+ def __init__(self, path_root: Path, name: str, db_prefix: str, prefix: str) -> None:
32
33
  self.__path = path_root / (db_prefix + self._filename_encode(name, suffix=''))
33
34
  self.__prefix = prefix
34
- self.__serializer = ValueSerializer(mode=ValueSerializerMode.filename_only)
35
+ self.__name_serializer = ValueSerializer(mode=ValueSerializerMode.filename_only)
36
+ self.__value_serializer = ValueSerializer(mode=ValueSerializerMode.any_string)
35
37
 
36
38
  def keys(self) -> Iterable[str]:
37
39
  for child in self.__path.iterdir():
@@ -48,7 +50,7 @@ class DictatureTableDirectory(DictatureTableMock):
48
50
  file_target = self.__item_path(item)
49
51
  file_target_tmp = file_target.with_suffix('.tmp')
50
52
 
51
- save_data = self.__serializer.serialize(value)
53
+ save_data = self.__value_serializer.serialize(value)
52
54
 
53
55
  file_target_tmp.write_text(save_data)
54
56
  file_target_tmp.rename(file_target)
@@ -56,7 +58,7 @@ class DictatureTableDirectory(DictatureTableMock):
56
58
  def get(self, item: str) -> Value:
57
59
  try:
58
60
  save_data = self.__item_path(item).read_text()
59
- return self.__serializer.deserialize(save_data)
61
+ return self.__value_serializer.deserialize(save_data)
60
62
  except FileNotFoundError:
61
63
  raise KeyError(item)
62
64
 
@@ -0,0 +1,53 @@
1
+ import gzip
2
+ import base64
3
+
4
+ from .mock import MockTransformer
5
+
6
+
7
+ class GzipTransformer(MockTransformer):
8
+ """
9
+ Compresses and decompresses text using Gzip.
10
+
11
+ The compressed data is Base64 encoded to ensure it can be represented as a string.
12
+ """
13
+ def __init__(self) -> None:
14
+ """
15
+ Initializes the GzipTransformer. No parameters needed for basic Gzip.
16
+ """
17
+ # No specific state needed for standard gzip compression/decompression
18
+ pass
19
+
20
+ def forward(self, text: str) -> str:
21
+ """
22
+ Compresses the input text using Gzip and returns a Base64 encoded string.
23
+ :param text: The original text string.
24
+ :return: A Base64 encoded string representing the Gzipped data.
25
+ """
26
+ byte_data = text.encode('utf-8')
27
+ compressed_bytes = gzip.compress(byte_data)
28
+ base64_bytes = base64.b64encode(compressed_bytes)
29
+ base64_string = base64_bytes.decode('ascii')
30
+ return base64_string
31
+
32
+ def backward(self, text: str) -> str:
33
+ """
34
+ Decompresses the Base64 encoded Gzip data back into the original text.
35
+ :param text: A Base64 encoded string representing Gzipped data.
36
+ :return: The original text string.
37
+ :raises ValueError: If the input string is not valid Base64 or not valid Gzip data.
38
+ """
39
+ try:
40
+ base64_bytes = text.encode('ascii')
41
+ compressed_bytes = base64.b64decode(base64_bytes)
42
+ original_bytes = gzip.decompress(compressed_bytes)
43
+ original_text = original_bytes.decode('utf-8')
44
+ return original_text
45
+ except (gzip.BadGzipFile, UnicodeDecodeError) as e:
46
+ # Catch errors related to Base64 decoding, Gzip decompression, or UTF-8 decoding
47
+ raise ValueError(f"Invalid input data for Gzip decompression: {e}") from e
48
+
49
+ @property
50
+ def static(self) -> bool:
51
+ return False
52
+
53
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dictature
3
- Version: 0.9.5
3
+ Version: 0.9.7
4
4
  Summary: dictature -- A generic wrapper around dict-like interface with mulitple backends
5
5
  Author-email: Adam Hlavacek <git@adamhlavacek.com>
6
6
  Project-URL: Homepage, https://github.com/esoadamo/dictature
@@ -78,5 +78,6 @@ dictionary = Dictature(
78
78
  Currently, the following transformers are supported:
79
79
  - `AESTransformer`: encrypts/decrypts the data using AES
80
80
  - `HmacTransformer`: signs the data using HMAC or performs hash integrity checks
81
+ - `GzipTransformer`: compresses given data
81
82
  - `PassthroughTransformer`: does nothing
82
83
  - `PipelineTransformer`: chains multiple transformers
@@ -14,6 +14,7 @@ src/dictature/backend/mock.py
14
14
  src/dictature/backend/sqlite.py
15
15
  src/dictature/transformer/__init__.py
16
16
  src/dictature/transformer/aes.py
17
+ src/dictature/transformer/gzip.py
17
18
  src/dictature/transformer/hmac.py
18
19
  src/dictature/transformer/mock.py
19
20
  src/dictature/transformer/passthrough.py
@@ -13,6 +13,7 @@ from src.dictature.transformer import PassthroughTransformer, PipelineTransforme
13
13
  from src.dictature.transformer.mock import MockTransformer
14
14
  from src.dictature.transformer.aes import AESTransformer
15
15
  from src.dictature.transformer.hmac import HmacTransformer
16
+ from src.dictature.transformer.gzip import GzipTransformer
16
17
 
17
18
 
18
19
  BACKENDS = [
@@ -26,6 +27,7 @@ TRANSFORMERS = [
26
27
  AESTransformer('password', True),
27
28
  HmacTransformer(),
28
29
  HmacTransformer('password'),
30
+ GzipTransformer(),
29
31
  PipelineTransformer([HmacTransformer(), AESTransformer('password', False)]),
30
32
  ]
31
33
 
File without changes
File without changes