tiferet 1.0.0a9__py3-none-any.whl → 1.0.0a11__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.
- tiferet/__init__.py +5 -1
- tiferet/contexts/__init__.py +7 -2
- tiferet/contexts/app.py +6 -6
- tiferet/contexts/container.py +19 -3
- tiferet/contexts/error.py +8 -9
- tiferet/contexts/feature.py +24 -1
- {tiferet-1.0.0a9.dist-info → tiferet-1.0.0a11.dist-info}/METADATA +4 -1
- {tiferet-1.0.0a9.dist-info → tiferet-1.0.0a11.dist-info}/RECORD +11 -11
- {tiferet-1.0.0a9.dist-info → tiferet-1.0.0a11.dist-info}/LICENSE +0 -0
- {tiferet-1.0.0a9.dist-info → tiferet-1.0.0a11.dist-info}/WHEEL +0 -0
- {tiferet-1.0.0a9.dist-info → tiferet-1.0.0a11.dist-info}/top_level.txt +0 -0
tiferet/__init__.py
CHANGED
tiferet/contexts/__init__.py
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# *** imports
|
2
|
+
|
3
|
+
# ** app
|
1
4
|
from .app import AppInterfaceContext
|
2
|
-
from .
|
3
|
-
from .error import ErrorContext
|
5
|
+
from .container import ContainerContext
|
6
|
+
from .error import ErrorContext
|
7
|
+
from .feature import FeatureContext
|
8
|
+
from .request import RequestContext
|
tiferet/contexts/app.py
CHANGED
@@ -118,7 +118,7 @@ class AppInterfaceContext(Model):
|
|
118
118
|
import json
|
119
119
|
|
120
120
|
# Return the response.
|
121
|
-
return json.loads(request.result)
|
121
|
+
return json.loads(request.result) if request.result else ''
|
122
122
|
|
123
123
|
# * method: run
|
124
124
|
def run(self, **kwargs):
|
@@ -134,11 +134,11 @@ class AppInterfaceContext(Model):
|
|
134
134
|
|
135
135
|
# Execute feature context and return session.
|
136
136
|
# Handle error and return response if triggered.
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
return
|
137
|
+
try:
|
138
|
+
self.execute_feature(request, **kwargs)
|
139
|
+
except Exception as e:
|
140
|
+
print('Error:', e)
|
141
|
+
return self.errors.handle_error(e)
|
142
142
|
|
143
143
|
# Handle response.
|
144
144
|
return self.handle_response(request)
|
tiferet/contexts/container.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# *** imports
|
2
2
|
|
3
3
|
# ** core
|
4
|
+
import os
|
4
5
|
from typing import Any
|
5
6
|
|
6
7
|
# ** app
|
@@ -78,11 +79,15 @@ class ContainerContext(Model):
|
|
78
79
|
:type data_flag: str
|
79
80
|
'''
|
80
81
|
|
81
|
-
# Add the attributes as
|
82
|
+
# Add the attributes and constants as empty dictionaries.
|
82
83
|
attributes = {}
|
84
|
+
constants = {}
|
83
85
|
|
84
86
|
# Get and set attributes and constants.
|
85
87
|
attrs, consts = container_repo.list_all()
|
88
|
+
|
89
|
+
# Parse the constants.
|
90
|
+
constants.update({key: self.parse_parameter(consts[key]) for key in consts})
|
86
91
|
|
87
92
|
# Add the attributes to the context.
|
88
93
|
for attr in attrs:
|
@@ -99,7 +104,7 @@ class ContainerContext(Model):
|
|
99
104
|
# Add any parameters as constants.
|
100
105
|
for dep in attr.dependencies:
|
101
106
|
for key in dep.parameters:
|
102
|
-
|
107
|
+
constants[key] = self.parse_parameter(dep.parameters[key])
|
103
108
|
|
104
109
|
# Add the constants and attributes to the context.
|
105
110
|
super().__init__(dict(
|
@@ -107,9 +112,20 @@ class ContainerContext(Model):
|
|
107
112
|
feature_flag=feature_flag,
|
108
113
|
data_flag=data_flag,
|
109
114
|
attributes=attributes,
|
110
|
-
constants=
|
115
|
+
constants=constants,
|
111
116
|
))
|
112
117
|
|
118
|
+
|
119
|
+
# * method: parse_environment_parameter
|
120
|
+
def parse_parameter(self, parameter: str) -> str:
|
121
|
+
|
122
|
+
# If the parameter is an environment variable, get the value.
|
123
|
+
if parameter.startswith('$env.'):
|
124
|
+
return os.getenv(parameter[5:])
|
125
|
+
|
126
|
+
# Otherwise, return the parameter.
|
127
|
+
return parameter
|
128
|
+
|
113
129
|
# * method: get_dependency
|
114
130
|
def get_dependency(self, attribute_id: str):
|
115
131
|
'''
|
tiferet/contexts/error.py
CHANGED
@@ -42,25 +42,24 @@ class ErrorContext(Model):
|
|
42
42
|
self.validate()
|
43
43
|
|
44
44
|
# * method: handle_error
|
45
|
-
def handle_error(self,
|
45
|
+
def handle_error(self, exception: Exception, lang: str = 'en_US', **kwargs) -> Tuple[bool, Any]:
|
46
46
|
'''
|
47
47
|
Handle an error.
|
48
48
|
|
49
|
-
:param
|
50
|
-
:type
|
49
|
+
:param exception: The exception to handle.
|
50
|
+
:type exception: Exception
|
51
|
+
:param lang: The language to use for the error message.
|
52
|
+
:type lang: str
|
51
53
|
:return: Whether the error was handled.
|
52
54
|
:rtype: bool
|
53
55
|
'''
|
54
56
|
|
55
57
|
# Execute the feature function and handle the errors.
|
56
|
-
|
57
|
-
|
58
|
-
return (False, None)
|
59
|
-
except AssertionError as e:
|
60
|
-
return (True, self.format_error_response(str(e)))
|
58
|
+
if isinstance(exception, AssertionError):
|
59
|
+
return self.format_error_response(str(exception), lang, **kwargs)
|
61
60
|
|
62
61
|
# * method: format_error_response
|
63
|
-
def format_error_response(self, error_message: str, lang: str
|
62
|
+
def format_error_response(self, error_message: str, lang: str, **kwargs) -> Any:
|
64
63
|
'''
|
65
64
|
Format the error response.
|
66
65
|
|
tiferet/contexts/feature.py
CHANGED
@@ -51,6 +51,20 @@ class FeatureContext(Model):
|
|
51
51
|
features=features,
|
52
52
|
))
|
53
53
|
self.container = container_context
|
54
|
+
|
55
|
+
# * method: parse_parameter
|
56
|
+
def parse_parameter(self, parameter: str) -> str:
|
57
|
+
'''
|
58
|
+
Parse a parameter.
|
59
|
+
|
60
|
+
:param parameter: The parameter to parse.
|
61
|
+
:type parameter: str
|
62
|
+
:return: The parsed parameter.
|
63
|
+
:rtype: str
|
64
|
+
'''
|
65
|
+
|
66
|
+
# Parse the parameter.
|
67
|
+
return self.container.parse_parameter(parameter)
|
54
68
|
|
55
69
|
# * method: execute
|
56
70
|
def execute(self, request: RequestContext, debug: bool = False, **kwargs):
|
@@ -71,12 +85,21 @@ class FeatureContext(Model):
|
|
71
85
|
# Get the feature command handler instance.
|
72
86
|
handler = self.container.get_dependency(command.attribute_id)
|
73
87
|
|
88
|
+
# Parse the command parameters
|
89
|
+
params = {
|
90
|
+
param:
|
91
|
+
self.parse_parameter(
|
92
|
+
command.params.get(param)
|
93
|
+
)
|
94
|
+
for param in command.params
|
95
|
+
}
|
96
|
+
|
74
97
|
# Execute the handler function.
|
75
98
|
# Handle assertion errors if pass on error is not set.
|
76
99
|
try:
|
77
100
|
result = handler.execute(
|
78
101
|
**request.data,
|
79
|
-
**
|
102
|
+
**params,
|
80
103
|
debug=debug,
|
81
104
|
**kwargs)
|
82
105
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: tiferet
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.0a11
|
4
4
|
Summary: A multi-purpose application framework embodying beauty in form.
|
5
5
|
Home-page: https://github.com/greatstrength/app
|
6
6
|
Download-URL: https://github.com/greatstrength/app
|
@@ -11,3 +11,6 @@ License-File: LICENSE
|
|
11
11
|
Requires-Dist: schematics>=2.1.1
|
12
12
|
Requires-Dist: pyyaml>=6.0.1
|
13
13
|
Requires-Dist: dependencies>=7.7.0
|
14
|
+
Provides-Extra: test
|
15
|
+
Requires-Dist: pytest>=8.3.3; extra == "test"
|
16
|
+
Requires-Dist: pytest_env>=1.1.5; extra == "test"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
tiferet/__init__.py,sha256=
|
1
|
+
tiferet/__init__.py,sha256=1CDYADhNKmHqE4yYf7RgcQcNQm34FTRR2w4WTzbm2Rk,70
|
2
2
|
tiferet/clients/__init__.py,sha256=hSa_PgXM2jw9iVRrJH_SQUlSVISK-T4tTfgRKnXKkzA,33
|
3
3
|
tiferet/clients/yaml.py,sha256=790LB7CpaMow_Ng8zB6jGmJnoqz8xjMYbfDLeMd4o3Q,2816
|
4
4
|
tiferet/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -6,11 +6,11 @@ tiferet/commands/container.py,sha256=L2IKJqEbRglw_LC144oYAkARr2Rixj8IFuC6Ro1jAqA
|
|
6
6
|
tiferet/commands/error.py,sha256=ixMYH0yrEWlMAVGDSRke3IGoWaOShfmiXntrUC2b3wY,573
|
7
7
|
tiferet/commands/feature.py,sha256=tXa-MDf14ByIJqwQFeSUu2QLUjHPdsyvFNhj1XeaQVk,2507
|
8
8
|
tiferet/configs/__init__.py,sha256=NfT6XFNcJznOLXjMuNmj3XeaOPVWwbc-N4kVWaVjuD0,845
|
9
|
-
tiferet/contexts/__init__.py,sha256=
|
10
|
-
tiferet/contexts/app.py,sha256=
|
11
|
-
tiferet/contexts/container.py,sha256=
|
12
|
-
tiferet/contexts/error.py,sha256=
|
13
|
-
tiferet/contexts/feature.py,sha256=
|
9
|
+
tiferet/contexts/__init__.py,sha256=HjI-9n29mFxN6ILSa3LBhLSVPRe-1V36ffQXSP9RavM,204
|
10
|
+
tiferet/contexts/app.py,sha256=9VxWliIX_Y0Y8CZXQzYLgzN89MabkFzkW2e7-3P5KrQ,3781
|
11
|
+
tiferet/contexts/container.py,sha256=qQzrAxGoq5yNqijMnVzE2wVwKprBmEVgiaBunnNcMd8,5704
|
12
|
+
tiferet/contexts/error.py,sha256=mS72JU7rlxs9yEeDj5ZW3DuJftYqmkyp8DOhzNUwtMw,2562
|
13
|
+
tiferet/contexts/feature.py,sha256=CnfgvYvApjkOa2fpZw9Vz6a7fsmiVx7mXaeZT2g9HGc,3589
|
14
14
|
tiferet/contexts/request.py,sha256=EwTyXVYi8z1t1ns_0yDrjY6qICIMPn1UvZpV7ULKReY,2756
|
15
15
|
tiferet/data/__init__.py,sha256=JKaeCw508WY15-etqdFJxPUUJxMxCAi6ASmA472D1_s,93
|
16
16
|
tiferet/data/app.py,sha256=TWWwP0MDpQ-LSKg9166CyPSeI7jjcklIfwBlLW_rT5c,9619
|
@@ -31,8 +31,8 @@ tiferet/repos/feature.py,sha256=GxOV8XHNwz9YY3I8Wch6GaDskvkdi8l1hM9E9fCg1y0,3644
|
|
31
31
|
tiferet/services/__init__.py,sha256=zB5elAFApNH435JLExPmWxvBmZcCtbAyai-KawUjr4E,101
|
32
32
|
tiferet/services/app.py,sha256=92GvC-Vh8FDZoYMLdgzQ3iS1TVL4uyIErk7NJ4rpYPI,1462
|
33
33
|
tiferet/services/container.py,sha256=ISJhkiNLV--nHbAv6Ajd3ug1cGiyazZoePJOCJu5n_s,1130
|
34
|
-
tiferet-1.0.
|
35
|
-
tiferet-1.0.
|
36
|
-
tiferet-1.0.
|
37
|
-
tiferet-1.0.
|
38
|
-
tiferet-1.0.
|
34
|
+
tiferet-1.0.0a11.dist-info/LICENSE,sha256=e8_GutFM0sxbRlgUaeVsGvJ5uE-KvruLApOzIoHy_zU,1513
|
35
|
+
tiferet-1.0.0a11.dist-info/METADATA,sha256=E1LI8jIwaqNUYA7rDRg-Sj7qeLwZ0voMKFZlS9hCtVU,536
|
36
|
+
tiferet-1.0.0a11.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
37
|
+
tiferet-1.0.0a11.dist-info/top_level.txt,sha256=g19Qw0j_VxPw-fgPF1TMPwbtHjnEhNQs0fa69wJZ6IM,8
|
38
|
+
tiferet-1.0.0a11.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|