| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b6a2a5f commit 3cbe24d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,8 @@ | |||
| 12 | 12 | ||
| 13 | 13 | from bpython.curtsiesfrontend.parse import parse | |
| 14 | 14 | from bpython.repl import Interpreter as ReplInterpreter | |
| 15 | + from bpython.config import getpreferredencoding | ||
| 16 | + from bpython._py3compat import py3 | ||
| 15 | 17 | ||
| 16 | 18 | default_colors = { | |
| 17 | 19 | Generic.Error: 'R', | |
@@ -75,66 +77,30 @@ def __init__(self, locals=None): | |||
| 75 | 77 | """ | |
| 76 | 78 | if locals is None: | |
| 77 | 79 | locals = {"__name__": "__console__", "__doc__": None} | |
| 78 | - ReplInterpreter.__init__(self, locals) | ||
| 80 | + ReplInterpreter.__init__(self, locals, getpreferredencoding()) | ||
| 81 | + | ||
| 79 | 82 | self.locals = locals | |
| 80 | 83 | self.compile = CommandCompiler() | |
| 81 | 84 | ||
| 82 | 85 | # typically changed after being instantiated | |
| 83 | 86 | self.write = lambda stuff: sys.stderr.write(stuff) | |
| 84 | 87 | self.outfile = self | |
| 85 | 88 | ||
| 86 | - def showsyntaxerror(self, filename=None): | ||
| 87 | - """Display the syntax error that just occurred. | ||
| 88 | - | ||
| 89 | - This doesn't display a stack trace because there isn't one. | ||
| 90 | - | ||
| 91 | - If a filename is given, it is stuffed in the exception instead | ||
| 92 | - of what was there before (because Python's parser always uses | ||
| 93 | - "<string>" when reading from a string). | ||
| 94 | - | ||
| 95 | - The output is written by self.write(), below. | ||
| 96 | - | ||
| 97 | - """ | ||
| 98 | - type, value, sys.last_traceback = sys.exc_info() | ||
| 99 | - sys.last_type = type | ||
| 100 | - sys.last_value = value | ||
| 101 | - if filename and type is SyntaxError: | ||
| 102 | - # Work hard to stuff the correct filename in the exception | ||
| 103 | - try: | ||
| 104 | - msg, (dummy_filename, lineno, offset, line) = value | ||
| 105 | - except: | ||
| 106 | - # Not the format we expect; leave it alone | ||
| 107 | - pass | ||
| 108 | - else: | ||
| 109 | - # Stuff in the right filename | ||
| 110 | - value = SyntaxError(msg, (filename, lineno, offset, line)) | ||
| 111 | - sys.last_value = value | ||
| 112 | - l = traceback.format_exception_only(type, value) | ||
| 113 | - tbtext = ''.join(l) | ||
| 89 | + def writetb(self, lines): | ||
| 90 | + tbtext = ''.join(lines) | ||
| 114 | 91 | lexer = get_lexer_by_name("pytb") | |
| 115 | 92 | self.format(tbtext, lexer) | |
| 116 | - | ||
| 117 | - def showtraceback(self): | ||
| 118 | - """Display the exception that just occurred. | ||
| 119 | - | ||
| 120 | - We remove the first stack item because it is our own code. | ||
| 121 | - | ||
| 122 | - | ||
| 123 | - """ | ||
| 124 | - type, value, tb = sys.exc_info() | ||
| 125 | - sys.last_type = type | ||
| 126 | - sys.last_value = value | ||
| 127 | - sys.last_traceback = tb | ||
| 128 | - tblist = traceback.extract_tb(tb) | ||
| 129 | - del tblist[:1] | ||
| 130 | - l = traceback.format_list(tblist) | ||
| 131 | - if l: | ||
| 132 | - l.insert(0, "Traceback (most recent call last):\n") | ||
| 133 | - l[len(l):] = traceback.format_exception_only(type, value) | ||
| 134 | - tbtext = ''.join(l) | ||
| 135 | - lexer = get_lexer_by_name("pytb", stripall=True) | ||
| 136 | - | ||
| 137 | - self.format(tbtext, lexer) | ||
| 93 | + # TODO for tracebacks get_lexer_by_name("pytb", stripall=True) | ||
| 94 | + | ||
| 95 | + if not py3: | ||
| 96 | + def runsource(self, source, filename="<input>", symbol="single", | ||
| 97 | + encode=True): | ||
| 98 | + # TODO: write a test for and implement encoding | ||
| 99 | + with self.timer: | ||
| 100 | + if encode: | ||
| 101 | + source = '#\n%s' % (source,) # dummy line so linenos match | ||
| 102 | + return code.InteractiveInterpreter.runsource(self, source, | ||
| 103 | + filename, symbol) | ||
| 138 | 104 | ||
| 139 | 105 | def format(self, tbtext, lexer): | |
| 140 | 106 | traceback_informative_formatter = BPythonFormatter(default_colors) | |
@@ -160,12 +126,6 @@ def format(self, tbtext, lexer): | |||
| 160 | 126 | cur_line.append((token, text)) | |
| 161 | 127 | assert cur_line == [], cur_line | |
| 162 | 128 | ||
| 163 | - def runsource(self, source, filename="<input>", symbol="single", | ||
| 164 | - encode=None): | ||
| 165 | - # TODO: encode does nothing | ||
| 166 | - with self.timer: | ||
| 167 | - return code.InteractiveInterpreter.runsource( | ||
| 168 | - self, source, filename, symbol) | ||
| 169 | 129 | ||
| 170 | 130 | def code_finished_will_parse(s, compiler): | |
| 171 | 131 | """Returns a tuple of whether the buffer could be complete and whether it | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -266,7 +266,7 @@ def __init__(self, | |||
| 266 | 266 | ||
| 267 | 267 | if interp is None: | |
| 268 | 268 | interp = Interp(locals=locals_) | |
| 269 | - interp.writetb = self.send_to_stderr | ||
| 269 | + interp.write = self.send_to_stderr | ||
| 270 | 270 | if banner is None: | |
| 271 | 271 | if config.help_key: | |
| 272 | 272 | banner = ' '.join((_('Welcome to bpython!'), | |
@@ -1347,7 +1347,7 @@ def reevaluate(self, insert_into_history=False): | |||
| 1347 | 1347 | ||
| 1348 | 1348 | if not self.weak_rewind: | |
| 1349 | 1349 | self.interp = self.interp.__class__() | |
| 1350 | - self.interp.writetb = self.send_to_stderr | ||
| 1350 | + self.interp.write = self.send_to_stderr | ||
| 1351 | 1351 | self.coderunner.interp = self.interp | |
| 1352 | 1352 | ||
| 1353 | 1353 | self.buffer = [] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,7 +77,8 @@ def test_runsource_bytes_over_128_syntax_error(self): | |||
| 77 | 77 | i.runsource(u"a = b'\xfe'") | |
| 78 | 78 | i.showsyntaxerror.assert_called_with() | |
| 79 | 79 | ||
| 80 | - @unittest.skipIf(py3, "only ASCII allowed in bytestrings in Python 3") | ||
| 80 | + @unittest.skip("Is the goal of encoding to get this to work?") | ||
| 81 | + @unittest.skipIf(py3, "bytes 128-255 only permitted in Py 2") | ||
| 81 | 82 | def test_runsource_bytes_over_128_syntax_error(self): | |
| 82 | 83 | i = interpreter.Interp() | |
| 83 | 84 | i.encoding = 'latin-1' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments