zlmdb 25.12.2__cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.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.
Files changed (76) hide show
  1. zlmdb/__init__.py +416 -0
  2. zlmdb/_database.py +990 -0
  3. zlmdb/_errors.py +31 -0
  4. zlmdb/_flatc/__init__.py +105 -0
  5. zlmdb/_lmdb_vendor/__init__.py +37 -0
  6. zlmdb/_lmdb_vendor/__main__.py +25 -0
  7. zlmdb/_lmdb_vendor/_config.py +10 -0
  8. zlmdb/_lmdb_vendor/_lmdb_cffi.cpython-314t-aarch64-linux-gnu.so +0 -0
  9. zlmdb/_lmdb_vendor/cffi.py +2606 -0
  10. zlmdb/_lmdb_vendor/tool.py +670 -0
  11. zlmdb/_meta.py +27 -0
  12. zlmdb/_pmap.py +1667 -0
  13. zlmdb/_schema.py +137 -0
  14. zlmdb/_transaction.py +181 -0
  15. zlmdb/_types.py +1596 -0
  16. zlmdb/_version.py +27 -0
  17. zlmdb/cli.py +41 -0
  18. zlmdb/flatbuffers/__init__.py +60 -0
  19. zlmdb/flatbuffers/_git_version.py +24 -0
  20. zlmdb/flatbuffers/_version.py +17 -0
  21. zlmdb/flatbuffers/builder.py +824 -0
  22. zlmdb/flatbuffers/compat.py +89 -0
  23. zlmdb/flatbuffers/encode.py +43 -0
  24. zlmdb/flatbuffers/flexbuffers.py +1570 -0
  25. zlmdb/flatbuffers/number_types.py +182 -0
  26. zlmdb/flatbuffers/packer.py +42 -0
  27. zlmdb/flatbuffers/reflection/AdvancedFeatures.py +10 -0
  28. zlmdb/flatbuffers/reflection/BaseType.py +25 -0
  29. zlmdb/flatbuffers/reflection/Enum.py +252 -0
  30. zlmdb/flatbuffers/reflection/EnumVal.py +144 -0
  31. zlmdb/flatbuffers/reflection/Field.py +325 -0
  32. zlmdb/flatbuffers/reflection/KeyValue.py +84 -0
  33. zlmdb/flatbuffers/reflection/Object.py +260 -0
  34. zlmdb/flatbuffers/reflection/RPCCall.py +195 -0
  35. zlmdb/flatbuffers/reflection/Schema.py +301 -0
  36. zlmdb/flatbuffers/reflection/SchemaFile.py +112 -0
  37. zlmdb/flatbuffers/reflection/Service.py +213 -0
  38. zlmdb/flatbuffers/reflection/Type.py +148 -0
  39. zlmdb/flatbuffers/reflection/__init__.py +0 -0
  40. zlmdb/flatbuffers/reflection.fbs +156 -0
  41. zlmdb/flatbuffers/table.py +129 -0
  42. zlmdb/flatbuffers/util.py +47 -0
  43. zlmdb/py.typed +0 -0
  44. zlmdb/tests/conftest.py +9 -0
  45. zlmdb/tests/lmdb/__init__.py +0 -0
  46. zlmdb/tests/lmdb/address_book.py +287 -0
  47. zlmdb/tests/lmdb/crash_test.py +339 -0
  48. zlmdb/tests/lmdb/cursor_test.py +333 -0
  49. zlmdb/tests/lmdb/env_test.py +919 -0
  50. zlmdb/tests/lmdb/getmulti_test.py +92 -0
  51. zlmdb/tests/lmdb/iteration_test.py +258 -0
  52. zlmdb/tests/lmdb/package_test.py +70 -0
  53. zlmdb/tests/lmdb/test_lmdb.py +188 -0
  54. zlmdb/tests/lmdb/testlib.py +185 -0
  55. zlmdb/tests/lmdb/tool_test.py +60 -0
  56. zlmdb/tests/lmdb/txn_test.py +575 -0
  57. zlmdb/tests/orm/MNodeLog.py +853 -0
  58. zlmdb/tests/orm/__init__.py +0 -0
  59. zlmdb/tests/orm/_schema_fbs.py +215 -0
  60. zlmdb/tests/orm/_schema_mnode_log.py +1202 -0
  61. zlmdb/tests/orm/_schema_py2.py +250 -0
  62. zlmdb/tests/orm/_schema_py3.py +307 -0
  63. zlmdb/tests/orm/_test_flatbuffers.py +144 -0
  64. zlmdb/tests/orm/_test_serialization.py +144 -0
  65. zlmdb/tests/orm/test_basic.py +217 -0
  66. zlmdb/tests/orm/test_etcd.py +275 -0
  67. zlmdb/tests/orm/test_pmap_indexes.py +466 -0
  68. zlmdb/tests/orm/test_pmap_types.py +90 -0
  69. zlmdb/tests/orm/test_pmaps.py +295 -0
  70. zlmdb/tests/orm/test_select.py +619 -0
  71. zlmdb-25.12.2.dist-info/METADATA +280 -0
  72. zlmdb-25.12.2.dist-info/RECORD +76 -0
  73. zlmdb-25.12.2.dist-info/WHEEL +7 -0
  74. zlmdb-25.12.2.dist-info/entry_points.txt +3 -0
  75. zlmdb-25.12.2.dist-info/licenses/LICENSE +167 -0
  76. zlmdb-25.12.2.dist-info/licenses/NOTICE +41 -0
@@ -0,0 +1,295 @@
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
+ import os
28
+ import sys
29
+ import pytest
30
+ import logging
31
+
32
+ import txaio
33
+
34
+ txaio.use_twisted()
35
+
36
+ import zlmdb # noqa
37
+
38
+ try:
39
+ from tempfile import TemporaryDirectory
40
+ except ImportError:
41
+ from backports.tempfile import TemporaryDirectory # type:ignore
42
+
43
+ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
44
+
45
+ if sys.version_info >= (3, 6):
46
+ from _schema_py3 import User, Schema1, Schema3, Schema4
47
+ else:
48
+ from _schema_py2 import User, Schema1, Schema3, Schema4
49
+
50
+
51
+ @pytest.fixture(scope="module")
52
+ def testset1():
53
+ users = []
54
+ for j in range(10):
55
+ for i in range(100):
56
+ user = User.create_test_user(oid=j * 100 + i, realm_oid=j)
57
+ users.append(user)
58
+ return users
59
+
60
+
61
+ def test_truncate_table():
62
+ with TemporaryDirectory() as dbpath:
63
+ logging.info("Using temporary directory {} for database".format(dbpath))
64
+
65
+ schema = Schema1()
66
+
67
+ stats = zlmdb.TransactionStats()
68
+ tabs = [
69
+ schema.tab_oid_json,
70
+ schema.tab_str_json,
71
+ schema.tab_uuid_json,
72
+ schema.tab_oid_cbor,
73
+ schema.tab_str_cbor,
74
+ schema.tab_uuid_cbor,
75
+ schema.tab_oid_pickle,
76
+ schema.tab_str_pickle,
77
+ schema.tab_uuid_pickle,
78
+ ]
79
+
80
+ with zlmdb.Database(dbpath) as db:
81
+ with db.begin(write=True, stats=stats) as txn:
82
+ for tab in tabs:
83
+ tab.truncate(txn)
84
+
85
+ logging.info(stats.puts)
86
+ logging.info(stats.dels)
87
+
88
+
89
+ def test_fill_check(testset1):
90
+ with TemporaryDirectory() as dbpath:
91
+ logging.info("Using temporary directory {} for database".format(dbpath))
92
+
93
+ schema = Schema3()
94
+
95
+ with zlmdb.Database(dbpath) as db:
96
+ with db.begin(write=True) as txn:
97
+ for user in testset1:
98
+ schema.users[txn, user.authid] = user
99
+
100
+ with zlmdb.Database(dbpath) as db:
101
+ with db.begin() as txn:
102
+ for user in testset1:
103
+ _user = schema.users[txn, user.authid]
104
+ assert _user
105
+ assert _user == user
106
+
107
+
108
+ def test_fill_check2(testset1):
109
+ with TemporaryDirectory() as dbpath:
110
+ logging.info("Using temporary directory {} for database".format(dbpath))
111
+
112
+ schema = Schema4()
113
+
114
+ with zlmdb.Database(dbpath) as db:
115
+ with db.begin(write=True) as txn:
116
+ for user in testset1:
117
+ schema.users[txn, user.oid] = user
118
+
119
+ with zlmdb.Database(dbpath) as db:
120
+ with db.begin() as txn:
121
+ for user in testset1:
122
+ _user = schema.users[txn, user.oid]
123
+ assert _user
124
+ assert _user == user
125
+
126
+
127
+ def test_select(testset1):
128
+ testset1_keys = set([user.authid for user in testset1])
129
+
130
+ with TemporaryDirectory() as dbpath:
131
+ logging.info("Using temporary directory {} for database".format(dbpath))
132
+
133
+ schema = Schema3()
134
+
135
+ with zlmdb.Database(dbpath) as db:
136
+ with db.begin(write=True) as txn:
137
+ for user in testset1:
138
+ schema.users[txn, user.authid] = user
139
+
140
+ with zlmdb.Database(dbpath) as db:
141
+ with db.begin() as txn:
142
+ i = 0
143
+ for authid, user in schema.users.select(txn):
144
+ i += 1
145
+ assert user
146
+ assert authid == user.authid
147
+ assert authid in testset1_keys
148
+
149
+
150
+ def test_count_all(testset1):
151
+ with TemporaryDirectory() as dbpath:
152
+ logging.info("Using temporary directory {} for database".format(dbpath))
153
+
154
+ schema = Schema3()
155
+
156
+ with zlmdb.Database(dbpath) as db:
157
+ # count on empty table
158
+ with db.begin() as txn:
159
+ cnt = schema.users.count(txn)
160
+ assert cnt == 0
161
+
162
+ # fill (and count on each insert)
163
+ with db.begin(write=True) as txn:
164
+ i = 0
165
+ for user in testset1:
166
+ schema.users[txn, user.authid] = user
167
+ i += 1
168
+
169
+ # table count within filling transaction
170
+ cnt = schema.users.count(txn)
171
+ assert cnt == i
172
+
173
+ # table count within transaction
174
+ cnt = schema.users.count(txn)
175
+ assert cnt == len(testset1)
176
+
177
+ # table count in new transaction
178
+ with db.begin() as txn:
179
+ cnt = schema.users.count(txn)
180
+ assert cnt == len(testset1)
181
+
182
+ # table count in new connection
183
+ with zlmdb.Database(dbpath) as db:
184
+ with db.begin() as txn:
185
+ cnt = schema.users.count(txn)
186
+ assert cnt == len(testset1)
187
+
188
+
189
+ def test_count_prefix(testset1):
190
+ with TemporaryDirectory() as dbpath:
191
+ logging.info("Using temporary directory {} for database".format(dbpath))
192
+
193
+ schema = Schema3()
194
+
195
+ with zlmdb.Database(dbpath) as db:
196
+ with db.begin(write=True) as txn:
197
+ for user in testset1:
198
+ schema.users[txn, user.authid] = user
199
+
200
+ n = len(testset1)
201
+ tests = [
202
+ (None, n),
203
+ ("", n),
204
+ ("test-", n),
205
+ ("test-1", 111),
206
+ ("test-11", 11),
207
+ ("test-111", 1),
208
+ ]
209
+ with zlmdb.Database(dbpath) as db:
210
+ with db.begin() as txn:
211
+ for prefix, num in tests:
212
+ cnt = schema.users.count(txn, prefix)
213
+ assert cnt == num
214
+
215
+
216
+ def test_fill_with_indexes(testset1):
217
+ with TemporaryDirectory() as dbpath:
218
+ logging.info("Using temporary directory {} for database".format(dbpath))
219
+
220
+ schema = Schema4()
221
+
222
+ with zlmdb.Database(dbpath) as db:
223
+ stats = zlmdb.TransactionStats()
224
+
225
+ with db.begin(write=True, stats=stats) as txn:
226
+ for user in testset1:
227
+ schema.users[txn, user.oid] = user
228
+
229
+ # check indexes has been written to (in addition to the table itself)
230
+ num_indexes = len(schema.users.indexes())
231
+ assert stats.puts == len(testset1) * (1 + num_indexes)
232
+
233
+
234
+ def test_truncate_table_with_index(testset1):
235
+ with TemporaryDirectory() as dbpath:
236
+ logging.info("Using temporary directory {} for database".format(dbpath))
237
+
238
+ schema = Schema4()
239
+
240
+ with zlmdb.Database(dbpath) as db:
241
+ with db.begin(write=True) as txn:
242
+ for user in testset1:
243
+ schema.users[txn, user.oid] = user
244
+
245
+ stats = zlmdb.TransactionStats()
246
+
247
+ with zlmdb.Database(dbpath) as db:
248
+ with db.begin(write=True, stats=stats) as txn:
249
+ records = schema.users.truncate(txn)
250
+ logging.info("table truncated: {}".format(records))
251
+
252
+ logging.info(stats.puts)
253
+ logging.info(stats.dels)
254
+
255
+
256
+ def test_rebuild_index(testset1):
257
+ with TemporaryDirectory() as dbpath:
258
+ logging.info("Using temporary directory {} for database".format(dbpath))
259
+
260
+ schema = Schema4()
261
+
262
+ with zlmdb.Database(dbpath) as db:
263
+ with db.begin(write=True) as txn:
264
+ for user in testset1:
265
+ schema.users[txn, user.oid] = user
266
+
267
+ with zlmdb.Database(dbpath) as db:
268
+ with db.begin(write=True) as txn:
269
+ records = schema.users.rebuild_index(txn, "idx1")
270
+ logging.info(
271
+ '\nrebuilt specific index "idx1" on "users": {} records affected'.format(
272
+ records
273
+ )
274
+ )
275
+
276
+
277
+ def test_rebuild_all_indexes(testset1):
278
+ with TemporaryDirectory() as dbpath:
279
+ logging.info("Using temporary directory {} for database".format(dbpath))
280
+
281
+ schema = Schema4()
282
+
283
+ with zlmdb.Database(dbpath) as db:
284
+ with db.begin(write=True) as txn:
285
+ for user in testset1:
286
+ schema.users[txn, user.oid] = user
287
+
288
+ with zlmdb.Database(dbpath) as db:
289
+ with db.begin(write=True) as txn:
290
+ records = schema.users.rebuild_indexes(txn)
291
+ logging.info(
292
+ '\nrebuilt all indexes on "users": {} records affected'.format(
293
+ records
294
+ )
295
+ )