Generators

Generate Python code from PSP templates.

This module holds the classes that generate the Python code resulting from the PSP template file. As the parser encounters PSP elements, it creates a new Generator object for that type of element. Each of these elements is put into a list maintained by the ParseEventHandler object. When it comes time to output the source code, each generator is called in turn to create its source.

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.

This software is based in part on work done by the Jakarta group.

class PSP.Generators.CharDataGenerator(chars)

Bases: GenericGenerator

This class handles standard character output, mostly HTML.

It just dumps it out. Need to handle all the escaping of characters. It’s just skipped for now.

__init__(chars)
generate(writer, phase=None)
generateChunk(writer, start=0, stop=None)
mergeData(cdGen)
class PSP.Generators.EndBlockGenerator

Bases: GenericGenerator

__init__()
generate(writer, phase=None)
class PSP.Generators.ExpressionGenerator(chars)

Bases: GenericGenerator

This class handles expression blocks.

It simply outputs the (hopefully) python expression within the block wrapped with a _formatter() call.

__init__(chars)
generate(writer, phase=None)
class PSP.Generators.GenericGenerator(ctxt=None)

Bases: object

Base class for all the generators

__init__(ctxt=None)
class PSP.Generators.IncludeGenerator(attrs, param, ctxt)

Bases: GenericGenerator

Handle psp:include directives.

This is a new version of this directive that actually forwards the request to the specified page.

__init__(attrs, param, ctxt)
generate(writer, phase=None)

Just insert theFunction.

class PSP.Generators.InsertGenerator(attrs, param, ctxt)

Bases: GenericGenerator

Include files designated by the psp:insert syntax.

If the attribute ‘static’ is set to True or 1, we include the file now, at compile time. Otherwise, we use a function added to every PSP page named __includeFile, which reads the file at run time.

__init__(attrs, param, ctxt)
generate(writer, phase=None)
class PSP.Generators.MethodEndGenerator(chars, attrs)

Bases: GenericGenerator

Part of class method generation.

After MethodGenerator, MethodEndGenerator actually generates the code for the method body.

__init__(chars, attrs)
generate(writer, phase=None)
class PSP.Generators.MethodGenerator(chars, attrs)

Bases: GenericGenerator

Generate class methods defined in the PSP page.

There are two parts to method generation. This class handles getting the method name and parameters set up.

__init__(chars, attrs)
generate(writer, phase=None)
class PSP.Generators.ScriptClassGenerator(chars, attrs)

Bases: GenericGenerator

Add Python code at the class level.

__init__(chars, attrs)
generate(writer, phase=None)
class PSP.Generators.ScriptFileGenerator(chars, attrs)

Bases: GenericGenerator

Add Python code at the file/module level.

__init__(chars, attrs)
generate(writer, phase=None)
class PSP.Generators.ScriptGenerator(chars, attrs)

Bases: GenericGenerator

Generate scripts.

__init__(chars, attrs)
generate(writer, phase=None)