velocity-python 0.0.2__py3-none-any.whl → 0.0.3__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.
Potentially problematic release.
This version of velocity-python might be problematic. Click here for more details.
- velocity/aws/handlers/response.py +158 -0
- velocity/misc/merge.py +35 -0
- {velocity_python-0.0.2.dist-info → velocity_python-0.0.3.dist-info}/METADATA +1 -1
- {velocity_python-0.0.2.dist-info → velocity_python-0.0.3.dist-info}/RECORD +7 -5
- {velocity_python-0.0.2.dist-info → velocity_python-0.0.3.dist-info}/LICENSE +0 -0
- {velocity_python-0.0.2.dist-info → velocity_python-0.0.3.dist-info}/WHEEL +0 -0
- {velocity_python-0.0.2.dist-info → velocity_python-0.0.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from velocity.misc.format import to_json
|
|
2
|
+
import sys
|
|
3
|
+
import traceback
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
DEBUG = (os.environ.get('ENV') != 'production') or \
|
|
7
|
+
(os.environ.get('DEBUG') == 'Y')
|
|
8
|
+
|
|
9
|
+
variants = [
|
|
10
|
+
'success',
|
|
11
|
+
'error',
|
|
12
|
+
'warning',
|
|
13
|
+
'info'
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Response:
|
|
18
|
+
def __init__(self):
|
|
19
|
+
self.actions = []
|
|
20
|
+
self.body = {
|
|
21
|
+
'actions': self.actions
|
|
22
|
+
}
|
|
23
|
+
self.raw = {
|
|
24
|
+
'statusCode': 200,
|
|
25
|
+
'body': '{}',
|
|
26
|
+
'headers': {
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
'Access-Control-Allow-Headers': '*',
|
|
29
|
+
'Access-Control-Allow-Origin': '*',
|
|
30
|
+
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def render(self):
|
|
35
|
+
self.raw['body'] = to_json(self.body)
|
|
36
|
+
return self.raw
|
|
37
|
+
|
|
38
|
+
def alert(self, message, title="Notification"):
|
|
39
|
+
self.actions.append({
|
|
40
|
+
'action': 'alert',
|
|
41
|
+
'payload': {
|
|
42
|
+
'title': title,
|
|
43
|
+
'message': message,
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def toast(self, message, variant='success'):
|
|
49
|
+
variant = variant.lower()
|
|
50
|
+
if variant not in variants:
|
|
51
|
+
raise Exception(f"Notistack variant {variant} not in {variants}")
|
|
52
|
+
self.actions.append({
|
|
53
|
+
'action': 'toast',
|
|
54
|
+
'payload': {
|
|
55
|
+
'options': {
|
|
56
|
+
'variant': variant,
|
|
57
|
+
},
|
|
58
|
+
'message': message
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
def load_object(self, payload):
|
|
64
|
+
self.actions.append({
|
|
65
|
+
'action': 'load-object',
|
|
66
|
+
'payload': payload
|
|
67
|
+
})
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
def update_store(self, payload):
|
|
71
|
+
self.actions.append({
|
|
72
|
+
'action': 'update-store',
|
|
73
|
+
'payload': payload
|
|
74
|
+
})
|
|
75
|
+
return self
|
|
76
|
+
|
|
77
|
+
def file_download(self, payload):
|
|
78
|
+
self.actions.append({
|
|
79
|
+
'action': 'file-download',
|
|
80
|
+
'payload': payload
|
|
81
|
+
})
|
|
82
|
+
return self
|
|
83
|
+
|
|
84
|
+
def status(self, code=None):
|
|
85
|
+
if code:
|
|
86
|
+
self.raw['statusCode'] = int(code)
|
|
87
|
+
return self.raw['statusCode']
|
|
88
|
+
|
|
89
|
+
def headers(self, headers=None):
|
|
90
|
+
if headers:
|
|
91
|
+
new = {}
|
|
92
|
+
for key in headers.keys():
|
|
93
|
+
new["-".join(w.capitalize()
|
|
94
|
+
for w in key.split('-'))] = headers[key]
|
|
95
|
+
self.raw['headers'].update(new)
|
|
96
|
+
return self.raw['headers']
|
|
97
|
+
|
|
98
|
+
def set_status(self, code):
|
|
99
|
+
self.status(code)
|
|
100
|
+
return self
|
|
101
|
+
|
|
102
|
+
def set_headers(self, headers):
|
|
103
|
+
self.headers(headers)
|
|
104
|
+
return self
|
|
105
|
+
|
|
106
|
+
def set_body(self, body):
|
|
107
|
+
self.body.update(body)
|
|
108
|
+
return self
|
|
109
|
+
|
|
110
|
+
def exception(self):
|
|
111
|
+
t, v, tb = sys.exc_info()
|
|
112
|
+
self.set_status(500)
|
|
113
|
+
self.set_body({
|
|
114
|
+
'python_exception': {
|
|
115
|
+
'type': str(t),
|
|
116
|
+
'value': str(v),
|
|
117
|
+
'traceback': traceback.format_exc() if DEBUG else None,
|
|
118
|
+
'tb': traceback.format_tb(tb) if DEBUG else None
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
def console(self, message, title="Notification"):
|
|
123
|
+
self.actions.append({
|
|
124
|
+
'action': 'console',
|
|
125
|
+
'payload': {
|
|
126
|
+
'title': title,
|
|
127
|
+
'message': message,
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
def redirect(self, location):
|
|
133
|
+
self.actions.append({
|
|
134
|
+
'action': 'redirect',
|
|
135
|
+
'payload': {'location': location}
|
|
136
|
+
})
|
|
137
|
+
return self
|
|
138
|
+
|
|
139
|
+
def signout(self, location):
|
|
140
|
+
self.actions.append({
|
|
141
|
+
'action': 'signout',
|
|
142
|
+
|
|
143
|
+
})
|
|
144
|
+
return self
|
|
145
|
+
|
|
146
|
+
def set_table(self, payload):
|
|
147
|
+
self.actions.append({
|
|
148
|
+
'action': 'set-table',
|
|
149
|
+
'payload': payload
|
|
150
|
+
})
|
|
151
|
+
return self
|
|
152
|
+
|
|
153
|
+
def set_repo(self, payload):
|
|
154
|
+
self.actions.append({
|
|
155
|
+
'action': 'set-repo',
|
|
156
|
+
'payload': payload
|
|
157
|
+
})
|
|
158
|
+
return self
|
velocity/misc/merge.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from copy import deepcopy
|
|
2
|
+
from functools import reduce
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def deep_merge(*dicts, update=False):
|
|
6
|
+
"""
|
|
7
|
+
Merges dicts deeply.
|
|
8
|
+
Parameters
|
|
9
|
+
----------
|
|
10
|
+
dicts : list[dict]
|
|
11
|
+
List of dicts.
|
|
12
|
+
update : bool
|
|
13
|
+
Whether to update the first dict or create a new dict.
|
|
14
|
+
Returns
|
|
15
|
+
-------
|
|
16
|
+
merged : dict
|
|
17
|
+
Merged dict.
|
|
18
|
+
"""
|
|
19
|
+
def merge_into(d1, d2):
|
|
20
|
+
for key in d2:
|
|
21
|
+
if key not in d1:
|
|
22
|
+
d1[key] = deepcopy(d2[key])
|
|
23
|
+
elif isinstance(d1[key], dict):
|
|
24
|
+
d1[key] = merge_into(d1[key], d2[key])
|
|
25
|
+
elif isinstance(d1[key], list) and isinstance(d2[key], list):
|
|
26
|
+
d1[key].extend(d2[key])
|
|
27
|
+
else:
|
|
28
|
+
d1[key] = deepcopy(d2[key])
|
|
29
|
+
|
|
30
|
+
return d1
|
|
31
|
+
|
|
32
|
+
if update:
|
|
33
|
+
return reduce(merge_into, dicts[1:], dicts[0])
|
|
34
|
+
else:
|
|
35
|
+
return reduce(merge_into, dicts, {})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: velocity-python
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: A rapid application development library for interfacing with data storage
|
|
5
5
|
Author-email: Paul Perez <pperez@codeclubs.org>
|
|
6
6
|
Project-URL: Homepage, https://codeclubs.org/projects/velocity
|
|
@@ -3,6 +3,7 @@ velocity/aws/__init__.py,sha256=9hVUbHjWh1HvD-xolBY_jLnV_bARlHyxkl5_l2nnINg,713
|
|
|
3
3
|
velocity/aws/context.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
velocity/aws/handlers/__init__.py,sha256=OVqAh3Ln501EnmWUz2fq4lhokGHga6KSPA82yU4kRQs,119
|
|
5
5
|
velocity/aws/handlers/lambda_handler.py,sha256=3mCFnFXCZReyOcNoFhj2kyXjokT8TsDb8Rc_IDasg6Q,4586
|
|
6
|
+
velocity/aws/handlers/response.py,sha256=mO4bW595_AVuYE0r-YXD2T5kZyVyCywCg4yAQJJowUo,3988
|
|
6
7
|
velocity/aws/handlers/sqs_handler.py,sha256=OBpmK0_ZTollITPFcQifpUfwjwNmR6Apkl0LKn2QJdk,2033
|
|
7
8
|
velocity/db/__init__.py,sha256=vrn2AFNAKaqTdnPwLFS0OcREcCtzUCOodlmH54U7ADg,200
|
|
8
9
|
velocity/db/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -28,9 +29,10 @@ velocity/misc/db.py,sha256=ZbAlVjSC-ASfVV69zlLjUqwndQnsUTBBjORyIBNrMUo,2842
|
|
|
28
29
|
velocity/misc/export.py,sha256=KA_ezon-jd874rHIDMeZSOWTCAuLcA7kayjWZVTewew,4863
|
|
29
30
|
velocity/misc/format.py,sha256=2GwdWOpUqmQjtLJKrHjQjTMFrATF6G1IXkLI1xVPB7U,2301
|
|
30
31
|
velocity/misc/mail.py,sha256=fKfJtEkRKO3f_JbHNw9ThxKHJnChlBMsQwmEDFgj264,2096
|
|
32
|
+
velocity/misc/merge.py,sha256=hBYPJy6lGL8lzb0wK1i1oEAyzragTWKF1rW9_PGHm6s,918
|
|
31
33
|
velocity/misc/timer.py,sha256=wMbV-1yNXeCJo_UPi5sTSslu9hPzokLaIKgd98tyG_4,536
|
|
32
|
-
velocity_python-0.0.
|
|
33
|
-
velocity_python-0.0.
|
|
34
|
-
velocity_python-0.0.
|
|
35
|
-
velocity_python-0.0.
|
|
36
|
-
velocity_python-0.0.
|
|
34
|
+
velocity_python-0.0.3.dist-info/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
|
|
35
|
+
velocity_python-0.0.3.dist-info/METADATA,sha256=YN39RH2RntrysuydXOCRtZfkEXoQoB111-6FiryUNss,8521
|
|
36
|
+
velocity_python-0.0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
37
|
+
velocity_python-0.0.3.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
|
|
38
|
+
velocity_python-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|