Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: run.py
import sys
[0] Fix | Delete
import linecache
[1] Fix | Delete
import time
[2] Fix | Delete
import socket
[3] Fix | Delete
import traceback
[4] Fix | Delete
import thread
[5] Fix | Delete
import threading
[6] Fix | Delete
import Queue
[7] Fix | Delete
[8] Fix | Delete
from idlelib import CallTips
[9] Fix | Delete
from idlelib import AutoComplete
[10] Fix | Delete
[11] Fix | Delete
from idlelib import RemoteDebugger
[12] Fix | Delete
from idlelib import RemoteObjectBrowser
[13] Fix | Delete
from idlelib import StackViewer
[14] Fix | Delete
from idlelib import rpc
[15] Fix | Delete
from idlelib import PyShell
[16] Fix | Delete
from idlelib import IOBinding
[17] Fix | Delete
[18] Fix | Delete
import __main__
[19] Fix | Delete
[20] Fix | Delete
LOCALHOST = '127.0.0.1'
[21] Fix | Delete
[22] Fix | Delete
import warnings
[23] Fix | Delete
[24] Fix | Delete
def idle_showwarning_subproc(
[25] Fix | Delete
message, category, filename, lineno, file=None, line=None):
[26] Fix | Delete
"""Show Idle-format warning after replacing warnings.showwarning.
[27] Fix | Delete
[28] Fix | Delete
The only difference is the formatter called.
[29] Fix | Delete
"""
[30] Fix | Delete
if file is None:
[31] Fix | Delete
file = sys.stderr
[32] Fix | Delete
try:
[33] Fix | Delete
file.write(PyShell.idle_formatwarning(
[34] Fix | Delete
message, category, filename, lineno, line))
[35] Fix | Delete
except IOError:
[36] Fix | Delete
pass # the file (probably stderr) is invalid - this warning gets lost.
[37] Fix | Delete
[38] Fix | Delete
_warnings_showwarning = None
[39] Fix | Delete
[40] Fix | Delete
def capture_warnings(capture):
[41] Fix | Delete
"Replace warning.showwarning with idle_showwarning_subproc, or reverse."
[42] Fix | Delete
[43] Fix | Delete
global _warnings_showwarning
[44] Fix | Delete
if capture:
[45] Fix | Delete
if _warnings_showwarning is None:
[46] Fix | Delete
_warnings_showwarning = warnings.showwarning
[47] Fix | Delete
warnings.showwarning = idle_showwarning_subproc
[48] Fix | Delete
else:
[49] Fix | Delete
if _warnings_showwarning is not None:
[50] Fix | Delete
warnings.showwarning = _warnings_showwarning
[51] Fix | Delete
_warnings_showwarning = None
[52] Fix | Delete
[53] Fix | Delete
capture_warnings(True)
[54] Fix | Delete
[55] Fix | Delete
# Thread shared globals: Establish a queue between a subthread (which handles
[56] Fix | Delete
# the socket) and the main thread (which runs user code), plus global
[57] Fix | Delete
# completion, exit and interruptable (the main thread) flags:
[58] Fix | Delete
[59] Fix | Delete
exit_now = False
[60] Fix | Delete
quitting = False
[61] Fix | Delete
interruptable = False
[62] Fix | Delete
[63] Fix | Delete
def main(del_exitfunc=False):
[64] Fix | Delete
"""Start the Python execution server in a subprocess
[65] Fix | Delete
[66] Fix | Delete
In the Python subprocess, RPCServer is instantiated with handlerclass
[67] Fix | Delete
MyHandler, which inherits register/unregister methods from RPCHandler via
[68] Fix | Delete
the mix-in class SocketIO.
[69] Fix | Delete
[70] Fix | Delete
When the RPCServer 'server' is instantiated, the TCPServer initialization
[71] Fix | Delete
creates an instance of run.MyHandler and calls its handle() method.
[72] Fix | Delete
handle() instantiates a run.Executive object, passing it a reference to the
[73] Fix | Delete
MyHandler object. That reference is saved as attribute rpchandler of the
[74] Fix | Delete
Executive instance. The Executive methods have access to the reference and
[75] Fix | Delete
can pass it on to entities that they command
[76] Fix | Delete
(e.g. RemoteDebugger.Debugger.start_debugger()). The latter, in turn, can
[77] Fix | Delete
call MyHandler(SocketIO) register/unregister methods via the reference to
[78] Fix | Delete
register and unregister themselves.
[79] Fix | Delete
[80] Fix | Delete
"""
[81] Fix | Delete
global exit_now
[82] Fix | Delete
global quitting
[83] Fix | Delete
global no_exitfunc
[84] Fix | Delete
no_exitfunc = del_exitfunc
[85] Fix | Delete
#time.sleep(15) # test subprocess not responding
[86] Fix | Delete
try:
[87] Fix | Delete
assert(len(sys.argv) > 1)
[88] Fix | Delete
port = int(sys.argv[-1])
[89] Fix | Delete
except:
[90] Fix | Delete
print>>sys.stderr, "IDLE Subprocess: no IP port passed in sys.argv."
[91] Fix | Delete
return
[92] Fix | Delete
[93] Fix | Delete
capture_warnings(True)
[94] Fix | Delete
sys.argv[:] = [""]
[95] Fix | Delete
sockthread = threading.Thread(target=manage_socket,
[96] Fix | Delete
name='SockThread',
[97] Fix | Delete
args=((LOCALHOST, port),))
[98] Fix | Delete
sockthread.setDaemon(True)
[99] Fix | Delete
sockthread.start()
[100] Fix | Delete
while 1:
[101] Fix | Delete
try:
[102] Fix | Delete
if exit_now:
[103] Fix | Delete
try:
[104] Fix | Delete
exit()
[105] Fix | Delete
except KeyboardInterrupt:
[106] Fix | Delete
# exiting but got an extra KBI? Try again!
[107] Fix | Delete
continue
[108] Fix | Delete
try:
[109] Fix | Delete
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
[110] Fix | Delete
except Queue.Empty:
[111] Fix | Delete
continue
[112] Fix | Delete
method, args, kwargs = request
[113] Fix | Delete
ret = method(*args, **kwargs)
[114] Fix | Delete
rpc.response_queue.put((seq, ret))
[115] Fix | Delete
except KeyboardInterrupt:
[116] Fix | Delete
if quitting:
[117] Fix | Delete
exit_now = True
[118] Fix | Delete
continue
[119] Fix | Delete
except SystemExit:
[120] Fix | Delete
capture_warnings(False)
[121] Fix | Delete
raise
[122] Fix | Delete
except:
[123] Fix | Delete
type, value, tb = sys.exc_info()
[124] Fix | Delete
try:
[125] Fix | Delete
print_exception()
[126] Fix | Delete
rpc.response_queue.put((seq, None))
[127] Fix | Delete
except:
[128] Fix | Delete
# Link didn't work, print same exception to __stderr__
[129] Fix | Delete
traceback.print_exception(type, value, tb, file=sys.__stderr__)
[130] Fix | Delete
exit()
[131] Fix | Delete
else:
[132] Fix | Delete
continue
[133] Fix | Delete
[134] Fix | Delete
def manage_socket(address):
[135] Fix | Delete
for i in range(3):
[136] Fix | Delete
time.sleep(i)
[137] Fix | Delete
try:
[138] Fix | Delete
server = MyRPCServer(address, MyHandler)
[139] Fix | Delete
break
[140] Fix | Delete
except socket.error as err:
[141] Fix | Delete
print>>sys.__stderr__,"IDLE Subprocess: socket error: "\
[142] Fix | Delete
+ err.args[1] + ", retrying...."
[143] Fix | Delete
else:
[144] Fix | Delete
print>>sys.__stderr__, "IDLE Subprocess: Connection to "\
[145] Fix | Delete
"IDLE GUI failed, exiting."
[146] Fix | Delete
show_socket_error(err, address)
[147] Fix | Delete
global exit_now
[148] Fix | Delete
exit_now = True
[149] Fix | Delete
return
[150] Fix | Delete
server.handle_request() # A single request only
[151] Fix | Delete
[152] Fix | Delete
def show_socket_error(err, address):
[153] Fix | Delete
import Tkinter
[154] Fix | Delete
import tkMessageBox
[155] Fix | Delete
root = Tkinter.Tk()
[156] Fix | Delete
fix_scaling(root)
[157] Fix | Delete
root.withdraw()
[158] Fix | Delete
if err.args[0] == 61: # connection refused
[159] Fix | Delete
msg = "IDLE's subprocess can't connect to %s:%d. This may be due "\
[160] Fix | Delete
"to your personal firewall configuration. It is safe to "\
[161] Fix | Delete
"allow this internal connection because no data is visible on "\
[162] Fix | Delete
"external ports." % address
[163] Fix | Delete
tkMessageBox.showerror("IDLE Subprocess Error", msg, parent=root)
[164] Fix | Delete
else:
[165] Fix | Delete
tkMessageBox.showerror("IDLE Subprocess Error",
[166] Fix | Delete
"Socket Error: %s" % err.args[1], parent=root)
[167] Fix | Delete
root.destroy()
[168] Fix | Delete
[169] Fix | Delete
def print_exception():
[170] Fix | Delete
import linecache
[171] Fix | Delete
linecache.checkcache()
[172] Fix | Delete
flush_stdout()
[173] Fix | Delete
efile = sys.stderr
[174] Fix | Delete
typ, val, tb = excinfo = sys.exc_info()
[175] Fix | Delete
sys.last_type, sys.last_value, sys.last_traceback = excinfo
[176] Fix | Delete
tbe = traceback.extract_tb(tb)
[177] Fix | Delete
print>>efile, '\nTraceback (most recent call last):'
[178] Fix | Delete
exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
[179] Fix | Delete
"RemoteDebugger.py", "bdb.py")
[180] Fix | Delete
cleanup_traceback(tbe, exclude)
[181] Fix | Delete
traceback.print_list(tbe, file=efile)
[182] Fix | Delete
lines = traceback.format_exception_only(typ, val)
[183] Fix | Delete
for line in lines:
[184] Fix | Delete
print>>efile, line,
[185] Fix | Delete
[186] Fix | Delete
def cleanup_traceback(tb, exclude):
[187] Fix | Delete
"Remove excluded traces from beginning/end of tb; get cached lines"
[188] Fix | Delete
orig_tb = tb[:]
[189] Fix | Delete
while tb:
[190] Fix | Delete
for rpcfile in exclude:
[191] Fix | Delete
if tb[0][0].count(rpcfile):
[192] Fix | Delete
break # found an exclude, break for: and delete tb[0]
[193] Fix | Delete
else:
[194] Fix | Delete
break # no excludes, have left RPC code, break while:
[195] Fix | Delete
del tb[0]
[196] Fix | Delete
while tb:
[197] Fix | Delete
for rpcfile in exclude:
[198] Fix | Delete
if tb[-1][0].count(rpcfile):
[199] Fix | Delete
break
[200] Fix | Delete
else:
[201] Fix | Delete
break
[202] Fix | Delete
del tb[-1]
[203] Fix | Delete
if len(tb) == 0:
[204] Fix | Delete
# exception was in IDLE internals, don't prune!
[205] Fix | Delete
tb[:] = orig_tb[:]
[206] Fix | Delete
print>>sys.stderr, "** IDLE Internal Exception: "
[207] Fix | Delete
rpchandler = rpc.objecttable['exec'].rpchandler
[208] Fix | Delete
for i in range(len(tb)):
[209] Fix | Delete
fn, ln, nm, line = tb[i]
[210] Fix | Delete
if nm == '?':
[211] Fix | Delete
nm = "-toplevel-"
[212] Fix | Delete
if fn.startswith("<pyshell#") and IOBinding.encoding != 'utf-8':
[213] Fix | Delete
ln -= 1 # correction for coding cookie
[214] Fix | Delete
if not line and fn.startswith("<pyshell#"):
[215] Fix | Delete
line = rpchandler.remotecall('linecache', 'getline',
[216] Fix | Delete
(fn, ln), {})
[217] Fix | Delete
tb[i] = fn, ln, nm, line
[218] Fix | Delete
[219] Fix | Delete
def flush_stdout():
[220] Fix | Delete
try:
[221] Fix | Delete
if sys.stdout.softspace:
[222] Fix | Delete
sys.stdout.softspace = 0
[223] Fix | Delete
sys.stdout.write("\n")
[224] Fix | Delete
except (AttributeError, EOFError):
[225] Fix | Delete
pass
[226] Fix | Delete
[227] Fix | Delete
def exit():
[228] Fix | Delete
"""Exit subprocess, possibly after first deleting sys.exitfunc
[229] Fix | Delete
[230] Fix | Delete
If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
[231] Fix | Delete
sys.exitfunc will be removed before exiting. (VPython support)
[232] Fix | Delete
[233] Fix | Delete
"""
[234] Fix | Delete
if no_exitfunc:
[235] Fix | Delete
try:
[236] Fix | Delete
del sys.exitfunc
[237] Fix | Delete
except AttributeError:
[238] Fix | Delete
pass
[239] Fix | Delete
capture_warnings(False)
[240] Fix | Delete
sys.exit(0)
[241] Fix | Delete
[242] Fix | Delete
[243] Fix | Delete
def fix_scaling(root):
[244] Fix | Delete
"""Scale fonts on HiDPI displays."""
[245] Fix | Delete
import tkFont
[246] Fix | Delete
scaling = float(root.tk.call('tk', 'scaling'))
[247] Fix | Delete
if scaling > 1.4:
[248] Fix | Delete
for name in tkFont.names(root):
[249] Fix | Delete
font = tkFont.Font(root=root, name=name, exists=True)
[250] Fix | Delete
size = int(font['size'])
[251] Fix | Delete
if size < 0:
[252] Fix | Delete
font['size'] = int(round(-0.75*size))
[253] Fix | Delete
[254] Fix | Delete
[255] Fix | Delete
class MyRPCServer(rpc.RPCServer):
[256] Fix | Delete
[257] Fix | Delete
def handle_error(self, request, client_address):
[258] Fix | Delete
"""Override RPCServer method for IDLE
[259] Fix | Delete
[260] Fix | Delete
Interrupt the MainThread and exit server if link is dropped.
[261] Fix | Delete
[262] Fix | Delete
"""
[263] Fix | Delete
global quitting
[264] Fix | Delete
try:
[265] Fix | Delete
raise
[266] Fix | Delete
except SystemExit:
[267] Fix | Delete
raise
[268] Fix | Delete
except EOFError:
[269] Fix | Delete
global exit_now
[270] Fix | Delete
exit_now = True
[271] Fix | Delete
thread.interrupt_main()
[272] Fix | Delete
except:
[273] Fix | Delete
erf = sys.__stderr__
[274] Fix | Delete
print>>erf, '\n' + '-'*40
[275] Fix | Delete
print>>erf, 'Unhandled server exception!'
[276] Fix | Delete
print>>erf, 'Thread: %s' % threading.currentThread().getName()
[277] Fix | Delete
print>>erf, 'Client Address: ', client_address
[278] Fix | Delete
print>>erf, 'Request: ', repr(request)
[279] Fix | Delete
traceback.print_exc(file=erf)
[280] Fix | Delete
print>>erf, '\n*** Unrecoverable, server exiting!'
[281] Fix | Delete
print>>erf, '-'*40
[282] Fix | Delete
quitting = True
[283] Fix | Delete
thread.interrupt_main()
[284] Fix | Delete
[285] Fix | Delete
class MyHandler(rpc.RPCHandler):
[286] Fix | Delete
[287] Fix | Delete
def handle(self):
[288] Fix | Delete
"""Override base method"""
[289] Fix | Delete
executive = Executive(self)
[290] Fix | Delete
self.register("exec", executive)
[291] Fix | Delete
self.console = self.get_remote_proxy("console")
[292] Fix | Delete
sys.stdin = PyShell.PseudoInputFile(self.console, "stdin",
[293] Fix | Delete
IOBinding.encoding)
[294] Fix | Delete
sys.stdout = PyShell.PseudoOutputFile(self.console, "stdout",
[295] Fix | Delete
IOBinding.encoding)
[296] Fix | Delete
sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr",
[297] Fix | Delete
IOBinding.encoding)
[298] Fix | Delete
[299] Fix | Delete
# Keep a reference to stdin so that it won't try to exit IDLE if
[300] Fix | Delete
# sys.stdin gets changed from within IDLE's shell. See issue17838.
[301] Fix | Delete
self._keep_stdin = sys.stdin
[302] Fix | Delete
[303] Fix | Delete
self.interp = self.get_remote_proxy("interp")
[304] Fix | Delete
rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)
[305] Fix | Delete
[306] Fix | Delete
def exithook(self):
[307] Fix | Delete
"override SocketIO method - wait for MainThread to shut us down"
[308] Fix | Delete
time.sleep(10)
[309] Fix | Delete
[310] Fix | Delete
def EOFhook(self):
[311] Fix | Delete
"Override SocketIO method - terminate wait on callback and exit thread"
[312] Fix | Delete
global quitting
[313] Fix | Delete
quitting = True
[314] Fix | Delete
thread.interrupt_main()
[315] Fix | Delete
[316] Fix | Delete
def decode_interrupthook(self):
[317] Fix | Delete
"interrupt awakened thread"
[318] Fix | Delete
global quitting
[319] Fix | Delete
quitting = True
[320] Fix | Delete
thread.interrupt_main()
[321] Fix | Delete
[322] Fix | Delete
[323] Fix | Delete
class Executive(object):
[324] Fix | Delete
[325] Fix | Delete
def __init__(self, rpchandler):
[326] Fix | Delete
self.rpchandler = rpchandler
[327] Fix | Delete
self.locals = __main__.__dict__
[328] Fix | Delete
self.calltip = CallTips.CallTips()
[329] Fix | Delete
self.autocomplete = AutoComplete.AutoComplete()
[330] Fix | Delete
[331] Fix | Delete
def runcode(self, code):
[332] Fix | Delete
global interruptable
[333] Fix | Delete
try:
[334] Fix | Delete
self.usr_exc_info = None
[335] Fix | Delete
interruptable = True
[336] Fix | Delete
try:
[337] Fix | Delete
exec code in self.locals
[338] Fix | Delete
finally:
[339] Fix | Delete
interruptable = False
[340] Fix | Delete
except SystemExit:
[341] Fix | Delete
# Scripts that raise SystemExit should just
[342] Fix | Delete
# return to the interactive prompt
[343] Fix | Delete
pass
[344] Fix | Delete
except:
[345] Fix | Delete
self.usr_exc_info = sys.exc_info()
[346] Fix | Delete
if quitting:
[347] Fix | Delete
exit()
[348] Fix | Delete
print_exception()
[349] Fix | Delete
jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
[350] Fix | Delete
if jit:
[351] Fix | Delete
self.rpchandler.interp.open_remote_stack_viewer()
[352] Fix | Delete
else:
[353] Fix | Delete
flush_stdout()
[354] Fix | Delete
[355] Fix | Delete
def interrupt_the_server(self):
[356] Fix | Delete
if interruptable:
[357] Fix | Delete
thread.interrupt_main()
[358] Fix | Delete
[359] Fix | Delete
def start_the_debugger(self, gui_adap_oid):
[360] Fix | Delete
return RemoteDebugger.start_debugger(self.rpchandler, gui_adap_oid)
[361] Fix | Delete
[362] Fix | Delete
def stop_the_debugger(self, idb_adap_oid):
[363] Fix | Delete
"Unregister the Idb Adapter. Link objects and Idb then subject to GC"
[364] Fix | Delete
self.rpchandler.unregister(idb_adap_oid)
[365] Fix | Delete
[366] Fix | Delete
def get_the_calltip(self, name):
[367] Fix | Delete
return self.calltip.fetch_tip(name)
[368] Fix | Delete
[369] Fix | Delete
def get_the_completion_list(self, what, mode):
[370] Fix | Delete
return self.autocomplete.fetch_completions(what, mode)
[371] Fix | Delete
[372] Fix | Delete
def stackviewer(self, flist_oid=None):
[373] Fix | Delete
if self.usr_exc_info:
[374] Fix | Delete
typ, val, tb = self.usr_exc_info
[375] Fix | Delete
else:
[376] Fix | Delete
return None
[377] Fix | Delete
flist = None
[378] Fix | Delete
if flist_oid is not None:
[379] Fix | Delete
flist = self.rpchandler.get_remote_proxy(flist_oid)
[380] Fix | Delete
while tb and tb.tb_frame.f_globals["__name__"] in ["rpc", "run"]:
[381] Fix | Delete
tb = tb.tb_next
[382] Fix | Delete
sys.last_type = typ
[383] Fix | Delete
sys.last_value = val
[384] Fix | Delete
item = StackViewer.StackTreeItem(flist, tb)
[385] Fix | Delete
return RemoteObjectBrowser.remote_object_tree_item(item)
[386] Fix | Delete
[387] Fix | Delete
capture_warnings(False) # Make sure turned off; see issue 18081
[388] Fix | Delete
[389] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function