Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, environment, source):
if isinstance(source, basestring):
self.source = parse_and_translate(environment, source)
elif isinstance(source, Node):
self.source = translate(environment, source)
else:
raise TypeError('unsupported source type %r' %
source.__class__.__name__)
self.environment = environment
self.generate_func = None
def __init__(self, extends, body, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.extends = extends
self.body = body
def get_items(self):
return [self.extends, self.body]
def __repr__(self):
return 'Template(%r, %r)' % (
self.extends,
self.body
)
class ForLoop(Node):
"""
A node that represents a for loop
"""
def __init__(self, item, seq, body, else_, recursive, lineno=None,
filename=None):
Node.__init__(self, lineno, filename)
self.item = item
self.seq = seq
self.body = body
self.else_ = else_
self.recursive = recursive
def get_items(self):
return [self.item, self.seq, self.body, self.else_, self.recursive]
"""
A node that stores multiple childnodes.
"""
def __init__(self, data, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
list.__init__(self, data)
def get_items(self):
return list(self)
def __repr__(self):
return 'NodeList(%s)' % list.__repr__(self)
class Template(Node):
"""
Node that represents a template.
"""
def __init__(self, extends, body, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.extends = extends
self.body = body
def get_items(self):
return [self.extends, self.body]
def __repr__(self):
return 'Template(%r, %r)' % (
self.extends,
self.body
def get_child_nodes(self):
return [x for x in self.get_items() if isinstance(x, Node)]
def __init__(self, body, filters, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.body = body
self.filters = filters
def get_items(self):
return [self.body] + list(self.filters)
def __repr__(self):
return 'Filter(%r, %r)' % (
self.body,
self.filters
)
class Block(Node):
"""
A node that represents a block.
"""
def __init__(self, name, body, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.name = name
self.body = body
def replace(self, node):
"""
Replace the current data with the copied data of another block
node.
"""
assert node.__class__ is Block
self.lineno = node.lineno
def __init__(self, expr, body, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.expr = expr
self.body = body
def get_items(self):
return [self.expr, self.body]
def __repr__(self):
return 'Call(%r, %r)' % (
self.expr,
self.body
)
class Set(Node):
"""
Allows defining own variables.
"""
def __init__(self, name, expr, scope_local, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.name = name
self.expr = expr
self.scope_local = scope_local
def get_items(self):
return [self.name, self.expr, self.scope_local]
def __repr__(self):
return 'Set(%r, %r, %r)' % (
self.name,
def __init__(self, text, variables, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.text = text
self.variables = variables
def get_items(self):
return [self.text] + list(self.variables)
def __repr__(self):
return 'Text(%r, %r)' % (
self.text,
self.variables
)
class NodeList(list, Node):
"""
A node that stores multiple childnodes.
"""
def __init__(self, data, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
list.__init__(self, data)
def get_items(self):
return list(self)
def __repr__(self):
return 'NodeList(%s)' % list.__repr__(self)
class Template(Node):
"""
Create an independent clone of this node.
"""
return copy(self)
def get_items(self):
return [self.name, self.body]
def __repr__(self):
return 'Block(%r, %r)' % (
self.name,
self.body
)
class Include(Node):
"""
A node that represents the include tag.
"""
def __init__(self, template, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.template = template
def get_items(self):
return [self.template]
def __repr__(self):
return 'Include(%r)' % (
self.template
)
"""
A node that represents the cycle statement.
"""
def __init__(self, seq, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.seq = seq
def get_items(self):
return [self.seq]
def __repr__(self):
return 'Cycle(%r)' % (self.seq,)
class Print(Node):
"""
A node that represents variable tags and print calls.
"""
def __init__(self, expr, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.expr = expr
def get_items(self):
return [self.expr]
def __repr__(self):
return 'Print(%r)' % (self.expr,)
class Macro(Node):
"""
A node that represents variable tags and print calls.
"""
def __init__(self, expr, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.expr = expr
def get_items(self):
return [self.expr]
def __repr__(self):
return 'Print(%r)' % (self.expr,)
class Macro(Node):
"""
A node that represents a macro.
"""
def __init__(self, name, arguments, body, lineno=None, filename=None):
Node.__init__(self, lineno, filename)
self.name = name
self.arguments = arguments
self.body = body
def get_items(self):
return [self.name] + list(chain(*self.arguments)) + [self.body]
def __repr__(self):
return 'Macro(%r, %r, %r)' % (
self.name,