durusmail: quixote-users: Module to map filesystem files into Quixote, revision 4
Module to map filesystem files into Quixote, revision 4
2002-11-14
Module to map filesystem files into Quixote, revision 4
Hamish Lawson
2002-11-14
I've attached revision 4 of my filesystem.py module for mapping static
filesystem files and legacy Python CGI scripts into Quixote.

Changes in this revision:

* The FilesystemFile and FilesystemFolder classes have been renamed
StaticFile and StaticFilesFolder, which I believe are more precise names
now that the module provides a wrapper for filesystem-based CGI scripts.

* The StaticFile, StaticFilesFolder and CGIScript classes now take an
optional  parameter 'follow_symlinks' that controls whether symbolic links
should be followed; by default they are not.

* If an exception occurs during execution of a CGI script, stdin and stdout
will still be restored to their original values.

* The StaticFile, StaticFilesFolder and CGIScript classes now insist on the
initial path being absolute.

Here are some examples of usage:

1. Map an individual filesystem file (possibly a symbolic link) and cache
its contents. (Because 'stylesheet.css' isn't a valid identifier name, we need
to use setattr to set it as an attribute of the current module.)

     this_module = sys.modules[__name__]
     setattr(
         this_module,
         "stylesheet.css",
         StaticFile(
             "/htdocs/legacy_app/stylesheet.css",
             use_cache=1,
             follow_symlinks=1
         )
     )

2. Map a complete filesytem folder containing static files, by default
not caching their contents.

     notes = StaticFilesFolder("/htdocs/legacy_app/notes")

3. Map a CGI script and cache the compiled script.

     this_module = sys.modules[__name__]
     setattr(
         this_module,
          "results.cgi",
          CGIScript("/htdocs/legacy_app/results.cgi", use_cache=1)
     )


Hamish Lawson
reply