Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0930c43

Browse files
committed
M PyShell.py
1. Format and print exceptions raised in user code. M rpc.py 1. Additional debug messages in rpc.py 2. Move debug message enable switch from SocketIO to Client and Server to allow separate activation. 3. Add indication of origin (client or server) to debug message 4. Add sequence number to appropriate debug messages 5. Pass string exception arg as a string rather than a tuple.
1 parent edb635f commit 0930c43

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import traceback
1212
import types
1313
import warnings
14+
import exceptions
1415

1516
import linecache
1617
from code import InteractiveInterpreter
@@ -340,6 +341,7 @@ def poll_subprocess(self):
340341
if clt is None:
341342
return
342343
response = clt.pollresponse(self.active_seq)
344+
# Reschedule myself in 50 ms
343345
self.tkconsole.text.after(50, self.poll_subprocess)
344346
if response:
345347
self.tkconsole.resetoutput()
@@ -362,14 +364,24 @@ def poll_subprocess(self):
362364
line = linecache.getline(fn, ln)
363365
tb[i] = fn, ln, nm, line
364366
traceback.print_list(tb, file=file)
365-
if mod and mod != "exceptions":
366-
name = mod + "." + name
367-
print >>file, name + ":", " ".join(map(str, args))
367+
# try to reinstantiate the exception, stuff in the args:
368+
try:
369+
etype = eval(mod + '.' + name)
370+
val = etype()
371+
val.args = args
372+
except TypeError: # string exception!
373+
etype = name
374+
val = args
375+
lines = traceback.format_exception_only(etype, val)
376+
for line in lines[:-1]:
377+
traceback._print(file, line, '')
378+
traceback._print(file, lines[-1], '')
368379
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
369380
self.remote_stack_viewer()
370381
elif how == "ERROR":
371-
print >>sys.__stderr__, "Oops:", how, what
372-
print >>file, "Oops:", how, what
382+
errmsg = "PyShell.ModifiedInterpreter: Subprocess ERROR:\n"
383+
print >>sys.__stderr__, errmsg, what
384+
print >>file, errmsg, what
373385
self.tkconsole.endexecuting()
374386

375387
def kill_subprocess(self):
@@ -416,6 +428,8 @@ def execfile(self, filename, source=None):
416428
code = compile(source, filename, "exec")
417429
except (OverflowError, SyntaxError):
418430
self.tkconsole.resetoutput()
431+
console = self.tkconsole.console
432+
print >>console, 'Traceback (most recent call last):'
419433
InteractiveInterpreter.showsyntaxerror(self, filename)
420434
self.tkconsole.showprompt()
421435
else:

Lib/idlelib/rpc.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ def get_request(self):
9090

9191
class SocketIO:
9292

93-
debugging = False
94-
9593
def __init__(self, sock, objtable=None, debugging=None):
9694
self.mainthread = threading.currentThread()
9795
if debugging is not None:
@@ -113,11 +111,10 @@ def close(self):
113111
def debug(self, *args):
114112
if not self.debugging:
115113
return
116-
s = str(threading.currentThread().getName())
114+
s = self.location + " " + str(threading.currentThread().getName())
117115
for a in args:
118116
s = s + " " + str(a)
119-
s = s + "\n"
120-
sys.__stderr__.write(s)
117+
print>>sys.__stderr__, s
121118

122119
def register(self, oid, object):
123120
self.objtable[oid] = object
@@ -159,44 +156,45 @@ def localcall(self, request):
159156
typ, val, tb = info = sys.exc_info()
160157
sys.last_type, sys.last_value, sys.last_traceback = info
161158
if isinstance(typ, type(Exception)):
162-
# Class exceptions
159+
# Class exception
163160
mod = typ.__module__
164161
name = typ.__name__
165162
if issubclass(typ, Exception):
166163
args = val.args
167164
else:
168165
args = (str(val),)
169166
else:
170-
# String exceptions
167+
# User string exception
171168
mod = None
172169
name = typ
173-
args = (str(val),)
170+
if val is None: val = ''
171+
args = str(val)
174172
tb = traceback.extract_tb(tb)
173+
self.debug("localcall:EXCEPTION: ", mod, name, args, tb)
175174
return ("EXCEPTION", (mod, name, args, tb))
176175

177176
def remotecall(self, oid, methodname, args, kwargs):
178-
self.debug("remotecall:", oid, methodname, args, kwargs)
177+
self.debug("remotecall:")
179178
seq = self.asynccall(oid, methodname, args, kwargs)
180-
ret = self.asyncreturn(seq)
181-
self.debug("return:", ret)
182-
return ret
179+
return self.asyncreturn(seq)
183180

184181
def asynccall(self, oid, methodname, args, kwargs):
185-
self.debug("asyncall:", oid, methodname, args, kwargs)
186182
request = ("call", (oid, methodname, args, kwargs))
187183
seq = self.putrequest(request)
184+
self.debug(("asyncall:%d:" % seq), oid, methodname, args, kwargs)
188185
return seq
189186

190187
def asyncreturn(self, seq):
191188
response = self.getresponse(seq)
192-
self.debug("asyncreturn:", response)
189+
self.debug(("asyncreturn:%d:" % seq), response)
193190
return self.decoderesponse(response)
194191

195192
def decoderesponse(self, response):
196193
how, what = response
197194
if how == "OK":
198195
return what
199196
if how == "EXCEPTION":
197+
self.debug("decoderesponse: Internal EXCEPTION:", what)
200198
mod, name, args, tb = what
201199
self.traceback = tb
202200
if mod: # not string exception
@@ -217,6 +215,7 @@ def decoderesponse(self, response):
217215
# do the best we can:
218216
raise name, args
219217
if how == "ERROR":
218+
self.debug("decoderesponse: Internal ERROR:", what)
220219
raise RuntimeError, what
221220
raise SystemError, (how, what)
222221

@@ -274,6 +273,7 @@ def newseq(self):
274273
return seq
275274

276275
def putmessage(self, message):
276+
##self.debug("putmessage: ", message)
277277
try:
278278
s = pickle.dumps(message)
279279
except:
@@ -345,6 +345,7 @@ def pollresponse(self, myseq, wait=0.0):
345345
wait = 0.0
346346
seq, resq = message
347347
if resq[0] == "call":
348+
self.debug("call_localcall:%d:" % seq)
348349
response = self.localcall(resq)
349350
self.putmessage((seq, response))
350351
continue
@@ -377,7 +378,8 @@ def __init__(self, oid):
377378

378379
class RPCHandler(SocketServer.BaseRequestHandler, SocketIO):
379380

380-
debugging = 0
381+
debugging = False
382+
location = "#S" # Server
381383

382384
def __init__(self, sock, addr, svr):
383385
svr.current_handler = self ## cgt xxx
@@ -393,6 +395,9 @@ def get_remote_proxy(self, oid):
393395

394396
class RPCClient(SocketIO):
395397

398+
debugging = False
399+
location = "#C" # Client
400+
396401
nextseq = 1 # Requests coming from the client are odd numbered
397402

398403
def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):

0 commit comments

Comments
 (0)