From 0100e306fdbf396c836149d9bf3eb642b5868c16 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 1 Mar 2013 19:02:24 -0800 Subject: gras: added 404 stats and pass top block --- python/gras/stats/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'python/gras/stats/__init__.py') diff --git a/python/gras/stats/__init__.py b/python/gras/stats/__init__.py index 596616d..ce570b0 100644 --- a/python/gras/stats/__init__.py +++ b/python/gras/stats/__init__.py @@ -21,19 +21,26 @@ class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): s.end_headers() s.wfile.write(get_stats_registry[0]()) return - s.send_response(200) - s.send_header("Content-type", "text/html") - s.end_headers() path = s.path if path.startswith('/'): path = path[1:] if not path: path = 'main.html' - s.wfile.write(open(os.path.join(__path__, path)).read()) + target = os.path.join(__path__, path) + if os.path.exists(target): + s.send_response(200) + s.send_header("Content-type", "text/html") + s.end_headers() + s.wfile.write(open(target).read()) + else: + s.send_response(404) + s.send_header("Content-type", "text/html") + s.end_headers() + s.wfile.write("

not found

") import select class http_server(object): - def __init__(self, args, get_stats_xml): - get_stats_registry[0] = get_stats_xml + def __init__(self, args, top_block): + get_stats_registry[0] = top_block.get_stats_xml server_class = BaseHTTPServer.HTTPServer self._httpd = server_class(args, MyHandler) -- cgit