zlmdb 25.10.1__cp314-cp314-manylinux_2_34_x86_64.whl

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.

Potentially problematic release.


This version of zlmdb might be problematic. Click here for more details.

Files changed (87) hide show
  1. flatbuffers/__init__.py +19 -0
  2. flatbuffers/_version.py +17 -0
  3. flatbuffers/builder.py +776 -0
  4. flatbuffers/compat.py +86 -0
  5. flatbuffers/encode.py +42 -0
  6. flatbuffers/flexbuffers.py +1527 -0
  7. flatbuffers/number_types.py +181 -0
  8. flatbuffers/packer.py +42 -0
  9. flatbuffers/reflection/AdvancedFeatures.py +10 -0
  10. flatbuffers/reflection/BaseType.py +24 -0
  11. flatbuffers/reflection/Enum.py +169 -0
  12. flatbuffers/reflection/EnumVal.py +96 -0
  13. flatbuffers/reflection/Field.py +208 -0
  14. flatbuffers/reflection/KeyValue.py +56 -0
  15. flatbuffers/reflection/Object.py +175 -0
  16. flatbuffers/reflection/RPCCall.py +131 -0
  17. flatbuffers/reflection/Schema.py +206 -0
  18. flatbuffers/reflection/SchemaFile.py +77 -0
  19. flatbuffers/reflection/Service.py +145 -0
  20. flatbuffers/reflection/Type.py +98 -0
  21. flatbuffers/reflection/__init__.py +0 -0
  22. flatbuffers/table.py +129 -0
  23. flatbuffers/util.py +43 -0
  24. zlmdb/__init__.py +312 -0
  25. zlmdb/_database.py +990 -0
  26. zlmdb/_errors.py +31 -0
  27. zlmdb/_meta.py +27 -0
  28. zlmdb/_pmap.py +1667 -0
  29. zlmdb/_schema.py +137 -0
  30. zlmdb/_transaction.py +181 -0
  31. zlmdb/_types.py +1596 -0
  32. zlmdb/_version.py +27 -0
  33. zlmdb/cli.py +41 -0
  34. zlmdb/flatbuffers/__init__.py +5 -0
  35. zlmdb/flatbuffers/reflection/AdvancedFeatures.py +10 -0
  36. zlmdb/flatbuffers/reflection/BaseType.py +25 -0
  37. zlmdb/flatbuffers/reflection/Enum.py +252 -0
  38. zlmdb/flatbuffers/reflection/EnumVal.py +144 -0
  39. zlmdb/flatbuffers/reflection/Field.py +325 -0
  40. zlmdb/flatbuffers/reflection/KeyValue.py +84 -0
  41. zlmdb/flatbuffers/reflection/Object.py +260 -0
  42. zlmdb/flatbuffers/reflection/RPCCall.py +195 -0
  43. zlmdb/flatbuffers/reflection/Schema.py +301 -0
  44. zlmdb/flatbuffers/reflection/SchemaFile.py +112 -0
  45. zlmdb/flatbuffers/reflection/Service.py +213 -0
  46. zlmdb/flatbuffers/reflection/Type.py +148 -0
  47. zlmdb/flatbuffers/reflection/__init__.py +0 -0
  48. zlmdb/flatbuffers/reflection.fbs +152 -0
  49. zlmdb/lmdb/__init__.py +37 -0
  50. zlmdb/lmdb/__main__.py +25 -0
  51. zlmdb/lmdb/_config.py +10 -0
  52. zlmdb/lmdb/_lmdb_cffi.cpython-314-x86_64-linux-gnu.so +0 -0
  53. zlmdb/lmdb/cffi.py +2606 -0
  54. zlmdb/lmdb/tool.py +670 -0
  55. zlmdb/tests/lmdb/__init__.py +0 -0
  56. zlmdb/tests/lmdb/address_book.py +287 -0
  57. zlmdb/tests/lmdb/crash_test.py +339 -0
  58. zlmdb/tests/lmdb/cursor_test.py +333 -0
  59. zlmdb/tests/lmdb/env_test.py +919 -0
  60. zlmdb/tests/lmdb/getmulti_test.py +92 -0
  61. zlmdb/tests/lmdb/iteration_test.py +258 -0
  62. zlmdb/tests/lmdb/package_test.py +70 -0
  63. zlmdb/tests/lmdb/test_lmdb.py +188 -0
  64. zlmdb/tests/lmdb/testlib.py +185 -0
  65. zlmdb/tests/lmdb/tool_test.py +60 -0
  66. zlmdb/tests/lmdb/txn_test.py +575 -0
  67. zlmdb/tests/orm/MNodeLog.py +853 -0
  68. zlmdb/tests/orm/__init__.py +0 -0
  69. zlmdb/tests/orm/_schema_fbs.py +215 -0
  70. zlmdb/tests/orm/_schema_mnode_log.py +1201 -0
  71. zlmdb/tests/orm/_schema_py2.py +250 -0
  72. zlmdb/tests/orm/_schema_py3.py +307 -0
  73. zlmdb/tests/orm/_test_flatbuffers.py +144 -0
  74. zlmdb/tests/orm/_test_serialization.py +144 -0
  75. zlmdb/tests/orm/test_basic.py +217 -0
  76. zlmdb/tests/orm/test_etcd.py +275 -0
  77. zlmdb/tests/orm/test_pmap_indexes.py +466 -0
  78. zlmdb/tests/orm/test_pmap_types.py +90 -0
  79. zlmdb/tests/orm/test_pmaps.py +295 -0
  80. zlmdb/tests/orm/test_select.py +619 -0
  81. zlmdb-25.10.1.dist-info/METADATA +264 -0
  82. zlmdb-25.10.1.dist-info/RECORD +87 -0
  83. zlmdb-25.10.1.dist-info/WHEEL +5 -0
  84. zlmdb-25.10.1.dist-info/entry_points.txt +2 -0
  85. zlmdb-25.10.1.dist-info/licenses/LICENSE +137 -0
  86. zlmdb-25.10.1.dist-info/licenses/NOTICE +41 -0
  87. zlmdb-25.10.1.dist-info/top_level.txt +2 -0
zlmdb/_schema.py ADDED
@@ -0,0 +1,137 @@
1
+ ###############################################################################
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) typedef int GmbH
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+ #
25
+ ###############################################################################
26
+
27
+ from zlmdb._pmap import PersistentMap
28
+
29
+
30
+ class Slot(object):
31
+ """
32
+ LMDB database slot. A slot is defined just by the convention of using
33
+ the first 2 bytes of keys in a LMDB database as the "slot index".
34
+
35
+ The 2 bytes are interpreted as an uint16 in big endian byte order.
36
+ """
37
+
38
+ def __init__(self, slot, name, pmap):
39
+ """
40
+
41
+ :param slot:
42
+ :param name:
43
+ :param pmap:
44
+ """
45
+ self.slot = slot
46
+ self.name = name
47
+ self.pmap = pmap
48
+
49
+
50
+ class Schema(object):
51
+ """
52
+ ZLMDB database schema definition.
53
+ """
54
+
55
+ SLOT_DATA_EMPTY = 0
56
+ """
57
+ Database slot is empty (unused, not necessarily zero'ed, but uninitialized).
58
+ """
59
+
60
+ SLOT_DATA_METADATA = 1
61
+ """
62
+ FIXME.
63
+ """
64
+
65
+ SLOT_DATA_TYPE = 2
66
+ """
67
+ FIXME.
68
+ """
69
+
70
+ SLOT_DATA_SEQUENCE = 3
71
+ """
72
+ FIXME.
73
+ """
74
+
75
+ SLOT_DATA_TABLE = 4
76
+ """
77
+ Database slot contains a persistent map, for example a map of type OID to Pickle.
78
+ """
79
+
80
+ SLOT_DATA_INDEX = 5
81
+ """
82
+ FIXME.
83
+ """
84
+
85
+ SLOT_DATA_REPLICATION = 6
86
+ """
87
+ FIXME.
88
+ """
89
+
90
+ SLOT_DATA_MATERIALIZATION = 7
91
+ """
92
+ FIXME.
93
+ """
94
+
95
+ def __init__(self):
96
+ self._index_to_slot = {}
97
+ self._name_to_slot = {}
98
+
99
+ def slot(
100
+ self,
101
+ slot_index,
102
+ marshal=None,
103
+ unmarshal=None,
104
+ build=None,
105
+ cast=None,
106
+ compress=False,
107
+ ):
108
+ """
109
+ Decorator for use on classes derived from zlmdb.PersistentMap. The decorator define slots
110
+ in a LMDB database schema based on persistent maps, and slot configuration.
111
+
112
+ :param slot_index:
113
+ :param marshal:
114
+ :param unmarshal:
115
+ :param build:
116
+ :param cast:
117
+ :param compress:
118
+ :return:
119
+ """
120
+
121
+ def decorate(o):
122
+ assert isinstance(o, PersistentMap)
123
+ name = o.__class__.__name__
124
+ assert slot_index not in self._index_to_slot
125
+ assert name not in self._name_to_slot
126
+ o._zlmdb_slot = slot_index
127
+ o._zlmdb_marshal = marshal
128
+ o._zlmdb_unmarshal = unmarshal
129
+ o._zlmdb_build = build
130
+ o._zlmdb_cast = cast
131
+ o._zlmdb_compress = compress
132
+ _slot = Slot(slot_index, name, o)
133
+ self._index_to_slot[slot_index] = _slot
134
+ self._name_to_slot[name] = _slot
135
+ return o
136
+
137
+ return decorate
zlmdb/_transaction.py ADDED
@@ -0,0 +1,181 @@
1
+ ###############################################################################
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) typedef int GmbH
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+ #
25
+ ###############################################################################
26
+ """Transactions"""
27
+
28
+ import struct
29
+ import zlmdb.lmdb as lmdb
30
+ from typing import Optional
31
+
32
+ from txaio import time_ns as walltime
33
+
34
+
35
+ class TransactionStats(object):
36
+ """
37
+ Value class for holding transaction statistics.
38
+ """
39
+
40
+ def __init__(self):
41
+ self.puts = 0
42
+ self.dels = 0
43
+ self._started = walltime()
44
+
45
+ @property
46
+ def started(self):
47
+ """
48
+
49
+ :return: start time in ns since epoch
50
+ """
51
+ return self._started
52
+
53
+ @property
54
+ def duration(self):
55
+ """
56
+
57
+ :return: duration in ns
58
+ """
59
+ if self._started:
60
+ return walltime() - self._started
61
+ else:
62
+ return 0
63
+
64
+ def reset(self):
65
+ """
66
+
67
+ :return:
68
+ """
69
+ self.puts = 0
70
+ self.dels = 0
71
+ self._started = walltime()
72
+
73
+
74
+ class Transaction(object):
75
+ """
76
+ Transactions in zLMDB are always run under an instance of this class.
77
+ """
78
+
79
+ PUT = 1
80
+ DEL = 2
81
+
82
+ def __init__(self, db, write=False, buffers=False, stats=None):
83
+ """
84
+
85
+ :param db:
86
+ :type db: zlmdb.Database
87
+
88
+ :param write:
89
+ :type write: bool
90
+
91
+ :param stats:
92
+ :type stats: TransactionStats
93
+ """
94
+ self._db = db
95
+ self._write = write
96
+ self._buffers = buffers
97
+ self._stats = stats
98
+ self._txn: Optional[lmdb.Transaction] = None
99
+ self._log = None
100
+
101
+ def __enter__(self):
102
+ assert self._txn is None
103
+
104
+ self._txn = lmdb.Transaction(
105
+ self._db._env, write=self._write, buffers=self._buffers
106
+ )
107
+ return self
108
+
109
+ def __exit__(self, exc_type, exc_value, traceback):
110
+ assert self._txn is not None
111
+
112
+ # https://docs.python.org/3/reference/datamodel.html#object.__exit__
113
+ # If the context was exited without an exception, all three arguments will be None.
114
+ if exc_type is None:
115
+ if self._log:
116
+ cnt = 0
117
+ for op, key in self._log:
118
+ _key = struct.pack(">H", 0)
119
+ _data = struct.pack(">H", op) + key
120
+ self._txn.put(_key, _data)
121
+ cnt += 1
122
+ self._txn.commit()
123
+ else:
124
+ self._txn.abort()
125
+
126
+ self._txn = None
127
+
128
+ def id(self):
129
+ """
130
+
131
+ :return:
132
+ """
133
+ assert self._txn is not None
134
+
135
+ return self._txn.id()
136
+
137
+ def get(self, key):
138
+ """
139
+
140
+ :param key:
141
+ :return:
142
+ """
143
+ assert self._txn is not None
144
+
145
+ return self._txn.get(key)
146
+
147
+ def put(self, key, data, overwrite=True):
148
+ """
149
+
150
+ :param key:
151
+ :param data:
152
+ :param overwrite:
153
+ :return:
154
+ """
155
+ assert self._txn is not None
156
+
157
+ # store the record, returning True if it was written, or False to indicate the key
158
+ # was already present and overwrite=False.
159
+ was_written = self._txn.put(key, data, overwrite=overwrite)
160
+ if was_written:
161
+ if self._stats:
162
+ self._stats.puts += 1
163
+ if self._log:
164
+ self._log.append((Transaction.PUT, key))
165
+ return was_written
166
+
167
+ def delete(self, key):
168
+ """
169
+
170
+ :param key:
171
+ :return:
172
+ """
173
+ assert self._txn is not None
174
+
175
+ was_deleted = self._txn.delete(key)
176
+ if was_deleted:
177
+ if self._stats:
178
+ self._stats.dels += 1
179
+ if self._log:
180
+ self._log.append((Transaction.DEL, key))
181
+ return was_deleted