velocity-python 0.0.12__py3-none-any.whl → 0.0.14__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/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = version = "0.0.12"
1
+ __version__ = version = "0.0.14"
2
2
 
3
3
  from . import aws
4
4
  from . import db
@@ -0,0 +1,52 @@
1
+ import support.app
2
+
3
+ engine = support.app.postgres()
4
+
5
+ @engine.transaction
6
+ class Context:
7
+ def __init__(self,
8
+ args,
9
+ postdata,
10
+ response,
11
+ event,
12
+ session,
13
+ aws_context):
14
+ self.__args = args
15
+ self.__postdata = postdata,
16
+ self.__response = response,
17
+ self.__session = session,
18
+ self.__aws_event = event,
19
+ self.__aws_context = aws_context
20
+
21
+
22
+ def postdata(self, keys=-1, default=None):
23
+ if keys == -1:
24
+ return self.__postdata
25
+ if not isinstance(keys, list):
26
+ keys = [keys]
27
+ data = self.__postdata
28
+ for key in keys:
29
+ if key in data:
30
+ data = data[key]
31
+ else:
32
+ return default
33
+ return data
34
+
35
+
36
+ def payload(self, keys=-1, default={}):
37
+ if 'payload' not in self.__postdata:
38
+ return default
39
+ if keys == -1:
40
+ return self.__postdata['payload']
41
+ if not isinstance(keys, list):
42
+ keys = [keys]
43
+ data = self.__postdata['payload']
44
+ for key in keys:
45
+ if key in data:
46
+ data = data[key]
47
+ else:
48
+ return default
49
+ return data
50
+
51
+ def action(self):
52
+ return self.__postdata('action', self.__args('action', ''))
@@ -5,18 +5,20 @@ import os
5
5
  import traceback
6
6
  from velocity.aws import DEBUG
7
7
  from support.app import helpers, AlertError, enqueue
8
+ import velocity.aws.handlers
9
+ print(velocity.aws.handlers)
8
10
  from response import Response
9
11
 
10
12
  class LambdaHandler:
11
- def __init__(self, event, context):
12
- self.event = event
13
- self.context = context
14
- self.serve_action_default = True
15
- self.skip_action = False
13
+ def __init__(self, aws_event, aws_context):
14
+ self.aws_event = aws_event
15
+ self.aws_context = aws_context
16
+ self.serve_action_default = True # Set to False to disable OnActionDefault
17
+ self.skip_action = False # Set to True to skip all actions
16
18
 
17
- requestContext = event.get("requestContext") or {}
19
+ requestContext = aws_event.get("requestContext") or {}
18
20
  identity = requestContext.get("identity") or {}
19
- headers = event.get("headers") or {}
21
+ headers = aws_event.get("headers") or {}
20
22
  auth = identity.get("cognitoAuthenticationProvider")
21
23
  self.session = {
22
24
  "authentication_provider": identity.get("cognitoAuthenticationProvider"),
@@ -27,7 +29,7 @@ class LambdaHandler:
27
29
  "is_smart_tv": headers.get("CloudFront-Is-SmartTV-Viewer") == "true",
28
30
  "is_tablet": headers.get("CloudFront-Is-Tablet-Viewer") == "true",
29
31
  "origin": headers.get("origin"),
30
- "path": event.get("path"),
32
+ "path": aws_event.get("path"),
31
33
  "referer": headers.get("Referer"),
32
34
  "source_ip": identity.get("sourceIp"),
33
35
  "user_agent": identity.get("userAgent"),
@@ -91,9 +93,16 @@ class LambdaHandler:
91
93
  postdata = {"raw_body": body}
92
94
 
93
95
  req_params = self.event.get("queryStringParameters") or {}
96
+ context = Context(
97
+ args=req_params,
98
+ postdata=postdata,
99
+ response=response,
100
+ event=self.aws_event,
101
+ session=self.session,
102
+ aws_context=self.aws_context)
94
103
  try:
95
104
  if hasattr(self, "beforeAction"):
96
- self.beforeAction(args=req_params, postdata=postdata, response=response)
105
+ self.beforeAction(context)
97
106
  actions = []
98
107
  action = postdata.get("action", req_params.get("action"))
99
108
  if action:
@@ -108,23 +117,19 @@ class LambdaHandler:
108
117
  if self.skip_action:
109
118
  break
110
119
  if hasattr(self, action):
111
- result = getattr(self, action)(
112
- args=req_params, postdata=postdata, response=response
113
- )
120
+ result = getattr(self, action)(context)
114
121
  if result and result != response:
115
122
  response.set_body(result)
116
123
  break
117
124
  if hasattr(self, "afterAction"):
118
- self.afterAction(args=req_params, postdata=postdata, response=response)
125
+ self.afterAction(context)
119
126
  except AlertError as e:
120
127
  response.alert(e.get_payload())
121
128
  except Exception as e:
122
129
  response.exception()
123
130
  if hasattr(self, "onError"):
124
131
  self.onError(
125
- args=req_params,
126
- postdata=postdata,
127
- response=response,
132
+ context,
128
133
  exc=e.__class__.__name__,
129
134
  tb=traceback.format_exc(),
130
135
  )
@@ -144,8 +149,8 @@ class LambdaHandler:
144
149
  )
145
150
  tx.table(helpers.get_tracking_table(user or self.session)).insert(data)
146
151
 
147
- def OnActionDefault(self, tx, args, postdata, response):
148
- return {"event": self.event, "postdata": postdata}
152
+ def OnActionDefault(self, tx, context):
153
+ return {"event": self.aws_event, "postdata": context.postdata}
149
154
 
150
155
  def OnActionTracking(self, tx, args, postdata, response):
151
156
  self.track(tx, postdata.get("payload", {}).get("data", {}))
@@ -6,9 +6,9 @@ import traceback
6
6
  from velocity.aws import DEBUG
7
7
 
8
8
  class SqsHandler:
9
- def __init__(self, event, context):
9
+ def __init__(self, event, aws_context):
10
10
  self.event = event
11
- self.context = context
11
+ self.aws_context = aws_context
12
12
  self.serve_action_default = True
13
13
  self.skip_action = False
14
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: velocity-python
3
- Version: 0.0.12
3
+ Version: 0.0.14
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
@@ -1,10 +1,10 @@
1
- velocity/__init__.py,sha256=mGhMWA4bnqoUDsNwKgEmLK4JeiZhNqFJQAp3UciIi4o,91
1
+ velocity/__init__.py,sha256=lipC6Zxo7CWeCHVvimBY8xUYGKHkaXCS34dVX5CqlYM,91
2
2
  velocity/aws/__init__.py,sha256=ukvGrS0R8p6HtYajexOAJ7Kn9CJNlx6yb58W7o-JrAg,620
3
- velocity/aws/context.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
3
  velocity/aws/handlers/__init__.py,sha256=xnpFZJVlC2uoeeFW4zuPST8wA8ajaQDky5Y6iXZzi3A,172
5
- velocity/aws/handlers/lambda_handler.py,sha256=8_YgqB_zw4cu_H8kIAMw3wyp0IRLtKipZTWWrKWbXlg,6019
4
+ velocity/aws/handlers/context.py,sha256=B9iVqJLwXQqPkHCLX8rBWyVz8Ri3REe5OLzB55x074w,1450
5
+ velocity/aws/handlers/lambda_handler.py,sha256=NWkzy32HrJfnM1qVcIgwlbqZ60en7iX6uQamGBX-DQw,6147
6
6
  velocity/aws/handlers/response.py,sha256=VN4uFI_wtHiqAyBLX-eeQlmCwj1hdIvokvZLjsOyCnw,3915
7
- velocity/aws/handlers/sqs_handler.py,sha256=VB9XMZVqUTeXxgUJswa8Hl8wYGtEKgFp3lQKJE5Icx0,3014
7
+ velocity/aws/handlers/sqs_handler.py,sha256=LmAuvwvlk3YJg1_ivODLCoaekWsn6MaCWtPgpkXU-O4,3026
8
8
  velocity/db/__init__.py,sha256=vrn2AFNAKaqTdnPwLFS0OcREcCtzUCOodlmH54U7ADg,200
9
9
  velocity/db/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  velocity/db/core/column.py,sha256=vB7dCrcIWFvRG1fgyzDQnEu7j_0KYxUuDSTCWVCYlPc,6153
@@ -31,8 +31,8 @@ velocity/misc/format.py,sha256=2GwdWOpUqmQjtLJKrHjQjTMFrATF6G1IXkLI1xVPB7U,2301
31
31
  velocity/misc/mail.py,sha256=fKfJtEkRKO3f_JbHNw9ThxKHJnChlBMsQwmEDFgj264,2096
32
32
  velocity/misc/merge.py,sha256=hBYPJy6lGL8lzb0wK1i1oEAyzragTWKF1rW9_PGHm6s,918
33
33
  velocity/misc/timer.py,sha256=wMbV-1yNXeCJo_UPi5sTSslu9hPzokLaIKgd98tyG_4,536
34
- velocity_python-0.0.12.dist-info/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
35
- velocity_python-0.0.12.dist-info/METADATA,sha256=4xZo4kczZ0DcxqWRioWW0DSWoy1tP878wG8ZjekqUcM,8522
36
- velocity_python-0.0.12.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
37
- velocity_python-0.0.12.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
38
- velocity_python-0.0.12.dist-info/RECORD,,
34
+ velocity_python-0.0.14.dist-info/LICENSE,sha256=aoN245GG8s9oRUU89KNiGTU4_4OtnNmVi4hQeChg6rM,1076
35
+ velocity_python-0.0.14.dist-info/METADATA,sha256=s2N0R4Gr1AaDc8Baivi91VneUIJHPuYyVlZa66P5KUY,8522
36
+ velocity_python-0.0.14.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
37
+ velocity_python-0.0.14.dist-info/top_level.txt,sha256=JW2vJPmodgdgSz7H6yoZvnxF8S3fTMIv-YJWCT1sNW0,9
38
+ velocity_python-0.0.14.dist-info/RECORD,,
velocity/aws/context.py DELETED
File without changes