PSP.PSPParser
index
/usr/local/share/webware/PSP/PSPParser.py

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.
 
(c) Copyright 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.
 
THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
 
This software is based in part on work done by the Jakarta group.

 
Modules
       
PSP.BraceConverter
PSP.PSPUtils
os
re

 
Classes
       
PSPParser

 
class PSPParser
    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 handle the current location in
the code. When it finds one, it calls a list of functions, the xxxChecks,
asking each if it recognizes the characters as its kind of input.
When the check functions 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 check function accepted.
 
  Methods defined here:
__init__(self, ctxt)
checkDirective(self, handler, reader)
Check for directives. I support two right now, page and include.
checkEndBlock(self, handler, reader)
checkExpression(self, handler, reader)
Look for "expressions" and handle them
checkInclude(self, handler, reader)
Check for inserting another pages output in this spot.
checkInsert(self, 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(self, handler, reader)
Check for class methods defined in the page.
 
I only support one format for these,
<psp:method name="xxx" params="xxx,xxx">
Then the function BODY, then <psp:method>.
checkScript(self, handler, reader)
The main thing we're after. Check for embedded scripts.
checkScriptClass(self, handler, reader)
Check for class level code.
 
Check for Python code that should go in the class definition.
 
<psp:class>
        def foo(self):
                return dosomething()
</psp:class>
checkScriptFile(self, handler, reader)
Check for file level code.
 
Check for Python code that should go in the beginning of the generated module.
 
<psp:file>
        import xyz
        print 'hi Mome!'
        def foo(): return 'foo'
</psp:file>
commentCheck(self, handler, reader)
Comments just get eaten.
flushCharData(self, 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(self, until=None, accept=None)
Parse the PSP file.
setEventHandler(self, handler)
Set the handler this parser will use when it finds PSP code.

Data and other attributes defined here:
checklist = [<function commentCheck at 0xe9aa28>, <function checkExpression at 0xe9aaa0>, <function checkDirective at 0xe9ab18>, <function checkEndBlock at 0xe9ab90>, <function checkScript at 0xe9ac08>, <function checkScriptFile at 0xe9ac80>, <function checkScriptClass at 0xe9acf8>, <function checkMethod at 0xe9ad70>, <function checkInclude at 0xe9ade8>, <function checkInsert at 0xe9ae60>]

 
Functions
       
StringIO(...)
StringIO([s]) -- Return a StringIO-like stream for reading or writing

 
Data
        AwakeCreated = 0
ResponseObject = 'res'