1.1 --- a/WebStack/Resources/Static.py Sun Nov 20 00:00:39 2005 +0000
1.2 +++ b/WebStack/Resources/Static.py Sun Nov 20 02:35:21 2005 +0000
1.3 @@ -68,10 +68,7 @@
1.4
1.5 pathname = os.path.abspath(os.path.join(self.directory, filename))
1.6 if not (pathname.startswith(os.path.join(self.directory, "/")) and os.path.exists(pathname) and os.path.isfile(pathname)):
1.7 - trans.set_response_code(404)
1.8 - trans.set_content_type(ContentType("text/plain"))
1.9 - out.write("Resource '%s' not found." % filename)
1.10 - raise EndOfResponse
1.11 + self.not_found(trans, filename)
1.12
1.13 # Get the extension.
1.14
1.15 @@ -84,6 +81,7 @@
1.16 media_type = self.media_types.get(None)
1.17
1.18 # Set the content type.
1.19 + # NOTE: Add other parts of the content type such as character encodings.
1.20
1.21 if media_type is not None:
1.22 trans.set_content_type(ContentType(media_type))
1.23 @@ -96,4 +94,17 @@
1.24 out.write(f.read())
1.25 f.close()
1.26
1.27 + def not_found(self, trans, filename):
1.28 +
1.29 + """
1.30 + Send the "not found" response using the given transaction, 'trans', and
1.31 + specifying the given 'filename' (if appropriate).
1.32 + """
1.33 +
1.34 + trans.set_response_code(404)
1.35 + trans.set_content_type(ContentType("text/plain"))
1.36 + out = trans.get_response_stream()
1.37 + out.write("Resource '%s' not found." % filename)
1.38 + raise EndOfResponse
1.39 +
1.40 # vim: tabstop=4 expandtab shiftwidth=4