ServletFactory

Servlet factory template.

class ServletFactory.PythonServletFactory(application)

Bases: ServletFactory

The factory for Python servlets.

This is the factory for ordinary Python servlets whose extensions are empty or .py. The servlets are unique per file since the file itself defines the servlet.

__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.

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.

flushCache()

Flush the servlet cache and start fresh.

Servlets that are currently in the wild may find their way back into the cache (this may be a problem).

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.

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.

class ServletFactory.ServletFactory(application)

Bases: object

Servlet factory template.

ServletFactory is an abstract class that defines the protocol for all servlet factories.

Servlet factories are used by the Application to create servlets for transactions.

A factory must inherit from this class and override uniqueness(), extensions() and either loadClass() or servletForTransaction(). Do not invoke the base class methods as they all raise AbstractErrors.

Each method is documented below.

__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.

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.

flushCache()

Flush the servlet cache and start fresh.

Servlets that are currently in the wild may find their way back into the cache (this may be a problem).

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.

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.

ServletFactory.iskeyword()

x.__contains__(y) <==> y in x.