Skip to content

Commit

Permalink
version 1.20240530.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed May 31, 2024
1 parent 69997b0 commit 0ac9a89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion py4web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Massimo Di Pierro <[email protected]>"
__license__ = "BSD-3-Clause"
__version__ = "1.20240530.1"
__version__ = "1.20240530.2"


def _maybe_gevent():
Expand Down
16 changes: 9 additions & 7 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@


def _before_request(*args, **kw):
[h(*args, **kw) for h in _REQUEST_HOOKS.before]
[ # pylint: disable=expression-not-assigned
h(*args, **kw) for h in _REQUEST_HOOKS.before
]


bottle.default_app().add_hook("before_request", _before_request)
Expand Down Expand Up @@ -1509,26 +1511,26 @@ def register_route(app_name, rule, kwargs, func):
}


def error_page(token, button_text=None, href="#", color=None, message=None):
def error_page(http_code, button_text=None, href="#", color=None, message=None):
"""Generates an error page"""
if button_text:
button_text = sanitize_html.escape(button_text)
href = sanitize_html.escape(href)
message = http.client.responses[token].upper() if message is None else message
message = http.client.responses[http_code].upper() if message is None else message
color = (
{"4": "#F44336", "5": "#607D8B"}.get(str(token)[0], "#2196F3")
{"4": "#F44336", "5": "#607D8B"}.get(str(http_code)[0], "#2196F3")
if not color
else color
)
context = dict(
code=token, message=message, button_text=button_text, href=href, color=color
code=http_code, message=message, button_text=button_text, href=href, color=color
)
# if client accepts 'application/json' - return json
if re.search(REGEX_APPJSON, request.headers.get("accept", "")):
response.status = code
response.status = http_code
return json.dumps(context)
# else - return html error-page
content = ERROR_PAGES.get(code) or ERROR_PAGES["*"]
content = ERROR_PAGES.get(http_code) or ERROR_PAGES["*"]
return render(content=content, context=context, delimiters="[[ ]]")


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py4web"
version = "1.20240530.1"
version = "1.20240530.2"
authors = [{ name="Massimo Di Pierro", email="[email protected]" },]
description = "A fast, stable, comprehensive web framework"
readme = "README.rst"
Expand Down

0 comments on commit 0ac9a89

Please sign in to comment.