Browse Source

[2298] modify the open_template() method

open_template() throws StatsHttpdDataError instead of IOError when the
specified file is not found. The parent class catches it and returns a
404 status code.
Naoki Kambe 12 years ago
parent
commit
27cb59ce18
1 changed files with 11 additions and 5 deletions
  1. 11 5
      src/bin/stats/stats_httpd.py.in

+ 11 - 5
src/bin/stats/stats_httpd.py.in

@@ -553,11 +553,17 @@ class StatsHttpd:
     def open_template(self, file_name):
         """It opens a template file, and it loads all lines to a
         string variable and returns string. Template object includes
-        the variable. Limitation of a file size isn't needed there."""
-        f = open(file_name, 'r')
-        lines = "".join(f.readlines())
-        f.close()
-        assert lines is not None
+        the variable. Limitation of a file size isn't needed there. XXXX"""
+        lines = None
+        f = None
+        try:
+            f = open(file_name, 'r')
+            lines = "".join(f.readlines())
+        except IOError as err:
+            raise StatsHttpdDataError(
+                "%s: %s" % (err.__class__.__name__, err))
+        finally:
+            if f: f.close()
         return string.Template(lines)
 
 if __name__ == "__main__":