appier 1.31.4__py2.py3-none-any.whl → 1.32.0__py2.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.
- appier/__init__.py +333 -52
- appier/amqp.py +29 -30
- appier/api.py +214 -212
- appier/asgi.py +54 -55
- appier/async_neo.py +46 -35
- appier/async_old.py +55 -42
- appier/asynchronous.py +7 -13
- appier/base.py +1762 -1429
- appier/bus.py +51 -52
- appier/cache.py +99 -84
- appier/common.py +9 -11
- appier/component.py +17 -19
- appier/compress.py +25 -28
- appier/config.py +96 -73
- appier/controller.py +9 -15
- appier/crypt.py +25 -21
- appier/data.py +73 -57
- appier/defines.py +191 -226
- appier/exceptions.py +103 -63
- appier/execution.py +94 -88
- appier/export.py +90 -88
- appier/extra.py +6 -13
- appier/extra_neo.py +8 -11
- appier/extra_old.py +18 -16
- appier/geo.py +57 -47
- appier/git.py +101 -90
- appier/graph.py +23 -24
- appier/http.py +520 -398
- appier/legacy.py +373 -180
- appier/log.py +90 -97
- appier/meta.py +42 -42
- appier/mock.py +32 -34
- appier/model.py +793 -681
- appier/model_a.py +208 -183
- appier/mongo.py +183 -107
- appier/observer.py +39 -31
- appier/part.py +23 -24
- appier/preferences.py +44 -47
- appier/queuing.py +78 -96
- appier/redisdb.py +40 -35
- appier/request.py +227 -175
- appier/scheduler.py +13 -18
- appier/serialize.py +37 -31
- appier/session.py +161 -147
- appier/settings.py +2 -11
- appier/smtp.py +53 -49
- appier/storage.py +39 -33
- appier/structures.py +50 -45
- appier/test/__init__.py +2 -11
- appier/test/base.py +111 -108
- appier/test/cache.py +28 -35
- appier/test/config.py +10 -19
- appier/test/crypt.py +3 -12
- appier/test/data.py +3 -12
- appier/test/exceptions.py +8 -17
- appier/test/export.py +16 -33
- appier/test/graph.py +27 -60
- appier/test/http.py +42 -54
- appier/test/legacy.py +20 -30
- appier/test/log.py +14 -35
- appier/test/mock.py +27 -123
- appier/test/model.py +79 -91
- appier/test/part.py +5 -14
- appier/test/preferences.py +5 -13
- appier/test/queuing.py +29 -37
- appier/test/request.py +61 -73
- appier/test/serialize.py +12 -23
- appier/test/session.py +10 -19
- appier/test/smtp.py +8 -14
- appier/test/structures.py +20 -24
- appier/test/typesf.py +14 -28
- appier/test/util.py +480 -438
- appier/typesf.py +251 -171
- appier/util.py +578 -407
- appier/validation.py +280 -143
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
- appier-1.32.0.dist-info/RECORD +86 -0
- appier-1.31.4.dist-info/RECORD +0 -86
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/top_level.txt +0 -0
appier/crypt.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -42,8 +33,8 @@ import array
|
|
|
42
33
|
from . import legacy
|
|
43
34
|
from . import exceptions
|
|
44
35
|
|
|
45
|
-
class Cipher(object):
|
|
46
36
|
|
|
37
|
+
class Cipher(object):
|
|
47
38
|
def __init__(self, key):
|
|
48
39
|
self.key = key
|
|
49
40
|
|
|
@@ -55,7 +46,8 @@ class Cipher(object):
|
|
|
55
46
|
@classmethod
|
|
56
47
|
def _cipher(cls, name):
|
|
57
48
|
for subclass in cls.__subclasses__():
|
|
58
|
-
if not subclass.__name__.lower() == name:
|
|
49
|
+
if not subclass.__name__.lower() == name:
|
|
50
|
+
continue
|
|
59
51
|
return subclass
|
|
60
52
|
return None
|
|
61
53
|
|
|
@@ -65,6 +57,7 @@ class Cipher(object):
|
|
|
65
57
|
def decrypt(self, data):
|
|
66
58
|
raise exceptions.NotImplementedError()
|
|
67
59
|
|
|
60
|
+
|
|
68
61
|
class RC4(Cipher):
|
|
69
62
|
"""
|
|
70
63
|
Class that implements the basis for the
|
|
@@ -119,6 +112,7 @@ class RC4(Cipher):
|
|
|
119
112
|
x = (x + self.box[i] + legacy.ord(self.key[i % len(self.key)])) % 256
|
|
120
113
|
self.box[i], self.box[x] = self.box[x], self.box[i]
|
|
121
114
|
|
|
115
|
+
|
|
122
116
|
class Spritz(Cipher):
|
|
123
117
|
"""
|
|
124
118
|
Class that implements the basis for the
|
|
@@ -150,7 +144,8 @@ class Spritz(Cipher):
|
|
|
150
144
|
|
|
151
145
|
def absorb(self, data):
|
|
152
146
|
data = bytearray(data)
|
|
153
|
-
for byte in data:
|
|
147
|
+
for byte in data:
|
|
148
|
+
self._absorb_byte(byte)
|
|
154
149
|
|
|
155
150
|
def shuffle(self):
|
|
156
151
|
self.whip(512)
|
|
@@ -161,20 +156,24 @@ class Spritz(Cipher):
|
|
|
161
156
|
self.a = 0
|
|
162
157
|
|
|
163
158
|
def whip(self, r):
|
|
164
|
-
for _ in range(r):
|
|
159
|
+
for _ in range(r):
|
|
160
|
+
self._update()
|
|
165
161
|
self.w = self._add(self.w, 2)
|
|
166
162
|
|
|
167
163
|
def crush(self):
|
|
168
164
|
for v in range(128):
|
|
169
|
-
if self.S[v] <= self.S[255 - v]:
|
|
165
|
+
if self.S[v] <= self.S[255 - v]:
|
|
166
|
+
continue
|
|
170
167
|
self._swap(v, 255 - v)
|
|
171
168
|
|
|
172
169
|
def squeeze(self, r):
|
|
173
|
-
if self.a > 0:
|
|
170
|
+
if self.a > 0:
|
|
171
|
+
self.shuffle()
|
|
174
172
|
return bytearray([self.drip() for _ in range(r)])
|
|
175
173
|
|
|
176
174
|
def drip(self):
|
|
177
|
-
if self.a > 0:
|
|
175
|
+
if self.a > 0:
|
|
176
|
+
self.shuffle()
|
|
178
177
|
self._update()
|
|
179
178
|
return self._output()
|
|
180
179
|
|
|
@@ -185,7 +184,11 @@ class Spritz(Cipher):
|
|
|
185
184
|
self._swap(self.i, self.j)
|
|
186
185
|
|
|
187
186
|
def _output(self):
|
|
188
|
-
self.z = self.S[
|
|
187
|
+
self.z = self.S[
|
|
188
|
+
self._add(
|
|
189
|
+
self.j, self.S[self._add(self.i, self.S[self._add(self.z, self.k)])]
|
|
190
|
+
)
|
|
191
|
+
]
|
|
189
192
|
return self.z
|
|
190
193
|
|
|
191
194
|
def _add(self, *args):
|
|
@@ -204,10 +207,11 @@ class Spritz(Cipher):
|
|
|
204
207
|
self.S = bytearray(range(256))
|
|
205
208
|
|
|
206
209
|
def _absorb_byte(self, byte):
|
|
207
|
-
self._absorb_nibble(byte &
|
|
210
|
+
self._absorb_nibble(byte & 0xF)
|
|
208
211
|
self._absorb_nibble(byte >> 4)
|
|
209
212
|
|
|
210
213
|
def _absorb_nibble(self, nibble):
|
|
211
|
-
if self.a == 128:
|
|
214
|
+
if self.a == 128:
|
|
215
|
+
self.shuffle()
|
|
212
216
|
self._swap(self.a, 128 + nibble)
|
|
213
217
|
self.a = self._add(self.a, 1)
|
appier/data.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -51,8 +42,8 @@ from . import config
|
|
|
51
42
|
from . import legacy
|
|
52
43
|
from . import exceptions
|
|
53
44
|
|
|
54
|
-
class DataAdapter(object):
|
|
55
45
|
|
|
46
|
+
class DataAdapter(object):
|
|
56
47
|
def __init__(self, *args, **kwargs):
|
|
57
48
|
self._inc = 0
|
|
58
49
|
self._machine_bytes = self.__machine_bytes()
|
|
@@ -89,11 +80,12 @@ class DataAdapter(object):
|
|
|
89
80
|
def drop_db_a(self, *args, **kwargs):
|
|
90
81
|
raise exceptions.NotImplementedError()
|
|
91
82
|
|
|
92
|
-
def object_id(self, value
|
|
93
|
-
if not value:
|
|
83
|
+
def object_id(self, value=None):
|
|
84
|
+
if not value:
|
|
85
|
+
return self._id()
|
|
94
86
|
if not len(value) == 24:
|
|
95
87
|
raise exceptions.OperationalError(
|
|
96
|
-
message
|
|
88
|
+
message="Expected object id of length 24 chars"
|
|
97
89
|
)
|
|
98
90
|
return value
|
|
99
91
|
|
|
@@ -105,11 +97,11 @@ class DataAdapter(object):
|
|
|
105
97
|
def _id(self):
|
|
106
98
|
token = struct.pack(">i", int(time.time()))
|
|
107
99
|
token += self._machine_bytes
|
|
108
|
-
token += struct.pack(">H", os.getpid() %
|
|
100
|
+
token += struct.pack(">H", os.getpid() % 0xFFFF)
|
|
109
101
|
self._inc_lock.acquire()
|
|
110
102
|
try:
|
|
111
103
|
token += struct.pack(">i", self._inc)[1:4]
|
|
112
|
-
self._inc = (self._inc + 1) %
|
|
104
|
+
self._inc = (self._inc + 1) % 0xFFFFFF
|
|
113
105
|
except Exception:
|
|
114
106
|
self._inc_lock.release()
|
|
115
107
|
token_s = binascii.hexlify(token)
|
|
@@ -123,8 +115,8 @@ class DataAdapter(object):
|
|
|
123
115
|
machine_hash.update(hostname)
|
|
124
116
|
return machine_hash.digest()[0:3]
|
|
125
117
|
|
|
126
|
-
class MongoAdapter(DataAdapter):
|
|
127
118
|
|
|
119
|
+
class MongoAdapter(DataAdapter):
|
|
128
120
|
def encoder(self):
|
|
129
121
|
return mongo.MongoEncoder
|
|
130
122
|
|
|
@@ -156,15 +148,16 @@ class MongoAdapter(DataAdapter):
|
|
|
156
148
|
def drop_db_a(self, *args, **kwargs):
|
|
157
149
|
return mongo.drop_db_a()
|
|
158
150
|
|
|
159
|
-
def object_id(self, value
|
|
160
|
-
if not value:
|
|
151
|
+
def object_id(self, value=None):
|
|
152
|
+
if not value:
|
|
153
|
+
return self._id()
|
|
161
154
|
return mongo.object_id(value)
|
|
162
155
|
|
|
163
156
|
def _id(self):
|
|
164
157
|
return mongo.object_id(None)
|
|
165
158
|
|
|
166
|
-
class TinyAdapter(DataAdapter):
|
|
167
159
|
|
|
160
|
+
class TinyAdapter(DataAdapter):
|
|
168
161
|
def __init__(self, *args, **kwargs):
|
|
169
162
|
DataAdapter.__init__(self, *args, **kwargs)
|
|
170
163
|
self.file_path = config.conf("TINY_PATH", "db.json")
|
|
@@ -181,16 +174,20 @@ class TinyAdapter(DataAdapter):
|
|
|
181
174
|
pass
|
|
182
175
|
|
|
183
176
|
def get_db(self):
|
|
184
|
-
if not self._db == None:
|
|
177
|
+
if not self._db == None:
|
|
178
|
+
return self._db
|
|
185
179
|
method = getattr(self, "_get_db_%s" % self.storage)
|
|
186
180
|
self._db = method()
|
|
187
181
|
return self._db
|
|
188
182
|
|
|
189
183
|
def drop_db(self, *args, **kwargs):
|
|
190
|
-
if self._db == None:
|
|
184
|
+
if self._db == None:
|
|
185
|
+
return
|
|
191
186
|
db = self.get_db()
|
|
192
|
-
if hasattr(db, "drop_tables"):
|
|
193
|
-
|
|
187
|
+
if hasattr(db, "drop_tables"):
|
|
188
|
+
db.drop_tables()
|
|
189
|
+
else:
|
|
190
|
+
db.purge_tables()
|
|
194
191
|
db.close()
|
|
195
192
|
self._db = None
|
|
196
193
|
method = getattr(self, "_drop_db_%s" % self.storage)
|
|
@@ -198,13 +195,13 @@ class TinyAdapter(DataAdapter):
|
|
|
198
195
|
|
|
199
196
|
def _get_db_json(self):
|
|
200
197
|
import tinydb
|
|
198
|
+
|
|
201
199
|
return tinydb.TinyDB(self.file_path)
|
|
202
200
|
|
|
203
201
|
def _get_db_memory(self):
|
|
204
202
|
import tinydb
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
)
|
|
203
|
+
|
|
204
|
+
return tinydb.TinyDB(storage=tinydb.storages.MemoryStorage)
|
|
208
205
|
|
|
209
206
|
def _drop_db_json(self):
|
|
210
207
|
os.remove(self.file_path)
|
|
@@ -212,8 +209,8 @@ class TinyAdapter(DataAdapter):
|
|
|
212
209
|
def _drop_db_memory(self):
|
|
213
210
|
pass
|
|
214
211
|
|
|
215
|
-
class Collection(object):
|
|
216
212
|
|
|
213
|
+
class Collection(object):
|
|
217
214
|
def __init__(self, owner, name):
|
|
218
215
|
self.owner = owner
|
|
219
216
|
self.name = name
|
|
@@ -249,20 +246,21 @@ class Collection(object):
|
|
|
249
246
|
return self.owner.object_id(*args, **kwargs)
|
|
250
247
|
|
|
251
248
|
def log(self, operation, *args, **kwargs):
|
|
252
|
-
show_queries = config.conf("SHOW_QUERIES", False, cast
|
|
253
|
-
if not show_queries:
|
|
249
|
+
show_queries = config.conf("SHOW_QUERIES", False, cast=bool)
|
|
250
|
+
if not show_queries:
|
|
251
|
+
return
|
|
254
252
|
logger = common.base().get_logger()
|
|
255
253
|
extra = kwargs or args
|
|
256
254
|
logger.debug(
|
|
257
|
-
"[%s] %10s -> %12s <-> %s"
|
|
258
|
-
(self.owner.name, operation, self.name, str(extra)[:2046])
|
|
255
|
+
"[%s] %10s -> %12s <-> %s"
|
|
256
|
+
% (self.owner.name, operation, self.name, str(extra)[:2046])
|
|
259
257
|
)
|
|
260
258
|
|
|
261
259
|
def _id(self, *args, **kwargs):
|
|
262
260
|
return self.owner._id(*args, **kwargs)
|
|
263
261
|
|
|
264
|
-
class MongoCollection(Collection):
|
|
265
262
|
|
|
263
|
+
class MongoCollection(Collection):
|
|
266
264
|
def __init__(self, owner, name, base):
|
|
267
265
|
Collection.__init__(self, owner, name)
|
|
268
266
|
self._base = base
|
|
@@ -307,23 +305,33 @@ class MongoCollection(Collection):
|
|
|
307
305
|
is_all = direction == "all"
|
|
308
306
|
is_default = direction in ("default", True)
|
|
309
307
|
is_multiple = isinstance(direction, (list, tuple))
|
|
310
|
-
is_direction =
|
|
311
|
-
|
|
308
|
+
is_direction = (
|
|
309
|
+
not is_default
|
|
310
|
+
and not is_all
|
|
311
|
+
and not is_simple
|
|
312
|
+
and (legacy.is_string(direction) or type(direction) == int)
|
|
313
|
+
)
|
|
312
314
|
is_single = is_simple or is_direction
|
|
313
315
|
|
|
314
|
-
if is_all:
|
|
315
|
-
|
|
316
|
-
if
|
|
316
|
+
if is_all:
|
|
317
|
+
kwargs["directions"] = "all"
|
|
318
|
+
if is_multiple:
|
|
319
|
+
kwargs["directions"] = direction
|
|
320
|
+
if is_direction:
|
|
321
|
+
args = list(args)
|
|
322
|
+
args[0] = [(args[0], direction)]
|
|
317
323
|
|
|
318
|
-
if is_single:
|
|
319
|
-
|
|
324
|
+
if is_single:
|
|
325
|
+
return mongo._store_ensure_index(self._base, *args, **kwargs)
|
|
326
|
+
else:
|
|
327
|
+
return mongo._store_ensure_index_many(self._base, *args, **kwargs)
|
|
320
328
|
|
|
321
329
|
def drop_indexes(self, *args, **kwargs):
|
|
322
330
|
self.log("drop_indexes", *args, **kwargs)
|
|
323
331
|
return self._base.drop_indexes()
|
|
324
332
|
|
|
325
|
-
class TinyCollection(Collection):
|
|
326
333
|
|
|
334
|
+
class TinyCollection(Collection):
|
|
327
335
|
def __init__(self, owner, name, base):
|
|
328
336
|
Collection.__init__(self, owner, name)
|
|
329
337
|
self._base = base
|
|
@@ -352,20 +360,22 @@ class TinyCollection(Collection):
|
|
|
352
360
|
object = self._base.get(condition)
|
|
353
361
|
found = True if object else False
|
|
354
362
|
if not found and not create:
|
|
355
|
-
raise exceptions.OperationalError(
|
|
356
|
-
|
|
357
|
-
)
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
else:
|
|
363
|
+
raise exceptions.OperationalError(message="No object found")
|
|
364
|
+
if not found:
|
|
365
|
+
object = dict(filter)
|
|
366
|
+
object = self._to_update(modification, object=object)
|
|
367
|
+
if found:
|
|
368
|
+
self.update(filter, {"$set": object})
|
|
369
|
+
else:
|
|
370
|
+
self.insert(object)
|
|
362
371
|
return dict(object)
|
|
363
372
|
|
|
364
373
|
def insert(self, *args, **kwargs):
|
|
365
374
|
self.log("insert", *args, **kwargs)
|
|
366
375
|
object = args[0] if len(args) > 0 else dict()
|
|
367
376
|
has_id = "_id" in object
|
|
368
|
-
if not has_id:
|
|
377
|
+
if not has_id:
|
|
378
|
+
object["_id"] = self._id()
|
|
369
379
|
self._base.insert(object)
|
|
370
380
|
return object
|
|
371
381
|
|
|
@@ -397,16 +407,18 @@ class TinyCollection(Collection):
|
|
|
397
407
|
|
|
398
408
|
def _to_condition(self, filter):
|
|
399
409
|
import tinydb
|
|
410
|
+
|
|
400
411
|
query = tinydb.Query()
|
|
401
412
|
condition = query._id.exists()
|
|
402
413
|
for name, value in legacy.iteritems(filter):
|
|
403
|
-
if name.startswith("$"):
|
|
414
|
+
if name.startswith("$"):
|
|
415
|
+
continue
|
|
404
416
|
query = tinydb.Query()
|
|
405
417
|
_condition = getattr(query, name).__eq__(value)
|
|
406
418
|
condition &= _condition
|
|
407
419
|
return condition
|
|
408
420
|
|
|
409
|
-
def _to_results(self, results, kwargs, build
|
|
421
|
+
def _to_results(self, results, kwargs, build=True):
|
|
410
422
|
sort = kwargs.get("sort", [])
|
|
411
423
|
skip = kwargs.get("skip", 0)
|
|
412
424
|
limit = kwargs.get("limit", None)
|
|
@@ -416,15 +428,19 @@ class TinyCollection(Collection):
|
|
|
416
428
|
|
|
417
429
|
def sorter(value):
|
|
418
430
|
result = []
|
|
419
|
-
for item in sort:
|
|
431
|
+
for item in sort:
|
|
432
|
+
result.append(value[item[0]])
|
|
420
433
|
return tuple(result)
|
|
421
434
|
|
|
422
|
-
if sort:
|
|
423
|
-
|
|
424
|
-
if
|
|
435
|
+
if sort:
|
|
436
|
+
results.sort(key=sorter, reverse=reverse)
|
|
437
|
+
if skip or limit:
|
|
438
|
+
results = results[slice(skip, skip + limit, 1)]
|
|
439
|
+
if build:
|
|
440
|
+
results = [dict(result) for result in results]
|
|
425
441
|
return results
|
|
426
442
|
|
|
427
|
-
def _to_update(self, modification, object
|
|
443
|
+
def _to_update(self, modification, object=None):
|
|
428
444
|
object = object or dict()
|
|
429
445
|
increments = modification.get("$inc", {})
|
|
430
446
|
mins = modification.get("$min", {})
|