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.
Files changed (53) hide show
  1. {py2http-0.1.70 → py2http-0.1.71}/PKG-INFO +1 -1
  2. {py2http-0.1.70 → py2http-0.1.71}/py2http/default_configs.py +8 -1
  3. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_error_statuses.py +38 -0
  4. {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/PKG-INFO +1 -1
  5. {py2http-0.1.70 → py2http-0.1.71}/setup.cfg +1 -1
  6. {py2http-0.1.70 → py2http-0.1.71}/LICENSE +0 -0
  7. {py2http-0.1.70 → py2http-0.1.71}/README.md +0 -0
  8. {py2http-0.1.70 → py2http-0.1.71}/py2http/__init__.py +0 -0
  9. {py2http-0.1.70 → py2http-0.1.71}/py2http/auth.py +0 -0
  10. {py2http-0.1.70 → py2http-0.1.71}/py2http/bottle_plugins.py +0 -0
  11. {py2http-0.1.70 → py2http-0.1.71}/py2http/config.py +0 -0
  12. {py2http-0.1.70 → py2http-0.1.71}/py2http/constants.py +0 -0
  13. {py2http-0.1.70 → py2http-0.1.71}/py2http/decorators.py +0 -0
  14. {py2http-0.1.70 → py2http-0.1.71}/py2http/diagnosis.py +0 -0
  15. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/__init__.py +0 -0
  16. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/custom_input_mapper.py +0 -0
  17. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/custom_input_mappers.py +0 -0
  18. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/example_service.py +0 -0
  19. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/example_service_bottle.py +0 -0
  20. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/example_service_flask.py +0 -0
  21. {py2http-0.1.70 → py2http-0.1.71}/py2http/examples/object_dispatch.py +0 -0
  22. {py2http-0.1.70 → py2http-0.1.71}/py2http/middleware.py +0 -0
  23. {py2http-0.1.70 → py2http-0.1.71}/py2http/obj_dispatch.py +0 -0
  24. {py2http-0.1.70 → py2http-0.1.71}/py2http/openapi_utils.py +0 -0
  25. {py2http-0.1.70 → py2http-0.1.71}/py2http/route_utils.py +0 -0
  26. {py2http-0.1.70 → py2http-0.1.71}/py2http/schema_tools.py +0 -0
  27. {py2http-0.1.70 → py2http-0.1.71}/py2http/service.py +0 -0
  28. {py2http-0.1.70 → py2http-0.1.71}/py2http/sizeof.py +0 -0
  29. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/__init__.py +0 -0
  30. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/example_service_test.py +0 -0
  31. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/objects_for_testing.py +0 -0
  32. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/simple_run_process_test.py +0 -0
  33. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_attr_dispatch.py +0 -0
  34. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_auth_plugins.py +0 -0
  35. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_binary_req.py +0 -0
  36. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_decorators.py +0 -0
  37. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_flask.py +0 -0
  38. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_instance_endpoints.py +0 -0
  39. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_jwt_middleware.py +0 -0
  40. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_not_set_defaults.py +0 -0
  41. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_obj_measuring.py +0 -0
  42. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_obj_ownership.py +0 -0
  43. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_p2h2p.py +0 -0
  44. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/test_positional_only.py +0 -0
  45. {py2http-0.1.70 → py2http-0.1.71}/py2http/tests/utils_for_testing.py +0 -0
  46. {py2http-0.1.70 → py2http-0.1.71}/py2http/types.py +0 -0
  47. {py2http-0.1.70 → py2http-0.1.71}/py2http/util.py +0 -0
  48. {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/SOURCES.txt +0 -0
  49. {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/dependency_links.txt +0 -0
  50. {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/not-zip-safe +0 -0
  51. {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/requires.txt +0 -0
  52. {py2http-0.1.70 → py2http-0.1.71}/py2http.egg-info/top_level.txt +0 -0
  53. {py2http-0.1.70 → py2http-0.1.71}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py2http
3
- Version: 0.1.70
3
+ Version: 0.1.71
4
4
  Summary: Declarative HTTP service entry point.
5
5
  Home-page: https://github.com/i2mint/py2http
6
6
  License: MIT
@@ -150,7 +150,14 @@ def bottle_error_handler(error: Exception):
150
150
 
151
151
 
152
152
  def flask_error_handler(error: Exception):
153
- raise NotImplementedError()
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"}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py2http
3
- Version: 0.1.70
3
+ Version: 0.1.71
4
4
  Summary: Declarative HTTP service entry point.
5
5
  Home-page: https://github.com/i2mint/py2http
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = py2http
3
- version = 0.1.70
3
+ version = 0.1.71
4
4
  url = https://github.com/i2mint/py2http
5
5
  root_url = https://github.com/i2mint
6
6
  platforms = any
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