fadodb 0.9.0__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.
- fadodb/__init__.py +30 -0
- fadodb/_database.py +194 -0
- fadodb/_library.py +199 -0
- fadodb/_server.py +79 -0
- fadodb-0.9.0.dist-info/METADATA +136 -0
- fadodb-0.9.0.dist-info/RECORD +8 -0
- fadodb-0.9.0.dist-info/WHEEL +4 -0
- fadodb-0.9.0.dist-info/licenses/LICENSE +201 -0
fadodb/__init__.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""FadoDB for Python: a database over HTTP, or in the same process.
|
|
2
|
+
|
|
3
|
+
Two ways to the same database, and one way to use it (ADR-0101, step C):
|
|
4
|
+
|
|
5
|
+
import fadodb
|
|
6
|
+
|
|
7
|
+
# A server, as the user whose key it is:
|
|
8
|
+
db = fadodb.connect("https://fado.acme.example", key="fado_Q329CE63C9_…")
|
|
9
|
+
|
|
10
|
+
# Or the database file itself, in this process, through the library
|
|
11
|
+
# of C; the program says who is calling:
|
|
12
|
+
db = fadodb.open("books.fado", caller={"id": "ann", "groups": ["sales"]})
|
|
13
|
+
|
|
14
|
+
invoice = db.exec("create", {"class": "Invoice", "id": "FV/2026/11/0042",
|
|
15
|
+
"values": {"number": "FV/2026/11/0042"}})["document"]
|
|
16
|
+
try:
|
|
17
|
+
db.exec("transition", {"class": "Invoice", "id": "FV/2026/11/0042",
|
|
18
|
+
"transition": "book"})
|
|
19
|
+
except fadodb.Refused as refusal:
|
|
20
|
+
print(refusal.code, refusal.message) # guard_false …
|
|
21
|
+
|
|
22
|
+
A command is a name and one JSON object, and its answer is one JSON
|
|
23
|
+
object: the commands of the command set, the same as a server takes at
|
|
24
|
+
POST /v1/<command>. A refusal is raised as Refused, with the code a
|
|
25
|
+
program branches on. Nothing but the standard library is needed.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from ._database import Database, NoAnswer, Permanent, Refused, connect, open
|
|
29
|
+
|
|
30
|
+
__all__ = ["Database", "NoAnswer", "Permanent", "Refused", "connect", "open"]
|
fadodb/_database.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""The database a program uses, whichever way it reaches it."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
__all__ = ["Database", "NoAnswer", "Permanent", "Refused", "connect", "open"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Refused(Exception):
|
|
9
|
+
"""A command the database did not carry out.
|
|
10
|
+
|
|
11
|
+
code is what a program branches on, such as forbidden or guard_false;
|
|
12
|
+
message says why in words, hint how to send it so that it is carried
|
|
13
|
+
out, and path names the member of the object it is about. answer is
|
|
14
|
+
the whole answer: a refused definition has its findings there, under
|
|
15
|
+
diagnostics. status is the status of the reply over HTTP, and None in
|
|
16
|
+
the same process.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, answer, status=None):
|
|
20
|
+
error = answer.get("error") if isinstance(answer, dict) else None
|
|
21
|
+
if not isinstance(error, dict):
|
|
22
|
+
error = {"code": "internal", "message": "the answer is a refusal without an error"}
|
|
23
|
+
self.answer = answer
|
|
24
|
+
self.status = status
|
|
25
|
+
self.code = error.get("code")
|
|
26
|
+
self.message = error.get("message", "")
|
|
27
|
+
self.hint = error.get("hint")
|
|
28
|
+
self.path = error.get("path")
|
|
29
|
+
super().__init__(f"{self.code}: {self.message}")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class NoAnswer(Exception):
|
|
33
|
+
"""No answer came through: the server was not reached, what answered
|
|
34
|
+
is not a FadoDB server, or the answer was cut off. The command may
|
|
35
|
+
have been carried out; one that carries a "key" is safely sent
|
|
36
|
+
again."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Permanent(Exception):
|
|
40
|
+
"""Raised by the program's function for an action, a refusal: an
|
|
41
|
+
answer that asking again would not change. The action is dead at
|
|
42
|
+
once, with these words; any other exception is tried again."""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def connect(url, key, *, timeout=60.0):
|
|
46
|
+
"""The database a server serves at url, as the user whose key it is.
|
|
47
|
+
|
|
48
|
+
Every command is judged by the rules of the database as that user's,
|
|
49
|
+
and written to its log under that user. timeout is how long one
|
|
50
|
+
command may take, in seconds, before NoAnswer.
|
|
51
|
+
"""
|
|
52
|
+
from ._server import Server
|
|
53
|
+
|
|
54
|
+
return Database(Server(url, key, timeout), None)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def open(path, *, caller=None, options=None, library=None, actions=None):
|
|
58
|
+
"""The database file at path, held in this process through the
|
|
59
|
+
library of C, and made when it does not exist.
|
|
60
|
+
|
|
61
|
+
caller is who the program says is calling, with the members a user
|
|
62
|
+
has: {"id": "ann", "kind": "person", "groups": ["sales"],
|
|
63
|
+
"system_groups": ["designers"], "today": "2026-11-27"}; None is
|
|
64
|
+
nobody. The engine trusts it: the program has said who it is.
|
|
65
|
+
Database.as_caller gives the same database to another caller.
|
|
66
|
+
|
|
67
|
+
options are the options of fado_open, such as {"timezone":
|
|
68
|
+
"Europe/Warsaw"}. library is the path of the library; when it is
|
|
69
|
+
None, the variable FADODB_LIBRARY of the environment names it, or
|
|
70
|
+
the one beside this package, or the one the system finds.
|
|
71
|
+
|
|
72
|
+
actions are the actions the program carries out itself, a function
|
|
73
|
+
by the name of each (ADR-0102): {"mail.send": send}. The function is
|
|
74
|
+
called with the call, a dict as a webhook gets it, from a thread of
|
|
75
|
+
the worker, and returns the action's result as a dict, or None for
|
|
76
|
+
nothing; raising Permanent refuses the call, and any other exception
|
|
77
|
+
fails it, to be tried again.
|
|
78
|
+
"""
|
|
79
|
+
from ._library import Opened
|
|
80
|
+
|
|
81
|
+
return Database(Opened(path, options, library, actions), caller)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# A command whose answer is a stream, which one call cannot answer.
|
|
85
|
+
_STREAMS = {"subscribe"}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class Database:
|
|
89
|
+
"""A database, over HTTP or in this process: the same commands, the
|
|
90
|
+
same answers."""
|
|
91
|
+
|
|
92
|
+
def __init__(self, door, caller):
|
|
93
|
+
self._door = door
|
|
94
|
+
self._caller = _caller_text(caller)
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def in_process(self):
|
|
98
|
+
"""Whether the database is held in this process."""
|
|
99
|
+
return self._door.in_process
|
|
100
|
+
|
|
101
|
+
def as_caller(self, caller):
|
|
102
|
+
"""The same database, for another caller. Only a database held
|
|
103
|
+
in this process has a caller of the program's choosing: over
|
|
104
|
+
HTTP, the key says who calls."""
|
|
105
|
+
if not self._door.in_process:
|
|
106
|
+
raise TypeError("over HTTP the key says who is calling: connect with that user's key")
|
|
107
|
+
return Database(self._door, caller)
|
|
108
|
+
|
|
109
|
+
def exec(self, command, object=None):
|
|
110
|
+
"""Runs one command and answers its answer, a dict. A refusal is
|
|
111
|
+
raised as Refused."""
|
|
112
|
+
if command in _STREAMS:
|
|
113
|
+
raise Refused({"error": {
|
|
114
|
+
"code": "not_supported",
|
|
115
|
+
"message": command + " answers a stream of events, and exec answers one object",
|
|
116
|
+
"hint": "wait_for_changes answers the same events, one call at a time"}})
|
|
117
|
+
text = json.dumps({} if object is None else object, ensure_ascii=False)
|
|
118
|
+
status, answer = self._door.exec(self._caller, command, text)
|
|
119
|
+
return _answered(status, answer)
|
|
120
|
+
|
|
121
|
+
def put_file(self, data, *, name=None, media_type=None):
|
|
122
|
+
"""Keeps the bytes of a file and answers its facts, {"hash": …,
|
|
123
|
+
"name": …, "media_type": …, "size": …}, for a command to commit in
|
|
124
|
+
a variable of the schema File."""
|
|
125
|
+
if not isinstance(data, (bytes, bytearray, memoryview)):
|
|
126
|
+
raise TypeError("the file is bytes")
|
|
127
|
+
status, answer = self._door.put_file(self._caller, name, media_type, bytes(data))
|
|
128
|
+
return _answered(status, answer)["file"]
|
|
129
|
+
|
|
130
|
+
def get_file(self, class_, id, hash, *, version=None, for_=None, reason=None):
|
|
131
|
+
"""Reads a file a document holds, under the rules of the document:
|
|
132
|
+
its facts and its bytes. version reads it as an earlier version of
|
|
133
|
+
the document held it, for_ says for whom the caller acts, and
|
|
134
|
+
reason is a content administrator's for reading past a rule."""
|
|
135
|
+
asked = {"class": class_, "id": id, "hash": hash}
|
|
136
|
+
if version is not None:
|
|
137
|
+
asked["version"] = version
|
|
138
|
+
if for_ is not None:
|
|
139
|
+
asked["for"] = for_
|
|
140
|
+
if reason is not None:
|
|
141
|
+
asked["reason"] = reason
|
|
142
|
+
status, answer, data = self._door.get_file(self._caller, asked)
|
|
143
|
+
return _file(_answered(status, answer)["file"]), data
|
|
144
|
+
|
|
145
|
+
def get_blob(self, hash, *, reason):
|
|
146
|
+
"""Reads bytes by their hash alone, which the engine does for a
|
|
147
|
+
content administrator and nobody else, with a reason the log of
|
|
148
|
+
reads keeps: their facts and their bytes."""
|
|
149
|
+
status, answer, data = self._door.get_blob(self._caller, {"hash": hash, "reason": reason})
|
|
150
|
+
return _file(_answered(status, answer)["file"]), data
|
|
151
|
+
|
|
152
|
+
def close(self):
|
|
153
|
+
"""Closes the database: in this process the file, for every caller
|
|
154
|
+
it was given to; over HTTP the connections. Closing again does
|
|
155
|
+
nothing."""
|
|
156
|
+
self._door.close()
|
|
157
|
+
|
|
158
|
+
def __enter__(self):
|
|
159
|
+
return self
|
|
160
|
+
|
|
161
|
+
def __exit__(self, *exc):
|
|
162
|
+
self.close()
|
|
163
|
+
return False
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _caller_text(caller):
|
|
167
|
+
if caller is None:
|
|
168
|
+
return ""
|
|
169
|
+
if isinstance(caller, str):
|
|
170
|
+
return caller
|
|
171
|
+
if not isinstance(caller, dict):
|
|
172
|
+
raise TypeError("the caller is a dict, such as {\"id\": \"ann\", \"groups\": [\"sales\"]}")
|
|
173
|
+
return json.dumps(caller, ensure_ascii=False)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _answered(status, text):
|
|
177
|
+
try:
|
|
178
|
+
answer = json.loads(text)
|
|
179
|
+
except ValueError:
|
|
180
|
+
raise NoAnswer("what answered is no JSON: " + text[:200]) from None
|
|
181
|
+
if not isinstance(answer, dict):
|
|
182
|
+
raise NoAnswer("what answered is no JSON object: " + text[:200])
|
|
183
|
+
if "error" in answer:
|
|
184
|
+
raise Refused(answer, status)
|
|
185
|
+
return answer
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _file(facts):
|
|
189
|
+
# A file of no known type is application/octet-stream, as a server
|
|
190
|
+
# serves it.
|
|
191
|
+
facts = dict(facts)
|
|
192
|
+
if not facts.get("media_type"):
|
|
193
|
+
facts["media_type"] = "application/octet-stream"
|
|
194
|
+
return facts
|
fadodb/_library.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""A database held in this process, through the library of C (ADR-0101)."""
|
|
2
|
+
|
|
3
|
+
import ctypes
|
|
4
|
+
import ctypes.util
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import threading
|
|
9
|
+
import weakref
|
|
10
|
+
|
|
11
|
+
# The files of the two libraries on each system (ADR-0102): libfadodb,
|
|
12
|
+
# with DuckDB, which a wheel carries, and libfadodb-core.
|
|
13
|
+
if sys.platform == "win32":
|
|
14
|
+
_NAMES = ("fadodb.dll", "fadodb-core.dll")
|
|
15
|
+
elif sys.platform == "darwin":
|
|
16
|
+
_NAMES = ("libfadodb.dylib", "libfadodb-core.dylib")
|
|
17
|
+
else:
|
|
18
|
+
_NAMES = ("libfadodb.so", "libfadodb-core.so")
|
|
19
|
+
|
|
20
|
+
# A process holds one library: a second Go library beside it would not
|
|
21
|
+
# work (ADR-0101, item 11). It is loaded the first time it is asked for.
|
|
22
|
+
_loaded = None
|
|
23
|
+
_loading = threading.Lock()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _load(path):
|
|
27
|
+
global _loaded
|
|
28
|
+
with _loading:
|
|
29
|
+
if _loaded is not None:
|
|
30
|
+
if path is not None and os.path.abspath(path) != _loaded[0]:
|
|
31
|
+
raise RuntimeError("this process already holds the library " + _loaded[0]
|
|
32
|
+
+ ", and a process holds one library")
|
|
33
|
+
return _loaded[1]
|
|
34
|
+
here = os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib")
|
|
35
|
+
candidates = [path] if path is not None else [
|
|
36
|
+
os.environ.get("FADODB_LIBRARY"),
|
|
37
|
+
*(os.path.join(here, name) for name in _NAMES),
|
|
38
|
+
ctypes.util.find_library("fadodb"),
|
|
39
|
+
ctypes.util.find_library("fadodb-core"),
|
|
40
|
+
]
|
|
41
|
+
tried = []
|
|
42
|
+
for candidate in candidates:
|
|
43
|
+
if not candidate:
|
|
44
|
+
continue
|
|
45
|
+
if os.sep in candidate or "/" in candidate:
|
|
46
|
+
if not os.path.exists(candidate):
|
|
47
|
+
tried.append(candidate)
|
|
48
|
+
continue
|
|
49
|
+
candidate = os.path.abspath(candidate)
|
|
50
|
+
lib = ctypes.CDLL(candidate)
|
|
51
|
+
_declare(lib)
|
|
52
|
+
_loaded = (candidate, lib)
|
|
53
|
+
return lib
|
|
54
|
+
raise FileNotFoundError(
|
|
55
|
+
"no library of FadoDB was found (" + ", ".join(tried or ["none was named"]) + "): "
|
|
56
|
+
"give its path as library, or in the variable FADODB_LIBRARY; scripts/library.sh build builds both as bin/library/"
|
|
57
|
+
+ _NAMES[0] + " and " + _NAMES[1])
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# The program's function for its actions, as fadodb.h declares it.
|
|
61
|
+
_ACTION = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint64, ctypes.c_char_p, ctypes.c_char_p)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _declare(lib):
|
|
65
|
+
u64, text, void = ctypes.c_uint64, ctypes.c_char_p, ctypes.c_void_p
|
|
66
|
+
out, size = ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_size_t)
|
|
67
|
+
lib.fado_open.argtypes = [text, text, out]
|
|
68
|
+
lib.fado_open.restype = u64
|
|
69
|
+
lib.fado_open_with.argtypes = [text, text, _ACTION, void, out]
|
|
70
|
+
lib.fado_open_with.restype = u64
|
|
71
|
+
lib.fado_answer.argtypes = [u64, text]
|
|
72
|
+
lib.fado_answer.restype = ctypes.c_int
|
|
73
|
+
# The answers are kept as pointers, so that they are given back.
|
|
74
|
+
lib.fado_exec.argtypes = [u64, text, text, text]
|
|
75
|
+
lib.fado_exec.restype = void
|
|
76
|
+
lib.fado_close.argtypes = [u64, out]
|
|
77
|
+
lib.fado_close.restype = ctypes.c_int
|
|
78
|
+
lib.fado_free.argtypes = [void]
|
|
79
|
+
lib.fado_free.restype = None
|
|
80
|
+
lib.fado_version.argtypes = []
|
|
81
|
+
lib.fado_version.restype = text
|
|
82
|
+
lib.fado_put_file.argtypes = [u64, text, text, text, ctypes.c_size_t]
|
|
83
|
+
lib.fado_put_file.restype = void
|
|
84
|
+
lib.fado_get_file.argtypes = [u64, text, text, out, size]
|
|
85
|
+
lib.fado_get_file.restype = void
|
|
86
|
+
lib.fado_get_blob.argtypes = [u64, text, text, out, size]
|
|
87
|
+
lib.fado_get_blob.restype = void
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _take(lib, pointer):
|
|
91
|
+
"""The text of an answer of the library, which is then given back."""
|
|
92
|
+
if not pointer:
|
|
93
|
+
return ""
|
|
94
|
+
try:
|
|
95
|
+
return ctypes.string_at(pointer).decode("utf-8")
|
|
96
|
+
finally:
|
|
97
|
+
lib.fado_free(pointer)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def version(library=None):
|
|
101
|
+
"""The version of the library, such as v0.9.0, or dev."""
|
|
102
|
+
return _load(library).fado_version().decode("utf-8")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class Opened:
|
|
106
|
+
"""One database the library opened, shared by every caller it is
|
|
107
|
+
given to."""
|
|
108
|
+
|
|
109
|
+
in_process = True
|
|
110
|
+
|
|
111
|
+
def __init__(self, path, options, library, actions=None):
|
|
112
|
+
from ._database import Refused
|
|
113
|
+
|
|
114
|
+
self._lib = _load(library)
|
|
115
|
+
options = dict(options or {})
|
|
116
|
+
carry_out = _ACTION()
|
|
117
|
+
if actions:
|
|
118
|
+
if "actions" in options:
|
|
119
|
+
raise TypeError("the actions are given once: as functions in actions, not as names in options")
|
|
120
|
+
for name, function in actions.items():
|
|
121
|
+
if not callable(function):
|
|
122
|
+
raise TypeError("the action " + name + " is given no function")
|
|
123
|
+
options["actions"] = sorted(actions)
|
|
124
|
+
carry_out = _ACTION(_carrier(self._lib, dict(actions)))
|
|
125
|
+
refusal = ctypes.c_void_p()
|
|
126
|
+
options_text = json.dumps(options, ensure_ascii=False).encode("utf-8")
|
|
127
|
+
self._n = self._lib.fado_open_with(os.fspath(path).encode("utf-8"), options_text, carry_out, None, ctypes.byref(refusal))
|
|
128
|
+
if self._n == 0:
|
|
129
|
+
raise Refused(json.loads(_take(self._lib, refusal.value)))
|
|
130
|
+
# A database nobody holds any more is closed, as a file is; the
|
|
131
|
+
# function for its actions lives as long as it.
|
|
132
|
+
self._finalizer = weakref.finalize(self, _close, self._lib, self._n, carry_out)
|
|
133
|
+
|
|
134
|
+
def exec(self, caller, command, object_text):
|
|
135
|
+
answer = self._lib.fado_exec(self._n, caller.encode("utf-8"), command.encode("utf-8"), object_text.encode("utf-8"))
|
|
136
|
+
return None, _take(self._lib, answer)
|
|
137
|
+
|
|
138
|
+
def put_file(self, caller, name, media_type, data):
|
|
139
|
+
asked = {}
|
|
140
|
+
if name is not None:
|
|
141
|
+
asked["name"] = name
|
|
142
|
+
if media_type is not None:
|
|
143
|
+
asked["media_type"] = media_type
|
|
144
|
+
object_text = json.dumps(asked, ensure_ascii=False).encode("utf-8")
|
|
145
|
+
answer = self._lib.fado_put_file(self._n, caller.encode("utf-8"), object_text, data, len(data))
|
|
146
|
+
return None, _take(self._lib, answer)
|
|
147
|
+
|
|
148
|
+
def get_file(self, caller, asked):
|
|
149
|
+
return self._get(self._lib.fado_get_file, caller, asked)
|
|
150
|
+
|
|
151
|
+
def get_blob(self, caller, asked):
|
|
152
|
+
return self._get(self._lib.fado_get_blob, caller, asked)
|
|
153
|
+
|
|
154
|
+
def _get(self, function, caller, asked):
|
|
155
|
+
data, length = ctypes.c_void_p(), ctypes.c_size_t()
|
|
156
|
+
object_text = json.dumps(asked, ensure_ascii=False).encode("utf-8")
|
|
157
|
+
answer = function(self._n, caller.encode("utf-8"), object_text, ctypes.byref(data), ctypes.byref(length))
|
|
158
|
+
got = None
|
|
159
|
+
if data.value:
|
|
160
|
+
try:
|
|
161
|
+
got = ctypes.string_at(data.value, length.value)
|
|
162
|
+
finally:
|
|
163
|
+
self._lib.fado_free(data.value)
|
|
164
|
+
return None, _take(self._lib, answer), got
|
|
165
|
+
|
|
166
|
+
def close(self):
|
|
167
|
+
self._finalizer()
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _close(lib, n, carry_out=None):
|
|
171
|
+
lib.fado_close(n, None)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _carrier(lib, actions):
|
|
175
|
+
"""The function the library calls for an action the program carries
|
|
176
|
+
out: it runs the program's function and answers with fado_answer."""
|
|
177
|
+
from ._database import Permanent
|
|
178
|
+
|
|
179
|
+
def carry_out(_context, call, action, object_text):
|
|
180
|
+
name = action.decode("utf-8")
|
|
181
|
+
try:
|
|
182
|
+
result = actions[name](json.loads(object_text.decode("utf-8")))
|
|
183
|
+
if result is None:
|
|
184
|
+
result = {}
|
|
185
|
+
if not isinstance(result, dict):
|
|
186
|
+
raise TypeError("the function for " + name + " returned " + type(result).__name__
|
|
187
|
+
+ ", and the result of an action is a dict of what it returns")
|
|
188
|
+
answer = {"result": result}
|
|
189
|
+
except Permanent as refusal:
|
|
190
|
+
answer = {"error": {"message": str(refusal) or name + " was refused", "permanent": True}}
|
|
191
|
+
except Exception as failure: # noqa: BLE001 - a failure of the program's function is tried again
|
|
192
|
+
answer = {"error": {"message": type(failure).__name__ + ": " + str(failure)}}
|
|
193
|
+
try:
|
|
194
|
+
text = json.dumps(answer, ensure_ascii=False)
|
|
195
|
+
except (TypeError, ValueError) as failure:
|
|
196
|
+
text = json.dumps({"error": {"message": "the result of " + name + " is no JSON: " + str(failure)}})
|
|
197
|
+
lib.fado_answer(call, text.encode("utf-8"))
|
|
198
|
+
|
|
199
|
+
return carry_out
|
fadodb/_server.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""A database a server serves, over HTTP (ADR-0055)."""
|
|
2
|
+
|
|
3
|
+
import email.message
|
|
4
|
+
import json
|
|
5
|
+
import urllib.error
|
|
6
|
+
import urllib.parse
|
|
7
|
+
import urllib.request
|
|
8
|
+
|
|
9
|
+
from ._database import NoAnswer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Server:
|
|
13
|
+
"""The commands of one database, sent to its server as one user."""
|
|
14
|
+
|
|
15
|
+
in_process = False
|
|
16
|
+
|
|
17
|
+
def __init__(self, url, key, timeout):
|
|
18
|
+
if not url.startswith(("http://", "https://")):
|
|
19
|
+
raise ValueError("the address of a server begins with https:// or http://")
|
|
20
|
+
self._base = url.rstrip("/") + "/v1/"
|
|
21
|
+
self._key = key
|
|
22
|
+
self._timeout = timeout
|
|
23
|
+
|
|
24
|
+
def _send(self, method, address, body=None, content_type=None):
|
|
25
|
+
headers = {"Authorization": "Bearer " + self._key, "Accept": "application/json"}
|
|
26
|
+
if body is not None:
|
|
27
|
+
# A body is sent with its own type, or none: never as a form,
|
|
28
|
+
# which is what urllib would say it is.
|
|
29
|
+
headers["Content-Type"] = content_type or ""
|
|
30
|
+
request = urllib.request.Request(self._base + address, data=body, method=method, headers=headers)
|
|
31
|
+
try:
|
|
32
|
+
with urllib.request.urlopen(request, timeout=self._timeout) as reply:
|
|
33
|
+
return reply.status, reply.headers, reply.read()
|
|
34
|
+
except urllib.error.HTTPError as reply:
|
|
35
|
+
try:
|
|
36
|
+
return reply.code, reply.headers, reply.read()
|
|
37
|
+
finally:
|
|
38
|
+
reply.close()
|
|
39
|
+
except (urllib.error.URLError, OSError) as failure:
|
|
40
|
+
raise NoAnswer("the server at " + self._base + " was not reached: " + str(failure)) from failure
|
|
41
|
+
|
|
42
|
+
def exec(self, caller, command, object_text):
|
|
43
|
+
status, _, body = self._send("POST", urllib.parse.quote(command, safe=""), object_text.encode("utf-8"), "application/json")
|
|
44
|
+
return status, body.decode("utf-8", "replace")
|
|
45
|
+
|
|
46
|
+
def put_file(self, caller, name, media_type, data):
|
|
47
|
+
address = "blobs"
|
|
48
|
+
if name is not None:
|
|
49
|
+
address += "?" + urllib.parse.urlencode({"name": name})
|
|
50
|
+
status, _, body = self._send("POST", address, data, media_type)
|
|
51
|
+
return status, body.decode("utf-8", "replace")
|
|
52
|
+
|
|
53
|
+
def get_file(self, caller, asked):
|
|
54
|
+
return self._get("file", asked)
|
|
55
|
+
|
|
56
|
+
def get_blob(self, caller, asked):
|
|
57
|
+
return self._get("blob", asked)
|
|
58
|
+
|
|
59
|
+
def _get(self, address, asked):
|
|
60
|
+
status, headers, body = self._send("GET", address + "?" + urllib.parse.urlencode(asked))
|
|
61
|
+
if status != 200:
|
|
62
|
+
return status, body.decode("utf-8", "replace"), None
|
|
63
|
+
# The facts of the file are in the headers of the reply, as the
|
|
64
|
+
# library answers them in JSON.
|
|
65
|
+
facts = {"hash": (headers.get("ETag") or "").strip('"'), "size": len(body)}
|
|
66
|
+
disposition = email.message.Message()
|
|
67
|
+
disposition["Content-Disposition"] = headers.get("Content-Disposition", "")
|
|
68
|
+
name = disposition.get_param("filename", header="Content-Disposition")
|
|
69
|
+
if name:
|
|
70
|
+
facts["name"] = name
|
|
71
|
+
media_type = (headers.get("Content-Type") or "").split(";")[0].strip()
|
|
72
|
+
if media_type:
|
|
73
|
+
facts["media_type"] = media_type
|
|
74
|
+
return status, json.dumps({"file": facts}), body
|
|
75
|
+
|
|
76
|
+
def close(self):
|
|
77
|
+
# Each request has its own connection, closed when it is
|
|
78
|
+
# answered.
|
|
79
|
+
pass
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fadodb
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: FadoDB for Python: a database over HTTP, or in the same process
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Project-URL: Homepage, https://fadodb.org
|
|
9
|
+
Project-URL: Source, https://github.com/MojoHand70/fadodb
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# FadoDB for Python
|
|
13
|
+
|
|
14
|
+
One package, two ways to the same database, and one way to use it
|
|
15
|
+
([ADR-0101](../../docs/adr/0101-the-library-of-c.md)). Nothing but
|
|
16
|
+
Python's own library is needed.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import fadodb
|
|
20
|
+
|
|
21
|
+
# A server, as the user whose key it is:
|
|
22
|
+
db = fadodb.connect("https://fado.acme.example", key="fado_Q329CE63C9_…")
|
|
23
|
+
|
|
24
|
+
# Or the database file itself, in this process, through the library of
|
|
25
|
+
# C; the program says who is calling:
|
|
26
|
+
db = fadodb.open("books.fado", caller={"id": "ann", "kind": "person", "groups": ["sales"]})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
A command is a name and one JSON object, and its answer is one JSON
|
|
30
|
+
object, a `dict`: the [commands](../../docs/manual/commands.md) a server
|
|
31
|
+
takes at `POST /v1/<command>`, answered the same. Ann of sales makes an
|
|
32
|
+
invoice, and Bob of accounting books it:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
ann = db # opened as Ann above
|
|
36
|
+
bob = db.as_caller({"id": "bob", "kind": "person", "groups": ["accounting"]})
|
|
37
|
+
|
|
38
|
+
ann.exec("create", {"class": "Invoice", "id": "FV/2026/11/0042",
|
|
39
|
+
"values": {"number": "FV/2026/11/0042"}})
|
|
40
|
+
try:
|
|
41
|
+
bob.exec("transition", {"class": "Invoice", "id": "FV/2026/11/0042", "transition": "book"})
|
|
42
|
+
except fadodb.Refused as refusal:
|
|
43
|
+
print(refusal.code, refusal.hint) # guard_false the guard: NOT ISBLANK(account)
|
|
44
|
+
|
|
45
|
+
bob.exec("set", {"class": "Invoice", "id": "FV/2026/11/0042", "values": {"account": "400-01"}})
|
|
46
|
+
bob.exec("transition", {"class": "Invoice", "id": "FV/2026/11/0042", "transition": "book"})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
A refusal is raised as `fadodb.Refused`: `code` is what a program
|
|
50
|
+
branches on, `message` and `hint` say why and what to send instead,
|
|
51
|
+
`path` names the member it is about, and `answer` is the whole answer,
|
|
52
|
+
with the findings of a refused definition under `diagnostics`.
|
|
53
|
+
`fadodb.NoAnswer` is raised when no answer came through; a command that
|
|
54
|
+
carries a `key` is then safely sent again.
|
|
55
|
+
|
|
56
|
+
`as_caller` is for a database in this process. Over HTTP the key says
|
|
57
|
+
who calls, so each user connects with their own key.
|
|
58
|
+
|
|
59
|
+
## Files
|
|
60
|
+
|
|
61
|
+
The bytes of a file travel beside the commands, and its facts in them:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
facts = ann.put_file(scan, name="taxi.pdf", media_type="application/pdf")
|
|
65
|
+
ann.exec("set", {"class": "Claim", "id": "C-7", "values": {"scan": facts}})
|
|
66
|
+
facts, data = bob.get_file("Claim", "C-7", facts["hash"])
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## The program's own actions
|
|
70
|
+
|
|
71
|
+
An action whose definition has no request is carried out by the
|
|
72
|
+
program, in the same process: a function by the name of the action.
|
|
73
|
+
It is called with the call, as a webhook gets it, from a thread of the
|
|
74
|
+
worker, and returns what the action returns:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
def post(call):
|
|
78
|
+
entry = books.post(amount=call["args"]["amount"], key=call["key"])
|
|
79
|
+
return {"entry": entry}
|
|
80
|
+
|
|
81
|
+
shop = fadodb.open("shop.fado", actions={"books.post": post})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`raise fadodb.Permanent("the period 2026-11 is closed")` refuses the
|
|
85
|
+
call, and the action is dead at once; any other exception is a failure,
|
|
86
|
+
tried again later. The call's `key` is the same at every attempt, so
|
|
87
|
+
the function makes twice once by it. Over HTTP the server carries out
|
|
88
|
+
the actions, and `fadodb.connect` takes none.
|
|
89
|
+
|
|
90
|
+
## Waiting for a change
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
after = bob.exec("wait_for_changes", {"classes": ["Invoice"]})["after"]
|
|
94
|
+
while True:
|
|
95
|
+
heard = bob.exec("wait_for_changes", {"classes": ["Invoice"], "after": after, "seconds": 60})
|
|
96
|
+
for event in heard["events"]:
|
|
97
|
+
...
|
|
98
|
+
after = heard["after"]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`subscribe`, whose answer is a stream, is refused with `not_supported`:
|
|
102
|
+
`wait_for_changes` answers the same events one call at a time.
|
|
103
|
+
|
|
104
|
+
## The library
|
|
105
|
+
|
|
106
|
+
`fadodb.open` loads the library of C: the path given as `library`, or
|
|
107
|
+
the one the variable `FADODB_LIBRARY` names, or the one beside the
|
|
108
|
+
package in `fadodb/lib`, or the one the system finds: `libfadodb`, with
|
|
109
|
+
DuckDB, before `libfadodb-core`. A database opened through `libfadodb`
|
|
110
|
+
keeps a copy of its documents in DuckDB beside its file, and the
|
|
111
|
+
questions that read everything, such as `flow`, are answered from it;
|
|
112
|
+
`fadodb.open(path, options={"analytics": {"memory": "2GB"}})` tells it
|
|
113
|
+
how much it may take. `scripts/library.sh build` builds both into
|
|
114
|
+
`bin/library/`. A process holds one library, and opens
|
|
115
|
+
as many databases through it as it needs. Every call may be made from
|
|
116
|
+
any thread: the library lets go of Python's lock while it works.
|
|
117
|
+
|
|
118
|
+
From v0.9.0 on, every release carries the package as wheels: one for each system with
|
|
119
|
+
`libfadodb` and DuckDB's library inside, which `fadodb.open` finds with
|
|
120
|
+
nothing named, about 35 MB, and
|
|
121
|
+
`fadodb-<version>-py3-none-any.whl` for every system without it, for a
|
|
122
|
+
program that talks to a server. `pip install` takes the file of the
|
|
123
|
+
release. A release also publishes them on PyPI, so from v0.9.0 on
|
|
124
|
+
`pip install fadodb` takes the right one for the machine.
|
|
125
|
+
|
|
126
|
+
## Its tests
|
|
127
|
+
|
|
128
|
+
The same tests run both ways: over HTTP against a `fadodb-core serve`
|
|
129
|
+
they start, with a user and a key for each caller, and in the same
|
|
130
|
+
process with the same callers.
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
make build library
|
|
134
|
+
FADODB_PROGRAM=bin/fadodb-core FADODB_LIBRARY=bin/libfadodb-core.so \
|
|
135
|
+
python3 -m unittest discover -s clients/py/tests
|
|
136
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
fadodb/__init__.py,sha256=Vevbix818xu5XrPKXxbjo42FWLLJfbtrSiR3mCKpOps,1326
|
|
2
|
+
fadodb/_database.py,sha256=70ydTxLC6AHeNIchrb0vtwyYM3H3QQaveUuoOO8uxbk,7767
|
|
3
|
+
fadodb/_library.py,sha256=ZbCu7c6Q2MkACAjXM-au5A4gFx9cp7922IPGYPM0rwg,8153
|
|
4
|
+
fadodb/_server.py,sha256=_zhKcr0gtN9vAAY5ERBJFbghbB5xg97_Tfwyq7Vm9E4,3280
|
|
5
|
+
fadodb-0.9.0.dist-info/METADATA,sha256=UruXVH7ZN0wkFcpdWfNMMKyPC-ff62dtGDKP4A5Xh1E,5419
|
|
6
|
+
fadodb-0.9.0.dist-info/WHEEL,sha256=vutixJBqqKqMF77IMBKqyHafxDuE2jHBbWj0SF4xU48,97
|
|
7
|
+
fadodb-0.9.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
8
|
+
fadodb-0.9.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|