This is called with the stream as returned by `tokenize` and wraps every token in a :class:`Token` and converts the value.
(self, stream, name=None, filename=None)
| 556 | return TokenStream(self.wrap(stream, name, filename), name, filename) |
| 557 | |
| 558 | def wrap(self, stream, name=None, filename=None): |
| 559 | """This is called with the stream as returned by `tokenize` and wraps |
| 560 | every token in a :class:`Token` and converts the value. |
| 561 | """ |
| 562 | for lineno, token, value in stream: |
| 563 | if token in ignored_tokens: |
| 564 | continue |
| 565 | elif token == 'linestatement_begin': |
| 566 | token = 'block_begin' |
| 567 | elif token == 'linestatement_end': |
| 568 | token = 'block_end' |
| 569 | # we are not interested in those tokens in the parser |
| 570 | elif token in ('raw_begin', 'raw_end'): |
| 571 | continue |
| 572 | elif token == 'data': |
| 573 | value = self._normalize_newlines(value) |
| 574 | elif token == 'keyword': |
| 575 | token = value |
| 576 | elif token == 'name': |
| 577 | value = str(value) |
| 578 | if check_ident and not value.isidentifier(): |
| 579 | raise TemplateSyntaxError( |
| 580 | 'Invalid character in identifier', |
| 581 | lineno, name, filename) |
| 582 | elif token == 'string': |
| 583 | # try to unescape string |
| 584 | try: |
| 585 | value = self._normalize_newlines(value[1:-1]) \ |
| 586 | .encode('ascii', 'backslashreplace') \ |
| 587 | .decode('unicode-escape') |
| 588 | except Exception as e: |
| 589 | msg = str(e).split(':')[-1].strip() |
| 590 | raise TemplateSyntaxError(msg, lineno, name, filename) |
| 591 | elif token == 'integer': |
| 592 | value = int(value) |
| 593 | elif token == 'float': |
| 594 | value = float(value) |
| 595 | elif token == 'operator': |
| 596 | token = operators[value] |
| 597 | yield Token(lineno, token, value) |
| 598 | |
| 599 | def tokeniter(self, source, name, filename=None, state=None): |
| 600 | """This method tokenizes the text and returns the tokens in a |
no test coverage detected