velocity-python 0.0.6__tar.gz → 0.0.7__tar.gz

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.

Files changed (45) hide show
  1. {velocity-python-0.0.6 → velocity-python-0.0.7}/PKG-INFO +1 -1
  2. {velocity-python-0.0.6 → velocity-python-0.0.7}/pyproject.toml +1 -1
  3. velocity-python-0.0.7/src/velocity/aws/handlers/lambda_handler.py +154 -0
  4. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/aws/handlers/response.py +1 -3
  5. velocity-python-0.0.7/src/velocity/aws/handlers/sqs_handler.py +85 -0
  6. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity_python.egg-info/PKG-INFO +1 -1
  7. velocity-python-0.0.6/src/velocity/aws/handlers/lambda_handler.py +0 -123
  8. velocity-python-0.0.6/src/velocity/aws/handlers/sqs_handler.py +0 -48
  9. {velocity-python-0.0.6 → velocity-python-0.0.7}/LICENSE +0 -0
  10. {velocity-python-0.0.6 → velocity-python-0.0.7}/README.md +0 -0
  11. {velocity-python-0.0.6 → velocity-python-0.0.7}/setup.cfg +0 -0
  12. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/__init__.py +0 -0
  13. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/aws/__init__.py +3 -3
  14. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/aws/context.py +0 -0
  15. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/aws/handlers/__init__.py +0 -0
  16. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/__init__.py +0 -0
  17. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/__init__.py +0 -0
  18. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/column.py +0 -0
  19. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/database.py +0 -0
  20. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/decorators.py +0 -0
  21. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/engine.py +0 -0
  22. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/exceptions.py +0 -0
  23. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/result.py +0 -0
  24. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/row.py +0 -0
  25. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/sequence.py +0 -0
  26. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/table.py +0 -0
  27. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/core/transaction.py +0 -0
  28. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/servers/__init__.py +0 -0
  29. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/servers/mysql.py +0 -0
  30. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/servers/postgres.py +0 -0
  31. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/servers/sql.py +0 -0
  32. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/servers/sqlite.py +0 -0
  33. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/db/servers/sqlserver.py +0 -0
  34. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/__init__.py +0 -0
  35. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/conv.py +0 -0
  36. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/db.py +0 -0
  37. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/export.py +0 -0
  38. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/format.py +0 -0
  39. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/mail.py +0 -0
  40. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/merge.py +0 -0
  41. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity/misc/timer.py +0 -0
  42. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity_python.egg-info/SOURCES.txt +0 -0
  43. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity_python.egg-info/dependency_links.txt +0 -0
  44. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity_python.egg-info/requires.txt +0 -0
  45. {velocity-python-0.0.6 → velocity-python-0.0.7}/src/velocity_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: velocity-python
3
- Version: 0.0.6
3
+ Version: 0.0.7
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,6 +1,6 @@
1
1
  [project]
2
2
  name = "velocity-python"
3
- version = "0.0.6"
3
+ version = "0.0.7"
4
4
  authors = [
5
5
  { name="Paul Perez", email="pperez@codeclubs.org" },
6
6
  ]
@@ -0,0 +1,154 @@
1
+ from velocity.misc.format import to_json
2
+ import json
3
+ import sys
4
+ import os
5
+ import traceback
6
+ from velocity.aws import DEBUG
7
+ from support.app import helpers, AlertError, enqueue
8
+ from response import Response
9
+
10
+ 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
16
+
17
+ requestContext = event.get("requestContext") or {}
18
+ identity = requestContext.get("identity") or {}
19
+ headers = event.get("headers") or {}
20
+ auth = identity.get("cognitoAuthenticationProvider")
21
+ self.session = {
22
+ "authentication_provider": identity.get("cognitoAuthenticationProvider"),
23
+ "authentication_type": identity.get("cognitoAuthenticationType"),
24
+ "cognito_user": identity.get("user"),
25
+ "is_desktop": headers.get("CloudFront-Is-Desktop-Viewer") == "true",
26
+ "is_mobile": headers.get("CloudFront-Is-Mobile-Viewer") == "true",
27
+ "is_smart_tv": headers.get("CloudFront-Is-SmartTV-Viewer") == "true",
28
+ "is_tablet": headers.get("CloudFront-Is-Tablet-Viewer") == "true",
29
+ "origin": headers.get("origin"),
30
+ "path": event.get("path"),
31
+ "referer": headers.get("Referer"),
32
+ "source_ip": identity.get("sourceIp"),
33
+ "user_agent": identity.get("userAgent"),
34
+ "sub": auth.split(":")[-1] if auth else None,
35
+ }
36
+ if self.session.get("is_mobile"):
37
+ self.session["device_type"] = "mobile"
38
+ elif self.session.get("is_desktop"):
39
+ self.session["device_type"] = "desktop"
40
+ elif self.session.get("is_tablet"):
41
+ self.session["device_type"] = "tablet"
42
+ elif self.session.get("is_smart_tv"):
43
+ self.session["device_type"] = "smart_tv"
44
+ else:
45
+ self.session["device_type"] = "unknown"
46
+
47
+ def log(self, tx, message, function=None):
48
+ if not function:
49
+ function = "<Unknown>"
50
+ idx = 0
51
+ while True:
52
+ try:
53
+ temp = sys._getframe(idx).f_code.co_name
54
+ except ValueError as e:
55
+ break
56
+ if temp in ["x", "log", "_transaction"]:
57
+ idx += 1
58
+ continue
59
+ function = temp
60
+ break
61
+
62
+ data = {
63
+ "app_name": os.environ["ProjectName"],
64
+ "source_ip": self.session["source_ip"],
65
+ "referer": self.session["referer"],
66
+ "user_agent": self.session["user_agent"],
67
+ "device_type": self.session["device_type"],
68
+ "function": function,
69
+ "message": message,
70
+ }
71
+ if "email_address" in self.session:
72
+ data["sys_modified_by"] = self.session["email_address"]
73
+ tx.table("sys_log").insert(data)
74
+
75
+ def serve(self, tx):
76
+ response = Response()
77
+ body = self.event.get("body")
78
+ postdata = {}
79
+ if isinstance(body, str) and len(body) > 0:
80
+ try:
81
+ postdata = json.loads(body)
82
+ except:
83
+ postdata = {"raw_body": body}
84
+ elif isinstance(body, dict):
85
+ postdata = body
86
+ elif isinstance(body, list) and len(body) > 0:
87
+ try:
88
+ new = "\n".join(body)
89
+ postdata = json.loads(new)
90
+ except:
91
+ postdata = {"raw_body": body}
92
+
93
+ req_params = self.event.get("queryStringParameters") or {}
94
+ try:
95
+ if hasattr(self, "beforeAction"):
96
+ self.beforeAction(args=req_params, postdata=postdata, response=response)
97
+ actions = []
98
+ action = postdata.get("action", req_params.get("action"))
99
+ if action:
100
+ actions.append(
101
+ f"on action {action.replace('-', ' ').replace('_', ' ')}".title().replace(
102
+ " ", ""
103
+ )
104
+ )
105
+ if self.serve_action_default:
106
+ actions.append("OnActionDefault")
107
+ for action in actions:
108
+ if self.skip_action:
109
+ break
110
+ if hasattr(self, action):
111
+ result = getattr(self, action)(
112
+ args=req_params, postdata=postdata, response=response
113
+ )
114
+ if result and result != response:
115
+ response.set_body(result)
116
+ break
117
+ if hasattr(self, "afterAction"):
118
+ self.afterAction(args=req_params, postdata=postdata, response=response)
119
+ except AlertError as e:
120
+ response.alert(e.get_payload())
121
+ except Exception as e:
122
+ response.exception()
123
+ if hasattr(self, "onError"):
124
+ self.onError(
125
+ args=req_params,
126
+ postdata=postdata,
127
+ response=response,
128
+ exc=e.__class__.__name__,
129
+ tb=traceback.format_exc(),
130
+ )
131
+
132
+ return response.render()
133
+
134
+ def track(self, tx, data={}, user=None):
135
+ data = data.copy()
136
+ data.update(
137
+ {
138
+ "source_ip": self.session["source_ip"],
139
+ "referer": self.session["referer"],
140
+ "user_agent": self.session["user_agent"],
141
+ "device_type": self.session["device_type"],
142
+ "sys_modified_by": self.session["email_address"],
143
+ }
144
+ )
145
+ tx.table(helpers.get_tracking_table(user or self.session)).insert(data)
146
+
147
+ def OnActionDefault(self, tx, args, postdata, response):
148
+ return {"event": self.event, "postdata": postdata}
149
+
150
+ def OnActionTracking(self, tx, args, postdata, response):
151
+ self.track(tx, postdata.get("payload", {}).get("data", {}))
152
+
153
+ def enqueue(self, tx, action, payload={}):
154
+ return enqueue(tx, action, payload, self.session["email_address"])
@@ -1,10 +1,8 @@
1
1
  from velocity.misc.format import to_json
2
2
  import sys
3
3
  import traceback
4
- import os
4
+ from velocity.aws import DEBUG
5
5
 
6
- DEBUG = (os.environ.get('ENV') != 'production') or \
7
- (os.environ.get('DEBUG') == 'Y')
8
6
 
9
7
  variants = [
10
8
  'success',
@@ -0,0 +1,85 @@
1
+ from velocity.misc.format import to_json
2
+ import json
3
+ import sys
4
+ import os
5
+ import traceback
6
+ from velocity.aws import DEBUG
7
+
8
+ class SqsHandler:
9
+ def __init__(self, event, context):
10
+ self.event = event
11
+ self.context = context
12
+ self.serve_action_default = True
13
+ self.skip_action = False
14
+
15
+ def log(self, tx, message, function=None):
16
+ if not function:
17
+ function = "<Unknown>"
18
+ idx = 0
19
+ while True:
20
+ try:
21
+ temp = sys._getframe(idx).f_code.co_name
22
+ except ValueError as e:
23
+ break
24
+ if temp in ["x", "log", "_transaction"]:
25
+ idx += 1
26
+ continue
27
+ function = temp
28
+ break
29
+
30
+ data = {
31
+ "app_name": os.environ["ProjectName"],
32
+ "referer": "SQS",
33
+ "user_agent": "QueueHandler",
34
+ "device_type": "Lambda",
35
+ "function": function,
36
+ "message": message,
37
+ "sys_modified_by": "lambda:BackOfficeQueueHandler",
38
+ }
39
+ tx.table("sys_log").insert(data)
40
+
41
+ def serve(self, tx):
42
+ records = self.event.get("Records", [])
43
+ for record in records:
44
+ attrs = record.get("attributes")
45
+ try:
46
+ postdata = {}
47
+ if record.get("body"):
48
+ postdata = json.loads(record.get("body"))
49
+ if hasattr(self, "beforeAction"):
50
+ self.beforeAction(attrs=attrs, postdata=postdata)
51
+ actions = []
52
+ action = postdata.get("action")
53
+ if action:
54
+ actions.append(
55
+ f"on action {action.replace('-', ' ').replace('_', ' ')}".title().replace(
56
+ " ", ""
57
+ )
58
+ )
59
+ if self.serve_action_default:
60
+ actions.append("OnActionDefault")
61
+ for action in actions:
62
+ if self.skip_action:
63
+ return
64
+ if hasattr(self, action):
65
+ getattr(self, action)(attrs=attrs, postdata=postdata)
66
+ break
67
+ if hasattr(self, "afterAction"):
68
+ self.afterAction(attrs=attrs, postdata=postdata)
69
+ except Exception as e:
70
+ if hasattr(self, "onError"):
71
+ self.onError(
72
+ attrs=attrs,
73
+ postdata=postdata,
74
+ exc=e.__class__.__name__,
75
+ tb=traceback.format_exc(),
76
+ )
77
+
78
+ def OnActionDefault(self, tx, attrs, postdata):
79
+ print(
80
+ f"""
81
+ [Warn] Action handler not found. Calling default action `SqsHandler.OnActionDefault` with the following parameters for attrs, and postdata:
82
+ attrs: {str(attrs)}
83
+ postdata: {str(postdata)}
84
+ """
85
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: velocity-python
3
- Version: 0.0.6
3
+ Version: 0.0.7
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,123 +0,0 @@
1
- from velocity.misc.format import to_json
2
- import json
3
- import pprint
4
- import traceback
5
-
6
- class LambdaHandler:
7
- def __init__(self, event, context):
8
- self.event = event
9
- self.context = context
10
- self.serve_action_default = True
11
-
12
- requestContext = event.get('requestContext', {})
13
- identity = requestContext.get('identity', {})
14
- headers = event.get('headers', {})
15
- self.session = {
16
- 'authentication_provider':
17
- identity.get('cognitoAuthenticationProvider'),
18
- 'authentication_type':
19
- identity.get('cognitoAuthenticationType'),
20
- 'cognito_user':
21
- identity.get('user'),
22
- 'is_desktop':
23
- headers.get('CloudFront-Is-Desktop-Viewer') == 'true',
24
- 'is_mobile':
25
- headers.get('CloudFront-Is-Mobile-Viewer') == 'true',
26
- 'is_smart_tv':
27
- headers.get('CloudFront-Is-SmartTV-Viewer') == 'true',
28
- 'is_tablet':
29
- headers.get('CloudFront-Is-Tablet-Viewer') == 'true',
30
- 'origin':
31
- headers.get('origin'),
32
- 'path':
33
- event.get('path'),
34
- 'referer':
35
- headers.get('Referer'),
36
- 'source_ip':
37
- identity.get('sourceIp'),
38
- 'user_agent':
39
- identity.get('userAgent'),
40
- }
41
- if self.session.get('is_mobile'):
42
- self.session['device_type'] = 'mobile'
43
- elif self.session.get('is_desktop'):
44
- self.session['device_type'] = 'desktop'
45
- elif self.session.get('is_tablet'):
46
- self.session['device_type'] = 'tablet'
47
- elif self.session.get('is_smart_tv'):
48
- self.session['device_type'] = 'smart_tv'
49
- else:
50
- self.session['device_type'] = 'unknown'
51
-
52
- def serve(self, tx):
53
- response = {
54
- 'statusCode': 200,
55
- 'body': '{}',
56
- 'headers': {
57
- 'Content-Type': 'application/json',
58
- "Access-Control-Allow-Origin": "*",
59
- },
60
- }
61
- try:
62
- postdata = {}
63
- if self.event.get('body'):
64
- postdata = json.loads(self.event.get('body'))
65
- req_params = self.event.get('queryStringParameters') or {}
66
- if hasattr(self, 'beforeAction'):
67
- self.beforeAction(args=req_params,
68
- postdata=postdata,
69
- response=response)
70
- actions = []
71
- action = postdata.get('action', req_params.get('action'))
72
- if action:
73
- actions.append(
74
- f"on action {action.replace('-', ' ').replace('_', ' ')}".
75
- title().replace(' ', ''))
76
- if self.serve_action_default:
77
- actions.append('OnActionDefault')
78
- for action in actions:
79
- if hasattr(self, action):
80
- getattr(self, action)(args=req_params,
81
- postdata=postdata,
82
- response=response)
83
- break
84
- if hasattr(self, 'afterAction'):
85
- self.afterAction(args=req_params,
86
- postdata=postdata,
87
- response=response)
88
-
89
- except Exception as e:
90
- response = {
91
- 'statusCode':
92
- 500,
93
- 'body':
94
- to_json({
95
- 'type': 'Unhandled Exception',
96
- 'error_message': str(e),
97
- 'user_message': 'Oops! An unhandled error occurred.',
98
- 'traceback': traceback.format_exc() if DEBUG else None
99
- }),
100
- 'headers': {
101
- 'Content-Type': 'application/json',
102
- 'Access-Control-Allow-Origin': '*'
103
- }
104
- }
105
- if hasattr(self, 'onError'):
106
- self.onError(args=req_params,
107
- postdata=postdata,
108
- response=response,
109
- exc=e,
110
- tb=traceback.format_exc())
111
-
112
- return response
113
-
114
- def OnActionDefault(self, tx, args, postdata, response):
115
- response['body'] = to_json({'event': self.event, 'postdata': postdata})
116
-
117
- def onError(self, tx, args, postdata, response, exc, tb):
118
- pprint.pprint({
119
- 'message': 'Unhandled Exception',
120
- 'exception': str(exc),
121
- 'traceback': traceback.format_exc()
122
- })
123
-
@@ -1,48 +0,0 @@
1
- from velocity.misc.format import to_json
2
- import json
3
- import traceback
4
-
5
- class SqsHandler:
6
- def __init__(self, event, context):
7
- self.event = event
8
- self.context = context
9
- self.serve_action_default = True
10
-
11
- def serve(self, tx):
12
- records = self.event.get('Records', [])
13
- print(f"Handling batch of {len(records)} records from SQS")
14
- for record in records:
15
- print(f"Start MessageId {record.get('messageId')}")
16
- attrs = record.get('attributes')
17
- try:
18
- postdata = {}
19
- if record.get('body'):
20
- postdata = json.loads(record.get('body'))
21
- if hasattr(self, 'beforeAction'):
22
- self.beforeAction(attrs=attrs, postdata=postdata)
23
- actions = []
24
- action = postdata.get('action')
25
- if action:
26
- actions.append(
27
- f"on action {action.replace('-', ' ').replace('_', ' ')}"
28
- .title().replace(' ', ''))
29
- if self.serve_action_default:
30
- actions.append('OnActionDefault')
31
- for action in actions:
32
- if hasattr(self, action):
33
- getattr(self, action)(attrs=attrs, postdata=postdata)
34
- break
35
- if hasattr(self, 'afterAction'):
36
- self.afterAction(attrs=attrs, postdata=postdata)
37
- except Exception as e:
38
- if hasattr(self, 'onError'):
39
- self.onError(attrs=attrs,
40
- postdata=postdata,
41
- exc=e,
42
- tb=traceback.format_exc())
43
-
44
- def OnActionDefault(self, tx, attrs, postdata):
45
- print(
46
- "Action handler not found. Calling default action `SqsHandler.OnActionDefault` with the following parameters for tx, attrs, and postdata:"
47
- )
48
- print({'tx': tx, 'attrs': attrs, 'postdata': postdata})
File without changes
@@ -1,12 +1,12 @@
1
1
  import os
2
2
  import requests
3
3
 
4
- from velocity.aws.handlers import LambdaHandler
5
- from velocity.aws.handlers import SqsHandler
6
-
7
4
  DEBUG = (os.environ.get('ENV') != 'production') \
8
5
  or (os.environ.get('DEBUG') == 'Y')
9
6
 
7
+ from velocity.aws.handlers import LambdaHandler
8
+ from velocity.aws.handlers import SqsHandler
9
+
10
10
  # This is helpful for running HTTPS clients on lambda.
11
11
  if os.path.exists('/opt/python/ca-certificates.crt'):
12
12
  os.environ["REQUESTS_CA_BUNDLE"] = '/opt/python/ca-certificates.crt'