foundationdb 7.4.7__py3-none-any.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.
fdb/__init__.py ADDED
@@ -0,0 +1,168 @@
1
+ #
2
+ # __init__.py
3
+ #
4
+ # This source file is part of the FoundationDB open source project
5
+ #
6
+ # Copyright 2013-2024 Apple Inc. and the FoundationDB project authors
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ # FoundationDB Python API
22
+
23
+ """Documentation for this API can be found at
24
+ https://apple.github.io/foundationdb/api-python.html"""
25
+
26
+ import fdb.apiversion
27
+
28
+ __version__ = fdb.apiversion.FDB_VERSION
29
+
30
+ LATEST_API_VERSION = fdb.apiversion.LATEST_API_VERSION
31
+
32
+
33
+
34
+ def open(*args, **kwargs):
35
+ raise RuntimeError("You must call api_version() before using any fdb methods")
36
+
37
+
38
+ init = open
39
+
40
+
41
+ def transactional(*args, **kwargs):
42
+ raise RuntimeError("You must call api_version() before using fdb.transactional")
43
+
44
+
45
+ def _add_symbols(module, symbols):
46
+ for symbol in symbols:
47
+ globals()[symbol] = getattr(module, symbol)
48
+
49
+
50
+ def is_api_version_selected():
51
+ return "_version" in globals()
52
+
53
+
54
+ def get_api_version():
55
+ if is_api_version_selected():
56
+ return globals()["_version"]
57
+ else:
58
+ raise RuntimeError("API version is not set")
59
+
60
+
61
+ def api_version(ver):
62
+ header_version = LATEST_API_VERSION
63
+
64
+ if "_version" in globals():
65
+ if globals()["_version"] != ver:
66
+ raise RuntimeError(
67
+ "FDB API already loaded at version %d" % globals()["_version"]
68
+ )
69
+ return
70
+
71
+ if ver < 13:
72
+ raise RuntimeError("FDB API versions before 13 are not supported")
73
+
74
+ if ver > header_version:
75
+ raise RuntimeError("Latest known FDB API version is %d" % header_version)
76
+
77
+ import fdb.impl
78
+
79
+ err = fdb.impl._capi.fdb_select_api_version_impl(ver, header_version)
80
+ if err == 2203: # api_version_not_supported, but that's not helpful to the user
81
+ max_supported_ver = fdb.impl._capi.fdb_get_max_api_version()
82
+ if header_version > max_supported_ver:
83
+ raise RuntimeError(
84
+ "This version of the FoundationDB Python binding is not supported by the installed "
85
+ "FoundationDB C library. The binding requires a library that supports API version "
86
+ "%d, but the installed library supports a maximum version of %d."
87
+ % (header_version, max_supported_ver)
88
+ )
89
+
90
+ else:
91
+ raise RuntimeError(
92
+ "API version %d is not supported by the installed FoundationDB C library."
93
+ % ver
94
+ )
95
+
96
+ elif err != 0:
97
+ raise RuntimeError("FoundationDB API error")
98
+
99
+ fdb.impl.init_c_api()
100
+
101
+ list = (
102
+ "FDBError",
103
+ "predicates",
104
+ "Future",
105
+ "Database",
106
+ "Tenant",
107
+ "Transaction",
108
+ "KeyValue",
109
+ "KeySelector",
110
+ "open",
111
+ "transactional",
112
+ "options",
113
+ "StreamingMode",
114
+ )
115
+
116
+ _add_symbols(fdb.impl, list)
117
+
118
+ if ver >= 630:
119
+ import fdb.tenant_management
120
+
121
+ if ver < 610:
122
+ globals()["init"] = getattr(fdb.impl, "init")
123
+ globals()["open"] = getattr(fdb.impl, "open_v609")
124
+ globals()["create_cluster"] = getattr(fdb.impl, "create_cluster")
125
+ globals()["Cluster"] = getattr(fdb.impl, "Cluster")
126
+
127
+ if ver > 22:
128
+ import fdb.locality
129
+
130
+ if ver == 13:
131
+ globals()["open"] = getattr(fdb.impl, "open_v13")
132
+ globals()["init"] = getattr(fdb.impl, "init_v13")
133
+
134
+ # Future.get got renamed to Future.wait in v14 to make room for
135
+ # Database.get, we have to undo that here
136
+ for name in dir(fdb.impl):
137
+ o = getattr(fdb.impl, name)
138
+ try:
139
+ if issubclass(o, fdb.impl.Future):
140
+ if hasattr(o, "wait"):
141
+ o.get = o.wait
142
+ except TypeError:
143
+ pass
144
+
145
+ # FDBRange used to be called FDBRangeIter and was an iterator,
146
+ # but it's now a container. In v13 we have to make it act like
147
+ # an iterator again.
148
+ def next(self):
149
+ if not hasattr(self, "__iterating"):
150
+ self.__iterating = iter(self)
151
+ return next(self.__iterating)
152
+
153
+ setattr(fdb.impl.FDBRange, "next", next)
154
+
155
+ globals()["_version"] = ver
156
+
157
+ import fdb.directory_impl
158
+
159
+ directory_symbols = (
160
+ "directory",
161
+ "DirectoryLayer",
162
+ )
163
+ _add_symbols(fdb.directory_impl, directory_symbols)
164
+
165
+ import fdb.subspace_impl
166
+
167
+ subspace_symbols = ("Subspace",)
168
+ _add_symbols(fdb.subspace_impl, subspace_symbols)
fdb/apiversion.py ADDED
@@ -0,0 +1,2 @@
1
+ LATEST_API_VERSION = 740
2
+ FDB_VERSION = "7.4.7"