py4web-debug-tools 0.1.2__py3-none-any.whl → 0.2.0.dev0__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.
- py4web_debug/core.py +22 -8
- py4web_debug/internals.py +46 -40
- {py4web_debug_tools-0.1.2.dist-info → py4web_debug_tools-0.2.0.dev0.dist-info}/METADATA +1 -1
- {py4web_debug_tools-0.1.2.dist-info → py4web_debug_tools-0.2.0.dev0.dist-info}/RECORD +6 -6
- {py4web_debug_tools-0.1.2.dist-info → py4web_debug_tools-0.2.0.dev0.dist-info}/WHEEL +0 -0
- {py4web_debug_tools-0.1.2.dist-info → py4web_debug_tools-0.2.0.dev0.dist-info}/top_level.txt +0 -0
py4web_debug/core.py
CHANGED
|
@@ -19,11 +19,20 @@ class DebugTools:
|
|
|
19
19
|
|
|
20
20
|
def enable(
|
|
21
21
|
self,
|
|
22
|
+
# general settings:
|
|
22
23
|
db: P4WDAL,
|
|
23
|
-
enabled: bool | None = None,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
enabled: bool | None = None, # OVERWRITES errorpage_enabled and debugbar_enabled
|
|
25
|
+
set_env_var: bool = True,
|
|
26
|
+
|
|
27
|
+
# error screen settings:
|
|
28
|
+
errorpage_enabled: bool = None, # value of 'enabled' is used by default
|
|
29
|
+
errorpage_renderer: typing.Callable = None,
|
|
30
|
+
|
|
31
|
+
# debugbar settings:
|
|
32
|
+
debugbar_enabled: bool = None, # value of 'enabled' is used by default
|
|
33
|
+
debugbar_fancy_rendering: bool = True,
|
|
34
|
+
debugbar_style: typing.Literal["bootstrap"] = "bootstrap",
|
|
35
|
+
debugbar_slow_threshold_ms: int = 10,
|
|
27
36
|
):
|
|
28
37
|
"""
|
|
29
38
|
By default, on_off looks at PY4WEB_DEBUG_MODE in the env
|
|
@@ -38,13 +47,18 @@ class DebugTools:
|
|
|
38
47
|
|
|
39
48
|
self.IS_DEBUG = enabled
|
|
40
49
|
if enabled:
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
if errorpage_enabled in (True, None):
|
|
51
|
+
patch_py4(errorpage_renderer)
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
if debugbar_enabled in (True, None):
|
|
54
|
+
self.debug_bar = DebugBar(db, debugbar_fancy_rendering, debugbar_style, debugbar_slow_threshold_ms)
|
|
55
|
+
|
|
56
|
+
if set_env_var:
|
|
57
|
+
# will change the result of is_debug (hopefully)
|
|
58
|
+
os.environ["PY4WEB_DEBUG_MODE"] = "1"
|
|
46
59
|
else:
|
|
47
60
|
self.debug_bar = DummyDebugBar()
|
|
48
61
|
|
|
49
62
|
|
|
50
63
|
tools = DebugTools()
|
|
64
|
+
|
py4web_debug/internals.py
CHANGED
|
@@ -30,6 +30,8 @@ def custom_error_page(
|
|
|
30
30
|
traceback="",
|
|
31
31
|
err_type: str | typing.Type | None = None,
|
|
32
32
|
bare_exception=None,
|
|
33
|
+
|
|
34
|
+
renderer=None
|
|
33
35
|
):
|
|
34
36
|
if err_type and not isinstance(err_type, str):
|
|
35
37
|
err_type = err_type.__name__
|
|
@@ -64,6 +66,9 @@ def custom_error_page(
|
|
|
64
66
|
return json.dumps(context)
|
|
65
67
|
# else - return html error-page
|
|
66
68
|
|
|
69
|
+
if renderer:
|
|
70
|
+
return renderer(context)
|
|
71
|
+
|
|
67
72
|
templates = {
|
|
68
73
|
"default": "error_default.html",
|
|
69
74
|
"DumpDieError": "dumpdie.html",
|
|
@@ -88,44 +93,45 @@ def custom_error_page(
|
|
|
88
93
|
)
|
|
89
94
|
|
|
90
95
|
|
|
91
|
-
def
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
96
|
+
def patch_py4(renderer=None):
|
|
97
|
+
def custom_catch_errors(app_name, func):
|
|
98
|
+
"""Catches and logs errors in an action; also sets request.app_name"""
|
|
99
|
+
|
|
100
|
+
@functools.wraps(func)
|
|
101
|
+
def wrapper(*func_args, **func_kwargs):
|
|
102
|
+
try:
|
|
103
|
+
request.app_name = app_name
|
|
104
|
+
ret = func(*func_args, **func_kwargs)
|
|
105
|
+
if isinstance(ret, dict):
|
|
106
|
+
response.headers["Content-Type"] = "application/json"
|
|
107
|
+
ret = dumps(ret)
|
|
108
|
+
return ret
|
|
109
|
+
except HTTP as http:
|
|
110
|
+
response.status = http.status
|
|
111
|
+
response.headers.update(http.headers)
|
|
112
|
+
return http.body
|
|
113
|
+
except bottle.HTTPResponse:
|
|
114
|
+
raise
|
|
115
|
+
except Exception as e:
|
|
116
|
+
snapshot = get_error_snapshot()
|
|
117
|
+
logging.error(snapshot["traceback"])
|
|
118
|
+
ticket_uuid = error_logger.log(request.app_name, snapshot) or "unknown"
|
|
119
|
+
response.status = 500
|
|
120
|
+
|
|
121
|
+
raise bottle.HTTPResponse(
|
|
122
|
+
body=custom_error_page(
|
|
123
|
+
500,
|
|
124
|
+
button_text=ticket_uuid,
|
|
125
|
+
href="/_dashboard/ticket/" + ticket_uuid,
|
|
126
|
+
traceback=traceback.format_exc(),
|
|
127
|
+
err_type=type(e),
|
|
128
|
+
bare_exception=e,
|
|
129
|
+
|
|
130
|
+
renderer=renderer
|
|
131
|
+
),
|
|
132
|
+
status=500,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return wrapper
|
|
136
|
+
|
|
131
137
|
action.catch_errors = custom_catch_errors
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
py4web_debug/__init__.py,sha256=OC9yuI3jIBjwi7KGL4uUNtQbyuzZcq913z31gfgSK7s,108
|
|
2
|
-
py4web_debug/core.py,sha256=
|
|
2
|
+
py4web_debug/core.py,sha256=Vydfzbiv0USgdrT_4hB6OtkXd3lNQOFTNRboI1sxejQ,1989
|
|
3
3
|
py4web_debug/debugbar.py,sha256=bzuJ4FX_bYzz0-V8f9A1bjkEmLbj8q00CAerCAu3aMs,7243
|
|
4
4
|
py4web_debug/dumping.py,sha256=AF4UVSyqI43JgxffjeoozQ0az0J5nvpeZVYtWuUlC6s,3496
|
|
5
5
|
py4web_debug/env.py,sha256=CXJX6nmNgGYL0Z9rt8fmQPO1UAydhW-Cv-zWObPlleQ,82
|
|
6
|
-
py4web_debug/internals.py,sha256=
|
|
6
|
+
py4web_debug/internals.py,sha256=J8pmil-GzxT2BPs4QSoVos5k27vFIi8nGfujTIX90U0,3844
|
|
7
7
|
py4web_debug/templates/debugbar.html,sha256=gbaBLBJpDIti9QAkDWXRP10_LEvCrQmK1GxFlbsHasA,7169
|
|
8
8
|
py4web_debug/templates/dumpdie.html,sha256=pFjRjs2VBZPo1nyfObCO5kksyQS9q-K4EqPdZNFo9lg,60
|
|
9
9
|
py4web_debug/templates/error_default.html,sha256=OGMvbHWb7xX91GH5Kx9WPXqv93ee7UcII5B-nUu3TYk,868
|
|
10
10
|
py4web_debug/templates/fancy_dumpdie.html,sha256=eaquCyAOM1QU3QMv__fIqgbmyFHOnwd495PMGMVOzo8,532
|
|
11
|
-
py4web_debug_tools-0.
|
|
12
|
-
py4web_debug_tools-0.
|
|
13
|
-
py4web_debug_tools-0.
|
|
14
|
-
py4web_debug_tools-0.
|
|
11
|
+
py4web_debug_tools-0.2.0.dev0.dist-info/METADATA,sha256=j3kOMOtXp9ftrCYPhqw1NJ4Lwgj7xcy6qn7Upv0V1JA,2627
|
|
12
|
+
py4web_debug_tools-0.2.0.dev0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
13
|
+
py4web_debug_tools-0.2.0.dev0.dist-info/top_level.txt,sha256=sZikb7uiewpax6SbMw-PL1La6xqDq8ZUbN7J9kFKodA,13
|
|
14
|
+
py4web_debug_tools-0.2.0.dev0.dist-info/RECORD,,
|
|
File without changes
|
{py4web_debug_tools-0.1.2.dist-info → py4web_debug_tools-0.2.0.dev0.dist-info}/top_level.txt
RENAMED
|
File without changes
|