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,213 @@
1
+ # automatically generated by the FlatBuffers compiler, do not modify
2
+
3
+ # namespace: reflection
4
+
5
+ import flatbuffers
6
+ from flatbuffers.compat import import_numpy
7
+
8
+ np = import_numpy()
9
+
10
+
11
+ class Service(object):
12
+ __slots__ = ["_tab"]
13
+
14
+ @classmethod
15
+ def GetRootAs(cls, buf, offset=0):
16
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
17
+ x = Service()
18
+ x.Init(buf, n + offset)
19
+ return x
20
+
21
+ @classmethod
22
+ def GetRootAsService(cls, buf, offset=0):
23
+ """This method is deprecated. Please switch to GetRootAs."""
24
+ return cls.GetRootAs(buf, offset)
25
+
26
+ @classmethod
27
+ def ServiceBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
28
+ return flatbuffers.util.BufferHasIdentifier(
29
+ buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed
30
+ )
31
+
32
+ # Service
33
+ def Init(self, buf, pos):
34
+ self._tab = flatbuffers.table.Table(buf, pos)
35
+
36
+ # Service
37
+ def Name(self):
38
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
39
+ if o != 0:
40
+ return self._tab.String(o + self._tab.Pos)
41
+ return None
42
+
43
+ # Service
44
+ def Calls(self, j):
45
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
46
+ if o != 0:
47
+ x = self._tab.Vector(o)
48
+ x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
49
+ x = self._tab.Indirect(x)
50
+ from reflection.RPCCall import RPCCall
51
+
52
+ obj = RPCCall()
53
+ obj.Init(self._tab.Bytes, x)
54
+ return obj
55
+ return None
56
+
57
+ # Service
58
+ def CallsLength(self):
59
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
60
+ if o != 0:
61
+ return self._tab.VectorLen(o)
62
+ return 0
63
+
64
+ # Service
65
+ def CallsIsNone(self):
66
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
67
+ return o == 0
68
+
69
+ # Service
70
+ def Attributes(self, j):
71
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
72
+ if o != 0:
73
+ x = self._tab.Vector(o)
74
+ x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
75
+ x = self._tab.Indirect(x)
76
+ from reflection.KeyValue import KeyValue
77
+
78
+ obj = KeyValue()
79
+ obj.Init(self._tab.Bytes, x)
80
+ return obj
81
+ return None
82
+
83
+ # Service
84
+ def AttributesLength(self):
85
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
86
+ if o != 0:
87
+ return self._tab.VectorLen(o)
88
+ return 0
89
+
90
+ # Service
91
+ def AttributesIsNone(self):
92
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
93
+ return o == 0
94
+
95
+ # Service
96
+ def Documentation(self, j):
97
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
98
+ if o != 0:
99
+ a = self._tab.Vector(o)
100
+ return self._tab.String(
101
+ a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)
102
+ )
103
+ return ""
104
+
105
+ # Service
106
+ def DocumentationLength(self):
107
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
108
+ if o != 0:
109
+ return self._tab.VectorLen(o)
110
+ return 0
111
+
112
+ # Service
113
+ def DocumentationIsNone(self):
114
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
115
+ return o == 0
116
+
117
+ # File that this Service is declared in.
118
+ # Service
119
+ def DeclarationFile(self):
120
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
121
+ if o != 0:
122
+ return self._tab.String(o + self._tab.Pos)
123
+ return None
124
+
125
+
126
+ def ServiceStart(builder):
127
+ builder.StartObject(5)
128
+
129
+
130
+ def Start(builder):
131
+ return ServiceStart(builder)
132
+
133
+
134
+ def ServiceAddName(builder, name):
135
+ builder.PrependUOffsetTRelativeSlot(
136
+ 0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0
137
+ )
138
+
139
+
140
+ def AddName(builder, name):
141
+ return ServiceAddName(builder, name)
142
+
143
+
144
+ def ServiceAddCalls(builder, calls):
145
+ builder.PrependUOffsetTRelativeSlot(
146
+ 1, flatbuffers.number_types.UOffsetTFlags.py_type(calls), 0
147
+ )
148
+
149
+
150
+ def AddCalls(builder, calls):
151
+ return ServiceAddCalls(builder, calls)
152
+
153
+
154
+ def ServiceStartCallsVector(builder, numElems):
155
+ return builder.StartVector(4, numElems, 4)
156
+
157
+
158
+ def StartCallsVector(builder, numElems):
159
+ return ServiceStartCallsVector(builder, numElems)
160
+
161
+
162
+ def ServiceAddAttributes(builder, attributes):
163
+ builder.PrependUOffsetTRelativeSlot(
164
+ 2, flatbuffers.number_types.UOffsetTFlags.py_type(attributes), 0
165
+ )
166
+
167
+
168
+ def AddAttributes(builder, attributes):
169
+ return ServiceAddAttributes(builder, attributes)
170
+
171
+
172
+ def ServiceStartAttributesVector(builder, numElems):
173
+ return builder.StartVector(4, numElems, 4)
174
+
175
+
176
+ def StartAttributesVector(builder, numElems):
177
+ return ServiceStartAttributesVector(builder, numElems)
178
+
179
+
180
+ def ServiceAddDocumentation(builder, documentation):
181
+ builder.PrependUOffsetTRelativeSlot(
182
+ 3, flatbuffers.number_types.UOffsetTFlags.py_type(documentation), 0
183
+ )
184
+
185
+
186
+ def AddDocumentation(builder, documentation):
187
+ return ServiceAddDocumentation(builder, documentation)
188
+
189
+
190
+ def ServiceStartDocumentationVector(builder, numElems):
191
+ return builder.StartVector(4, numElems, 4)
192
+
193
+
194
+ def StartDocumentationVector(builder, numElems):
195
+ return ServiceStartDocumentationVector(builder, numElems)
196
+
197
+
198
+ def ServiceAddDeclarationFile(builder, declarationFile):
199
+ builder.PrependUOffsetTRelativeSlot(
200
+ 4, flatbuffers.number_types.UOffsetTFlags.py_type(declarationFile), 0
201
+ )
202
+
203
+
204
+ def AddDeclarationFile(builder, declarationFile):
205
+ return ServiceAddDeclarationFile(builder, declarationFile)
206
+
207
+
208
+ def ServiceEnd(builder):
209
+ return builder.EndObject()
210
+
211
+
212
+ def End(builder):
213
+ return ServiceEnd(builder)
@@ -0,0 +1,148 @@
1
+ # automatically generated by the FlatBuffers compiler, do not modify
2
+
3
+ # namespace: reflection
4
+
5
+ import flatbuffers
6
+ from flatbuffers.compat import import_numpy
7
+
8
+ np = import_numpy()
9
+
10
+
11
+ class Type(object):
12
+ __slots__ = ["_tab"]
13
+
14
+ @classmethod
15
+ def GetRootAs(cls, buf, offset=0):
16
+ n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
17
+ x = Type()
18
+ x.Init(buf, n + offset)
19
+ return x
20
+
21
+ @classmethod
22
+ def GetRootAsType(cls, buf, offset=0):
23
+ """This method is deprecated. Please switch to GetRootAs."""
24
+ return cls.GetRootAs(buf, offset)
25
+
26
+ @classmethod
27
+ def TypeBufferHasIdentifier(cls, buf, offset, size_prefixed=False):
28
+ return flatbuffers.util.BufferHasIdentifier(
29
+ buf, offset, b"\x42\x46\x42\x53", size_prefixed=size_prefixed
30
+ )
31
+
32
+ # Type
33
+ def Init(self, buf, pos):
34
+ self._tab = flatbuffers.table.Table(buf, pos)
35
+
36
+ # Type
37
+ def BaseType(self):
38
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
39
+ if o != 0:
40
+ return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
41
+ return 0
42
+
43
+ # Type
44
+ def Element(self):
45
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
46
+ if o != 0:
47
+ return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
48
+ return 0
49
+
50
+ # Type
51
+ def Index(self):
52
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
53
+ if o != 0:
54
+ return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos)
55
+ return -1
56
+
57
+ # Type
58
+ def FixedLength(self):
59
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
60
+ if o != 0:
61
+ return self._tab.Get(
62
+ flatbuffers.number_types.Uint16Flags, o + self._tab.Pos
63
+ )
64
+ return 0
65
+
66
+ # The size (octets) of the `base_type` field.
67
+ # Type
68
+ def BaseSize(self):
69
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
70
+ if o != 0:
71
+ return self._tab.Get(
72
+ flatbuffers.number_types.Uint32Flags, o + self._tab.Pos
73
+ )
74
+ return 4
75
+
76
+ # The size (octets) of the `element` field, if present.
77
+ # Type
78
+ def ElementSize(self):
79
+ o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
80
+ if o != 0:
81
+ return self._tab.Get(
82
+ flatbuffers.number_types.Uint32Flags, o + self._tab.Pos
83
+ )
84
+ return 0
85
+
86
+
87
+ def TypeStart(builder):
88
+ builder.StartObject(6)
89
+
90
+
91
+ def Start(builder):
92
+ return TypeStart(builder)
93
+
94
+
95
+ def TypeAddBaseType(builder, baseType):
96
+ builder.PrependInt8Slot(0, baseType, 0)
97
+
98
+
99
+ def AddBaseType(builder, baseType):
100
+ return TypeAddBaseType(builder, baseType)
101
+
102
+
103
+ def TypeAddElement(builder, element):
104
+ builder.PrependInt8Slot(1, element, 0)
105
+
106
+
107
+ def AddElement(builder, element):
108
+ return TypeAddElement(builder, element)
109
+
110
+
111
+ def TypeAddIndex(builder, index):
112
+ builder.PrependInt32Slot(2, index, -1)
113
+
114
+
115
+ def AddIndex(builder, index):
116
+ return TypeAddIndex(builder, index)
117
+
118
+
119
+ def TypeAddFixedLength(builder, fixedLength):
120
+ builder.PrependUint16Slot(3, fixedLength, 0)
121
+
122
+
123
+ def AddFixedLength(builder, fixedLength):
124
+ return TypeAddFixedLength(builder, fixedLength)
125
+
126
+
127
+ def TypeAddBaseSize(builder, baseSize):
128
+ builder.PrependUint32Slot(4, baseSize, 4)
129
+
130
+
131
+ def AddBaseSize(builder, baseSize):
132
+ return TypeAddBaseSize(builder, baseSize)
133
+
134
+
135
+ def TypeAddElementSize(builder, elementSize):
136
+ builder.PrependUint32Slot(5, elementSize, 0)
137
+
138
+
139
+ def AddElementSize(builder, elementSize):
140
+ return TypeAddElementSize(builder, elementSize)
141
+
142
+
143
+ def TypeEnd(builder):
144
+ return builder.EndObject()
145
+
146
+
147
+ def End(builder):
148
+ return TypeEnd(builder)
File without changes
@@ -0,0 +1,156 @@
1
+ // This schema defines objects that represent a parsed schema, like
2
+ // the binary version of a .fbs file.
3
+ // This could be used to operate on unknown FlatBuffers at runtime.
4
+ // It can even ... represent itself (!)
5
+
6
+ namespace reflection;
7
+
8
+ // These must correspond to the enum in idl.h.
9
+ enum BaseType : byte {
10
+ None,
11
+ UType,
12
+ Bool,
13
+ Byte,
14
+ UByte,
15
+ Short,
16
+ UShort,
17
+ Int,
18
+ UInt,
19
+ Long,
20
+ ULong,
21
+ Float,
22
+ Double,
23
+ String,
24
+ Vector,
25
+ Obj, // Used for tables & structs.
26
+ Union,
27
+ Array,
28
+ Vector64,
29
+
30
+ // Add any new type above this value.
31
+ MaxBaseType
32
+ }
33
+
34
+ table Type {
35
+ base_type:BaseType;
36
+ element:BaseType = None; // Only if base_type == Vector
37
+ // or base_type == Array.
38
+ index:int = -1; // If base_type == Object, index into "objects" below.
39
+ // If base_type == Union, UnionType, or integral derived
40
+ // from an enum, index into "enums" below.
41
+ // If base_type == Vector && element == Union or UnionType.
42
+ fixed_length:uint16 = 0; // Only if base_type == Array.
43
+ /// The size (octets) of the `base_type` field.
44
+ base_size:uint = 4; // 4 Is a common size due to offsets being that size.
45
+ /// The size (octets) of the `element` field, if present.
46
+ element_size:uint = 0;
47
+ }
48
+
49
+ table KeyValue {
50
+ key:string (required, key);
51
+ value:string;
52
+ }
53
+
54
+ table EnumVal {
55
+ name:string (required);
56
+ value:long (key);
57
+ object:Object (deprecated);
58
+ union_type:Type;
59
+ documentation:[string];
60
+ attributes:[KeyValue];
61
+ }
62
+
63
+ table Enum {
64
+ name:string (required, key);
65
+ values:[EnumVal] (required); // In order of their values.
66
+ is_union:bool = false;
67
+ underlying_type:Type (required);
68
+ attributes:[KeyValue];
69
+ documentation:[string];
70
+ /// File that this Enum is declared in.
71
+ declaration_file: string;
72
+ }
73
+
74
+ table Field {
75
+ name:string (required, key);
76
+ type:Type (required);
77
+ id:ushort;
78
+ offset:ushort; // Offset into the vtable for tables, or into the struct.
79
+ default_integer:long = 0;
80
+ default_real:double = 0.0;
81
+ deprecated:bool = false;
82
+ required:bool = false;
83
+ key:bool = false;
84
+ attributes:[KeyValue];
85
+ documentation:[string];
86
+ optional:bool = false;
87
+ /// Number of padding octets to always add after this field. Structs only.
88
+ padding:uint16 = 0;
89
+ /// If the field uses 64-bit offsets.
90
+ offset64:bool = false;
91
+ }
92
+
93
+ table Object { // Used for both tables and structs.
94
+ name:string (required, key);
95
+ fields:[Field] (required); // Sorted.
96
+ is_struct:bool = false;
97
+ minalign:int;
98
+ bytesize:int; // For structs.
99
+ attributes:[KeyValue];
100
+ documentation:[string];
101
+ /// File that this Object is declared in.
102
+ declaration_file: string;
103
+ }
104
+
105
+ table RPCCall {
106
+ name:string (required, key);
107
+ request:Object (required); // must be a table (not a struct)
108
+ response:Object (required); // must be a table (not a struct)
109
+ attributes:[KeyValue];
110
+ documentation:[string];
111
+ }
112
+
113
+ table Service {
114
+ name:string (required, key);
115
+ calls:[RPCCall];
116
+ attributes:[KeyValue];
117
+ documentation:[string];
118
+ /// File that this Service is declared in.
119
+ declaration_file: string;
120
+ }
121
+
122
+ /// New schema language features that are not supported by old code generators.
123
+ enum AdvancedFeatures : ulong (bit_flags) {
124
+ AdvancedArrayFeatures,
125
+ AdvancedUnionFeatures,
126
+ OptionalScalars,
127
+ DefaultVectorsAndStrings,
128
+ }
129
+
130
+ /// File specific information.
131
+ /// Symbols declared within a file may be recovered by iterating over all
132
+ /// symbols and examining the `declaration_file` field.
133
+ table SchemaFile {
134
+ /// Filename, relative to project root.
135
+ filename:string (required, key);
136
+ /// Names of included files, relative to project root.
137
+ included_filenames:[string];
138
+ }
139
+
140
+ table Schema {
141
+ objects:[Object] (required); // Sorted.
142
+ enums:[Enum] (required); // Sorted.
143
+ file_ident:string;
144
+ file_ext:string;
145
+ root_table:Object;
146
+ services:[Service]; // Sorted.
147
+ advanced_features:AdvancedFeatures;
148
+ /// All the files used in this compilation. Files are relative to where
149
+ /// flatc was invoked.
150
+ fbs_files:[SchemaFile]; // Sorted.
151
+ }
152
+
153
+ root_type Schema;
154
+
155
+ file_identifier "BFBS";
156
+ file_extension "bfbs";
@@ -0,0 +1,129 @@
1
+ # Copyright 2014 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from . import encode
16
+ from . import number_types as N
17
+
18
+
19
+ class Table(object):
20
+ """Table wraps a byte slice and provides read access to its data.
21
+
22
+ The variable `Pos` indicates the root of the FlatBuffers object therein."""
23
+
24
+ __slots__ = ("Bytes", "Pos")
25
+
26
+ def __init__(self, buf, pos):
27
+ N.enforce_number(pos, N.UOffsetTFlags)
28
+
29
+ self.Bytes = buf
30
+ self.Pos = pos
31
+
32
+ def Offset(self, vtableOffset):
33
+ """Offset provides access into the Table's vtable.
34
+
35
+ Deprecated fields are ignored by checking the vtable's length."""
36
+
37
+ vtable = self.Pos - self.Get(N.SOffsetTFlags, self.Pos)
38
+ vtableEnd = self.Get(N.VOffsetTFlags, vtable)
39
+ if vtableOffset < vtableEnd:
40
+ return self.Get(N.VOffsetTFlags, vtable + vtableOffset)
41
+ return 0
42
+
43
+ def Indirect(self, off):
44
+ """Indirect retrieves the relative offset stored at `offset`."""
45
+ N.enforce_number(off, N.UOffsetTFlags)
46
+ return off + encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
47
+
48
+ def String(self, off):
49
+ """String gets a string from data stored inside the flatbuffer."""
50
+ N.enforce_number(off, N.UOffsetTFlags)
51
+ off += encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
52
+ start = off + N.UOffsetTFlags.bytewidth
53
+ length = encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
54
+ return bytes(self.Bytes[start : start + length])
55
+
56
+ def VectorLen(self, off):
57
+ """VectorLen retrieves the length of the vector whose offset is stored
58
+ at "off" in this object."""
59
+ N.enforce_number(off, N.UOffsetTFlags)
60
+
61
+ off += self.Pos
62
+ off += encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
63
+ ret = encode.Get(N.UOffsetTFlags.packer_type, self.Bytes, off)
64
+ return ret
65
+
66
+ def Vector(self, off):
67
+ """Vector retrieves the start of data of the vector whose offset is
68
+ stored at "off" in this object."""
69
+ N.enforce_number(off, N.UOffsetTFlags)
70
+
71
+ off += self.Pos
72
+ x = off + self.Get(N.UOffsetTFlags, off)
73
+ # data starts after metadata containing the vector length
74
+ x += N.UOffsetTFlags.bytewidth
75
+ return x
76
+
77
+ def Union(self, t2, off):
78
+ """Union initializes any Table-derived type to point to the union at
79
+ the given offset."""
80
+ assert type(t2) is Table
81
+ N.enforce_number(off, N.UOffsetTFlags)
82
+
83
+ off += self.Pos
84
+ t2.Pos = off + self.Get(N.UOffsetTFlags, off)
85
+ t2.Bytes = self.Bytes
86
+
87
+ def Get(self, flags, off):
88
+ """
89
+ Get retrieves a value of the type specified by `flags` at the
90
+ given offset.
91
+ """
92
+ N.enforce_number(off, N.UOffsetTFlags)
93
+ return flags.py_type(encode.Get(flags.packer_type, self.Bytes, off))
94
+
95
+ def GetSlot(self, slot, d, validator_flags):
96
+ N.enforce_number(slot, N.VOffsetTFlags)
97
+ if validator_flags is not None:
98
+ N.enforce_number(d, validator_flags)
99
+ off = self.Offset(slot)
100
+ if off == 0:
101
+ return d
102
+ return self.Get(validator_flags, self.Pos + off)
103
+
104
+ def GetVectorAsNumpy(self, flags, off):
105
+ """
106
+ GetVectorAsNumpy returns the vector that starts at `Vector(off)`
107
+ as a numpy array with the type specified by `flags`. The array is
108
+ a `view` into Bytes, so modifying the returned array will
109
+ modify Bytes in place.
110
+ """
111
+ offset = self.Vector(off)
112
+ length = self.VectorLen(off) # TODO: length accounts for bytewidth, right?
113
+ numpy_dtype = N.to_numpy_type(flags)
114
+ return encode.GetVectorAsNumpy(numpy_dtype, self.Bytes, length, offset)
115
+
116
+ def GetVOffsetTSlot(self, slot, d):
117
+ """
118
+ GetVOffsetTSlot retrieves the VOffsetT that the given vtable location
119
+ points to. If the vtable value is zero, the default value `d`
120
+ will be returned.
121
+ """
122
+
123
+ N.enforce_number(slot, N.VOffsetTFlags)
124
+ N.enforce_number(d, N.VOffsetTFlags)
125
+
126
+ off = self.Offset(slot)
127
+ if off == 0:
128
+ return d
129
+ return off
@@ -0,0 +1,47 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from . import encode
16
+ from . import number_types
17
+ from . import packer
18
+
19
+
20
+ def GetSizePrefix(buf, offset):
21
+ """Extract the size prefix from a buffer."""
22
+ return encode.Get(packer.int32, buf, offset)
23
+
24
+
25
+ def GetBufferIdentifier(buf, offset, size_prefixed=False):
26
+ """Extract the file_identifier from a buffer"""
27
+ if size_prefixed:
28
+ # increase offset by size of UOffsetTFlags
29
+ offset += number_types.UOffsetTFlags.bytewidth
30
+ # increase offset by size of root table pointer
31
+ offset += number_types.UOffsetTFlags.bytewidth
32
+ # end of FILE_IDENTIFIER
33
+ end = offset + encode.FILE_IDENTIFIER_LENGTH
34
+ return buf[offset:end]
35
+
36
+
37
+ def BufferHasIdentifier(buf, offset, file_identifier, size_prefixed=False):
38
+ got = GetBufferIdentifier(buf, offset, size_prefixed=size_prefixed)
39
+ return got == file_identifier
40
+
41
+
42
+ def RemoveSizePrefix(buf, offset):
43
+ """
44
+ Create a slice of a size-prefixed buffer that has
45
+ its position advanced just past the size prefix.
46
+ """
47
+ return buf, offset + number_types.Int32Flags.bytewidth
zlmdb/py.typed ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ # conftest.py - pytest configuration for zlmdb tests
2
+ #
3
+ # This file is loaded by pytest before any test collection happens.
4
+ # It ensures txaio framework is selected before any zlmdb imports,
5
+ # which is required because zlmdb uses txaio for logging internally.
6
+
7
+ import txaio
8
+
9
+ txaio.use_twisted()
File without changes