+++ /dev/null
-# -*- coding: utf-8 -*-
-"""
- jinja.ast
- ~~~~~~~~~
-
- Advance Syntax Tree for jinja.
-
- :copyright: 2006 by Armin Ronacher.
- :license: BSD, see LICENSE for more details.
-"""
-
-class Node(object):
- """
- Baseclass of all nodes. For instance checking.
- """
- __slots__ = ()
-
- def __init__(self):
- raise TypeError('cannot create %r instances' %
- self.__class__.__name__)
-
-
-class Expression(list, Node):
- """
- Node that helds childnodes. Normally just used temporary.
- """
- __slots__ = ()
-
- def __init__(self, *args, **kwargs):
- super(Expression, self).__init__(*args, **kwargs)
-
- def __repr__(self):
- return 'Expression(%s)' % list.__repr__(self)
-
-
-class Comment(Node):
- """
- Node that helds a comment. We keep comments in the data
- if some translator wants to forward it into the generated
- code (for example the python translator).
- """
- __slots__ = ('pos', 'comment',)
-
- def __init__(self, pos, comment):
- self.pos = pos
- self.comment = comment
-
- def __repr__(self):
- return 'Comment(%r, %r)' % (self.pos, self.comment)
-
-
-class Page(Node):
- """
- Node that helds all root nodes.
- """
- __slots__ = ('filename', 'nodes')
-
- def __init__(self, filename, nodes):
- self.filename = filename
- self.nodes = nodes
-
- def __repr__(self):
- return 'Page(%r, %r)' % (
- self.filename,
- self.nodes
- )
-
-
-class Variable(Node):
- """
- Node for variables
- """
- __slots__ = ('pos', 'expression')
-
- def __init__(self, pos, expression):
- self.pos = pos
- self.expression = expression
-
- def __repr__(self):
- return 'Variable(%r)' % self.expression
-
-
-class Data(Node):
- """
- Node for data outside of tags.
- """
- __slots__ = ('pos', 'data')
-
- def __init__(self, pos, data):
- self.pos = pos
- self.data = data
-
- def __repr__(self):
- return 'Data(%d, %r)' % (self.pos, self.data)
-
-
-class Name(Node):
- """
- Node for names.
- """
- __slots__ = ('pos', 'data')
-
- def __init__(self, pos, data):
- self.pos = pos
- self.data = data
-
- def __repr__(self):
- return 'Name(%d, %r)' % (self.pos, self.data)
from jinja.lexer import Lexer
from jinja.parser import Parser
from jinja.exceptions import TagNotFound, FilterNotFound
-from jinja.defaults import DEFAULT_TAGS, DEFAULT_FILTERS
+from jinja.defaults import DEFAULT_FILTERS
class Environment(object):
self.template_charset = template_charset
self.charset = charset
self.loader = loader
- self.tags = tags or DEFAULT_TAGS.copy()
self.filters = filters or DEFAULT_FILTERS.copy()
# create lexer
parser = Parser(self, source)
return parser.parse_page()
- def get_tag(self, name):
- """
- Return the tag for a specific name. Raise a `TagNotFound` exception
- if a tag with this name is not registered.
- """
- if name not in self._tags:
- raise TagNotFound(name)
- return self._tags[name]
-
def get_filter(self, name):
"""
Return the filter for a given name. Raise a `FilterNotFound` exception