Changeset 391 for python/trunk/Lib/idlelib/run.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/idlelib/run.py
r2 r391 1 1 import sys 2 import io 2 3 import linecache 3 4 import time … … 8 9 import Queue 9 10 10 import CallTips 11 import AutoComplete 12 13 import RemoteDebugger 14 import RemoteObjectBrowser 15 import StackViewer 16 import rpc 11 from idlelib import CallTips 12 from idlelib import AutoComplete 13 14 from idlelib import RemoteDebugger 15 from idlelib import RemoteObjectBrowser 16 from idlelib import StackViewer 17 from idlelib import rpc 18 from idlelib import PyShell 19 from idlelib import IOBinding 17 20 18 21 import __main__ … … 20 23 LOCALHOST = '127.0.0.1' 21 24 22 try: 23 import warnings 24 except ImportError: 25 pass 26 else: 27 def idle_formatwarning_subproc(message, category, filename, lineno, 28 file=None, line=None): 29 """Format warnings the IDLE way""" 30 s = "\nWarning (from warnings module):\n" 31 s += ' File \"%s\", line %s\n' % (filename, lineno) 32 line = linecache.getline(filename, lineno).strip() \ 33 if line is None else line 34 if line: 35 s += " %s\n" % line 36 s += "%s: %s\n" % (category.__name__, message) 37 return s 38 warnings.formatwarning = idle_formatwarning_subproc 25 import warnings 26 27 def idle_showwarning_subproc( 28 message, category, filename, lineno, file=None, line=None): 29 """Show Idle-format warning after replacing warnings.showwarning. 30 31 The only difference is the formatter called. 32 """ 33 if file is None: 34 file = sys.stderr 35 try: 36 file.write(PyShell.idle_formatwarning( 37 message, category, filename, lineno, line)) 38 except IOError: 39 pass # the file (probably stderr) is invalid - this warning gets lost. 40 41 _warnings_showwarning = None 42 43 def capture_warnings(capture): 44 "Replace warning.showwarning with idle_showwarning_subproc, or reverse." 45 46 global _warnings_showwarning 47 if capture: 48 if _warnings_showwarning is None: 49 _warnings_showwarning = warnings.showwarning 50 warnings.showwarning = idle_showwarning_subproc 51 else: 52 if _warnings_showwarning is not None: 53 warnings.showwarning = _warnings_showwarning 54 _warnings_showwarning = None 55 56 capture_warnings(True) 39 57 40 58 # Thread shared globals: Establish a queue between a subthread (which handles … … 68 86 global no_exitfunc 69 87 no_exitfunc = del_exitfunc 70 port = 883371 88 #time.sleep(15) # test subprocess not responding 72 if sys.argv[1:]: 73 port = int(sys.argv[1]) 89 try: 90 assert(len(sys.argv) > 1) 91 port = int(sys.argv[-1]) 92 except: 93 print>>sys.stderr, "IDLE Subprocess: no IP port passed in sys.argv." 94 return 95 96 capture_warnings(True) 74 97 sys.argv[:] = [""] 75 98 sockthread = threading.Thread(target=manage_socket, … … 98 121 continue 99 122 except SystemExit: 123 capture_warnings(False) 100 124 raise 101 125 except: … … 117 141 server = MyRPCServer(address, MyHandler) 118 142 break 119 except socket.error ,err:143 except socket.error as err: 120 144 print>>sys.__stderr__,"IDLE Subprocess: socket error: "\ 121 + err [1] + ", retrying...."145 + err.args[1] + ", retrying...." 122 146 else: 123 147 print>>sys.__stderr__, "IDLE Subprocess: Connection to "\ … … 134 158 root = Tkinter.Tk() 135 159 root.withdraw() 136 if err [0] == 61: # connection refused160 if err.args[0] == 61: # connection refused 137 161 msg = "IDLE's subprocess can't connect to %s:%d. This may be due "\ 138 162 "to your personal firewall configuration. It is safe to "\ … … 141 165 tkMessageBox.showerror("IDLE Subprocess Error", msg, parent=root) 142 166 else: 143 tkMessageBox.showerror("IDLE Subprocess Error", "Socket Error: %s" % err[1]) 167 tkMessageBox.showerror("IDLE Subprocess Error", 168 "Socket Error: %s" % err.args[1]) 144 169 root.destroy() 145 170 … … 212 237 except AttributeError: 213 238 pass 239 capture_warnings(False) 214 240 sys.exit(0) 215 241 … … 244 270 thread.interrupt_main() 245 271 246 247 272 class MyHandler(rpc.RPCHandler): 248 273 … … 251 276 executive = Executive(self) 252 277 self.register("exec", executive) 253 sys.stdin = self.console = self.get_remote_proxy("stdin") 254 sys.stdout = self.get_remote_proxy("stdout") 255 sys.stderr = self.get_remote_proxy("stderr") 256 import IOBinding 257 sys.stdin.encoding = sys.stdout.encoding = \ 258 sys.stderr.encoding = IOBinding.encoding 278 self.console = self.get_remote_proxy("console") 279 sys.stdin = PyShell.PseudoInputFile(self.console, "stdin", 280 IOBinding.encoding) 281 sys.stdout = PyShell.PseudoOutputFile(self.console, "stdout", 282 IOBinding.encoding) 283 sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr", 284 IOBinding.encoding) 285 286 # Keep a reference to stdin so that it won't try to exit IDLE if 287 # sys.stdin gets changed from within IDLE's shell. See issue17838. 288 self._keep_stdin = sys.stdin 289 259 290 self.interp = self.get_remote_proxy("interp") 260 291 rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05) … … 294 325 finally: 295 326 interruptable = False 327 except SystemExit: 328 # Scripts that raise SystemExit should just 329 # return to the interactive prompt 330 pass 296 331 except: 297 332 self.usr_exc_info = sys.exc_info() 298 333 if quitting: 299 334 exit() 300 # even print a user code SystemExit exception, continue301 335 print_exception() 302 336 jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>") … … 337 371 item = StackViewer.StackTreeItem(flist, tb) 338 372 return RemoteObjectBrowser.remote_object_tree_item(item) 373 374 capture_warnings(False) # Make sure turned off; see issue 18081
Note:
See TracChangeset
for help on using the changeset viewer.