def __init__(self, text=None, filename=None): if filename == None and text == None: raise AttributeError("need a filename or text for a Code object") return if filename: self.filename = filename self.text = get_text(filename) elif text: self.text = text self.lines = self.text.split("\n") self.linebreak_indices = get_linebreak_indices(self.text) self.levels = get_indent_levels(self.lines) self.ignore_lines = get_ignore_lines(self.lines) self.stripped = [] # lines without whitespace or comments for line_no, line in enumerate(self.lines): if self.ignore_lines[line_no]: self.stripped.append("") else: self.stripped.append(strip(line))
def show_indent(f): """Utility function to show the expected and actual indents for a file""" code = get_text(f) lines = code.split("\n") levels = get_indent_levels(lines) errors = FeatureIndentation(code) ignore = get_ignore_lines(lines) for line_no, line in enumerate(lines): if line_no in errors: print print for i in range(line_no - 3, line_no): print str(levels[i]) + "\t" + lines[i] print str(levels[line_no]) + "\t" + line print " ^^^ " print errors[line_no] print for i in range(line_no+1, line_no+3): print str(levels[i]) + "\t" + lines[i] print print