velocity-python 0.0.95__tar.gz → 0.0.97__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 (71) hide show
  1. {velocity_python-0.0.95 → velocity_python-0.0.97}/PKG-INFO +1 -1
  2. {velocity_python-0.0.95 → velocity_python-0.0.97}/pyproject.toml +1 -1
  3. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/__init__.py +1 -1
  4. velocity_python-0.0.97/src/velocity/aws/handlers/sqs_handler.py +224 -0
  5. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity_python.egg-info/PKG-INFO +1 -1
  6. velocity_python-0.0.95/src/velocity/aws/handlers/sqs_handler.py +0 -97
  7. {velocity_python-0.0.95 → velocity_python-0.0.97}/LICENSE +0 -0
  8. {velocity_python-0.0.95 → velocity_python-0.0.97}/README.md +0 -0
  9. {velocity_python-0.0.95 → velocity_python-0.0.97}/setup.cfg +0 -0
  10. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/app/__init__.py +0 -0
  11. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/app/invoices.py +0 -0
  12. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/app/orders.py +0 -0
  13. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/app/payments.py +0 -0
  14. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/app/purchase_orders.py +0 -0
  15. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/aws/__init__.py +0 -0
  16. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/aws/amplify.py +0 -0
  17. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/aws/handlers/__init__.py +0 -0
  18. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/aws/handlers/context.py +0 -0
  19. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/aws/handlers/lambda_handler.py +0 -0
  20. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/aws/handlers/response.py +0 -0
  21. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/__init__.py +0 -0
  22. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/__init__.py +0 -0
  23. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/column.py +0 -0
  24. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/database.py +0 -0
  25. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/decorators.py +0 -0
  26. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/engine.py +0 -0
  27. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/exceptions.py +0 -0
  28. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/result.py +0 -0
  29. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/row.py +0 -0
  30. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/sequence.py +0 -0
  31. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/table.py +0 -0
  32. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/core/transaction.py +0 -0
  33. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/__init__.py +0 -0
  34. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/mysql.py +0 -0
  35. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/mysql_reserved.py +0 -0
  36. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/postgres/__init__.py +0 -0
  37. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/postgres/operators.py +0 -0
  38. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/postgres/reserved.py +0 -0
  39. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/postgres/sql.py +0 -0
  40. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/postgres/types.py +0 -0
  41. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/sqlite.py +0 -0
  42. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/sqlite_reserved.py +0 -0
  43. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/sqlserver.py +0 -0
  44. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/sqlserver_reserved.py +0 -0
  45. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/db/servers/tablehelper.py +0 -0
  46. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/__init__.py +0 -0
  47. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/conv/__init__.py +0 -0
  48. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/conv/iconv.py +0 -0
  49. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/conv/oconv.py +0 -0
  50. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/db.py +0 -0
  51. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/export.py +0 -0
  52. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/format.py +0 -0
  53. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/mail.py +0 -0
  54. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/merge.py +0 -0
  55. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/timer.py +0 -0
  56. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity/misc/tools.py +0 -0
  57. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity_python.egg-info/SOURCES.txt +0 -0
  58. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity_python.egg-info/dependency_links.txt +0 -0
  59. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity_python.egg-info/requires.txt +0 -0
  60. {velocity_python-0.0.95 → velocity_python-0.0.97}/src/velocity_python.egg-info/top_level.txt +0 -0
  61. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_db.py +0 -0
  62. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_email_processing.py +0 -0
  63. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_format.py +0 -0
  64. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_iconv.py +0 -0
  65. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_merge.py +0 -0
  66. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_oconv.py +0 -0
  67. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_postgres.py +0 -0
  68. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_response.py +0 -0
  69. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_spreadsheet_functions.py +0 -0
  70. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_sql_builder.py +0 -0
  71. {velocity_python-0.0.95 → velocity_python-0.0.97}/tests/test_timer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: velocity-python
3
- Version: 0.0.95
3
+ Version: 0.0.97
4
4
  Summary: A rapid application development library for interfacing with data storage
5
5
  Author-email: Velocity Team <contact@example.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "velocity-python"
7
- version = "0.0.95"
7
+ version = "0.0.97"
8
8
  authors = [
9
9
  { name="Velocity Team", email="contact@example.com" },
10
10
  ]
@@ -1,4 +1,4 @@
1
- __version__ = version = "0.0.95"
1
+ __version__ = version = "0.0.97"
2
2
 
3
3
  from . import aws
4
4
  from . import db
@@ -0,0 +1,224 @@
1
+ """
2
+ SQS Handler Module
3
+
4
+ This module provides a base class for handling AWS SQS events in Lambda functions.
5
+ It includes logging capabilities, action routing, and error handling.
6
+ """
7
+
8
+ import json
9
+ import os
10
+ import sys
11
+ import traceback
12
+ from typing import Any, Dict, Optional
13
+
14
+ from velocity.aws import DEBUG
15
+ from velocity.aws.handlers import context as VelocityContext
16
+ from velocity.misc.format import to_json
17
+
18
+
19
+ class SqsHandler:
20
+ """
21
+ Base class for handling SQS events in AWS Lambda functions.
22
+
23
+ Provides structured processing of SQS records with automatic action routing,
24
+ logging capabilities, and error handling hooks.
25
+ """
26
+
27
+ def __init__(self, aws_event: Dict[str, Any], aws_context: Any,
28
+ context_class=VelocityContext.Context):
29
+ """
30
+ Initialize the SQS handler.
31
+
32
+ Args:
33
+ aws_event: The AWS Lambda event containing SQS records
34
+ aws_context: The AWS Lambda context object
35
+ context_class: The context class to use for processing
36
+ """
37
+ self.aws_event = aws_event
38
+ self.aws_context = aws_context
39
+ self.serve_action_default = True
40
+ self.skip_action = False
41
+ self.ContextClass = context_class
42
+
43
+ def log(self, tx, message: str, function: Optional[str] = None):
44
+ """
45
+ Log a message to the system log table.
46
+
47
+ Args:
48
+ tx: Database transaction object
49
+ message: The message to log
50
+ function: Optional function name, auto-detected if not provided
51
+ """
52
+ if not function:
53
+ function = self._get_calling_function()
54
+
55
+ data = {
56
+ "app_name": os.environ.get("ProjectName", "Unknown"),
57
+ "referer": "SQS",
58
+ "user_agent": "QueueHandler",
59
+ "device_type": "Lambda",
60
+ "function": function,
61
+ "message": message,
62
+ "sys_modified_by": "Lambda:BackOfficeQueueHandler",
63
+ }
64
+ tx.table("sys_log").insert(data)
65
+
66
+ def _get_calling_function(self) -> str:
67
+ """
68
+ Get the name of the calling function by inspecting the call stack.
69
+
70
+ Returns:
71
+ The name of the calling function or "<Unknown>" if not found
72
+ """
73
+ skip_functions = {"x", "log", "_transaction", "_get_calling_function"}
74
+
75
+ for idx in range(10): # Limit search to prevent infinite loops
76
+ try:
77
+ frame = sys._getframe(idx)
78
+ function_name = frame.f_code.co_name
79
+
80
+ if function_name not in skip_functions:
81
+ return function_name
82
+
83
+ except ValueError:
84
+ # No more frames in the stack
85
+ break
86
+
87
+ return "<Unknown>"
88
+
89
+ def serve(self, tx):
90
+ """
91
+ Process all SQS records in the event.
92
+
93
+ Args:
94
+ tx: Database transaction object
95
+ """
96
+ records = self.aws_event.get("Records", [])
97
+
98
+ for record in records:
99
+ self._process_record(tx, record)
100
+
101
+ def _process_record(self, tx, record: Dict[str, Any]):
102
+ """
103
+ Process a single SQS record.
104
+
105
+ Args:
106
+ tx: Database transaction object
107
+ record: Individual SQS record to process
108
+ """
109
+ attrs = record.get("attributes", {})
110
+ postdata = {}
111
+
112
+ # Parse message body if present
113
+ body = record.get("body")
114
+ if body:
115
+ try:
116
+ postdata = json.loads(body)
117
+ except json.JSONDecodeError as e:
118
+ print(f"Failed to parse SQS message body as JSON: {e}")
119
+ postdata = {"raw_body": body}
120
+
121
+ # Create local context for this record
122
+ local_context = self.ContextClass(
123
+ aws_event=self.aws_event,
124
+ aws_context=self.aws_context,
125
+ args=attrs,
126
+ postdata=postdata,
127
+ response=None,
128
+ session=None,
129
+ )
130
+
131
+ try:
132
+ self._execute_actions(local_context)
133
+ except Exception as e:
134
+ if hasattr(self, "onError"):
135
+ self.onError(
136
+ local_context,
137
+ exc=e.__class__.__name__,
138
+ tb=traceback.format_exc(),
139
+ )
140
+ else:
141
+ # Re-raise if no error handler is defined
142
+ raise
143
+
144
+ def _execute_actions(self, local_context):
145
+ """
146
+ Execute the appropriate actions for the given context.
147
+
148
+ Args:
149
+ local_context: The context object for this record
150
+ """
151
+ # Execute beforeAction hook if available
152
+ if hasattr(self, "beforeAction"):
153
+ self.beforeAction(local_context)
154
+
155
+ # Determine which actions to execute
156
+ actions = self._get_actions_to_execute(local_context)
157
+
158
+ # Execute the first matching action
159
+ for action in actions:
160
+ if self.skip_action:
161
+ return
162
+
163
+ if hasattr(self, action):
164
+ getattr(self, action)(local_context)
165
+ break
166
+
167
+ # Execute afterAction hook if available
168
+ if hasattr(self, "afterAction"):
169
+ self.afterAction(local_context)
170
+
171
+ def _get_actions_to_execute(self, local_context) -> list:
172
+ """
173
+ Get the list of actions to execute for the given context.
174
+
175
+ Args:
176
+ local_context: The context object for this record
177
+
178
+ Returns:
179
+ List of action method names to try executing
180
+ """
181
+ actions = []
182
+
183
+ # Add specific action if available
184
+ action = local_context.action()
185
+ if action:
186
+ action_method = self._format_action_name(action)
187
+ actions.append(action_method)
188
+
189
+ # Add default action if enabled
190
+ if self.serve_action_default:
191
+ actions.append("OnActionDefault")
192
+
193
+ return actions
194
+
195
+ def _format_action_name(self, action: str) -> str:
196
+ """
197
+ Format an action string into a method name.
198
+
199
+ Args:
200
+ action: The raw action string
201
+
202
+ Returns:
203
+ Formatted method name
204
+ """
205
+ formatted = action.replace('-', ' ').replace('_', ' ')
206
+ return f"on action {formatted}".title().replace(" ", "")
207
+
208
+ def OnActionDefault(self, tx, context):
209
+ """
210
+ Default action handler when no specific action is found.
211
+
212
+ Args:
213
+ tx: Database transaction object
214
+ context: The context object for this record
215
+ """
216
+ action = context.action() if hasattr(context, 'action') else 'unknown'
217
+ warning_message = (
218
+ f"[Warn] Action handler not found. Calling default action "
219
+ f"`SqsHandler.OnActionDefault` with the following parameters:\n"
220
+ f" - action: {action}\n"
221
+ f" - attrs: {context.args()}\n"
222
+ f" - postdata: {context.postdata()}"
223
+ )
224
+ print(warning_message)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: velocity-python
3
- Version: 0.0.95
3
+ Version: 0.0.97
4
4
  Summary: A rapid application development library for interfacing with data storage
5
5
  Author-email: Velocity Team <contact@example.com>
6
6
  License: MIT
@@ -1,97 +0,0 @@
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 velocity.aws.handlers import context as VelocityContext
8
-
9
-
10
- class SqsHandler:
11
-
12
- def __init__(self, aws_event, aws_context, context_class=VelocityContext.Context):
13
- self.aws_event = aws_event
14
- self.aws_context = aws_context
15
- self.serve_action_default = True
16
- self.skip_action = False
17
- self.ContextClass = context_class
18
-
19
- def log(self, tx, message, function=None):
20
- if not function:
21
- function = "<Unknown>"
22
- idx = 0
23
- while True:
24
- try:
25
- temp = sys._getframe(idx).f_code.co_name
26
- except ValueError as e:
27
- break
28
- if temp in ["x", "log", "_transaction"]:
29
- idx += 1
30
- continue
31
- function = temp
32
- break
33
-
34
- data = {
35
- "app_name": os.environ["ProjectName"],
36
- "referer": "SQS",
37
- "user_agent": "QueueHandler",
38
- "device_type": "Lambda",
39
- "function": function,
40
- "message": message,
41
- "sys_modified_by": "lambda:BackOfficeQueueHandler",
42
- }
43
- tx.table("sys_log").insert(data)
44
-
45
- def serve(self, tx):
46
- records = self.aws_event.get("Records", [])
47
- for record in records:
48
- attrs = record.get("attributes")
49
- postdata = {}
50
- if record.get("body"):
51
- postdata = json.loads(record.get("body"))
52
-
53
- local_context = self.ContextClass(
54
- aws_event=self.aws_event,
55
- aws_context=self.aws_context,
56
- args=attrs,
57
- postdata=postdata,
58
- response=None,
59
- session=None,
60
- )
61
- try:
62
- if hasattr(self, "beforeAction"):
63
- self.beforeAction(local_context)
64
- actions = []
65
- action = local_context.action()
66
- if action:
67
- actions.append(
68
- f"on action {action.replace('-', ' ').replace('_', ' ')}".title().replace(
69
- " ", ""
70
- )
71
- )
72
- if self.serve_action_default:
73
- actions.append("OnActionDefault")
74
- for action in actions:
75
- if self.skip_action:
76
- return
77
- if hasattr(self, action):
78
- getattr(self, action)(local_context)
79
- break
80
- if hasattr(self, "afterAction"):
81
- self.afterAction(local_context)
82
- except Exception as e:
83
- if hasattr(self, "onError"):
84
- self.onError(
85
- local_context,
86
- exc=e.__class__.__name__,
87
- tb=traceback.format_exc(),
88
- )
89
-
90
- def OnActionDefault(self, tx, context):
91
- print(
92
- f"""
93
- [Warn] Action handler not found. Calling default action `SqsHandler.OnActionDefault` with the following parameters for attrs, and postdata:
94
- attrs: {str(context.args())}
95
- postdata: {str(context.postdata())}
96
- """
97
- )