Package web2py :: Package gluon :: Module template :: Class TemplateParser
[hide private]
[frames] | no frames]

Class TemplateParser

source code

object --+
         |
        TemplateParser

Instance Methods [hide private]
 
__init__(self, text, name='ParserContainer', context={}, path='views/', writer='response.write', lexers={}, delimiters=('{{', '}}'), _super_nodes=[])
text -- text to parse context -- context to parse in path -- folder path to templates writer -- string of writer class to use lexers -- dict of custom lexers to use.
source code
 
to_string(self)
Return the parsed template with correct indentation.
source code
 
__str__(self)
Make sure str works exactly the same as python 3
source code
 
__unicode__(self)
Make sure str works exactly the same as python 3
source code
 
reindent(self, text)
Reindents a string of unindented python code.
source code
 
_raise_error(self, message='', text=1)
Raise an error using itself as the filename and textual content.
source code
 
_get_file_text(self, filename)
Attempt to open ``filename`` and retrieve its text.
source code
 
include(self, content, filename)
Include ``filename`` here.
source code
 
extend(self, filename)
Extend ``filename``.
source code
 
parse(self, text) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Class Variables [hide private]
  r_tag = re.compile(r'(?s)(\{\{.*?\}\})')
  r_multiline = re.compile(r'(?s)(""".*?""")|(\'\'\'.*?\'\'\')')
  re_block = re.compile(r'(?s)^(elif |else:|except:|except |fina...
  re_unblock = re.compile(r'(?s)^(return|continue|break|raise)( ...
  re_pass = re.compile(r'(?s)^pass( .*)?$')
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, text, name='ParserContainer', context={}, path='views/', writer='response.write', lexers={}, delimiters=('{{', '}}'), _super_nodes=[])
(Constructor)

source code 

text -- text to parse
context -- context to parse in
path -- folder path to templates
writer -- string of writer class to use
lexers -- dict of custom lexers to use.
delimiters -- for example ('{{','}}')
_super_nodes -- a list of nodes to check for inclusion
                this should only be set by "self.extend"
                It contains a list of SuperNodes from a child
                template that need to be handled.

Overrides: object.__init__

to_string(self)

source code 

Return the parsed template with correct indentation.

Used to make it easier to port to python3.

__str__(self)
(Informal representation operator)

source code 
Make sure str works exactly the same as python 3
Overrides: object.__str__

_get_file_text(self, filename)

source code 

Attempt to open ``filename`` and retrieve its text.

This will use self.path to search for the file.

extend(self, filename)

source code 
Extend ``filename``. Anything not declared in a block defined by the parent will be placed in the parent templates ``{{include}}`` block.

Class Variable Details [hide private]

re_block

Value:
re.compile(r'(?s)^(elif |else:|except:|except |finally:).*$')

re_unblock

Value:
re.compile(r'(?s)^(return|continue|break|raise)( .*)?$')