(tokens, name, context)
| 937 | |
| 938 | |
| 939 | def parse_for(tokens, name, context): |
| 940 | first, pos = tokens[0] |
| 941 | tokens = tokens[1:] |
| 942 | context = ('for',) + context |
| 943 | content = [] |
| 944 | assert first.startswith('for ') |
| 945 | if first.endswith(':'): |
| 946 | first = first[:-1] |
| 947 | first = first[3:].strip() |
| 948 | match = in_re.search(first) |
| 949 | if not match: |
| 950 | raise TemplateError( |
| 951 | 'Bad for (no "in") in %r' % first, |
| 952 | position=pos, name=name) |
| 953 | vars = first[:match.start()] |
| 954 | if '(' in vars: |
| 955 | raise TemplateError( |
| 956 | 'You cannot have () in the variable section of a for loop (%r)' |
| 957 | % vars, position=pos, name=name) |
| 958 | vars = tuple([ |
| 959 | v.strip() for v in first[:match.start()].split(',') |
| 960 | if v.strip()]) |
| 961 | expr = first[match.end():] |
| 962 | while 1: |
| 963 | if not tokens: |
| 964 | raise TemplateError( |
| 965 | 'No {{endfor}}', |
| 966 | position=pos, name=name) |
| 967 | if (isinstance(tokens[0], tuple) and tokens[0][0] == 'endfor'): |
| 968 | return ('for', pos, vars, expr, content), tokens[1:] |
| 969 | next_chunk, tokens = parse_expr(tokens, name, context) |
| 970 | content.append(next_chunk) |
| 971 | |
| 972 | |
| 973 | def parse_default(tokens, name, context): |
no test coverage detected