ยปCore Development>Code coverage>Lib/idlelib/rstrip.py

Python code coverage for Lib/idlelib/rstrip.py

#countcontent
1n/a'Provides "Strip trailing whitespace" under the "Format" menu.'
2n/a
3n/aclass RstripExtension:
4n/a
5n/a menudefs = [
6n/a ('format', [None, ('Strip trailing whitespace', '<<do-rstrip>>'), ] ), ]
7n/a
8n/a def __init__(self, editwin):
9n/a self.editwin = editwin
10n/a self.editwin.text.bind("<<do-rstrip>>", self.do_rstrip)
11n/a
12n/a def do_rstrip(self, event=None):
13n/a
14n/a text = self.editwin.text
15n/a undo = self.editwin.undo
16n/a
17n/a undo.undo_block_start()
18n/a
19n/a end_line = int(float(text.index('end')))
20n/a for cur in range(1, end_line):
21n/a txt = text.get('%i.0' % cur, '%i.end' % cur)
22n/a raw = len(txt)
23n/a cut = len(txt.rstrip())
24n/a # Since text.delete() marks file as changed, even if not,
25n/a # only call it when needed to actually delete something.
26n/a if cut < raw:
27n/a text.delete('%i.%i' % (cur, cut), '%i.end' % cur)
28n/a
29n/a undo.undo_block_stop()
30n/a
31n/aif __name__ == "__main__":
32n/a import unittest
33n/a unittest.main('idlelib.idle_test.test_rstrip', verbosity=2, exit=False)