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.
Files changed (81) hide show
  1. appier/__init__.py +333 -52
  2. appier/amqp.py +29 -30
  3. appier/api.py +214 -212
  4. appier/asgi.py +54 -55
  5. appier/async_neo.py +46 -35
  6. appier/async_old.py +55 -42
  7. appier/asynchronous.py +7 -13
  8. appier/base.py +1762 -1429
  9. appier/bus.py +51 -52
  10. appier/cache.py +99 -84
  11. appier/common.py +9 -11
  12. appier/component.py +17 -19
  13. appier/compress.py +25 -28
  14. appier/config.py +96 -73
  15. appier/controller.py +9 -15
  16. appier/crypt.py +25 -21
  17. appier/data.py +73 -57
  18. appier/defines.py +191 -226
  19. appier/exceptions.py +103 -63
  20. appier/execution.py +94 -88
  21. appier/export.py +90 -88
  22. appier/extra.py +6 -13
  23. appier/extra_neo.py +8 -11
  24. appier/extra_old.py +18 -16
  25. appier/geo.py +57 -47
  26. appier/git.py +101 -90
  27. appier/graph.py +23 -24
  28. appier/http.py +520 -398
  29. appier/legacy.py +373 -180
  30. appier/log.py +90 -97
  31. appier/meta.py +42 -42
  32. appier/mock.py +32 -34
  33. appier/model.py +793 -681
  34. appier/model_a.py +208 -183
  35. appier/mongo.py +183 -107
  36. appier/observer.py +39 -31
  37. appier/part.py +23 -24
  38. appier/preferences.py +44 -47
  39. appier/queuing.py +78 -96
  40. appier/redisdb.py +40 -35
  41. appier/request.py +227 -175
  42. appier/scheduler.py +13 -18
  43. appier/serialize.py +37 -31
  44. appier/session.py +161 -147
  45. appier/settings.py +2 -11
  46. appier/smtp.py +53 -49
  47. appier/storage.py +39 -33
  48. appier/structures.py +50 -45
  49. appier/test/__init__.py +2 -11
  50. appier/test/base.py +111 -108
  51. appier/test/cache.py +28 -35
  52. appier/test/config.py +10 -19
  53. appier/test/crypt.py +3 -12
  54. appier/test/data.py +3 -12
  55. appier/test/exceptions.py +8 -17
  56. appier/test/export.py +16 -33
  57. appier/test/graph.py +27 -60
  58. appier/test/http.py +42 -54
  59. appier/test/legacy.py +20 -30
  60. appier/test/log.py +14 -35
  61. appier/test/mock.py +27 -123
  62. appier/test/model.py +79 -91
  63. appier/test/part.py +5 -14
  64. appier/test/preferences.py +5 -13
  65. appier/test/queuing.py +29 -37
  66. appier/test/request.py +61 -73
  67. appier/test/serialize.py +12 -23
  68. appier/test/session.py +10 -19
  69. appier/test/smtp.py +8 -14
  70. appier/test/structures.py +20 -24
  71. appier/test/typesf.py +14 -28
  72. appier/test/util.py +480 -438
  73. appier/typesf.py +251 -171
  74. appier/util.py +578 -407
  75. appier/validation.py +280 -143
  76. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
  77. appier-1.32.0.dist-info/RECORD +86 -0
  78. appier-1.31.4.dist-info/RECORD +0 -86
  79. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
  80. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
  81. {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/top_level.txt +0 -0
appier/api.py CHANGED
@@ -2,7 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  # Hive Appier Framework
5
- # Copyright (c) 2008-2022 Hive Solutions Lda.
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
- __version__ = "1.0.0"
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,6 +42,7 @@ from . import observer
51
42
  from . import exceptions
52
43
  from . import structures
53
44
 
45
+
54
46
  class API(observer.Observable):
55
47
  """
56
48
  Abstract and top level API class that should be used
@@ -63,71 +55,68 @@ class API(observer.Observable):
63
55
 
64
56
  SINGLETON = None
65
57
 
66
- def __init__(self, owner = None, *args, **kwargs):
58
+ def __init__(self, owner=None, *args, **kwargs):
67
59
  observer.Observable.__init__(self, *args, **kwargs)
68
60
  self.owner = owner or base.APP
69
- if not hasattr(self, "auth_callback"): self.auth_callback = None
61
+ if not hasattr(self, "auth_callback"):
62
+ self.auth_callback = None
70
63
 
71
64
  @classmethod
72
65
  def singleton(cls, *args, **kwargs):
73
66
  callback = kwargs.pop("scallback", None)
74
- if cls.SINGLETON: return cls.SINGLETON
67
+ if cls.SINGLETON:
68
+ return cls.SINGLETON
75
69
  cls.SINGLETON = cls(*args, **kwargs)
76
- if callback: callback(cls.SINGLETON)
70
+ if callback:
71
+ callback(cls.SINGLETON)
77
72
  return cls.SINGLETON
78
73
 
79
74
  def get(
80
75
  self,
81
76
  url,
82
- headers = None,
83
- params = None,
84
- handle = None,
85
- silent = None,
86
- redirect = None,
87
- timeout = None,
88
- callback = True,
89
- extra = None,
77
+ headers=None,
78
+ params=None,
79
+ handle=None,
80
+ silent=None,
81
+ redirect=None,
82
+ timeout=None,
83
+ callback=True,
84
+ extra=None,
90
85
  **kwargs
91
86
  ):
92
87
  headers = headers or dict()
93
88
  extra = extra or dict()
94
89
  params = structures.OrderedDict(params or kwargs)
95
90
  auth_callback = self.auth_callback if callback else None
96
- self.build(
97
- "GET",
98
- url,
99
- headers = headers,
100
- params = params,
101
- kwargs = kwargs
102
- )
91
+ self.build("GET", url, headers=headers, params=params, kwargs=kwargs)
103
92
  return self.request(
104
93
  http.get,
105
94
  url,
106
- params = params,
107
- headers = headers,
108
- handle = handle,
109
- silent = silent,
110
- redirect = redirect,
111
- timeout = timeout,
112
- auth_callback = auth_callback,
95
+ params=params,
96
+ headers=headers,
97
+ handle=handle,
98
+ silent=silent,
99
+ redirect=redirect,
100
+ timeout=timeout,
101
+ auth_callback=auth_callback,
113
102
  **extra
114
103
  )
115
104
 
116
105
  def post(
117
106
  self,
118
107
  url,
119
- data = None,
120
- data_j = None,
121
- data_m = None,
122
- headers = None,
123
- params = None,
124
- mime = None,
125
- handle = None,
126
- silent = None,
127
- redirect = None,
128
- timeout = None,
129
- callback = True,
130
- extra = None,
108
+ data=None,
109
+ data_j=None,
110
+ data_m=None,
111
+ headers=None,
112
+ params=None,
113
+ mime=None,
114
+ handle=None,
115
+ silent=None,
116
+ redirect=None,
117
+ timeout=None,
118
+ callback=True,
119
+ extra=None,
131
120
  **kwargs
132
121
  ):
133
122
  headers = headers or dict()
@@ -137,46 +126,46 @@ class API(observer.Observable):
137
126
  self.build(
138
127
  "POST",
139
128
  url,
140
- data = data,
141
- data_j = data_j,
142
- data_m = data_m,
143
- headers = headers,
144
- params = params,
145
- mime = mime,
146
- kwargs = kwargs
129
+ data=data,
130
+ data_j=data_j,
131
+ data_m=data_m,
132
+ headers=headers,
133
+ params=params,
134
+ mime=mime,
135
+ kwargs=kwargs,
147
136
  )
148
137
  return self.request(
149
138
  http.post,
150
139
  url,
151
- params = params,
152
- data = data,
153
- data_j = data_j,
154
- data_m = data_m,
155
- headers = headers,
156
- mime = mime,
157
- handle = handle,
158
- silent = silent,
159
- redirect = redirect,
160
- timeout = timeout,
161
- auth_callback = auth_callback,
140
+ params=params,
141
+ data=data,
142
+ data_j=data_j,
143
+ data_m=data_m,
144
+ headers=headers,
145
+ mime=mime,
146
+ handle=handle,
147
+ silent=silent,
148
+ redirect=redirect,
149
+ timeout=timeout,
150
+ auth_callback=auth_callback,
162
151
  **extra
163
152
  )
164
153
 
165
154
  def put(
166
155
  self,
167
156
  url,
168
- data = None,
169
- data_j = None,
170
- data_m = None,
171
- headers = None,
172
- params = None,
173
- mime = None,
174
- handle = None,
175
- silent = None,
176
- redirect = None,
177
- timeout = None,
178
- callback = True,
179
- extra = None,
157
+ data=None,
158
+ data_j=None,
159
+ data_m=None,
160
+ headers=None,
161
+ params=None,
162
+ mime=None,
163
+ handle=None,
164
+ silent=None,
165
+ redirect=None,
166
+ timeout=None,
167
+ callback=True,
168
+ extra=None,
180
169
  **kwargs
181
170
  ):
182
171
  headers = headers or dict()
@@ -186,83 +175,77 @@ class API(observer.Observable):
186
175
  self.build(
187
176
  "PUT",
188
177
  url,
189
- data = data,
190
- data_j = data_j,
191
- data_m = data_m,
192
- headers = headers,
193
- params = params,
194
- mime = mime,
195
- kwargs = kwargs
178
+ data=data,
179
+ data_j=data_j,
180
+ data_m=data_m,
181
+ headers=headers,
182
+ params=params,
183
+ mime=mime,
184
+ kwargs=kwargs,
196
185
  )
197
186
  return self.request(
198
187
  http.put,
199
188
  url,
200
- params = params,
201
- data = data,
202
- data_j = data_j,
203
- data_m = data_m,
204
- headers = headers,
205
- mime = mime,
206
- handle = handle,
207
- silent = silent,
208
- redirect = redirect,
209
- timeout = timeout,
210
- auth_callback = auth_callback,
189
+ params=params,
190
+ data=data,
191
+ data_j=data_j,
192
+ data_m=data_m,
193
+ headers=headers,
194
+ mime=mime,
195
+ handle=handle,
196
+ silent=silent,
197
+ redirect=redirect,
198
+ timeout=timeout,
199
+ auth_callback=auth_callback,
211
200
  **extra
212
201
  )
213
202
 
214
203
  def delete(
215
204
  self,
216
205
  url,
217
- headers = None,
218
- params = None,
219
- handle = None,
220
- silent = None,
221
- redirect = None,
222
- timeout = None,
223
- callback = True,
224
- extra = None,
206
+ headers=None,
207
+ params=None,
208
+ handle=None,
209
+ silent=None,
210
+ redirect=None,
211
+ timeout=None,
212
+ callback=True,
213
+ extra=None,
225
214
  **kwargs
226
215
  ):
227
216
  headers = headers or dict()
228
217
  extra = extra or dict()
229
218
  params = structures.OrderedDict(params or kwargs)
230
219
  auth_callback = self.auth_callback if callback else None
231
- self.build(
232
- "DELETE",
233
- url,
234
- headers = headers,
235
- params = params,
236
- kwargs = kwargs
237
- )
220
+ self.build("DELETE", url, headers=headers, params=params, kwargs=kwargs)
238
221
  return self.request(
239
222
  http.delete,
240
223
  url,
241
- params = params,
242
- headers = headers,
243
- handle = handle,
244
- silent = silent,
245
- redirect = redirect,
246
- timeout = timeout,
247
- auth_callback = auth_callback,
224
+ params=params,
225
+ headers=headers,
226
+ handle=handle,
227
+ silent=silent,
228
+ redirect=redirect,
229
+ timeout=timeout,
230
+ auth_callback=auth_callback,
248
231
  **extra
249
232
  )
250
233
 
251
234
  def patch(
252
235
  self,
253
236
  url,
254
- data = None,
255
- data_j = None,
256
- data_m = None,
257
- headers = None,
258
- params = None,
259
- mime = None,
260
- handle = None,
261
- silent = None,
262
- redirect = None,
263
- timeout = None,
264
- callback = True,
265
- extra = None,
237
+ data=None,
238
+ data_j=None,
239
+ data_m=None,
240
+ headers=None,
241
+ params=None,
242
+ mime=None,
243
+ handle=None,
244
+ silent=None,
245
+ redirect=None,
246
+ timeout=None,
247
+ callback=True,
248
+ extra=None,
266
249
  **kwargs
267
250
  ):
268
251
  headers = headers or dict()
@@ -272,48 +255,50 @@ class API(observer.Observable):
272
255
  self.build(
273
256
  "PATCH",
274
257
  url,
275
- data = data,
276
- data_j = data_j,
277
- data_m = data_m,
278
- headers = headers,
279
- params = params,
280
- mime = mime,
281
- kwargs = kwargs
258
+ data=data,
259
+ data_j=data_j,
260
+ data_m=data_m,
261
+ headers=headers,
262
+ params=params,
263
+ mime=mime,
264
+ kwargs=kwargs,
282
265
  )
283
266
  return self.request(
284
267
  http.patch,
285
268
  url,
286
- params = params,
287
- data = data,
288
- data_j = data_j,
289
- data_m = data_m,
290
- headers = headers,
291
- mime = mime,
292
- handle = handle,
293
- silent = silent,
294
- redirect = redirect,
295
- timeout = timeout,
296
- auth_callback = auth_callback,
269
+ params=params,
270
+ data=data,
271
+ data_j=data_j,
272
+ data_m=data_m,
273
+ headers=headers,
274
+ mime=mime,
275
+ handle=handle,
276
+ silent=silent,
277
+ redirect=redirect,
278
+ timeout=timeout,
279
+ auth_callback=auth_callback,
297
280
  **extra
298
281
  )
299
282
 
300
283
  def request(self, method, *args, **kwargs):
301
- try: result = method(*args, **kwargs)
284
+ try:
285
+ result = method(*args, **kwargs)
302
286
  except exceptions.HTTPError as exception:
303
287
  self.handle_error(exception)
304
- else: return result
288
+ else:
289
+ return result
305
290
 
306
291
  def build(
307
292
  self,
308
293
  method,
309
294
  url,
310
- data = None,
311
- data_j = None,
312
- data_m = None,
313
- headers = None,
314
- params = None,
315
- mime = None,
316
- kwargs = None
295
+ data=None,
296
+ data_j=None,
297
+ data_m=None,
298
+ headers=None,
299
+ params=None,
300
+ mime=None,
301
+ kwargs=None,
317
302
  ):
318
303
  pass
319
304
 
@@ -322,8 +307,11 @@ class API(observer.Observable):
322
307
 
323
308
  @property
324
309
  def logger(self):
325
- if self.owner: return self.owner.logger
326
- else: return logging.getLogger()
310
+ if self.owner:
311
+ return self.owner.logger
312
+ else:
313
+ return logging.getLogger()
314
+
327
315
 
328
316
  class OAuthAPI(API):
329
317
  """
@@ -355,10 +343,11 @@ class OAuthAPI(API):
355
343
  self.mode = OAuthAPI.OAUTH_MODE
356
344
 
357
345
  def handle_error(self, error):
358
- if not error.code in http.AUTH_ERRORS: raise error
346
+ if not error.code in http.AUTH_ERRORS:
347
+ raise error
359
348
  raise exceptions.OAuthAccessError(
360
- message = "Problems using access token found must re-authorize",
361
- original = error
349
+ message="Problems using access token found must re-authorize",
350
+ original=error,
362
351
  )
363
352
 
364
353
  def is_direct(self):
@@ -370,8 +359,8 @@ class OAuthAPI(API):
370
359
  def _get_mode(self):
371
360
  return OAuthAPI.OAUTH_MODE
372
361
 
373
- class OAuth1API(OAuthAPI):
374
362
 
363
+ class OAuth1API(OAuthAPI):
375
364
  def __init__(self, *args, **kwargs):
376
365
  OAuthAPI.__init__(self, *args, **kwargs)
377
366
  self.oauth_token = None
@@ -381,33 +370,36 @@ class OAuth1API(OAuthAPI):
381
370
  self,
382
371
  method,
383
372
  url,
384
- data = None,
385
- data_j = None,
386
- data_m = None,
387
- headers = None,
388
- params = None,
389
- mime = None,
390
- kwargs = None
373
+ data=None,
374
+ data_j=None,
375
+ data_m=None,
376
+ headers=None,
377
+ params=None,
378
+ mime=None,
379
+ kwargs=None,
391
380
  ):
392
- if not self.is_oauth(): return
381
+ if not self.is_oauth():
382
+ return
393
383
  auth = kwargs.pop("auth", self.auth_default)
394
- if auth: self.auth_header(method, url, headers, kwargs)
384
+ if auth:
385
+ self.auth_header(method, url, headers, kwargs)
395
386
 
396
- def auth_header(self, method, url, headers, kwargs, sign_method = "HMAC-SHA1"):
397
- if not sign_method == "HMAC-SHA1": raise exceptions.NotImplementedError()
387
+ def auth_header(self, method, url, headers, kwargs, sign_method="HMAC-SHA1"):
388
+ if not sign_method == "HMAC-SHA1":
389
+ raise exceptions.NotImplementedError()
398
390
 
399
- if not self.client_key: raise exceptions.SecurityError(
400
- message = "No client key defined, mandatory"
401
- )
402
- if not self.client_secret: raise exceptions.SecurityError(
403
- message = "No client secret defined, mandatory"
404
- )
391
+ if not self.client_key:
392
+ raise exceptions.SecurityError(message="No client key defined, mandatory")
393
+ if not self.client_secret:
394
+ raise exceptions.SecurityError(
395
+ message="No client secret defined, mandatory"
396
+ )
405
397
 
406
398
  oauth_callback = kwargs.pop("oauth_callback", None)
407
399
 
408
400
  params = []
409
401
 
410
- encoded = http._quote(kwargs, safe = "~")
402
+ encoded = http._quote(kwargs, safe="~")
411
403
  items = encoded.items()
412
404
  params.extend(items)
413
405
 
@@ -416,41 +408,49 @@ class OAuth1API(OAuthAPI):
416
408
  oauth_timestamp = str(int(time.time()))
417
409
 
418
410
  authorization = dict(
419
- oauth_nonce = oauth_nonce,
420
- oauth_signature_method = sign_method,
421
- oauth_timestamp = oauth_timestamp,
422
- oauth_consumer_key = self.client_key,
423
- oauth_version = "1.0"
411
+ oauth_nonce=oauth_nonce,
412
+ oauth_signature_method=sign_method,
413
+ oauth_timestamp=oauth_timestamp,
414
+ oauth_consumer_key=self.client_key,
415
+ oauth_version="1.0",
424
416
  )
425
- if self.oauth_token: authorization["oauth_token"] = self.oauth_token
426
- if oauth_callback: authorization["oauth_callback"] = oauth_callback
417
+ if self.oauth_token:
418
+ authorization["oauth_token"] = self.oauth_token
419
+ if oauth_callback:
420
+ authorization["oauth_callback"] = oauth_callback
427
421
 
428
- encoded = http._quote(authorization, safe = "~")
422
+ encoded = http._quote(authorization, safe="~")
429
423
  items = encoded.items()
430
424
  params.extend(items)
431
425
  params.sort()
432
426
 
433
427
  signature_base = "&".join(["%s=%s" % (key, value) for key, value in params])
434
- signature_extra = "&".join([
435
- legacy.quote(method, safe = "~"),
436
- legacy.quote(url, safe = "~"),
437
- legacy.quote(signature_base, safe = "~")
438
- ])
428
+ signature_extra = "&".join(
429
+ [
430
+ legacy.quote(method, safe="~"),
431
+ legacy.quote(url, safe="~"),
432
+ legacy.quote(signature_base, safe="~"),
433
+ ]
434
+ )
439
435
 
440
- if self.oauth_token_secret: key = "%s&%s" % (self.client_secret, self.oauth_token_secret)
441
- else: key = "%s&" % self.client_secret
436
+ if self.oauth_token_secret:
437
+ key = "%s&%s" % (self.client_secret, self.oauth_token_secret)
438
+ else:
439
+ key = "%s&" % self.client_secret
442
440
 
443
- if legacy.is_unicode(key): key = key.encode("utf-8")
444
- if legacy.is_unicode(signature_extra): signature_extra = signature_extra.encode("utf-8")
441
+ if legacy.is_unicode(key):
442
+ key = key.encode("utf-8")
443
+ if legacy.is_unicode(signature_extra):
444
+ signature_extra = signature_extra.encode("utf-8")
445
445
 
446
446
  oauth_signature = hmac.new(key, signature_extra, hashlib.sha1).digest()
447
447
  oauth_signature = base64.b64encode(oauth_signature)
448
448
  oauth_signature = legacy.str(oauth_signature)
449
449
 
450
450
  authorization["oauth_signature"] = oauth_signature
451
- authorization = http._quote(authorization, safe = "~")
451
+ authorization = http._quote(authorization, safe="~")
452
452
  authorization = authorization.items()
453
- authorization = ["%s=\"%s\"" % (key, value) for key, value in authorization]
453
+ authorization = ['%s="%s"' % (key, value) for key, value in authorization]
454
454
 
455
455
  authorization_s = ", ".join(authorization)
456
456
  authorization_s = "OAuth %s" % authorization_s
@@ -461,8 +461,8 @@ class OAuth1API(OAuthAPI):
461
461
  def auth_default(self):
462
462
  return True
463
463
 
464
- class OAuth2API(OAuthAPI):
465
464
 
465
+ class OAuth2API(OAuthAPI):
466
466
  def __init__(self, *args, **kwargs):
467
467
  OAuthAPI.__init__(self, *args, **kwargs)
468
468
  self.access_token = None
@@ -471,15 +471,16 @@ class OAuth2API(OAuthAPI):
471
471
  self,
472
472
  method,
473
473
  url,
474
- data = None,
475
- data_j = None,
476
- data_m = None,
477
- headers = None,
478
- params = None,
479
- mime = None,
480
- kwargs = None
474
+ data=None,
475
+ data_j=None,
476
+ data_m=None,
477
+ headers=None,
478
+ params=None,
479
+ mime=None,
480
+ kwargs=None,
481
481
  ):
482
- if not self.is_oauth(): return
482
+ if not self.is_oauth():
483
+ return
483
484
  token = kwargs.pop("token", self.token_default)
484
485
  if token and "param" in self.oauth_types:
485
486
  kwargs[self.oauth_param] = self.get_access_token()
@@ -487,9 +488,10 @@ class OAuth2API(OAuthAPI):
487
488
  headers["Authorization"] = "Bearer %s" % self.get_access_token()
488
489
 
489
490
  def get_access_token(self):
490
- if self.access_token: return self.access_token
491
+ if self.access_token:
492
+ return self.access_token
491
493
  raise exceptions.OAuthAccessError(
492
- message = "No access token found must re-authorize"
494
+ message="No access token found must re-authorize"
493
495
  )
494
496
 
495
497
  @property