py4web-debug-tools 1.3.4__tar.gz → 1.4.0__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.
Files changed (23) hide show
  1. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/PKG-INFO +14 -14
  2. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/README.md +1 -3
  3. py4web_debug_tools-1.4.0/pyproject.toml +179 -0
  4. py4web_debug_tools-1.3.4/pyproject.toml → py4web_debug_tools-1.4.0/pyproject.toml.orig +49 -20
  5. py4web_debug_tools-1.4.0/src/py4web_debug/__about__.py +3 -0
  6. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/core.py +2 -1
  7. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/internals.py +11 -1
  8. py4web_debug_tools-1.3.4/.gitignore +0 -8
  9. py4web_debug_tools-1.3.4/CHANGELOG.md +0 -89
  10. py4web_debug_tools-1.3.4/src/py4web_debug/__about__.py +0 -1
  11. py4web_debug_tools-1.3.4/tests/test_dumping.py +0 -120
  12. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/__init__.py +0 -0
  13. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/_internals.py +0 -0
  14. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/debugbar.py +0 -0
  15. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/dumping.py +0 -0
  16. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/env.py +0 -0
  17. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/py.typed +0 -0
  18. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/templates/debugbar.html +0 -0
  19. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/templates/dumpdie.html +0 -0
  20. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/templates/error_default.html +0 -0
  21. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/templates/fancy_dumpdie.html +0 -0
  22. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/types.py +0 -0
  23. {py4web_debug_tools-1.3.4 → py4web_debug_tools-1.4.0}/src/py4web_debug/wsgi.py +0 -0
@@ -1,10 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py4web-debug-tools
3
- Version: 1.3.4
3
+ Version: 1.4.0
4
4
  Summary: Debug Tools for py4web
5
- Project-URL: Documentation, https://github.com/trialandsuccess/py4web-debug-tools#readme
6
- Project-URL: Issues, https://github.com/trialandsuccess/py4web-debug-tools/issues
7
- Project-URL: Source, https://github.com/trialandsuccess/py4web-debug-tools
5
+ Keywords:
6
+ Author: Robin van der Noord
8
7
  Author-email: Robin van der Noord <contact@trialandsuccess.nl>
9
8
  License-Expression: MIT
10
9
  Classifier: Development Status :: 4 - Beta
@@ -12,19 +11,22 @@ Classifier: Programming Language :: Python
12
11
  Classifier: Programming Language :: Python :: 3.10
13
12
  Classifier: Programming Language :: Python :: 3.11
14
13
  Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.14
15
15
  Classifier: Programming Language :: Python :: Implementation :: CPython
16
16
  Classifier: Programming Language :: Python :: Implementation :: PyPy
17
- Requires-Python: >=3.10
18
- Requires-Dist: configurable-json>=1.1
19
17
  Requires-Dist: py4web
18
+ Requires-Dist: yatl
20
19
  Requires-Dist: pydal
20
+ Requires-Dist: configurable-json>=1.1
21
21
  Requires-Dist: typing-extensions
22
- Requires-Dist: yatl
22
+ Requires-Dist: su6[all] ; extra == 'dev'
23
+ Requires-Dist: pytest ; extra == 'dev'
24
+ Requires-Dist: dotmap ; extra == 'dev'
25
+ Requires-Python: >=3.10
26
+ Project-URL: Documentation, https://github.com/trialandsuccess/py4web-debug-tools#readme
27
+ Project-URL: Issues, https://github.com/trialandsuccess/py4web-debug-tools/issues
28
+ Project-URL: Source, https://github.com/trialandsuccess/py4web-debug-tools
23
29
  Provides-Extra: dev
24
- Requires-Dist: dotmap; extra == 'dev'
25
- Requires-Dist: hatch; extra == 'dev'
26
- Requires-Dist: pytest; extra == 'dev'
27
- Requires-Dist: su6[all]; extra == 'dev'
28
30
  Description-Content-Type: text/markdown
29
31
 
30
32
  # py4web debug tools
@@ -109,9 +111,7 @@ You can modify your `py4web_uwsgi.py` file:
109
111
  # yes:
110
112
  from py4web_debug import wsgi
111
113
 
112
- application = wsgi(apps_folder="apps",
113
- password_file='password.txt',
114
- dashboard_mode="full")
114
+ application = wsgi(apps_folder="apps", password_file="password.txt", dashboard_mode="full")
115
115
  ```
116
116
 
117
117
  After this, you can `tools.enable` as before.
@@ -80,9 +80,7 @@ You can modify your `py4web_uwsgi.py` file:
80
80
  # yes:
81
81
  from py4web_debug import wsgi
82
82
 
83
- application = wsgi(apps_folder="apps",
84
- password_file='password.txt',
85
- dashboard_mode="full")
83
+ application = wsgi(apps_folder="apps", password_file="password.txt", dashboard_mode="full")
86
84
  ```
87
85
 
88
86
  After this, you can `tools.enable` as before.
@@ -0,0 +1,179 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.12.4,<0.13"]
3
+ build-backend = "uv_build"
4
+
5
+ [template.plugins.default]
6
+ src-layout = true
7
+
8
+ [tool.setuptools.package-data]
9
+ py4web_debug = ["py.typed"]
10
+
11
+ [tool.uv.build-backend]
12
+ module-name = "py4web_debug"
13
+
14
+ [tool.vommit]
15
+ allow_breaking_bang = true
16
+ allow_breaking_footer = true
17
+ prerelease_token = "beta"
18
+ confirm = true
19
+ ignore = []
20
+
21
+ [tool.vommit.git]
22
+ enabled = true
23
+ origin = "origin"
24
+ branch = "master"
25
+ on_wrong_branch = "error"
26
+ tag_format = "v{version}"
27
+ commit_format = "{version}"
28
+
29
+ [tool.vommit.changelog]
30
+ enabled = true
31
+ file = "CHANGELOG.md"
32
+ include_prereleases = false
33
+ placeholder = "<!--next-version-placeholder-->"
34
+ placeholder_regex = "<auto>"
35
+ entry_title_format = "## v{version} ({date:%Y-%m-%d})"
36
+
37
+ [tool.vommit.changelog.levels]
38
+ feat = "Feature{s}"
39
+ fix = "Fix{es}"
40
+ break = "Breaking Change{s}"
41
+ docs = "Documentation"
42
+ perf = "Performance"
43
+
44
+ [tool.vommit.pypi]
45
+ enabled = true
46
+ use_keyring = true
47
+
48
+ [tool.vommit.commands]
49
+ clean = "rm -rf ./dist"
50
+ build = "uv build"
51
+ publish = "uv publish"
52
+ post_publish = ""
53
+
54
+ [tool.vommit.version_bump_map]
55
+ break = "major"
56
+ feat = "minor"
57
+ fix = "patch"
58
+ perf = "patch"
59
+
60
+ [tool.pytest.ini_options]
61
+ testpaths = ["tests"]
62
+ pythonpath = ["."]
63
+
64
+ [tool.su6]
65
+ directory = "src"
66
+ include = []
67
+ exclude = ["pytest"]
68
+ stop-after-first-failure = true
69
+
70
+ [tool.black]
71
+ target-version = ["py311"]
72
+ line-length = 120
73
+ extend-exclude = '''
74
+ # A regex preceded with ^/ will apply only to files and directories
75
+ # in the root of the project.
76
+ (
77
+ ^.*\.bak\/.+ # ignore every .bak directory
78
+ ^.*venv.+\/.+ # ignore every venv directory
79
+ venv.+|.+\.bak # idk why it suddenly works, let's not touch it
80
+ )
81
+ '''
82
+
83
+ [tool.mypy]
84
+ python_version = "3.11"
85
+ no_implicit_optional = false
86
+ ignore_missing_imports = true
87
+ strict = true
88
+ exclude = [
89
+ "venv",
90
+ ".bak",
91
+ ]
92
+
93
+ [tool.ruff]
94
+ target-version = "py311"
95
+ line-length = 120
96
+ extend-exclude = [
97
+ "*.bak/",
98
+ "venv*/",
99
+ ]
100
+
101
+ [tool.ruff.lint]
102
+ select = [
103
+ "F",
104
+ "E",
105
+ "W",
106
+ "Q",
107
+ "A",
108
+ "SIM",
109
+ "ARG",
110
+ "RUF",
111
+ ]
112
+ unfixable = ["F401"]
113
+ ignore = ["RUF013"]
114
+
115
+ [tool.bandit]
116
+ exclude_dirs = [
117
+ ".bak",
118
+ "venv",
119
+ ]
120
+ skips = ["B108"]
121
+
122
+ [tool.isort]
123
+ profile = "black"
124
+ extend_skip_glob = ["*.bak/*"]
125
+
126
+ [tool.pydocstyle]
127
+ convention = "google"
128
+ match-dir = '(?!venv)[^\.].*'
129
+ add_select = [
130
+ "D213",
131
+ "D416",
132
+ "D417",
133
+ ]
134
+ add_ignore = [
135
+ "D200",
136
+ "D212",
137
+ ]
138
+
139
+ [project]
140
+ name = "py4web-debug-tools"
141
+ description = "Debug Tools for py4web"
142
+ readme = "README.md"
143
+ requires-python = ">=3.10"
144
+ license = "MIT"
145
+ keywords = []
146
+ classifiers = [
147
+ "Development Status :: 4 - Beta",
148
+ "Programming Language :: Python",
149
+ "Programming Language :: Python :: 3.10",
150
+ "Programming Language :: Python :: 3.11",
151
+ "Programming Language :: Python :: 3.12",
152
+ "Programming Language :: Python :: 3.14",
153
+ "Programming Language :: Python :: Implementation :: CPython",
154
+ "Programming Language :: Python :: Implementation :: PyPy",
155
+ ]
156
+ dependencies = [
157
+ "py4web",
158
+ "yatl",
159
+ "pydal",
160
+ "configurable-json >= 1.1",
161
+ "typing-extensions",
162
+ ]
163
+ version = "1.4.0"
164
+
165
+ [[project.authors]]
166
+ name = "Robin van der Noord"
167
+ email = "contact@trialandsuccess.nl"
168
+
169
+ [project.urls]
170
+ Documentation = "https://github.com/trialandsuccess/py4web-debug-tools#readme"
171
+ Issues = "https://github.com/trialandsuccess/py4web-debug-tools/issues"
172
+ Source = "https://github.com/trialandsuccess/py4web-debug-tools"
173
+
174
+ [project.optional-dependencies]
175
+ dev = [
176
+ "su6[all]",
177
+ "pytest",
178
+ "dotmap",
179
+ ]
@@ -1,6 +1,6 @@
1
1
  [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
2
+ requires = ["uv_build>=0.12.4,<0.13"]
3
+ build-backend = "uv_build"
4
4
 
5
5
  [template.plugins.default]
6
6
  src-layout = true
@@ -8,17 +8,11 @@ src-layout = true
8
8
  [tool.setuptools.package-data]
9
9
  "py4web_debug" = ["py.typed"]
10
10
 
11
- [tool.hatch.build.targets.wheel]
12
- packages = ["src/py4web_debug"]
13
-
14
- [tool.hatch.build]
15
- artifacts = [
16
- "src/py4web_debug/templates/*.html"
17
- ]
11
+ [tool.uv.build-backend]
12
+ module-name = "py4web_debug"
18
13
 
19
14
  [project]
20
15
  name = "py4web-debug-tools"
21
- dynamic = ["version"]
22
16
  description = 'Debug Tools for py4web'
23
17
  readme = "README.md"
24
18
  requires-python = ">=3.10"
@@ -33,6 +27,7 @@ classifiers = [
33
27
  "Programming Language :: Python :: 3.10",
34
28
  "Programming Language :: Python :: 3.11",
35
29
  "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.14",
36
31
  "Programming Language :: Python :: Implementation :: CPython",
37
32
  "Programming Language :: Python :: Implementation :: PyPy",
38
33
  ]
@@ -43,6 +38,7 @@ dependencies = [
43
38
  "configurable-json >= 1.1",
44
39
  "typing-extensions",
45
40
  ]
41
+ version = "1.4.0"
46
42
 
47
43
 
48
44
  [project.urls]
@@ -53,23 +49,56 @@ Source = "https://github.com/trialandsuccess/py4web-debug-tools"
53
49
  [project.optional-dependencies]
54
50
  dev = [
55
51
  "su6[all]",
56
- "hatch",
57
52
  "pytest",
58
53
  "dotmap",
59
54
  ]
60
55
 
61
56
 
62
- [tool.hatch.version]
63
- path = "src/py4web_debug/__about__.py"
57
+ [tool.vommit]
58
+ allow_breaking_bang = true
59
+ allow_breaking_footer = true
60
+ prerelease_token = "beta"
61
+ confirm = true
62
+ ignore = []
64
63
 
65
- [tool.semantic_release]
64
+ [tool.vommit.git]
65
+ enabled = true
66
+ origin = "origin"
66
67
  branch = "master"
67
- version_variable = "src/py4web_debug/__about__.py:__version__"
68
- change_log = "CHANGELOG.md"
69
- upload_to_repository = false
70
- upload_to_release = false
71
- build_command = "hatch build"
72
-
68
+ on_wrong_branch = "error"
69
+ tag_format = "v{version}"
70
+ commit_format = "{version}"
71
+
72
+ [tool.vommit.changelog]
73
+ enabled = true
74
+ file = "CHANGELOG.md"
75
+ include_prereleases = false
76
+ placeholder = "<!--next-version-placeholder-->"
77
+ placeholder_regex = "<auto>"
78
+ entry_title_format = "## v{version} ({date:%Y-%m-%d})"
79
+
80
+ [tool.vommit.changelog.levels]
81
+ feat = "Feature{s}"
82
+ fix = "Fix{es}"
83
+ break = "Breaking Change{s}"
84
+ docs = "Documentation"
85
+ perf = "Performance"
86
+
87
+ [tool.vommit.pypi]
88
+ enabled = true
89
+ use_keyring = true
90
+
91
+ [tool.vommit.commands]
92
+ clean = "rm -rf ./dist"
93
+ build = "uv build"
94
+ publish = "uv publish"
95
+ post_publish = ""
96
+
97
+ [tool.vommit.version_bump_map]
98
+ break = "major"
99
+ feat = "minor"
100
+ fix = "patch"
101
+ perf = "patch"
73
102
 
74
103
  [tool.pytest.ini_options]
75
104
  testpaths = ["tests"]
@@ -0,0 +1,3 @@
1
+ from importlib.metadata import version
2
+
3
+ __version__ = version("py4web-debug-tools")
@@ -52,6 +52,7 @@ class DebugTools:
52
52
  debugbar_fancy_rendering: bool = True,
53
53
  debugbar_style: typing.Literal["bootstrap"] = "bootstrap",
54
54
  debugbar_slow_threshold_ms: int = 10,
55
+ errorpage_json_renderer: T_Renderer = None,
55
56
  ) -> None:
56
57
  """
57
58
  By default, on_off looks at PY4WEB_DEBUG_MODE in the env
@@ -73,7 +74,7 @@ class DebugTools:
73
74
 
74
75
  if enabled:
75
76
  if self.config.errorpage.enabled:
76
- patch_py4(errorpage_renderer, error_logger)
77
+ patch_py4(errorpage_renderer, error_logger, json_renderer=errorpage_json_renderer)
77
78
 
78
79
  if self.config.debugbar.enabled:
79
80
  if not db:
@@ -51,6 +51,7 @@ def custom_error_page(
51
51
  err_type: str | typing.Type[Exception] | None = None,
52
52
  bare_exception: typing.Optional[Exception | str] = None,
53
53
  renderer: T_Renderer = None,
54
+ json_renderer: T_Renderer = None,
54
55
  ) -> str:
55
56
  if err_type and not isinstance(err_type, str):
56
57
  err_type = err_type.__name__
@@ -78,6 +79,10 @@ def custom_error_page(
78
79
  # if client accepts 'application/json' - return json
79
80
  if re.search(REGEX_APPJSON, request.headers.get("accept", "")):
80
81
  response.status = code
82
+ response.headers["Content-Type"] = "application/json"
83
+ if json_renderer:
84
+ return json_renderer(context)
85
+
81
86
  return dump(context)
82
87
  # else - return html error-page
83
88
 
@@ -119,9 +124,12 @@ T_Logger = typing.Callable[[ErrorSnapshot], None]
119
124
  class patch_py4:
120
125
  # THIS IS ONLY CALLED ONCE, WHEN tools.enable IS CALLED OR py4web_debug.wsgi IS USED!
121
126
  renderer: T_Renderer | None = None
127
+ json_renderer: T_Renderer | None = None
122
128
  logger: T_Logger | typing.Literal[False] | None = None
123
129
 
124
- def __init__(_, renderer: T_Renderer = None, logger: T_Logger | bool | None = None):
130
+ def __init__(
131
+ _, renderer: T_Renderer = None, logger: T_Logger | bool | None = None, json_renderer: T_Renderer = None
132
+ ):
125
133
  # note: don't use self, use patch_py4 instead
126
134
  if logger is True:
127
135
  # use default logger:
@@ -169,6 +177,7 @@ class patch_py4:
169
177
  err_type=type(e),
170
178
  bare_exception=e,
171
179
  renderer=getattr(patch_py4, "renderer", None),
180
+ json_renderer=getattr(patch_py4, "json_renderer", None),
172
181
  ),
173
182
  status=500,
174
183
  )
@@ -181,5 +190,6 @@ class patch_py4:
181
190
 
182
191
  # allows swapping renderer on the fly with tools.set_renderer():
183
192
  patch_py4.renderer = renderer
193
+ patch_py4.json_renderer = json_renderer
184
194
  _logger = getattr(patch_py4, "logger", None) or logger
185
195
  patch_py4.logger = staticmethod(_logger) if callable(_logger) else _logger
@@ -1,8 +0,0 @@
1
- venv
2
- apps
3
- *.pyc
4
- build
5
- dist
6
- *.egg-info
7
- .idea
8
- .env
@@ -1,89 +0,0 @@
1
- # Changelog
2
-
3
- <!--next-version-placeholder-->
4
-
5
- ## v1.3.4 (2026-08-06)
6
-
7
- ### Fix
8
-
9
- * Improved error message if json failed to `dump()` ([`920b786`](https://github.com/trialandsuccess/py4web-debug-tools/commit/920b78685cfc89cf27269972326562da7c4d05f6))
10
-
11
- ## v1.3.3 (2026-08-06)
12
-
13
- ### Fix
14
-
15
- * Fix JSON dumping for TypeDAL model classes and DotMap-like objects whose dynamic attribute lookup makes hasattr()
16
- return misleading results. ([PR 2](https://github.com/trialandsuccess/py4web-debug-tools/pull/2))
17
-
18
-
19
- ## v1.3.2 (2025-12-12)
20
-
21
- ### Fix
22
-
23
- * Use existing debug-tools `dump` instead of py4web's `dumps`, hopefully to prevent circular import error ([`0d5afad`](https://github.com/trialandsuccess/py4web-debug-tools/commit/0d5afad2904834cf80d9252b89816b7ae360249a))
24
-
25
- ## v1.3.1 (2025-04-01)
26
-
27
- ### Fix
28
-
29
- * **dbg:** Detect more variable names ([`a80556c`](https://github.com/trialandsuccess/py4web-debug-tools/commit/a80556c2d35f89a5c0f900518074b7800dfeb844))
30
-
31
- ## v1.3.0 (2025-04-01)
32
-
33
- ### Feature
34
-
35
- * Add `dbg` helper ([`b7529e3`](https://github.com/trialandsuccess/py4web-debug-tools/commit/b7529e32bcaa88a237fa505d26afe3f013d0bdf2))
36
-
37
- ## v1.2.2 (2024-11-20)
38
-
39
- ### Fix
40
-
41
- * Replace 'self' with 'patch_py4' for better stability ([`6987942`](https://github.com/trialandsuccess/py4web-debug-tools/commit/6987942347b993cf767166b6f3dac90e75989130))
42
-
43
- ## v1.2.1 (2024-11-20)
44
-
45
- ### Fix
46
-
47
- * Allow logger to be set to False in case you're using py4webs default logger (PY4WEB_ERRORLOG=:stderr) ([`43639f3`](https://github.com/trialandsuccess/py4web-debug-tools/commit/43639f377d92b2f8b96bbdb31f61251fde95f831))
48
-
49
- ## v1.2.0 (2023-11-06)
50
- ### Feature
51
- * Allow custom `error_logger` for tools.enable ([`a8301bc`](https://github.com/trialandsuccess/py4web-debug-tools/commit/a8301bc1762984fc5af420075acdc09e97bcc378))
52
-
53
- ## v1.1.4 (2023-07-19)
54
-
55
-
56
- ## v1.1.3 (2023-07-19)
57
- ### Fix
58
- * Error page renderer can also be False (in addition to None or a method) ([`41d33aa`](https://github.com/trialandsuccess/py4web-debug-tools/commit/41d33aae9e307034b2818641c041f1dd6c8364fc))
59
-
60
- ## v1.1.2 (2023-07-19)
61
- ### Fix
62
- * Wrapper can also return an HTTP response! ([`4431d80`](https://github.com/trialandsuccess/py4web-debug-tools/commit/4431d8094162dc9100aab2798571b87e5a076ed4))
63
-
64
- ## v1.1.1 (2023-07-19)
65
- ### Fix
66
- * Bump `configurable-json` to new typed version ([`52fa55a`](https://github.com/trialandsuccess/py4web-debug-tools/commit/52fa55a3eb0d8e95064ddb9ecae820a2fa229a9a))
67
-
68
- ### Documentation
69
- * Updated changelog ([`15a9517`](https://github.com/trialandsuccess/py4web-debug-tools/commit/15a9517f149b9bff272306c64165e9e62845e8d0))
70
-
71
- ## v1.1.0 (2023-07-19)
72
-
73
- Moved to hatch build system.
74
-
75
- ## v1.0.0 (2023-07-17)
76
- ### Feature
77
- * **config:** Multiple minor changes: ([`bb14fec`](https://github.com/trialandsuccess/py4web-debug-tools/commit/bb14fec07780826eb7f550cb9c5d0ed24df1f8b3))
78
- * **debugbar:** Added required files ([`afc690f`](https://github.com/trialandsuccess/py4web-debug-tools/commit/afc690fb96ec2c9d54547434caffe7c1469302b1))
79
- * **p4w-debug:** Initial module setup ([`b36c53c`](https://github.com/trialandsuccess/py4web-debug-tools/commit/b36c53c30206189bfcfcbea1c7236f12ae8becab))
80
-
81
- ### Fix
82
- * Expose `is_debug` from the top-level library ([`dd73055`](https://github.com/trialandsuccess/py4web-debug-tools/commit/dd7305596a90db3b5902dcaa7d4e5f5c22c693c6))
83
- * Expose `is_debug` from the top-level library ([`ee835e8`](https://github.com/trialandsuccess/py4web-debug-tools/commit/ee835e84983e74aa03825b346074469563e58fe6))
84
- * **tools:** 'db' is only required when debugbar is used (debugbar_enabled=True) ([`dba49b8`](https://github.com/trialandsuccess/py4web-debug-tools/commit/dba49b85149b8aa8cf5992529be6942cd9b08de4))
85
-
86
- ### Documentation
87
- * **readme:** Updated for style and missing `wsgi` ([`9394747`](https://github.com/trialandsuccess/py4web-debug-tools/commit/9394747b2e48a30c1902f5852955f85f9524c6b3))
88
- * **tools:** Include all parameters of .enable() ([`90ccffc`](https://github.com/trialandsuccess/py4web-debug-tools/commit/90ccffcf6342b68434ad64ad945aea4c7c516cf1))
89
- * **README:** Updated explaination ([`3f3b6b3`](https://github.com/trialandsuccess/py4web-debug-tools/commit/3f3b6b3f2f2fca29f4ac15851082e2e49ae288f8))
@@ -1 +0,0 @@
1
- __version__ = "1.3.4"
@@ -1,120 +0,0 @@
1
- from types import SimpleNamespace
2
-
3
- import pytest
4
- from dotmap import DotMap
5
- from pytest import MonkeyPatch
6
-
7
- from src.py4web_debug.dumping import DDJsonEncoder, DumpDieError, DumpSerializationError, dd, dump
8
-
9
-
10
- def _sample_dotmap() -> DotMap:
11
- data = DotMap()
12
- data.a = 1
13
- data.b.c = "nested"
14
- return data
15
-
16
-
17
- def test_dump_handles_dotmap():
18
- # dump() should serialize a DotMap without crashing.
19
- result = dump(_sample_dotmap(), with_headers=False)
20
-
21
- assert '"a": 1' in result
22
- assert '"c": "nested"' in result
23
-
24
-
25
- def test_dd_handles_dotmap(monkeypatch: MonkeyPatch):
26
- # dd() should not crash on a DotMap; in debug mode it raises a DumpDieError
27
- # (by design) instead of letting json serialization blow up.
28
- monkeypatch.setenv("PY4WEB_DEBUG_MODE", "1")
29
-
30
- try:
31
- dd(_sample_dotmap(), fancy=False)
32
- except DumpDieError as e:
33
- assert '"a": 1' in str(e)
34
- else:
35
- raise AssertionError("dd() should raise DumpDieError in debug mode")
36
-
37
-
38
- def test_default_crashes_on_bare_dotmap():
39
- """
40
- DotMap's __getattr__ returns an empty DotMap for ANY missing attribute
41
- instead of raising AttributeError, so hasattr(dotmap, "as_list") is
42
- always True even though `as_list` isn't a real method on it.
43
-
44
- Note: dump()/dd() never hit this for a *bare* DotMap in practice, because
45
- DotMap is a dict subclass and gets recognized (and recursed into) by
46
- configurablejson's encoder before _default() is ever called - see
47
- test_dump_handles_dotmap above, which passes fine. This test instead
48
- calls DDJsonEncoder._default() directly, to pin the underlying flaw that
49
- both this and the TypeDAL-model-class crash below share.
50
-
51
- FAILS until DDJsonEncoder._default() is fixed:
52
- TypeError: 'DotMap' object is not callable
53
- """
54
- d = DotMap({"label": "Dashboard"})
55
-
56
- DDJsonEncoder._default(d)
57
-
58
-
59
- class _TableMetaLike(type):
60
- """
61
- Reproduces TypeDAL's `TableMeta.__getattr__`: for an unbound model class,
62
- any attribute that isn't a real column falls through to `return None`
63
- instead of raising AttributeError (see typedal/tables.py TableMeta.__getattr__).
64
- """
65
-
66
- def __getattr__(cls, name: str) -> None:
67
- return None
68
-
69
-
70
- class Offering(metaclass=_TableMetaLike):
71
- """Stand-in for a real TypeDAL model class, e.g. used as menu["model"]."""
72
-
73
-
74
- def test_dump_reproduces_as_list_crash_on_model_class_value():
75
- """
76
- Real-world crash reproduction (whitelabel AdminMenuFixture):
77
- admin nav menu entries are plain dicts that carry a `"model"` key holding
78
- the *model class itself* (e.g. `Offering`, not an instance). Wrapping such
79
- an entry in a DotMap (for dot-access in templates) doesn't cause this —
80
- a plain dict crashes identically, see test below.
81
-
82
- FAILS until DDJsonEncoder._default() is fixed: it does
83
- `if hasattr(o, "as_list"): o.as_list()` without checking it's callable.
84
- TypeDAL's TableMeta.__getattr__ returns None for unknown attributes on a
85
- model class instead of raising AttributeError, so hasattr() lies and
86
- `o.as_list()` becomes `None()`. Matches production traceback exactly:
87
- dumping.py:42 in _default -> TypeError: 'NoneType' object is not callable.
88
- """
89
- entry = DotMap({"label": "Aanbod beheren", "icon": "fas fa-masks-theater", "model": Offering})
90
-
91
- dump(entry, with_headers=False)
92
-
93
-
94
- def test_dump_reproduces_as_list_crash_without_dotmap():
95
- # Same crash with a plain dict: DotMap is incidental, not the cause.
96
- entry1 = {"label": "Aanbod beheren", "model": Offering}
97
- dump(entry1, with_headers=False)
98
-
99
- entry2 = SimpleNamespace(label="Aanbod beheren", model=Offering)
100
- dump(entry2, with_headers=False)
101
-
102
-
103
- def test_dump_wraps_unexpected_errors_with_context():
104
- """
105
- Force *some other* JSON-serialization failure (a plain circular reference,
106
- nothing to do with DotMap/permissive __getattr__) to prove dump() wraps
107
- whatever goes wrong with a nicer, actionable error instead of leaking a
108
- bare exception from deep inside json.dumps()/DDJsonEncoder.
109
- """
110
- circular: dict = {}
111
- circular["self"] = circular
112
-
113
- with pytest.raises(DumpSerializationError) as exc_info:
114
- dump(circular, with_headers=False)
115
-
116
- err = exc_info.value
117
- assert "could not JSON-serialize" in str(err)
118
- assert "dict" in str(err) # names the top-level type that was being dumped
119
- assert isinstance(err.__cause__, ValueError) # original error is preserved/chained
120
- assert "circular" in str(err.__cause__).lower()