PSPParser

The PSP parser.

This module handles the actual reading of the characters in the source PSP file and checking it for valid psp tokens. When it finds one, it calls ParseEventHandler with the characters it found.

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.PSPParser.PSPParser(ctxt)

Bases: object

The main PSP parser class.

The PSPParser class does the actual sniffing through the input file looking for anything we’re interested in. Basically, it starts by looking at the code looking for a ‘<’ symbol. It looks at the code by working with a PSPReader object, which handles the current location in the code. When it finds one, it calls a list of checker methods, asking each if it recognizes the characters as its kind of input. When the checker methods look at the characters, if they want it, they go ahead and gobble it up and set up to create it in the servlet when the time comes. When they return, they return true if they accept the character, and the PSPReader object cursor is positioned past the end of the block that the checker method accepted.

__init__(ctxt)
checkDirective(handler, reader)

Check for directives; for now we support only page and include.

checkEndBlock(handler, reader)

Check for the end of a block.

checkExpression(handler, reader)

Look for “expressions” and handle them.

checkInclude(handler, reader)

Check for inserting another pages output in this spot.

checkInsert(handler, reader)

Check for straight character dumps.

No big hurry for this. It’s almost the same as the page include directive. This is only a partial implementation of what JSP does. JSP can pull it from another server, servlet, JSP page, etc.

checkMethod(handler, reader)

Check for class methods defined in the page.

We only support one format for these, <psp:method name="xxx" params="xxx,xxx"> Then the function body, then </psp:method>.

checkScript(handler, reader)

The main thing we’re after. Check for embedded scripts.

checkScriptClass(handler, reader)

Check for class level code.

Check for Python code that should go in the class definition:

<psp:class>
    def foo(self):
        return self.dosomething()
</psp:class>
checkScriptFile(handler, reader)

Check for file level code.

Check for Python code that must go to the top of the generated module:

<psp:file>
    import xyz
    print('hi Mome!')
    def foo(): return 'foo'
</psp:file>
checklist = [<function PSPParser.commentCheck>, <function PSPParser.checkExpression>, <function PSPParser.checkDirective>, <function PSPParser.checkEndBlock>, <function PSPParser.checkScript>, <function PSPParser.checkScriptFile>, <function PSPParser.checkScriptClass>, <function PSPParser.checkMethod>, <function PSPParser.checkInclude>, <function PSPParser.checkInsert>]
commentCheck(_handler, reader)

Comments just get eaten.

flushCharData(start, stop)

Dump everything to the char data handler.

Dump all the HTML that we’ve accumulated over to the character data handler in the event handler object.

parse(until=None)

Parse the PSP file.

setEventHandler(handler)

Set the handler this parser will use when it finds PSP code.

PSP.PSPParser.checker(method)

Decorator for adding a method to the checklist.