(self, filename)
| 77 | return True |
| 78 | |
| 79 | def checksyntax(self, filename): |
| 80 | self.shell = shell = self.flist.open_shell() |
| 81 | saved_stream = shell.get_warning_stream() |
| 82 | shell.set_warning_stream(shell.stderr) |
| 83 | with open(filename, 'rb') as f: |
| 84 | source = f.read() |
| 85 | if b'\r' in source: |
| 86 | source = source.replace(b'\r\n', b'\n') |
| 87 | source = source.replace(b'\r', b'\n') |
| 88 | if source and source[-1] != ord(b'\n'): |
| 89 | source = source + b'\n' |
| 90 | editwin = self.editwin |
| 91 | text = editwin.text |
| 92 | text.tag_remove("ERROR", "1.0", "end") |
| 93 | try: |
| 94 | # If successful, return the compiled code |
| 95 | return compile(source, filename, "exec") |
| 96 | except (SyntaxError, OverflowError, ValueError) as value: |
| 97 | msg = getattr(value, 'msg', '') or value or "<no detail available>" |
| 98 | lineno = getattr(value, 'lineno', '') or 1 |
| 99 | offset = getattr(value, 'offset', '') or 0 |
| 100 | if offset == 0: |
| 101 | lineno += 1 #mark end of offending line |
| 102 | pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) |
| 103 | editwin.colorize_syntax_error(text, pos) |
| 104 | self.errorbox("SyntaxError", "%-20s" % msg) |
| 105 | return False |
| 106 | finally: |
| 107 | shell.set_warning_stream(saved_stream) |
| 108 | |
| 109 | def run_custom_event(self, event): |
| 110 | return self.run_module_event(event, customize=True) |
no test coverage detected