summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2021-01-29 19:21:26 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-26 10:25:08 +0100
commit179ee13eb37348cd87169a198aec18fedccc8668 (patch)
treeb7fb8bd4e824e66de1913bfbdc97c901ea6a7f52 /django
parent0c7e880e13b837dd76276c04ebdc338bb76d1379 (diff)
Refs #24121 -- Added __repr__() to FilterExpression, Lexer, Parser, and Token.
Diffstat (limited to 'django')
-rw-r--r--django/template/base.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 85ce3c2abd..b1eec99655 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -308,7 +308,7 @@ class Token:
self.lineno = lineno
self.position = position
- def __str__(self):
+ def __repr__(self):
token_name = self.token_type.name.capitalize()
return ('<%s token: "%s...">' %
(token_name, self.contents[:20].replace('\n', '')))
@@ -334,6 +334,13 @@ class Lexer:
self.template_string = template_string
self.verbatim = False
+ def __repr__(self):
+ return '<%s template_string="%s...", verbatim=%s>' % (
+ self.__class__.__qualname__,
+ self.template_string[:20].replace('\n', ''),
+ self.verbatim,
+ )
+
def tokenize(self):
"""
Return a list of tokens from a given template_string.
@@ -423,6 +430,9 @@ class Parser:
self.add_library(builtin)
self.origin = origin
+ def __repr__(self):
+ return '<%s tokens=%r>' % (self.__class__.__qualname__, self.tokens)
+
def parse(self, parse_until=None):
"""
Iterate through the parser tokens and compiles each one into a node.
@@ -723,6 +733,9 @@ class FilterExpression:
def __str__(self):
return self.token
+ def __repr__(self):
+ return "<%s %r>" % (self.__class__.__qualname__, self.token)
+
class Variable:
"""