Servlet Plugins

When using a file server object with the HTTP servlet framework, it is possible to associate a special purpose handler or plugin with requests against files with a particular extension. When a request is made against such a file, the plugin is used as an intermediary for the creation of a servlet to handle that request. The plugin can return a servlet which was loaded into the application at startup, or might also load the servlet from the file or otherwise generate a servlet on the fly.

This feature means that the functionality of an application can to a degree be extended but without the need to have such functionality hardwired into the application itself. The functionality of an applica- tion might even be extended or reduced at run time by the simple act of adding or removing files from the file system. This eliminates the need to restart an application everytime a change is required.

Python Plugin

To support implementations of HTTP servlets being contained within files residing in the file system, as opposed to being hardwired into the application itself, the PythonPlugin class is provided. This gives greater flexibility as it would not be necessary to restart the application to add in new function- ality. The plugin can also detect when a servlet file has been modified and automatically reload it as necessary.

So that the Python import mechanism can find these files, they should be given a ".py" extension. This mapping is however not built in and it is necessary to register the extension as being associated with the particular plugin in question.

filesrvr = netsvc.FileServer(os.getcwd()) filesrvr.plugin(".py",netsvc.PythonPlugin())

105

Page 105
Image 105
Python 7.0pl5, Python Manual manual Servlet Plugins, Python Plugin