From 12c64ad48a9e7e0b1cd967d4c20a0aff6f5e5c90 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 18 Oct 2016 09:34:06 -0600 Subject: [PATCH] Send tracebacks to browser --- devel-server.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/devel-server.py b/devel-server.py index 9330761..5543f83 100755 --- a/devel-server.py +++ b/devel-server.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import cgi import glob import http.server import mistune @@ -7,6 +8,8 @@ import os import pathlib import puzzles import socketserver +import sys +import traceback try: from http.server import HTTPStatus @@ -48,7 +51,20 @@ class ThreadingServer(socketserver.ThreadingMixIn, http.server.HTTPServer): pass -class MothHandler(http.server.CGIHTTPRequestHandler): +class MothHandler(http.server.SimpleHTTPRequestHandler): + def handle_one_request(self): + try: + super().handle_one_request() + except: + tbtype, value, tb = sys.exc_info() + tblist = traceback.format_tb(tb, None) + traceback.format_exception_only(tbtype, value) + page = ("# Traceback (most recent call last)\n" + + " " + + " ".join(tblist[:-1]) + + tblist[-1]) + self.serve_md(page) + + def do_GET(self): if self.path == "/": self.serve_front()