PSPServletFactory

This module handles requests from the application for PSP pages.

Copyright (c) by Jay Love, 2000 (mailto:jsliv@jslove.org)

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make.

class PSP.PSPServletFactory.PSPServletFactory(application)

Bases: ServletFactory

Servlet Factory for PSP files.

__init__(application)

Create servlet factory.

Stores a reference to the application in self._app, because subclasses may or may not need to talk back to the application to do their work.

clearFileCache()

Clear class files stored on disk.

computeClassName(pageName)

Generates a (hopefully) unique class/file name for each PSP file.

Argument: pageName: the path to the PSP source file Returns: a unique name for the class generated fom this PSP source file

extensions()

Return a list of extensions that match this handler.

Extensions should include the dot. An empty string indicates a file with no extension and is a valid value. The extension ‘.*’ is a special case that is looked for a URL’s extension doesn’t match anything.

fileEncoding()

Return the file encoding used in PSP files.

flushCache()

Clean out the cache of classes in memory and on disk.

importAsPackage(transaction, serverSidePathToImport)

Import requested module.

Imports the module at the given path in the proper package/subpackage for the current request. For example, if the transaction has the URL http://localhost/Webware/MyContextDirectory/MySubdirectory/MyPage and path = ‘some/random/path/MyModule.py’ and the context is configured to have the name ‘MyContext’ then this function imports the module at that path as MyContext.MySubdirectory.MyModule . Note that the context name may differ from the name of the directory containing the context, even though they are usually the same by convention.

Note that the module imported may have a different name from the servlet name specified in the URL. This is used in PSP.

loadClass(transaction, path)

Load the appropriate class.

Given a transaction and a path, load the class for creating these servlets. Caching, pooling, and threadsafeness are all handled by servletForTransaction. This method is not expected to be threadsafe.

loadClassFromFile(transaction, fileName, className)

Create an actual class instance.

The module containing the class is imported as though it were a module within the context’s package (and appropriate subpackages).

name()

Return the name of the factory.

This is a convenience for the class name.

returnServlet(servlet)

Return servlet to the pool.

Called by Servlet.close(), which returns the servlet to the servlet pool if necessary.

servletForTransaction(transaction)

Return a new servlet that will handle the transaction.

This method handles caching, and will call loadClass(trans, filepath) if no cache is found. Caching is generally controlled by servlets with the canBeReused() and canBeThreaded() methods.

uniqueness()

Return uniqueness type.

Returns a string to indicate the uniqueness of the ServletFactory’s servlets. The Application needs to know if the servlets are unique per file, per extension or per application.

Return values are ‘file’, ‘extension’ and ‘application’.

NOTE: Application so far only supports ‘file’ uniqueness.