# HG changeset patch # User paulb # Date 1132454121 0 # Node ID 1a7de62d35c4c2490edb67f9f3a0242a2b9fad7f # Parent 26d9b08d05f5063a97551d1f96160680944d8bc9 [project @ 2005-11-20 02:35:21 by paulb] Added support for subclassing DirectoryResource and defining different "not found" behaviour. diff -r 26d9b08d05f5 -r 1a7de62d35c4 WebStack/Resources/Static.py --- a/WebStack/Resources/Static.py Sun Nov 20 00:00:39 2005 +0000 +++ b/WebStack/Resources/Static.py Sun Nov 20 02:35:21 2005 +0000 @@ -68,10 +68,7 @@ pathname = os.path.abspath(os.path.join(self.directory, filename)) if not (pathname.startswith(os.path.join(self.directory, "/")) and os.path.exists(pathname) and os.path.isfile(pathname)): - trans.set_response_code(404) - trans.set_content_type(ContentType("text/plain")) - out.write("Resource '%s' not found." % filename) - raise EndOfResponse + self.not_found(trans, filename) # Get the extension. @@ -84,6 +81,7 @@ media_type = self.media_types.get(None) # Set the content type. + # NOTE: Add other parts of the content type such as character encodings. if media_type is not None: trans.set_content_type(ContentType(media_type)) @@ -96,4 +94,17 @@ out.write(f.read()) f.close() + def not_found(self, trans, filename): + + """ + Send the "not found" response using the given transaction, 'trans', and + specifying the given 'filename' (if appropriate). + """ + + trans.set_response_code(404) + trans.set_content_type(ContentType("text/plain")) + out = trans.get_response_stream() + out.write("Resource '%s' not found." % filename) + raise EndOfResponse + # vim: tabstop=4 expandtab shiftwidth=4