summaryrefslogtreecommitdiff
path: root/deps/v8/third_party/jinja2/nodes.py
diff options
context:
space:
mode:
authorMichaƫl Zasso <targos@protonmail.com>2018-05-31 11:11:57 +0200
committerMyles Borins <mylesborins@google.com>2018-06-01 09:58:27 +0200
commit352a525eb984b8fa2d6f0f6fd68395e6a080bba4 (patch)
treea105ae93f8fd8f533cce19a429f1b6e95d6e11ca /deps/v8/third_party/jinja2/nodes.py
parentfaf449ca0490f5371dc6cbbc94a87eb697b00fcc (diff)
downloadandroid-node-v8-352a525eb984b8fa2d6f0f6fd68395e6a080bba4.tar.gz
android-node-v8-352a525eb984b8fa2d6f0f6fd68395e6a080bba4.tar.bz2
android-node-v8-352a525eb984b8fa2d6f0f6fd68395e6a080bba4.zip
deps: update V8 to 6.7.288.43
PR-URL: https://github.com/nodejs/node/pull/19989 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/third_party/jinja2/nodes.py')
-rw-r--r--deps/v8/third_party/jinja2/nodes.py184
1 files changed, 132 insertions, 52 deletions
diff --git a/deps/v8/third_party/jinja2/nodes.py b/deps/v8/third_party/jinja2/nodes.py
index d32046ce5c..4d9a01ad8b 100644
--- a/deps/v8/third_party/jinja2/nodes.py
+++ b/deps/v8/third_party/jinja2/nodes.py
@@ -9,7 +9,7 @@
`get_nodes` used by the parser and translator in order to normalize
python and jinja nodes.
- :copyright: (c) 2010 by the Jinja Team.
+ :copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
import types
@@ -17,7 +17,7 @@ import operator
from collections import deque
from jinja2.utils import Markup
-from jinja2._compat import izip, with_metaclass, text_type
+from jinja2._compat import izip, with_metaclass, text_type, PY2
#: the types we support for context functions
@@ -242,6 +242,35 @@ class Node(with_metaclass(NodeType, object)):
arg in self.fields)
)
+ def dump(self):
+ def _dump(node):
+ if not isinstance(node, Node):
+ buf.append(repr(node))
+ return
+
+ buf.append('nodes.%s(' % node.__class__.__name__)
+ if not node.fields:
+ buf.append(')')
+ return
+ for idx, field in enumerate(node.fields):
+ if idx:
+ buf.append(', ')
+ value = getattr(node, field)
+ if isinstance(value, list):
+ buf.append('[')
+ for idx, item in enumerate(value):
+ if idx:
+ buf.append(', ')
+ _dump(item)
+ buf.append(']')
+ else:
+ _dump(value)
+ buf.append(')')
+ buf = []
+ _dump(self)
+ return ''.join(buf)
+
+
class Stmt(Node):
"""Base node for all statements."""
@@ -285,7 +314,7 @@ class For(Stmt):
class If(Stmt):
"""If `test` is true, `body` is rendered, else `else_`."""
- fields = ('test', 'body', 'else_')
+ fields = ('test', 'body', 'elif_', 'else_')
class Macro(Stmt):
@@ -308,6 +337,15 @@ class FilterBlock(Stmt):
fields = ('body', 'filter')
+class With(Stmt):
+ """Specific node for with statements. In older versions of Jinja the
+ with statement was implemented on the base of the `Scope` node instead.
+
+ .. versionadded:: 2.9.3
+ """
+ fields = ('targets', 'values', 'body')
+
+
class Block(Stmt):
"""A node that represents a block."""
fields = ('name', 'body', 'scoped')
@@ -349,7 +387,7 @@ class Assign(Stmt):
class AssignBlock(Stmt):
"""Assigns a block to a target."""
- fields = ('target', 'body')
+ fields = ('target', 'filter', 'body')
class Expr(Node):
@@ -427,6 +465,18 @@ class Name(Expr):
'True', 'False', 'None')
+class NSRef(Expr):
+ """Reference to a namespace value assignment"""
+ fields = ('name', 'attr')
+
+ def can_assign(self):
+ # We don't need any special checks here; NSRef assignments have a
+ # runtime check to ensure the target is a namespace object which will
+ # have been checked already as it is created using a normal assignment
+ # which goes through a `Name` node.
+ return True
+
+
class Literal(Expr):
"""Baseclass for literals."""
abstract = True
@@ -441,7 +491,14 @@ class Const(Literal):
fields = ('value',)
def as_const(self, eval_ctx=None):
- return self.value
+ rv = self.value
+ if PY2 and type(rv) is text_type and \
+ self.environment.policies['compiler.ascii_str']:
+ try:
+ rv = rv.encode('ascii')
+ except UnicodeError:
+ pass
+ return rv
@classmethod
def from_untrusted(cls, value, lineno=None, environment=None):
@@ -542,6 +599,25 @@ class CondExpr(Expr):
return self.expr2.as_const(eval_ctx)
+def args_as_const(node, eval_ctx):
+ args = [x.as_const(eval_ctx) for x in node.args]
+ kwargs = dict(x.as_const(eval_ctx) for x in node.kwargs)
+
+ if node.dyn_args is not None:
+ try:
+ args.extend(node.dyn_args.as_const(eval_ctx))
+ except Exception:
+ raise Impossible()
+
+ if node.dyn_kwargs is not None:
+ try:
+ kwargs.update(node.dyn_kwargs.as_const(eval_ctx))
+ except Exception:
+ raise Impossible()
+
+ return args, kwargs
+
+
class Filter(Expr):
"""This node applies a filter on an expression. `name` is the name of
the filter, the rest of the fields are the same as for :class:`Call`.
@@ -549,39 +625,43 @@ class Filter(Expr):
If the `node` of a filter is `None` the contents of the last buffer are
filtered. Buffers are created by macros and filter blocks.
"""
+
fields = ('node', 'name', 'args', 'kwargs', 'dyn_args', 'dyn_kwargs')
def as_const(self, eval_ctx=None):
eval_ctx = get_eval_context(self, eval_ctx)
+
if eval_ctx.volatile or self.node is None:
raise Impossible()
+
# we have to be careful here because we call filter_ below.
# if this variable would be called filter, 2to3 would wrap the
# call in a list beause it is assuming we are talking about the
# builtin filter function here which no longer returns a list in
# python 3. because of that, do not rename filter_ to filter!
filter_ = self.environment.filters.get(self.name)
+
if filter_ is None or getattr(filter_, 'contextfilter', False):
raise Impossible()
- obj = self.node.as_const(eval_ctx)
- args = [x.as_const(eval_ctx) for x in self.args]
+
+ # We cannot constant handle async filters, so we need to make sure
+ # to not go down this path.
+ if (
+ eval_ctx.environment.is_async
+ and getattr(filter_, 'asyncfiltervariant', False)
+ ):
+ raise Impossible()
+
+ args, kwargs = args_as_const(self, eval_ctx)
+ args.insert(0, self.node.as_const(eval_ctx))
+
if getattr(filter_, 'evalcontextfilter', False):
args.insert(0, eval_ctx)
elif getattr(filter_, 'environmentfilter', False):
args.insert(0, self.environment)
- kwargs = dict(x.as_const(eval_ctx) for x in self.kwargs)
- if self.dyn_args is not None:
- try:
- args.extend(self.dyn_args.as_const(eval_ctx))
- except Exception:
- raise Impossible()
- if self.dyn_kwargs is not None:
- try:
- kwargs.update(self.dyn_kwargs.as_const(eval_ctx))
- except Exception:
- raise Impossible()
+
try:
- return filter_(obj, *args, **kwargs)
+ return filter_(*args, **kwargs)
except Exception:
raise Impossible()
@@ -590,8 +670,24 @@ class Test(Expr):
"""Applies a test on an expression. `name` is the name of the test, the
rest of the fields are the same as for :class:`Call`.
"""
+
fields = ('node', 'name', 'args', 'kwargs', 'dyn_args', 'dyn_kwargs')
+ def as_const(self, eval_ctx=None):
+ test = self.environment.tests.get(self.name)
+
+ if test is None:
+ raise Impossible()
+
+ eval_ctx = get_eval_context(self, eval_ctx)
+ args, kwargs = args_as_const(self, eval_ctx)
+ args.insert(0, self.node.as_const(eval_ctx))
+
+ try:
+ return test(*args, **kwargs)
+ except Exception:
+ raise Impossible()
+
class Call(Expr):
"""Calls an expression. `args` is a list of arguments, `kwargs` a list
@@ -602,38 +698,6 @@ class Call(Expr):
"""
fields = ('node', 'args', 'kwargs', 'dyn_args', 'dyn_kwargs')
- def as_const(self, eval_ctx=None):
- eval_ctx = get_eval_context(self, eval_ctx)
- if eval_ctx.volatile:
- raise Impossible()
- obj = self.node.as_const(eval_ctx)
-
- # don't evaluate context functions
- args = [x.as_const(eval_ctx) for x in self.args]
- if isinstance(obj, _context_function_types):
- if getattr(obj, 'contextfunction', False):
- raise Impossible()
- elif getattr(obj, 'evalcontextfunction', False):
- args.insert(0, eval_ctx)
- elif getattr(obj, 'environmentfunction', False):
- args.insert(0, self.environment)
-
- kwargs = dict(x.as_const(eval_ctx) for x in self.kwargs)
- if self.dyn_args is not None:
- try:
- args.extend(self.dyn_args.as_const(eval_ctx))
- except Exception:
- raise Impossible()
- if self.dyn_kwargs is not None:
- try:
- kwargs.update(self.dyn_kwargs.as_const(eval_ctx))
- except Exception:
- raise Impossible()
- try:
- return obj(*args, **kwargs)
- except Exception:
- raise Impossible()
-
class Getitem(Expr):
"""Get an attribute or item from an expression and prefer the item."""
@@ -701,7 +765,7 @@ class Concat(Expr):
class Compare(Expr):
"""Compares an expression with some other expressions. `ops` must be a
- list of :class:`Operand`\s.
+ list of :class:`Operand`\\s.
"""
fields = ('expr', 'ops')
@@ -894,6 +958,22 @@ class Scope(Stmt):
fields = ('body',)
+class OverlayScope(Stmt):
+ """An overlay scope for extensions. This is a largely unoptimized scope
+ that however can be used to introduce completely arbitrary variables into
+ a sub scope from a dictionary or dictionary like object. The `context`
+ field has to evaluate to a dictionary object.
+
+ Example usage::
+
+ OverlayScope(context=self.call_method('get_context'),
+ body=[...])
+
+ .. versionadded:: 2.10
+ """
+ fields = ('context', 'body')
+
+
class EvalContextModifier(Stmt):
"""Modifies the eval context. For each option that should be modified,
a :class:`Keyword` has to be added to the :attr:`options` list.