| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8edeadc commit b5dac4d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,6 @@ | |||
| 29 | 29 | Name.Class:'d', | |
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | - | ||
| 33 | 32 | class BPythonFormatter(Formatter): | |
| 34 | 33 | """This is subclassed from the custom formatter for bpython. | |
| 35 | 34 | Its format() method receives the tokensource | |
@@ -58,7 +57,7 @@ def format(self, tokensource, outfile): | |||
| 58 | 57 | outfile.write(str(parse(o.rstrip()))) | |
| 59 | 58 | ||
| 60 | 59 | class Interp(code.InteractiveInterpreter): | |
| 61 | - def __init__(self, locals=None, outfile=sys.__stderr__): | ||
| 60 | + def __init__(self, locals=None): | ||
| 62 | 61 | """Constructor. | |
| 63 | 62 | ||
| 64 | 63 | The optional 'locals' argument specifies the dictionary in | |
@@ -73,7 +72,10 @@ def __init__(self, locals=None, outfile=sys.__stderr__): | |||
| 73 | 72 | locals = {"__name__": "__console__", "__doc__": None} | |
| 74 | 73 | self.locals = locals | |
| 75 | 74 | self.compile = CommandCompiler() | |
| 76 | - self.outfile = outfile | ||
| 75 | + | ||
| 76 | + # typically changed after being instantiated | ||
| 77 | + self.write = lambda stuff: sys.stderr.write(stuff) | ||
| 78 | + self.outfile = self | ||
| 77 | 79 | ||
| 78 | 80 | def showsyntaxerror(self, filename=None): | |
| 79 | 81 | """Display the syntax error that just occurred. | |
@@ -113,10 +115,10 @@ def showsyntaxerror(self, filename=None): | |||
| 113 | 115 | if text.endswith('\n'): | |
| 114 | 116 | cur_line.append((token,text)) | |
| 115 | 117 | if no_format_mode: | |
| 116 | - traceback_code_formatter.format(cur_line,self.outfile) | ||
| 118 | + traceback_code_formatter.format(cur_line, self.outfile) | ||
| 117 | 119 | no_format_mode = False | |
| 118 | 120 | else: | |
| 119 | - traceback_informative_formatter.format(cur_line,self.outfile) | ||
| 121 | + traceback_informative_formatter.format(cur_line, self.outfile) | ||
| 120 | 122 | cur_line = [] | |
| 121 | 123 | elif text == ' ' and cur_line == []: | |
| 122 | 124 | no_format_mode = True | |
@@ -154,10 +156,10 @@ def showtraceback(self): | |||
| 154 | 156 | if text.endswith('\n'): | |
| 155 | 157 | cur_line.append((token,text)) | |
| 156 | 158 | if no_format_mode: | |
| 157 | - traceback_code_formatter.format(cur_line,self.outfile) | ||
| 159 | + traceback_code_formatter.format(cur_line, self.outfile) | ||
| 158 | 160 | no_format_mode = False | |
| 159 | 161 | else: | |
| 160 | - traceback_informative_formatter.format(cur_line,self.outfile) | ||
| 162 | + traceback_informative_formatter.format(cur_line, self.outfile) | ||
| 161 | 163 | cur_line = [] | |
| 162 | 164 | elif text == ' ' and cur_line == []: | |
| 163 | 165 | no_format_mode = True | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -239,6 +239,7 @@ def __init__(self, | |||
| 239 | 239 | # state was passed in | |
| 240 | 240 | if interp is None: | |
| 241 | 241 | interp = Interp(locals=locals_) | |
| 242 | + interp.writetb = self.send_to_stderr | ||
| 242 | 243 | if banner is None: | |
| 243 | 244 | banner = _('Welcome to bpython! Press <%s> for help.') % config.help_key | |
| 244 | 245 | config.autocomplete_mode = autocomplete.SIMPLE # only one implemented currently | |
@@ -1107,6 +1108,7 @@ def reevaluate(self, insert_into_history=False): | |||
| 1107 | 1108 | ||
| 1108 | 1109 | if not self.weak_rewind: | |
| 1109 | 1110 | self.interp = self.interp.__class__() | |
| 1111 | + self.interp.writetb = self.send_to_stderr | ||
| 1110 | 1112 | self.coderunner.interp = self.interp | |
| 1111 | 1113 | ||
| 1112 | 1114 | self.buffer = [] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments