From b200d2043093b6746cc5a4951b5a5eb271faa498 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 18 Sep 2020 15:01:53 -0400 Subject: [PATCH] minor cleanups/rearranging --- src/allmydata/web/common.py | 15 +++++++-------- src/allmydata/web/common_py3.py | 9 --------- src/allmydata/web/directory.py | 3 +-- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index e6e818e7a..6035e2884 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -1,10 +1,10 @@ import time import json +from functools import wraps from twisted.web import http, server, resource, template from twisted.python import log -from twisted.python.failure import Failure from nevow import loaders, appserver from nevow.rend import Page from nevow.inevow import IRequest @@ -22,7 +22,6 @@ from allmydata.util.encodingutil import to_bytes, quote_output # Originally part of this module, so still part of its API: from .common_py3 import ( # noqa: F401 get_arg, abbreviate_time, MultiFormatResource, WebError, - BadRequest, ) @@ -516,23 +515,23 @@ def exception_to_child(f): @wraps(f) def g(self, name, req): try: - return m(self, name, req) + return f(self, name, req) except Exception as e: description, status = humanize_exception(e) - return ErrorPage(status, "Error", description) + return resource.ErrorPage(status, "Error", description) return g -def render_exception(m): +def render_exception(f): """ Decorate a ``render_*`` method with exception handling behavior to render an error page reflecting the exception. """ - @wraps(m) + @wraps(f) def g(self, request): try: - return m(self, request) + return f(self, request) except Exception as e: description, status = humanize_exception(e) - return ErrorPage(status, "Error", description).render(request) + return resource.ErrorPage(status, "Error", description).render(request) return g diff --git a/src/allmydata/web/common_py3.py b/src/allmydata/web/common_py3.py index f532e9000..06751a8e8 100644 --- a/src/allmydata/web/common_py3.py +++ b/src/allmydata/web/common_py3.py @@ -23,15 +23,6 @@ class WebError(Exception): self.code = code -class BadRequest(resource.ErrorPage): - """ - ``BadRequest`` is a specialiation of ``ErrorPage`` which returns the HTTP - response code **BAD REQUEST**. - """ - def __init__(self, message=""): - resource.ErrorPage.__init__(self, http.BAD_REQUEST, "Bad Request", message) - - def get_arg(ctx_or_req, argname, default=None, multiple=False): """Extract an argument from either the query args (req.args) or the form body fields (req.fields). If multiple=False, this returns a single value diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 3ad935bab..4d7aa1bd1 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -2,7 +2,6 @@ import json import urllib from datetime import timedelta -from functools import wraps from zope.interface import implementer from twisted.internet import defer @@ -680,7 +679,7 @@ class DirectoryAsHTML(Element): try: children = yield self.node.list() except Exception as e: - text, code = humanize_failure(Failure(e)) + text, code = humanize_exception(e) children = None self.dirnode_children_error = text