Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: PyShell.py
#! /usr/bin/python2.7
[0] Fix | Delete
from __future__ import print_function
[1] Fix | Delete
[2] Fix | Delete
import os
[3] Fix | Delete
import os.path
[4] Fix | Delete
import sys
[5] Fix | Delete
import string
[6] Fix | Delete
import getopt
[7] Fix | Delete
import re
[8] Fix | Delete
import socket
[9] Fix | Delete
import time
[10] Fix | Delete
import threading
[11] Fix | Delete
import io
[12] Fix | Delete
[13] Fix | Delete
import linecache
[14] Fix | Delete
from code import InteractiveInterpreter
[15] Fix | Delete
from platform import python_version, system
[16] Fix | Delete
[17] Fix | Delete
try:
[18] Fix | Delete
from Tkinter import *
[19] Fix | Delete
except ImportError:
[20] Fix | Delete
print("** IDLE can't import Tkinter.\n"
[21] Fix | Delete
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
[22] Fix | Delete
sys.exit(1)
[23] Fix | Delete
import tkMessageBox
[24] Fix | Delete
[25] Fix | Delete
from idlelib.EditorWindow import EditorWindow, fixwordbreaks
[26] Fix | Delete
from idlelib.FileList import FileList
[27] Fix | Delete
from idlelib.ColorDelegator import ColorDelegator
[28] Fix | Delete
from idlelib.UndoDelegator import UndoDelegator
[29] Fix | Delete
from idlelib.OutputWindow import OutputWindow
[30] Fix | Delete
from idlelib.configHandler import idleConf
[31] Fix | Delete
from idlelib import rpc
[32] Fix | Delete
from idlelib import Debugger
[33] Fix | Delete
from idlelib import RemoteDebugger
[34] Fix | Delete
from idlelib import macosxSupport
[35] Fix | Delete
from idlelib import IOBinding
[36] Fix | Delete
[37] Fix | Delete
IDENTCHARS = string.ascii_letters + string.digits + "_"
[38] Fix | Delete
HOST = '127.0.0.1' # python execution server on localhost loopback
[39] Fix | Delete
PORT = 0 # someday pass in host, port for remote debug capability
[40] Fix | Delete
[41] Fix | Delete
try:
[42] Fix | Delete
from signal import SIGTERM
[43] Fix | Delete
except ImportError:
[44] Fix | Delete
SIGTERM = 15
[45] Fix | Delete
[46] Fix | Delete
# Override warnings module to write to warning_stream. Initialize to send IDLE
[47] Fix | Delete
# internal warnings to the console. ScriptBinding.check_syntax() will
[48] Fix | Delete
# temporarily redirect the stream to the shell window to display warnings when
[49] Fix | Delete
# checking user's code.
[50] Fix | Delete
warning_stream = sys.__stderr__ # None, at least on Windows, if no console.
[51] Fix | Delete
import warnings
[52] Fix | Delete
[53] Fix | Delete
def idle_formatwarning(message, category, filename, lineno, line=None):
[54] Fix | Delete
"""Format warnings the IDLE way."""
[55] Fix | Delete
[56] Fix | Delete
s = "\nWarning (from warnings module):\n"
[57] Fix | Delete
s += ' File \"%s\", line %s\n' % (filename, lineno)
[58] Fix | Delete
if line is None:
[59] Fix | Delete
line = linecache.getline(filename, lineno)
[60] Fix | Delete
line = line.strip()
[61] Fix | Delete
if line:
[62] Fix | Delete
s += " %s\n" % line
[63] Fix | Delete
s += "%s: %s\n" % (category.__name__, message)
[64] Fix | Delete
return s
[65] Fix | Delete
[66] Fix | Delete
def idle_showwarning(
[67] Fix | Delete
message, category, filename, lineno, file=None, line=None):
[68] Fix | Delete
"""Show Idle-format warning (after replacing warnings.showwarning).
[69] Fix | Delete
[70] Fix | Delete
The differences are the formatter called, the file=None replacement,
[71] Fix | Delete
which can be None, the capture of the consequence AttributeError,
[72] Fix | Delete
and the output of a hard-coded prompt.
[73] Fix | Delete
"""
[74] Fix | Delete
if file is None:
[75] Fix | Delete
file = warning_stream
[76] Fix | Delete
try:
[77] Fix | Delete
file.write(idle_formatwarning(
[78] Fix | Delete
message, category, filename, lineno, line=line))
[79] Fix | Delete
file.write(">>> ")
[80] Fix | Delete
except (AttributeError, IOError):
[81] Fix | Delete
pass # if file (probably __stderr__) is invalid, skip warning.
[82] Fix | Delete
[83] Fix | Delete
_warnings_showwarning = None
[84] Fix | Delete
[85] Fix | Delete
def capture_warnings(capture):
[86] Fix | Delete
"Replace warning.showwarning with idle_showwarning, or reverse."
[87] Fix | Delete
[88] Fix | Delete
global _warnings_showwarning
[89] Fix | Delete
if capture:
[90] Fix | Delete
if _warnings_showwarning is None:
[91] Fix | Delete
_warnings_showwarning = warnings.showwarning
[92] Fix | Delete
warnings.showwarning = idle_showwarning
[93] Fix | Delete
else:
[94] Fix | Delete
if _warnings_showwarning is not None:
[95] Fix | Delete
warnings.showwarning = _warnings_showwarning
[96] Fix | Delete
_warnings_showwarning = None
[97] Fix | Delete
[98] Fix | Delete
capture_warnings(True)
[99] Fix | Delete
[100] Fix | Delete
def extended_linecache_checkcache(filename=None,
[101] Fix | Delete
orig_checkcache=linecache.checkcache):
[102] Fix | Delete
"""Extend linecache.checkcache to preserve the <pyshell#...> entries
[103] Fix | Delete
[104] Fix | Delete
Rather than repeating the linecache code, patch it to save the
[105] Fix | Delete
<pyshell#...> entries, call the original linecache.checkcache()
[106] Fix | Delete
(skipping them), and then restore the saved entries.
[107] Fix | Delete
[108] Fix | Delete
orig_checkcache is bound at definition time to the original
[109] Fix | Delete
method, allowing it to be patched.
[110] Fix | Delete
"""
[111] Fix | Delete
cache = linecache.cache
[112] Fix | Delete
save = {}
[113] Fix | Delete
for key in list(cache):
[114] Fix | Delete
if key[:1] + key[-1:] == '<>':
[115] Fix | Delete
save[key] = cache.pop(key)
[116] Fix | Delete
orig_checkcache(filename)
[117] Fix | Delete
cache.update(save)
[118] Fix | Delete
[119] Fix | Delete
# Patch linecache.checkcache():
[120] Fix | Delete
linecache.checkcache = extended_linecache_checkcache
[121] Fix | Delete
[122] Fix | Delete
[123] Fix | Delete
class PyShellEditorWindow(EditorWindow):
[124] Fix | Delete
"Regular text edit window in IDLE, supports breakpoints"
[125] Fix | Delete
[126] Fix | Delete
def __init__(self, *args):
[127] Fix | Delete
self.breakpoints = []
[128] Fix | Delete
EditorWindow.__init__(self, *args)
[129] Fix | Delete
self.text.bind("<<set-breakpoint-here>>", self.set_breakpoint_here)
[130] Fix | Delete
self.text.bind("<<clear-breakpoint-here>>", self.clear_breakpoint_here)
[131] Fix | Delete
self.text.bind("<<open-python-shell>>", self.flist.open_shell)
[132] Fix | Delete
[133] Fix | Delete
self.breakpointPath = os.path.join(idleConf.GetUserCfgDir(),
[134] Fix | Delete
'breakpoints.lst')
[135] Fix | Delete
# whenever a file is changed, restore breakpoints
[136] Fix | Delete
def filename_changed_hook(old_hook=self.io.filename_change_hook,
[137] Fix | Delete
self=self):
[138] Fix | Delete
self.restore_file_breaks()
[139] Fix | Delete
old_hook()
[140] Fix | Delete
self.io.set_filename_change_hook(filename_changed_hook)
[141] Fix | Delete
if self.io.filename:
[142] Fix | Delete
self.restore_file_breaks()
[143] Fix | Delete
self.color_breakpoint_text()
[144] Fix | Delete
[145] Fix | Delete
rmenu_specs = [
[146] Fix | Delete
("Cut", "<<cut>>", "rmenu_check_cut"),
[147] Fix | Delete
("Copy", "<<copy>>", "rmenu_check_copy"),
[148] Fix | Delete
("Paste", "<<paste>>", "rmenu_check_paste"),
[149] Fix | Delete
("Set Breakpoint", "<<set-breakpoint-here>>", None),
[150] Fix | Delete
("Clear Breakpoint", "<<clear-breakpoint-here>>", None)
[151] Fix | Delete
]
[152] Fix | Delete
[153] Fix | Delete
def color_breakpoint_text(self, color=True):
[154] Fix | Delete
"Turn colorizing of breakpoint text on or off"
[155] Fix | Delete
if self.io is None:
[156] Fix | Delete
# possible due to update in restore_file_breaks
[157] Fix | Delete
return
[158] Fix | Delete
if color:
[159] Fix | Delete
theme = idleConf.CurrentTheme()
[160] Fix | Delete
cfg = idleConf.GetHighlight(theme, "break")
[161] Fix | Delete
else:
[162] Fix | Delete
cfg = {'foreground': '', 'background': ''}
[163] Fix | Delete
self.text.tag_config('BREAK', cfg)
[164] Fix | Delete
[165] Fix | Delete
def set_breakpoint(self, lineno):
[166] Fix | Delete
text = self.text
[167] Fix | Delete
filename = self.io.filename
[168] Fix | Delete
text.tag_add("BREAK", "%d.0" % lineno, "%d.0" % (lineno+1))
[169] Fix | Delete
try:
[170] Fix | Delete
self.breakpoints.index(lineno)
[171] Fix | Delete
except ValueError: # only add if missing, i.e. do once
[172] Fix | Delete
self.breakpoints.append(lineno)
[173] Fix | Delete
try: # update the subprocess debugger
[174] Fix | Delete
debug = self.flist.pyshell.interp.debugger
[175] Fix | Delete
debug.set_breakpoint_here(filename, lineno)
[176] Fix | Delete
except: # but debugger may not be active right now....
[177] Fix | Delete
pass
[178] Fix | Delete
[179] Fix | Delete
def set_breakpoint_here(self, event=None):
[180] Fix | Delete
text = self.text
[181] Fix | Delete
filename = self.io.filename
[182] Fix | Delete
if not filename:
[183] Fix | Delete
text.bell()
[184] Fix | Delete
return
[185] Fix | Delete
lineno = int(float(text.index("insert")))
[186] Fix | Delete
self.set_breakpoint(lineno)
[187] Fix | Delete
[188] Fix | Delete
def clear_breakpoint_here(self, event=None):
[189] Fix | Delete
text = self.text
[190] Fix | Delete
filename = self.io.filename
[191] Fix | Delete
if not filename:
[192] Fix | Delete
text.bell()
[193] Fix | Delete
return
[194] Fix | Delete
lineno = int(float(text.index("insert")))
[195] Fix | Delete
try:
[196] Fix | Delete
self.breakpoints.remove(lineno)
[197] Fix | Delete
except:
[198] Fix | Delete
pass
[199] Fix | Delete
text.tag_remove("BREAK", "insert linestart",\
[200] Fix | Delete
"insert lineend +1char")
[201] Fix | Delete
try:
[202] Fix | Delete
debug = self.flist.pyshell.interp.debugger
[203] Fix | Delete
debug.clear_breakpoint_here(filename, lineno)
[204] Fix | Delete
except:
[205] Fix | Delete
pass
[206] Fix | Delete
[207] Fix | Delete
def clear_file_breaks(self):
[208] Fix | Delete
if self.breakpoints:
[209] Fix | Delete
text = self.text
[210] Fix | Delete
filename = self.io.filename
[211] Fix | Delete
if not filename:
[212] Fix | Delete
text.bell()
[213] Fix | Delete
return
[214] Fix | Delete
self.breakpoints = []
[215] Fix | Delete
text.tag_remove("BREAK", "1.0", END)
[216] Fix | Delete
try:
[217] Fix | Delete
debug = self.flist.pyshell.interp.debugger
[218] Fix | Delete
debug.clear_file_breaks(filename)
[219] Fix | Delete
except:
[220] Fix | Delete
pass
[221] Fix | Delete
[222] Fix | Delete
def store_file_breaks(self):
[223] Fix | Delete
"Save breakpoints when file is saved"
[224] Fix | Delete
# XXX 13 Dec 2002 KBK Currently the file must be saved before it can
[225] Fix | Delete
# be run. The breaks are saved at that time. If we introduce
[226] Fix | Delete
# a temporary file save feature the save breaks functionality
[227] Fix | Delete
# needs to be re-verified, since the breaks at the time the
[228] Fix | Delete
# temp file is created may differ from the breaks at the last
[229] Fix | Delete
# permanent save of the file. Currently, a break introduced
[230] Fix | Delete
# after a save will be effective, but not persistent.
[231] Fix | Delete
# This is necessary to keep the saved breaks synched with the
[232] Fix | Delete
# saved file.
[233] Fix | Delete
#
[234] Fix | Delete
# Breakpoints are set as tagged ranges in the text.
[235] Fix | Delete
# Since a modified file has to be saved before it is
[236] Fix | Delete
# run, and since self.breakpoints (from which the subprocess
[237] Fix | Delete
# debugger is loaded) is updated during the save, the visible
[238] Fix | Delete
# breaks stay synched with the subprocess even if one of these
[239] Fix | Delete
# unexpected breakpoint deletions occurs.
[240] Fix | Delete
breaks = self.breakpoints
[241] Fix | Delete
filename = self.io.filename
[242] Fix | Delete
try:
[243] Fix | Delete
with open(self.breakpointPath,"r") as old_file:
[244] Fix | Delete
lines = old_file.readlines()
[245] Fix | Delete
except IOError:
[246] Fix | Delete
lines = []
[247] Fix | Delete
try:
[248] Fix | Delete
with open(self.breakpointPath,"w") as new_file:
[249] Fix | Delete
for line in lines:
[250] Fix | Delete
if not line.startswith(filename + '='):
[251] Fix | Delete
new_file.write(line)
[252] Fix | Delete
self.update_breakpoints()
[253] Fix | Delete
breaks = self.breakpoints
[254] Fix | Delete
if breaks:
[255] Fix | Delete
new_file.write(filename + '=' + str(breaks) + '\n')
[256] Fix | Delete
except IOError as err:
[257] Fix | Delete
if not getattr(self.root, "breakpoint_error_displayed", False):
[258] Fix | Delete
self.root.breakpoint_error_displayed = True
[259] Fix | Delete
tkMessageBox.showerror(title='IDLE Error',
[260] Fix | Delete
message='Unable to update breakpoint list:\n%s'
[261] Fix | Delete
% str(err),
[262] Fix | Delete
parent=self.text)
[263] Fix | Delete
[264] Fix | Delete
def restore_file_breaks(self):
[265] Fix | Delete
self.text.update() # this enables setting "BREAK" tags to be visible
[266] Fix | Delete
if self.io is None:
[267] Fix | Delete
# can happen if IDLE closes due to the .update() call
[268] Fix | Delete
return
[269] Fix | Delete
filename = self.io.filename
[270] Fix | Delete
if filename is None:
[271] Fix | Delete
return
[272] Fix | Delete
if os.path.isfile(self.breakpointPath):
[273] Fix | Delete
lines = open(self.breakpointPath,"r").readlines()
[274] Fix | Delete
for line in lines:
[275] Fix | Delete
if line.startswith(filename + '='):
[276] Fix | Delete
breakpoint_linenumbers = eval(line[len(filename)+1:])
[277] Fix | Delete
for breakpoint_linenumber in breakpoint_linenumbers:
[278] Fix | Delete
self.set_breakpoint(breakpoint_linenumber)
[279] Fix | Delete
[280] Fix | Delete
def update_breakpoints(self):
[281] Fix | Delete
"Retrieves all the breakpoints in the current window"
[282] Fix | Delete
text = self.text
[283] Fix | Delete
ranges = text.tag_ranges("BREAK")
[284] Fix | Delete
linenumber_list = self.ranges_to_linenumbers(ranges)
[285] Fix | Delete
self.breakpoints = linenumber_list
[286] Fix | Delete
[287] Fix | Delete
def ranges_to_linenumbers(self, ranges):
[288] Fix | Delete
lines = []
[289] Fix | Delete
for index in range(0, len(ranges), 2):
[290] Fix | Delete
lineno = int(float(ranges[index].string))
[291] Fix | Delete
end = int(float(ranges[index+1].string))
[292] Fix | Delete
while lineno < end:
[293] Fix | Delete
lines.append(lineno)
[294] Fix | Delete
lineno += 1
[295] Fix | Delete
return lines
[296] Fix | Delete
[297] Fix | Delete
# XXX 13 Dec 2002 KBK Not used currently
[298] Fix | Delete
# def saved_change_hook(self):
[299] Fix | Delete
# "Extend base method - clear breaks if module is modified"
[300] Fix | Delete
# if not self.get_saved():
[301] Fix | Delete
# self.clear_file_breaks()
[302] Fix | Delete
# EditorWindow.saved_change_hook(self)
[303] Fix | Delete
[304] Fix | Delete
def _close(self):
[305] Fix | Delete
"Extend base method - clear breaks when module is closed"
[306] Fix | Delete
self.clear_file_breaks()
[307] Fix | Delete
EditorWindow._close(self)
[308] Fix | Delete
[309] Fix | Delete
[310] Fix | Delete
class PyShellFileList(FileList):
[311] Fix | Delete
"Extend base class: IDLE supports a shell and breakpoints"
[312] Fix | Delete
[313] Fix | Delete
# override FileList's class variable, instances return PyShellEditorWindow
[314] Fix | Delete
# instead of EditorWindow when new edit windows are created.
[315] Fix | Delete
EditorWindow = PyShellEditorWindow
[316] Fix | Delete
[317] Fix | Delete
pyshell = None
[318] Fix | Delete
[319] Fix | Delete
def open_shell(self, event=None):
[320] Fix | Delete
if self.pyshell:
[321] Fix | Delete
self.pyshell.top.wakeup()
[322] Fix | Delete
else:
[323] Fix | Delete
self.pyshell = PyShell(self)
[324] Fix | Delete
if self.pyshell:
[325] Fix | Delete
if not self.pyshell.begin():
[326] Fix | Delete
return None
[327] Fix | Delete
return self.pyshell
[328] Fix | Delete
[329] Fix | Delete
[330] Fix | Delete
class ModifiedColorDelegator(ColorDelegator):
[331] Fix | Delete
"Extend base class: colorizer for the shell window itself"
[332] Fix | Delete
[333] Fix | Delete
def __init__(self):
[334] Fix | Delete
ColorDelegator.__init__(self)
[335] Fix | Delete
self.LoadTagDefs()
[336] Fix | Delete
[337] Fix | Delete
def recolorize_main(self):
[338] Fix | Delete
self.tag_remove("TODO", "1.0", "iomark")
[339] Fix | Delete
self.tag_add("SYNC", "1.0", "iomark")
[340] Fix | Delete
ColorDelegator.recolorize_main(self)
[341] Fix | Delete
[342] Fix | Delete
def LoadTagDefs(self):
[343] Fix | Delete
ColorDelegator.LoadTagDefs(self)
[344] Fix | Delete
theme = idleConf.CurrentTheme()
[345] Fix | Delete
self.tagdefs.update({
[346] Fix | Delete
"stdin": {'background':None,'foreground':None},
[347] Fix | Delete
"stdout": idleConf.GetHighlight(theme, "stdout"),
[348] Fix | Delete
"stderr": idleConf.GetHighlight(theme, "stderr"),
[349] Fix | Delete
"console": idleConf.GetHighlight(theme, "console"),
[350] Fix | Delete
})
[351] Fix | Delete
[352] Fix | Delete
def removecolors(self):
[353] Fix | Delete
# Don't remove shell color tags before "iomark"
[354] Fix | Delete
for tag in self.tagdefs:
[355] Fix | Delete
self.tag_remove(tag, "iomark", "end")
[356] Fix | Delete
[357] Fix | Delete
class ModifiedUndoDelegator(UndoDelegator):
[358] Fix | Delete
"Extend base class: forbid insert/delete before the I/O mark"
[359] Fix | Delete
[360] Fix | Delete
def insert(self, index, chars, tags=None):
[361] Fix | Delete
try:
[362] Fix | Delete
if self.delegate.compare(index, "<", "iomark"):
[363] Fix | Delete
self.delegate.bell()
[364] Fix | Delete
return
[365] Fix | Delete
except TclError:
[366] Fix | Delete
pass
[367] Fix | Delete
UndoDelegator.insert(self, index, chars, tags)
[368] Fix | Delete
[369] Fix | Delete
def delete(self, index1, index2=None):
[370] Fix | Delete
try:
[371] Fix | Delete
if self.delegate.compare(index1, "<", "iomark"):
[372] Fix | Delete
self.delegate.bell()
[373] Fix | Delete
return
[374] Fix | Delete
except TclError:
[375] Fix | Delete
pass
[376] Fix | Delete
UndoDelegator.delete(self, index1, index2)
[377] Fix | Delete
[378] Fix | Delete
[379] Fix | Delete
class MyRPCClient(rpc.RPCClient):
[380] Fix | Delete
[381] Fix | Delete
def handle_EOF(self):
[382] Fix | Delete
"Override the base class - just re-raise EOFError"
[383] Fix | Delete
raise EOFError
[384] Fix | Delete
[385] Fix | Delete
[386] Fix | Delete
class ModifiedInterpreter(InteractiveInterpreter):
[387] Fix | Delete
[388] Fix | Delete
def __init__(self, tkconsole):
[389] Fix | Delete
self.tkconsole = tkconsole
[390] Fix | Delete
locals = sys.modules['__main__'].__dict__
[391] Fix | Delete
InteractiveInterpreter.__init__(self, locals=locals)
[392] Fix | Delete
self.save_warnings_filters = None
[393] Fix | Delete
self.restarting = False
[394] Fix | Delete
self.subprocess_arglist = None
[395] Fix | Delete
self.port = PORT
[396] Fix | Delete
self.original_compiler_flags = self.compile.compiler.flags
[397] Fix | Delete
[398] Fix | Delete
_afterid = None
[399] Fix | Delete
rpcclt = None
[400] Fix | Delete
rpcpid = None
[401] Fix | Delete
[402] Fix | Delete
def spawn_subprocess(self):
[403] Fix | Delete
if self.subprocess_arglist is None:
[404] Fix | Delete
self.subprocess_arglist = self.build_subprocess_arglist()
[405] Fix | Delete
args = self.subprocess_arglist
[406] Fix | Delete
self.rpcpid = os.spawnv(os.P_NOWAIT, sys.executable, args)
[407] Fix | Delete
[408] Fix | Delete
def build_subprocess_arglist(self):
[409] Fix | Delete
assert (self.port!=0), (
[410] Fix | Delete
"Socket should have been assigned a port number.")
[411] Fix | Delete
w = ['-W' + s for s in sys.warnoptions]
[412] Fix | Delete
if 1/2 > 0: # account for new division
[413] Fix | Delete
w.append('-Qnew')
[414] Fix | Delete
# Maybe IDLE is installed and is being accessed via sys.path,
[415] Fix | Delete
# or maybe it's not installed and the idle.py script is being
[416] Fix | Delete
# run from the IDLE source directory.
[417] Fix | Delete
del_exitf = idleConf.GetOption('main', 'General', 'delete-exitfunc',
[418] Fix | Delete
default=False, type='bool')
[419] Fix | Delete
if __name__ == 'idlelib.PyShell':
[420] Fix | Delete
command = "__import__('idlelib.run').run.main(%r)" % (del_exitf,)
[421] Fix | Delete
else:
[422] Fix | Delete
command = "__import__('run').main(%r)" % (del_exitf,)
[423] Fix | Delete
if sys.platform[:3] == 'win' and ' ' in sys.executable:
[424] Fix | Delete
# handle embedded space in path by quoting the argument
[425] Fix | Delete
decorated_exec = '"%s"' % sys.executable
[426] Fix | Delete
else:
[427] Fix | Delete
decorated_exec = sys.executable
[428] Fix | Delete
return [decorated_exec] + w + ["-c", command, str(self.port)]
[429] Fix | Delete
[430] Fix | Delete
def start_subprocess(self):
[431] Fix | Delete
addr = (HOST, self.port)
[432] Fix | Delete
# GUI makes several attempts to acquire socket, listens for connection
[433] Fix | Delete
for i in range(3):
[434] Fix | Delete
time.sleep(i)
[435] Fix | Delete
try:
[436] Fix | Delete
self.rpcclt = MyRPCClient(addr)
[437] Fix | Delete
break
[438] Fix | Delete
except socket.error:
[439] Fix | Delete
pass
[440] Fix | Delete
else:
[441] Fix | Delete
self.display_port_binding_error()
[442] Fix | Delete
return None
[443] Fix | Delete
# if PORT was 0, system will assign an 'ephemeral' port. Find it out:
[444] Fix | Delete
self.port = self.rpcclt.listening_sock.getsockname()[1]
[445] Fix | Delete
# if PORT was not 0, probably working with a remote execution server
[446] Fix | Delete
if PORT != 0:
[447] Fix | Delete
# To allow reconnection within the 2MSL wait (cf. Stevens TCP
[448] Fix | Delete
# V1, 18.6), set SO_REUSEADDR. Note that this can be problematic
[449] Fix | Delete
# on Windows since the implementation allows two active sockets on
[450] Fix | Delete
# the same address!
[451] Fix | Delete
self.rpcclt.listening_sock.setsockopt(socket.SOL_SOCKET,
[452] Fix | Delete
socket.SO_REUSEADDR, 1)
[453] Fix | Delete
self.spawn_subprocess()
[454] Fix | Delete
#time.sleep(20) # test to simulate GUI not accepting connection
[455] Fix | Delete
# Accept the connection from the Python execution server
[456] Fix | Delete
self.rpcclt.listening_sock.settimeout(10)
[457] Fix | Delete
try:
[458] Fix | Delete
self.rpcclt.accept()
[459] Fix | Delete
except socket.timeout:
[460] Fix | Delete
self.display_no_subprocess_error()
[461] Fix | Delete
return None
[462] Fix | Delete
self.rpcclt.register("console", self.tkconsole)
[463] Fix | Delete
self.rpcclt.register("stdin", self.tkconsole.stdin)
[464] Fix | Delete
self.rpcclt.register("stdout", self.tkconsole.stdout)
[465] Fix | Delete
self.rpcclt.register("stderr", self.tkconsole.stderr)
[466] Fix | Delete
self.rpcclt.register("flist", self.tkconsole.flist)
[467] Fix | Delete
self.rpcclt.register("linecache", linecache)
[468] Fix | Delete
self.rpcclt.register("interp", self)
[469] Fix | Delete
self.transfer_path(with_cwd=True)
[470] Fix | Delete
self.poll_subprocess()
[471] Fix | Delete
return self.rpcclt
[472] Fix | Delete
[473] Fix | Delete
def restart_subprocess(self, with_cwd=False, filename=''):
[474] Fix | Delete
if self.restarting:
[475] Fix | Delete
return self.rpcclt
[476] Fix | Delete
self.restarting = True
[477] Fix | Delete
# close only the subprocess debugger
[478] Fix | Delete
debug = self.getdebugger()
[479] Fix | Delete
if debug:
[480] Fix | Delete
try:
[481] Fix | Delete
# Only close subprocess debugger, don't unregister gui_adap!
[482] Fix | Delete
RemoteDebugger.close_subprocess_debugger(self.rpcclt)
[483] Fix | Delete
except:
[484] Fix | Delete
pass
[485] Fix | Delete
# Kill subprocess, spawn a new one, accept connection.
[486] Fix | Delete
self.rpcclt.close()
[487] Fix | Delete
self.unix_terminate()
[488] Fix | Delete
console = self.tkconsole
[489] Fix | Delete
was_executing = console.executing
[490] Fix | Delete
console.executing = False
[491] Fix | Delete
self.spawn_subprocess()
[492] Fix | Delete
try:
[493] Fix | Delete
self.rpcclt.accept()
[494] Fix | Delete
except socket.timeout:
[495] Fix | Delete
self.display_no_subprocess_error()
[496] Fix | Delete
return None
[497] Fix | Delete
self.transfer_path(with_cwd=with_cwd)
[498] Fix | Delete
console.stop_readline()
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function