MCPcopy
hub / github.com/pallets/jinja / Token

Class Token

src/jinja2/lexer.py:269–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267
268
269class Token(t.NamedTuple):
270 lineno: int
271 type: str
272 value: str
273
274 def __str__(self) -> str:
275 return describe_token(self)
276
277 def test(self, expr: str) -> bool:
278 """Test a token against a token expression. This can either be a
279 token type or ``'token_type:token_value'``. This can only test
280 against string values and types.
281 """
282 # here we do a regular string equality check as test_any is usually
283 # passed an iterable of not interned strings.
284 if self.type == expr:
285 return True
286
287 if ":" in expr:
288 return expr.split(":", 1) == [self.type, self.value]
289
290 return False
291
292 def test_any(self, *iterable: str) -> bool:
293 """Test against multiple token expressions."""
294 return any(self.test(expr) for expr in iterable)
295
296
297class TokenStreamIterator:

Callers 6

interpolateMethod · 0.90
TestTokenStreamClass · 0.90
filter_streamMethod · 0.90
__init__Method · 0.85
closeMethod · 0.85
wrapMethod · 0.85

Calls

no outgoing calls

Tested by 1

interpolateMethod · 0.72