Subsections
8. Internal API
This section describe the public methods/attributes/classes of PyWork. Is intended
to people interested in extending its functionality and/or join the project. But
if you a web developer you may also be interested in PyWork internals. This chapter
is organized with one secetion per "PyWork" module.
This modules is the binding point of mod_python and PyWork. ModPython
loads this module and calls it directly to process its requests
The module defines the following function
-
-
Process an apache request. This function is called by mod_python/apache when
a request enters its Request Handling phase.
This module defines the Action class, and a class to load actions from
an XML.
The module defines the following exceptions and classes.
- exception ActionConfigurationError
-
This exception is raised when a configuration error is found when
loading the XML pywork-map.xml file.
- exception ActionInstanceError
-
This exception is raised when an exception is raised creating
an instance of an Action
Action instances support the following methods and
attributes. Action is PyWork's framework main class.
-
-
This is the authentication Action method. It is called on the
authentication phase. By default returns True
-
-
This is the pre execution method called before execute.
-
-
This is the main Action method, it should alway be overwritten.
It's called by PyWork on the client class after all parameters
are set. It should return a string identifying the view to be
displayd or None , and set the "_redirectUri" attribute.
-
-
This is the post execution method called after execute.
-
-
Binds a parameter to a method. It receives the parameter name (a string)
and the method object as second argument.
-
-
Unbinds a previously binded parameter to a method.
-
-
If set to True tells the action object to accept any parameter
and store it in "_form" if no property is found. USE WITH CARE!
- _descriptor
-
The value of _descriptor is set upon action instantiation
with the data retrieved from the configuration file. See
ActionDescriptor.
- _redirectUri
-
PyWork examines this value after calling the execute method
and if its not None redirects the response to the specified
URL.
- _session
-
This is the session object , normally it's a dictionary.
It is set before calling the execute method.
- _name
-
This is the full virtual URI of the request executing
It is set before calling the execute method.
- _form
-
This is a dictionary containing all parameters that were not found
as properties, if variableFormProperties is set to True.
- _locale
-
If the client sends an "Accept-Language" header, PyWork will
try to parse the clients locale and set it here.
- _context
-
A reference to the main PyWork controller. It will serve you
for accessing configuration directives and more.
ActionMap instances support the following methods and
attributes. This class is the structure that uses PyWork to
resolve the URI's into actions.
-
-
This method is called by PyWork to load all the information
from a pywork-map.xml file. It also receives a reference to the global
configuration and availableViews, to resolve and validate the XML data.
-
-
Given an actionId (the virtual URI) returns the corresponding
descriptor (see ActionDescriptor), or None if not found.
This module defines the descriptor for actions, views, and view handlers.
The module defines the following classes.
ActionDescriptor instances support the following methods and
attributes. ActionDescriptors are created when action elements are
read from the configuration file.
-
-
This method returns an instance of the Action
described by this object. If the creation is successfull
it sets the "_descriptor" attribute with self.
- name
-
The name of the action.
- moduleName
-
The module where the action class resides.
- className
-
The class implementing Action
- classObject
-
The class object. It serves to create instances at runtime
- context
-
The context in which the action is being executed. It's
set at runtime by PyWork, and has a reference to the controller
, see Controller.
- views
-
A dictionary containing all the available views
for this action. Each key is the view name, and the
elements are references to view descriptors, see
ViewDescriptor
ViewDescriptor instances support the following methods and
attributes. ViewDescriptors are created when view elements are
read from the configuration file.
- name
-
The name of the view. This name identifies the view.
- viewHandlerName
-
The identifier of the view handler that will be used to
process this view.
- viewFile
-
The view file to be processed.
- viewContentType
-
The content type to be used when writing the view output
to the response.
ViewHandlerDescriptor instances support the following methods and
attributes. ViewHandlersDescriptors are created when view-handler elements are
read from the configuration file.
-
-
This method returns an instance subclass of ViewHandler
. If the creation is successfull it sets the "_descriptor"attribute with self.
- name
-
The name of the view handler.
- moduleName
-
The module where the view handler class resides.
- className
-
The class implementing ViewHandler
- classObject
-
The class object. It serves to create instances at configuration time
This module defines the Controller class. Instances of this class are
in charge of resceiving the requests, calling action methods and calling
the views. Normally there would be one instance per interpreter.
The module defines the following class.
Controller instances support the following methods and
attributes. An instance of Controller is created by pywork, and
its reused between requests.
-
-
This method is in charge of processing all the request. It receives
the apache request and calls the proper action and view.
-
-
This method gets the value of a global configuration directive
of PyWork (see pywork.xml).
- gconf
-
A reference the global configuration see Configuration.
- gaction
-
A reference the action configuration see ActionMap.
- gview
-
A reference the view handlers configuration see ViewHandlerMap.
This module defines the Configuration class.
The module defines the following exceptions and classes.
- exception ConfigurationError
-
This exception is raised when a configuration error is found when
loading the XML pywork.xml file.
Configuration instances support the following methods and
attributes.
-
-
This method is called by PyWork to load all the information
from a pywork.xml file.
-
-
Returns the value of property as loaded from the configuration
file.
-
-
Returns the value of property converted to an int.
-
-
Searches str for strings of the form:
And returns a string with all values resolved by calling
getconf.
This module defines the View Handler class and the 3 view thecnologies,
namely: PYTHON, ZPT and XSLT.
The module defines the following exceptions, classes and functions.
- exception ViewHandlerConfigurationError
-
This exception is raised when a configuration error is found when
loading the XML pywork-views.xml file.
-
-
extension may be a sequence or a simple value. This function
is called by PyWork to register certain extension with the
view specified by name.
-
-
It examins file to see it it ends with some of the
registered extensions, if matches returns the correspongin
view name, otherwise None is returned.
ViewHandler instances support the following methods and
attributes. ViewHandler is the base class for view processing classes.
-
-
This method should always be overwritten is called by
the controller when the view is to be displayed.
- descriptor
-
The value of descriptor is set before calling
the object's display method. With the corresponding view
descriptor, see ViewDescriptor.
- action
-
The value of action is set before calling
the object's display method. With the action executed,
, see Action.
- context
-
The context in which the action is being executed. It's
set at runtime by PyWork, and has a reference to the controller
, see Controller.
- viewFile
-
The view file to be processed.
PythonViewHandler support the PYTHON view techonology. It
does not define anything more than ViewHandler.
ZPTViewHandler support the ZPT view techonology. It
does not define anything more than ViewHandler. This
class is available if you have installed the ZPT package.
XSLTViewHandler support the XSLT view techonology. It
does not define anything more than ViewHandler. This
class is available if you have installed the libxml2, libxslt
python bindings. See the chapter Installation.
This module defines the utility functions, to load modules and objects.
And generate XML.
The module defines the following exceptions and functions.
- exception ClassResolveError
-
This exception is raised when PyWork tries to create an instance
of user class and fails.
-
-
This functions return the full path of the file, searching
in PyWork's path. See Installation.
-
-
Returns filename MTIME. Its used for the configuration
utilities.
-
-
Loads module and returns a reference to object.
If running inside mod_python , apache.import_module its used
otherwise, standard python imports are used. Module maybe
module.submodule.submodule... etc.
-
-
Transform the action into an XML. See XSLT view for more information.
This function is implemented in C if module compilation
was successful, otherwise is implemented in Python.
See About this document... for information on suggesting changes.