MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / PythonIndenter

Class PythonIndenter

tools/python-3.11.9-amd64/Tools/scripts/pindent.py:98–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96start = 'if', 'while', 'for', 'try', 'with', 'def', 'class'
97
98class PythonIndenter:
99
100 def __init__(self, fpi = sys.stdin, fpo = sys.stdout,
101 indentsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
102 self.fpi = fpi
103 self.fpo = fpo
104 self.indentsize = indentsize
105 self.tabsize = tabsize
106 self.lineno = 0
107 self.expandtabs = expandtabs
108 self._write = fpo.write
109 self.kwprog = re.compile(
110 r'^(?:\s|\\\n)*(?P<kw>[a-z]+)'
111 r'((?:\s|\\\n)+(?P<id>[a-zA-Z_]\w*))?'
112 r'[^\w]')
113 self.endprog = re.compile(
114 r'^(?:\s|\\\n)*#?\s*end\s+(?P<kw>[a-z]+)'
115 r'(\s+(?P<id>[a-zA-Z_]\w*))?'
116 r'[^\w]')
117 self.wsprog = re.compile(r'^[ \t]*')
118 # end def __init__
119
120 def write(self, line):
121 if self.expandtabs:
122 self._write(line.expandtabs(self.tabsize))
123 else:
124 self._write(line)
125 # end if
126 # end def write
127
128 def readline(self):
129 line = self.fpi.readline()
130 if line: self.lineno += 1
131 # end if
132 return line
133 # end def readline
134
135 def error(self, fmt, *args):
136 if args: fmt = fmt % args
137 # end if
138 sys.stderr.write('Error at line %d: %s\n' % (self.lineno, fmt))
139 self.write('### %s ###\n' % fmt)
140 # end def error
141
142 def getline(self):
143 line = self.readline()
144 while line[-2:] == '\\\n':
145 line2 = self.readline()
146 if not line2: break
147 # end if
148 line += line2
149 # end while
150 return line
151 # end def getline
152
153 def putline(self, line, indent):
154 tabs, spaces = divmod(indent*self.indentsize, self.tabsize)
155 i = self.wsprog.match(line).end()

Callers 6

complete_filterFunction · 0.85
delete_filterFunction · 0.85
reformat_filterFunction · 0.85
complete_stringFunction · 0.85
delete_stringFunction · 0.85
reformat_stringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected