py2http 0.1.70__tar.gz → 0.1.71__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.
- {py2http-0.1.70 → py2http-0.1.71}/PKG-INFO +1 -1
- {py2http-0.1.70 → py2http-0.1.71}/py2http/default_configs.py +8 -1
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_error_statuses.py +38 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/PKG-INFO +1 -1
- {py2http-0.1.70 → py2http-0.1.71}/setup.cfg +1 -1
- {py2http-0.1.70 → py2http-0.1.71}/LICENSE +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/README.md +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/__init__.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/auth.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/bottle_plugins.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/config.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/constants.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/decorators.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/diagnosis.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/__init__.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/custom_input_mapper.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/custom_input_mappers.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/example_service.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/example_service_bottle.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/example_service_flask.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/object_dispatch.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/middleware.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/obj_dispatch.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/openapi_utils.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/route_utils.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/schema_tools.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/service.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/sizeof.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/__init__.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/example_service_test.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/objects_for_testing.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/simple_run_process_test.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_attr_dispatch.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_auth_plugins.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_binary_req.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_decorators.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_flask.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_instance_endpoints.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_jwt_middleware.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_not_set_defaults.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_obj_measuring.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_obj_ownership.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_p2h2p.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_positional_only.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/utils_for_testing.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/types.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http/util.py +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/SOURCES.txt +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/dependency_links.txt +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/not-zip-safe +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/requires.txt +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/top_level.txt +0 -0
- {py2http-0.1.70 → py2http-0.1.71}/setup.py +0 -0
|
@@ -150,7 +150,14 @@ def bottle_error_handler(error: Exception):
|
|
|
150
150
|
|
|
151
151
|
|
|
152
152
|
def flask_error_handler(error: Exception):
|
|
153
|
-
|
|
153
|
+
"""The ``(body, status, headers)`` a Flask view returns for an error, mapped like
|
|
154
|
+
the bottle handler (``OPAQUE_ERRORS`` hides the text of a 500)."""
|
|
155
|
+
message = str(error)
|
|
156
|
+
status = error_status(error)
|
|
157
|
+
if status == 500 and os.getenv("OPAQUE_ERRORS", None):
|
|
158
|
+
message = "Internal server error"
|
|
159
|
+
status_line = f"400 {type(error).__name__}" if status == 400 else status
|
|
160
|
+
return {"error": message}, status_line, _status_headers(status)
|
|
154
161
|
|
|
155
162
|
|
|
156
163
|
def default_error_handler(error: Exception):
|
|
@@ -63,3 +63,41 @@ def test_aiohttp_error_handler(error, status):
|
|
|
63
63
|
assert caught.value.status == status
|
|
64
64
|
if status == 500:
|
|
65
65
|
assert "internal detail" not in caught.value.text
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@pytest.mark.parametrize("error, status", CASES)
|
|
69
|
+
def test_flask_error_handler(error, status, monkeypatch):
|
|
70
|
+
flask = pytest.importorskip("flask")
|
|
71
|
+
monkeypatch.delenv("PY2HTTP_WWW_AUTHENTICATE", raising=False)
|
|
72
|
+
monkeypatch.setenv("PY2HTTP_FRAMEWORK", "flask")
|
|
73
|
+
from py2http.default_configs import default_error_handler
|
|
74
|
+
|
|
75
|
+
app = flask.Flask(__name__)
|
|
76
|
+
|
|
77
|
+
@app.route("/fail")
|
|
78
|
+
def fail():
|
|
79
|
+
return default_error_handler(error)
|
|
80
|
+
|
|
81
|
+
response = app.test_client().get("/fail")
|
|
82
|
+
assert response.status_code == status
|
|
83
|
+
assert set(response.get_json()) == {"error"}
|
|
84
|
+
if status == 400: # as the bottle handler: the status line names the error
|
|
85
|
+
assert response.status == f"400 {type(error).__name__}"
|
|
86
|
+
if status == 401:
|
|
87
|
+
assert response.headers["WWW-Authenticate"] == "Bearer"
|
|
88
|
+
else:
|
|
89
|
+
assert "WWW-Authenticate" not in response.headers
|
|
90
|
+
if status == 500:
|
|
91
|
+
assert "internal detail" in response.get_json()["error"]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_flask_opaque_errors_hides_500_text(monkeypatch):
|
|
95
|
+
flask = pytest.importorskip("flask")
|
|
96
|
+
monkeypatch.setenv("OPAQUE_ERRORS", "1")
|
|
97
|
+
from py2http.default_configs import flask_error_handler
|
|
98
|
+
|
|
99
|
+
app = flask.Flask(__name__)
|
|
100
|
+
app.add_url_rule(
|
|
101
|
+
"/f", "f", lambda: flask_error_handler(KeyError("internal detail"))
|
|
102
|
+
)
|
|
103
|
+
assert app.test_client().get("/f").get_json() == {"error": "Internal server error"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|