Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/idlelib/run.py

    r2 r391  
    11import sys
     2import io
    23import linecache
    34import time
     
    89import Queue
    910
    10 import CallTips
    11 import AutoComplete
    12 
    13 import RemoteDebugger
    14 import RemoteObjectBrowser
    15 import StackViewer
    16 import rpc
     11from idlelib import CallTips
     12from idlelib import AutoComplete
     13
     14from idlelib import RemoteDebugger
     15from idlelib import RemoteObjectBrowser
     16from idlelib import StackViewer
     17from idlelib import rpc
     18from idlelib import PyShell
     19from idlelib import IOBinding
    1720
    1821import __main__
     
    2023LOCALHOST = '127.0.0.1'
    2124
    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
     25import warnings
     26
     27def 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
     43def 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
     56capture_warnings(True)
    3957
    4058# Thread shared globals: Establish a queue between a subthread (which handles
     
    6886    global no_exitfunc
    6987    no_exitfunc = del_exitfunc
    70     port = 8833
    7188    #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)
    7497    sys.argv[:] = [""]
    7598    sockthread = threading.Thread(target=manage_socket,
     
    98121            continue
    99122        except SystemExit:
     123            capture_warnings(False)
    100124            raise
    101125        except:
     
    117141            server = MyRPCServer(address, MyHandler)
    118142            break
    119         except socket.error, err:
     143        except socket.error as err:
    120144            print>>sys.__stderr__,"IDLE Subprocess: socket error: "\
    121                                         + err[1] + ", retrying...."
     145                                        + err.args[1] + ", retrying...."
    122146    else:
    123147        print>>sys.__stderr__, "IDLE Subprocess: Connection to "\
     
    134158    root = Tkinter.Tk()
    135159    root.withdraw()
    136     if err[0] == 61: # connection refused
     160    if err.args[0] == 61: # connection refused
    137161        msg = "IDLE's subprocess can't connect to %s:%d.  This may be due "\
    138162              "to your personal firewall configuration.  It is safe to "\
     
    141165        tkMessageBox.showerror("IDLE Subprocess Error", msg, parent=root)
    142166    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])
    144169    root.destroy()
    145170
     
    212237        except AttributeError:
    213238            pass
     239    capture_warnings(False)
    214240    sys.exit(0)
    215241
     
    244270            thread.interrupt_main()
    245271
    246 
    247272class MyHandler(rpc.RPCHandler):
    248273
     
    251276        executive = Executive(self)
    252277        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
    259290        self.interp = self.get_remote_proxy("interp")
    260291        rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)
     
    294325            finally:
    295326                interruptable = False
     327        except SystemExit:
     328            # Scripts that raise SystemExit should just
     329            # return to the interactive prompt
     330            pass
    296331        except:
    297332            self.usr_exc_info = sys.exc_info()
    298333            if quitting:
    299334                exit()
    300             # even print a user code SystemExit exception, continue
    301335            print_exception()
    302336            jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
     
    337371        item = StackViewer.StackTreeItem(flist, tb)
    338372        return RemoteObjectBrowser.remote_object_tree_item(item)
     373
     374capture_warnings(False)  # Make sure turned off; see issue 18081
Note: See TracChangeset for help on using the changeset viewer.