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

Method expect

src/jinja2/lexer.py:403–425  ·  view source on GitHub ↗

Expect a given token type and return it. This accepts the same argument as :meth:`jinja2.lexer.Token.test`.

(self, expr: str)

Source from the content-addressed store, hash-verified

401 self.closed = True
402
403 def expect(self, expr: str) -> Token:
404 """Expect a given token type and return it. This accepts the same
405 argument as :meth:`jinja2.lexer.Token.test`.
406 """
407 if not self.current.test(expr):
408 expr = describe_token_expr(expr)
409
410 if self.current.type is TOKEN_EOF:
411 raise TemplateSyntaxError(
412 f"unexpected end of template, expected {expr!r}.",
413 self.current.lineno,
414 self.name,
415 self.filename,
416 )
417
418 raise TemplateSyntaxError(
419 f"expected token {expr!r}, got {describe_token(self.current)!r}",
420 self.current.lineno,
421 self.name,
422 self.filename,
423 )
424
425 return next(self)
426
427
428def get_lexer(environment: "Environment") -> "Lexer":

Callers 15

parseMethod · 0.80
_parse_blockMethod · 0.80
parseMethod · 0.80
parse_statementsMethod · 0.80
parse_forMethod · 0.80
parse_ifMethod · 0.80
parse_withMethod · 0.80
parse_blockMethod · 0.80
parse_importMethod · 0.80
parse_fromMethod · 0.80
parse_signatureMethod · 0.80
parse_printMethod · 0.80

Calls 4

describe_token_exprFunction · 0.85
TemplateSyntaxErrorClass · 0.85
describe_tokenFunction · 0.85
testMethod · 0.45

Tested by 1

parseMethod · 0.64