From 7dab85e8b1de9101cadcc75768672a7ca26da3b8 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 25 Jul 2012 00:16:24 +1200 Subject: Handle file access denied errors in previews. --- libpathod/app.py | 51 ++++++++++++++++++++++-------------------- libpathod/templates/frame.html | 2 +- 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'libpathod') diff --git a/libpathod/app.py b/libpathod/app.py index 79c0fc71..cf66f8d4 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -75,8 +75,12 @@ def onelog(lid): return render("onelog.html", section="log", alog=l, lid=lid) -@app.route('/response_preview') -def response_preview(): +def _preview(is_request): + if is_request: + template = "request_preview.html" + else: + template = "response_preview.html" + spec = request.args["spec"] args = dict( spec = spec, @@ -85,37 +89,36 @@ def response_preview(): error = None ) try: - r = rparse.parse_response(app.config["pathod"].request_settings, spec) + if is_request: + r = rparse.parse_request(app.config["pathod"].request_settings, spec) + else: + r = rparse.parse_response(app.config["pathod"].request_settings, spec) except rparse.ParseException, v: args["syntaxerror"] = str(v) args["marked"] = v.marked() - return render("response_preview.html", **args) + return render(template, **args) + except rparse.FileAccessDenied: + args["error"] = "File access is disabled." + return render(template, **args) s = cStringIO.StringIO() r.preview_safe() - r.serve(s, check=app.config["pathod"].check_size) + + if is_request: + r.serve(s, check=app.config["pathod"].check_size, host="example.com") + else: + r.serve(s, check=app.config["pathod"].check_size) + args["output"] = utils.escape_unprintables(s.getvalue()) - return render("response_preview.html", **args) + return render(template, **args) +@app.route('/response_preview') +def response_preview(): + return _preview(False) + + @app.route('/request_preview') def request_preview(): - spec = request.args["spec"] - args = dict( - spec = spec, - section = "main", - syntaxerror = None, - error = None - ) - try: - r = rparse.parse_request(app.config["pathod"].request_settings, spec) - except rparse.ParseException, v: - args["syntaxerror"] = str(v) - args["marked"] = v.marked() - return render("request_preview.html", **args) + return _preview(True) - s = cStringIO.StringIO() - r.preview_safe() - r.serve(s, check=app.config["pathod"].check_size, host="example.com") - args["output"] = utils.escape_unprintables(s.getvalue()) - return render("request_preview.html", **args) diff --git a/libpathod/templates/frame.html b/libpathod/templates/frame.html index 416f3eca..d91004e4 100644 --- a/libpathod/templates/frame.html +++ b/libpathod/templates/frame.html @@ -77,7 +77,7 @@ $.localScroll( { duration: 300, - offset: {top: -100} + offset: {top: -45} } ); }); -- cgit v1.2.3