Browse Source

CherryPy bug 1200 is no longer an issue

tags/nilmdb-2.0.0
Jim Paris 2 years ago
parent
commit
ad85c3dd29
2 changed files with 0 additions and 26 deletions
  1. +0
    -4
      nilmdb/server/server.py
  2. +0
    -22
      nilmdb/server/serverutil.py

+ 0
- 4
nilmdb/server/server.py View File

@@ -20,7 +20,6 @@ import traceback
from nilmdb.server.serverutil import (
chunked_response,
response_type,
workaround_cp_bug_1200,
exception_to_httperror,
CORS_allow,
json_to_request_params,
@@ -282,7 +281,6 @@ class Stream(NilmApp):
if len(self.db.stream_list(path = path)) != 1:
raise cherrypy.HTTPError("404", "No such stream: " + path)

@workaround_cp_bug_1200
def content(start, end):
# Note: disable chunked responses to see tracebacks from here.
while True:
@@ -322,7 +320,6 @@ class Stream(NilmApp):
if diffpath and len(self.db.stream_list(path = diffpath)) != 1:
raise cherrypy.HTTPError("404", "No such stream: " + diffpath)

@workaround_cp_bug_1200
def content(start, end):
# Note: disable chunked responses to see tracebacks from here.
while True:
@@ -375,7 +372,6 @@ class Stream(NilmApp):
content_type = "text/plain"
cherrypy.response.headers['Content-Type'] = content_type

@workaround_cp_bug_1200
def content(start, end):
# Note: disable chunked responses to see tracebacks from here.
if count:


+ 0
- 22
nilmdb/server/serverutil.py View File

@@ -38,28 +38,6 @@ def response_type(content_type):
return func(*args, **kwargs)
return decorator.decorator(wrapper)

@decorator.decorator
def workaround_cp_bug_1200(func, *args, **kwargs): # pragma: no cover
"""Decorator to work around CherryPy bug #1200 in a response
generator.

Even if chunked responses are disabled, LookupError or
UnicodeError exceptions may still be swallowed by CherryPy due to
bug #1200. This throws them as generic Exceptions instead so that
they make it through.
"""
exc_info = None
try:
for val in func(*args, **kwargs):
yield val
except (LookupError, UnicodeError):
# Re-raise it, but maintain the original traceback
exc_info = sys.exc_info()
new_exc = Exception(exc_info[0].__name__ + ": " + str(exc_info[1]))
raise new_exc.with_traceback(exc_info[2])
finally:
del exc_info

def exception_to_httperror(*expected):
"""Return a decorator-generating function that catches expected
errors and throws a HTTPError describing it instead.


Loading…
Cancel
Save