mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-29 17:28:53 +00:00
minor cleanups/rearranging
This commit is contained in:
parent
97872118a5
commit
b200d20430
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user