MCPcopy Index your code
hub / github.com/python/cpython / IndentSearcher

Class IndentSearcher

Lib/idlelib/editor.py:1575–1617  ·  view source on GitHub ↗

Manage initial indent guess, returned by run method.

Source from the content-addressed store, hash-verified

1573
1574
1575class IndentSearcher:
1576 "Manage initial indent guess, returned by run method."
1577
1578 def __init__(self, text):
1579 self.text = text
1580 self.i = self.finished = 0
1581 self.blkopenline = self.indentedline = None
1582
1583 def readline(self):
1584 if self.finished:
1585 return ""
1586 i = self.i = self.i + 1
1587 mark = repr(i) + ".0"
1588 if self.text.compare(mark, ">=", "end"):
1589 return ""
1590 return self.text.get(mark, mark + " lineend+1c")
1591
1592 def tokeneater(self, type, token, start, end, line,
1593 INDENT=tokenize.INDENT,
1594 NAME=tokenize.NAME,
1595 OPENERS=('class', 'def', 'for', 'if', 'match', 'try',
1596 'while', 'with')):
1597 if self.finished:
1598 pass
1599 elif type == NAME and token in OPENERS:
1600 self.blkopenline = line
1601 elif type == INDENT and self.blkopenline:
1602 self.indentedline = line
1603 self.finished = 1
1604
1605 def run(self):
1606 """Return 2 lines containing block opener and indent.
1607
1608 Either the indent line or both may be None.
1609 """
1610 try:
1611 tokens = tokenize.generate_tokens(self.readline)
1612 for token in tokens:
1613 self.tokeneater(*token)
1614 except (tokenize.TokenError, SyntaxError):
1615 # Stopping the tokenizer early can trigger spurious errors.
1616 pass
1617 return self.blkopenline, self.indentedline
1618
1619### end autoindent code ###
1620

Callers 1

guess_indentMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…