def checkMethod(self, 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>. """ if not reader.matches('<psp:method'): return False start = reader.mark() reader.advance(11) attrs = reader.parseTagAttributes() checkAttributes('method', attrs, (['name'], ['params'])) reader.skipSpaces() if not reader.matches('>'): raise PSPParserException('Expected method declaration close') reader.advance(1) stop = reader.mark() handler.setTemplateInfo(self.tmplStart, self.tmplStop) handler.handleMethod(start, stop, attrs) start = stop # skip past the close marker, return the point before the close marker stop = reader.skipUntil('</psp:method>') handler.handleMethodEnd(start, stop, attrs) return True
def checkDirective(self, handler, reader): """Check for directives; for now we support only page and include.""" if not reader.matches('<%@'): return False start = reader.mark() reader.advance(3) reader.skipSpaces() for directive in ('page', 'include', 'taglib'): if reader.matches(directive): match = directive break else: raise PSPParserException('Invalid directive') reader.advance(len(match)) # parse the directive attr:val pair dictionary attrs = reader.parseTagAttributes() if match == 'page': checkAttributes('Page directive', attrs, ([], set([ 'imports', 'extends', 'method', 'isThreadSafe', 'isInstanceSafe', 'indentType', 'indentSpaces', 'gobbleWhitespace', 'formatter']))) elif match == 'include': checkAttributes('Include directive', attrs, (['file'], [])) else: raise PSPParserException('%s directive not implemented' % match) reader.skipSpaces() # skip to where we expect a close tag if reader.matches('%>'): reader.advance(2) # advance past it else: raise PSPParserException('Directive not terminated') stop = reader.mark() handler.setTemplateInfo(self.tmplStart, self.tmplStop) handler.handleDirective(match, start, stop, attrs) return True
def checkInclude(self, handler, reader): """Check for inserting another pages output in this spot.""" if not reader.matches('<psp:include'): return False reader.advance(12) reader.skipSpaces() attrs = reader.parseTagAttributes() checkAttributes('include', attrs, (['path'], [])) reader.skipSpaces() if not reader.matches('>'): raise PSPParserException('Include bodies not implemented') reader.advance(1) handler.setTemplateInfo(self.tmplStart, self.tmplStop) handler.handleInclude(attrs, None) return True
def 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. """ if not reader.matches('<psp:insert'): return False reader.advance(11) reader.skipSpaces() attrs = reader.parseTagAttributes() checkAttributes('insert', attrs, (['file'], [])) reader.skipSpaces() if not reader.matches('>'): raise PSPParserException('Insert bodies not implemented') reader.advance(1) handler.setTemplateInfo(self.tmplStart, self.tmplStop) handler.handleInsert(attrs, None) return True