MCPcopy Create free account
hub / github.com/webpy/webpy / python_lookahead

Method python_lookahead

web/template.py:384–398  ·  view source on GitHub ↗

Returns the first python token from the given text. >>> python_lookahead = Parser().python_lookahead >>> python_lookahead('for i in range(10):') 'for' >>> python_lookahead('else:') 'elsweb/template.py >>> python_lookahead(' x = 1') ' '

(self, text)

Source from the content-addressed store, hash-verified

382 return AssignmentNode(line.strip()), text
383
384 def python_lookahead(self, text):
385 """Returns the first python token from the given text.
386
387 >>> python_lookahead = Parser().python_lookahead
388 >>> python_lookahead('for i in range(10):')
389 'for'
390 >>> python_lookahead('else:')
391 'elsweb/template.py
392 >>> python_lookahead(' x = 1')
393 ' '
394 """
395 i = iter([text])
396 readline = lambda: next(i)
397 tokens = tokenize.generate_tokens(readline)
398 return next(tokens)[1]
399
400 def python_tokens(self, text):
401 i = iter([text])

Callers 2

read_sectionMethod · 0.95
read_block_sectionMethod · 0.95

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected