|
|
@@ -39,7 +39,7 @@ def chunked_response(func): |
|
|
|
def workaround_cp_bug_1200(func): # pragma: no cover (just a workaround) |
|
|
|
"""Decorator to work around CherryPy bug #1200 in a response |
|
|
|
generator""" |
|
|
|
# Even if chunked responses are disabled, you may still miss miss |
|
|
|
# Even if chunked responses are disabled, you may still miss |
|
|
|
# LookupError, or UnicodeError exceptions due to CherryPy bug |
|
|
|
# #1200. This throws them as generic Exceptions insteads. |
|
|
|
import traceback |
|
|
@@ -53,10 +53,15 @@ def workaround_cp_bug_1200(func): # pragma: no cover (just a workaround) |
|
|
|
traceback.format_exc()) |
|
|
|
return wrapper |
|
|
|
|
|
|
|
# Note that this decorator can't be used directly on a CherryPy |
|
|
|
# reequest handler, because CherryPy does tricks with introspection to |
|
|
|
# figure out whether the function parameters match the HTTP request. |
|
|
|
# A decorator would result in mismatched parameters giving a 500 |
|
|
|
# response, when it should be 404. To keep things happy, use this |
|
|
|
# to decorate a function inside the handler. |
|
|
|
def exception_to_httperror(*expected): |
|
|
|
"""Return a decorator that catches expected errors and throws a |
|
|
|
HTTPError describing it instead. This lets us still raise proper |
|
|
|
500 Internal Server Errors when it's something unexpected.""" |
|
|
|
HTTPError describing it instead.""" |
|
|
|
def decorator(func): |
|
|
|
@functools.wraps(func) |
|
|
|
def wrapper(*args, **kwargs): |
|
|
|