MCPcopy Create free account
hub / github.com/numpy/numpy / parse_for

Function parse_for

tools/npy_tempita/__init__.py:939–970  ·  view source on GitHub ↗
(tokens, name, context)

Source from the content-addressed store, hash-verified

937
938
939def 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
973def parse_default(tokens, name, context):

Callers 1

parse_exprFunction · 0.85

Calls 6

TemplateErrorClass · 0.85
parse_exprFunction · 0.85
startswithMethod · 0.80
endswithMethod · 0.80
stripMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected