diff options
author | Josh Blum | 2013-03-01 19:02:24 -0800 |
---|---|---|
committer | Josh Blum | 2013-03-01 19:02:24 -0800 |
commit | 0100e306fdbf396c836149d9bf3eb642b5868c16 (patch) | |
tree | 04279c87df6d553742bbfaf426b511c7ccceaee3 /python/gras | |
parent | e0b551087fc28372dd0d07751f72916dfe092576 (diff) | |
download | sandhi-0100e306fdbf396c836149d9bf3eb642b5868c16.tar.gz sandhi-0100e306fdbf396c836149d9bf3eb642b5868c16.tar.bz2 sandhi-0100e306fdbf396c836149d9bf3eb642b5868c16.zip |
gras: added 404 stats and pass top block
Diffstat (limited to 'python/gras')
-rw-r--r-- | python/gras/stats/__init__.py | 19 |
1 files changed, 13 insertions, 6 deletions
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("<p>not found</p>") 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) |