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

 
Classes
       
PSPParser
exceptions.Exception(exceptions.BaseException)
PSPParserException

 
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 0xf6b230>, <function checkExpression at 0xf6b2a8>, <function checkDirective at 0xf6b320>, <function checkEndBlock at 0xf6b398>, <function checkScript at 0xf6b410>, <function checkScriptFile at 0xf6b488>, <function checkScriptClass at 0xf6b500>, <function checkMethod at 0xf6b578>, <function checkInclude at 0xf6b5f0>, <function checkInsert at 0xf6b668>]

 
class PSPParserException(exceptions.Exception)
    
Method resolution order:
PSPParserException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object at 0x5d4560>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

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

 
Data
        AwakeCreated = 0
ResponseObject = 'res'