class TemplateIfParser
from django.template.defaulttags import TemplateIfParser
Ancestors (MRO)
- builtins.object
- django.template.smartif.IfParser
- django.template.defaulttags.TemplateIfParser
Attribute | Type | Defined in |
---|---|---|
__dict__ |
getset_descriptor
|
django.template.smartif.IfParser |
__weakref__ |
getset_descriptor
|
django.template.smartif.IfParser |
Attribute | Value | Defined in |
---|---|---|
error_class |
<class 'django.template.exceptions.TemplateSyntaxError'> |
django.template.defaulttags.TemplateIfParser |
error_class |
<class 'ValueError'> |
django.template.smartif.IfParser |
def __init__(self, parser, *args, **kwargs)
django.template.defaulttags.TemplateIfParser
django.template.defaulttags.TemplateIfParser
Initialize self. See help(type(self)) for accurate signature.
def __init__(self, parser, *args, **kwargs):
self.template_parser = parser
super().__init__(*args, **kwargs)
django.template.smartif.IfParser
Initialize self. See help(type(self)) for accurate signature.
def __init__(self, tokens):
# Turn 'is','not' and 'not','in' into single tokens.
num_tokens = len(tokens)
mapped_tokens = []
i = 0
while i < num_tokens:
token = tokens[i]
if token == "is" and i + 1 < num_tokens and tokens[i + 1] == "not":
token = "is not"
i += 1 # skip 'not'
elif token == "not" and i + 1 < num_tokens and tokens[i + 1] == "in":
token = "not in"
i += 1 # skip 'in'
mapped_tokens.append(self.translate_token(token))
i += 1
self.tokens = mapped_tokens
self.pos = 0
self.current_token = self.next_token()
def create_var(self, value)
django.template.defaulttags.TemplateIfParser
django.template.defaulttags.TemplateIfParser
def create_var(self, value):
return TemplateLiteral(self.template_parser.compile_filter(value), value)
django.template.smartif.IfParser
def create_var(self, value):
return Literal(value)
def expression(self, rbp=0)
django.template.smartif.IfParser
def expression(self, rbp=0):
t = self.current_token
self.current_token = self.next_token()
left = t.nud(self)
while rbp < self.current_token.lbp:
t = self.current_token
self.current_token = self.next_token()
left = t.led(left, self)
return left
def next_token(self)
django.template.smartif.IfParser
def next_token(self):
if self.pos >= len(self.tokens):
return EndToken
else:
retval = self.tokens[self.pos]
self.pos += 1
return retval
def parse(self)
django.template.smartif.IfParser
def parse(self):
retval = self.expression()
# Check that we have exhausted all the tokens
if self.current_token is not EndToken:
raise self.error_class(
"Unused '%s' at end of if expression." % self.current_token.display()
)
return retval
def translate_token(self, token)
django.template.smartif.IfParser
def translate_token(self, token):
try:
op = OPERATORS[token]
except (KeyError, TypeError):
return self.create_var(token)
else:
return op()