py4web-debug-tools 0.1.2__tar.gz → 0.2.0.dev0__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.
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/PKG-INFO +1 -1
- py4web-debug-tools-0.2.0.dev0/py4web_debug/core.py +64 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/internals.py +46 -40
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/PKG-INFO +1 -1
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/setup.py +1 -1
- py4web-debug-tools-0.1.2/py4web_debug/core.py +0 -50
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/README.md +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/__init__.py +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/debugbar.py +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/dumping.py +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/env.py +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/debugbar.html +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/dumpdie.html +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/error_default.html +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/fancy_dumpdie.html +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/SOURCES.txt +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/dependency_links.txt +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/requires.txt +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/top_level.txt +0 -0
- {py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/setup.cfg +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Transforms janky 'internals' into easy to work with tool
|
|
2
|
+
import os
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from py4web import DAL as P4WDAL
|
|
6
|
+
|
|
7
|
+
from .debugbar import DummyDebugBar, DebugBar
|
|
8
|
+
from .env import is_debug
|
|
9
|
+
from .internals import patch_py4
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DebugTools:
|
|
13
|
+
# by default, it is not enabled! This is so you can still import it on production,
|
|
14
|
+
# but don't actually show any debug info. enable(on_off) can be called with e.g. an ENV variable
|
|
15
|
+
enabled = False
|
|
16
|
+
db: P4WDAL
|
|
17
|
+
debug_bar = DummyDebugBar()
|
|
18
|
+
IS_DEBUG: bool = is_debug()
|
|
19
|
+
|
|
20
|
+
def enable(
|
|
21
|
+
self,
|
|
22
|
+
# general settings:
|
|
23
|
+
db: P4WDAL,
|
|
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,
|
|
36
|
+
):
|
|
37
|
+
"""
|
|
38
|
+
By default, on_off looks at PY4WEB_DEBUG_MODE in the env
|
|
39
|
+
|
|
40
|
+
@todo: debugbar style (bootstrap/default, bulma, ...)
|
|
41
|
+
"""
|
|
42
|
+
if enabled is None:
|
|
43
|
+
enabled = is_debug()
|
|
44
|
+
|
|
45
|
+
self.db = db
|
|
46
|
+
self.enabled = enabled
|
|
47
|
+
|
|
48
|
+
self.IS_DEBUG = enabled
|
|
49
|
+
if enabled:
|
|
50
|
+
if errorpage_enabled in (True, None):
|
|
51
|
+
patch_py4(errorpage_renderer)
|
|
52
|
+
|
|
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"
|
|
59
|
+
else:
|
|
60
|
+
self.debug_bar = DummyDebugBar()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
tools = DebugTools()
|
|
64
|
+
|
|
@@ -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
|
|
@@ -7,7 +7,7 @@ dependencies = ["py4web", "yatl", "pydal", "configurable-json"]
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="py4web-debug-tools",
|
|
10
|
-
version="0.
|
|
10
|
+
version="0.2.0-dev",
|
|
11
11
|
description="Debug Tools for py4web",
|
|
12
12
|
author="Robin van der Noord",
|
|
13
13
|
author_email="contact@trialandsuccess.nl",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Transforms janky 'internals' into easy to work with tool
|
|
2
|
-
import os
|
|
3
|
-
import typing
|
|
4
|
-
|
|
5
|
-
from py4web import DAL as P4WDAL
|
|
6
|
-
|
|
7
|
-
from .debugbar import DummyDebugBar, DebugBar
|
|
8
|
-
from .env import is_debug
|
|
9
|
-
from .internals import patch_py4
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DebugTools:
|
|
13
|
-
# by default, it is not enabled! This is so you can still import it on production,
|
|
14
|
-
# but don't actually show any debug info. enable(on_off) can be called with e.g. an ENV variable
|
|
15
|
-
enabled = False
|
|
16
|
-
db: P4WDAL
|
|
17
|
-
debug_bar = DummyDebugBar()
|
|
18
|
-
IS_DEBUG: bool = is_debug()
|
|
19
|
-
|
|
20
|
-
def enable(
|
|
21
|
-
self,
|
|
22
|
-
db: P4WDAL,
|
|
23
|
-
enabled: bool | None = None,
|
|
24
|
-
fancy_rendering=True,
|
|
25
|
-
bar_style: typing.Literal["bootstrap"] = "bootstrap",
|
|
26
|
-
slow_threshold_ms=10,
|
|
27
|
-
):
|
|
28
|
-
"""
|
|
29
|
-
By default, on_off looks at PY4WEB_DEBUG_MODE in the env
|
|
30
|
-
|
|
31
|
-
@todo: debugbar style (bootstrap/default, bulma, ...)
|
|
32
|
-
"""
|
|
33
|
-
if enabled is None:
|
|
34
|
-
enabled = is_debug()
|
|
35
|
-
|
|
36
|
-
self.db = db
|
|
37
|
-
self.enabled = enabled
|
|
38
|
-
|
|
39
|
-
self.IS_DEBUG = enabled
|
|
40
|
-
if enabled:
|
|
41
|
-
patch_py4()
|
|
42
|
-
self.debug_bar = DebugBar(db, fancy_rendering, bar_style, slow_threshold_ms)
|
|
43
|
-
|
|
44
|
-
# will change the result of is_debug (hopefully)
|
|
45
|
-
os.environ["PY4WEB_DEBUG_MODE"] = "1"
|
|
46
|
-
else:
|
|
47
|
-
self.debug_bar = DummyDebugBar()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
tools = DebugTools()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/debugbar.html
RENAMED
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/dumpdie.html
RENAMED
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/error_default.html
RENAMED
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug/templates/fancy_dumpdie.html
RENAMED
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/requires.txt
RENAMED
|
File without changes
|
{py4web-debug-tools-0.1.2 → py4web-debug-tools-0.2.0.dev0}/py4web_debug_tools.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|