[Idle-dev] CVS: idle PyShell.py,1.35,1.36 rpc.py,1.9,1.10

Kurt B. Kaiser kbk@users.sourceforge.net
Fri, 06 Dec 2002 13:45:27 -0800


Update of /cvsroot/idlefork/idle
In directory sc8-pr-cvs1:/tmp/cvs-serv23461

Modified Files:
	PyShell.py rpc.py 
Log Message:
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.


Index: PyShell.py
===================================================================
RCS file: /cvsroot/idlefork/idle/PyShell.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** PyShell.py	30 Nov 2002 18:49:10 -0000	1.35
--- PyShell.py	6 Dec 2002 21:45:23 -0000	1.36
***************
*** 12,15 ****
--- 12,16 ----
  import types
  import warnings
+ import exceptions
  
  import linecache
***************
*** 341,344 ****
--- 342,346 ----
              return
          response = clt.pollresponse(self.active_seq)
+         # Reschedule myself in 50 ms
          self.tkconsole.text.after(50, self.poll_subprocess)
          if response:
***************
*** 363,374 ****
                          tb[i] = fn, ln, nm, line
                  traceback.print_list(tb, file=file)
!                 if mod and mod != "exceptions":
!                     name = mod + "." + name
!                 print >>file, name + ":", " ".join(map(str, args))
                  if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
                      self.remote_stack_viewer()
              elif how == "ERROR":
!                 print >>sys.__stderr__, "Oops:", how, what
!                 print >>file, "Oops:", how, what
              self.tkconsole.endexecuting()
  
--- 365,386 ----
                          tb[i] = fn, ln, nm, line
                  traceback.print_list(tb, file=file)
!                 # try to reinstantiate the exception, stuff in the args:
!                 try:
!                     etype = eval(mod + '.' + name)
!                     val = etype()
!                     val.args = args
!                 except TypeError:  # string exception!
!                     etype = name
!                     val = args
!                 lines = traceback.format_exception_only(etype, val)
!                 for line in lines[:-1]:
!                     traceback._print(file, line, '')
!                 traceback._print(file, lines[-1], '')
                  if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
                      self.remote_stack_viewer()
              elif how == "ERROR":
!                 errmsg = "PyShell.ModifiedInterpreter: Subprocess ERROR:\n"
!                 print >>sys.__stderr__, errmsg, what
!                 print >>file, errmsg, what
              self.tkconsole.endexecuting()
  
***************
*** 417,420 ****
--- 429,434 ----
          except (OverflowError, SyntaxError):
              self.tkconsole.resetoutput()
+             console = self.tkconsole.console
+             print >>console, 'Traceback (most recent call last):'
              InteractiveInterpreter.showsyntaxerror(self, filename)
              self.tkconsole.showprompt()

Index: rpc.py
===================================================================
RCS file: /cvsroot/idlefork/idle/rpc.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** rpc.py	30 Nov 2002 06:18:00 -0000	1.9
--- rpc.py	6 Dec 2002 21:45:24 -0000	1.10
***************
*** 91,96 ****
  class SocketIO:
  
-     debugging = False
- 
      def __init__(self, sock, objtable=None, debugging=None):
          self.mainthread = threading.currentThread()
--- 91,94 ----
***************
*** 114,122 ****
          if not self.debugging:
              return
!         s = str(threading.currentThread().getName())
          for a in args:
              s = s + " " + str(a)
!         s = s + "\n"
!         sys.__stderr__.write(s)
  
      def register(self, oid, object):
--- 112,119 ----
          if not self.debugging:
              return
!         s = self.location + " " + str(threading.currentThread().getName())
          for a in args:
              s = s + " " + str(a)
!         print>>sys.__stderr__, s
  
      def register(self, oid, object):
***************
*** 160,164 ****
              sys.last_type, sys.last_value, sys.last_traceback = info
              if isinstance(typ, type(Exception)):
!                 # Class exceptions
                  mod = typ.__module__
                  name = typ.__name__
--- 157,161 ----
              sys.last_type, sys.last_value, sys.last_traceback = info
              if isinstance(typ, type(Exception)):
!                 # Class exception
                  mod = typ.__module__
                  name = typ.__name__
***************
*** 168,194 ****
                      args = (str(val),)
              else:
!                 # String exceptions
                  mod = None
                  name = typ
!                 args = (str(val),)
              tb = traceback.extract_tb(tb)
              return ("EXCEPTION", (mod, name, args, tb))
  
      def remotecall(self, oid, methodname, args, kwargs):
!         self.debug("remotecall:", oid, methodname, args, kwargs) 
          seq = self.asynccall(oid, methodname, args, kwargs)
!         ret = self.asyncreturn(seq)
!         self.debug("return:", ret)
!         return ret
  
      def asynccall(self, oid, methodname, args, kwargs):
-         self.debug("asyncall:", oid, methodname, args, kwargs)
          request = ("call", (oid, methodname, args, kwargs))
          seq = self.putrequest(request)
          return seq
  
      def asyncreturn(self, seq):
          response = self.getresponse(seq)
!         self.debug("asyncreturn:", response)
          return self.decoderesponse(response)
  
--- 165,191 ----
                      args = (str(val),)
              else:
!                 # User string exception
                  mod = None
                  name = typ
!                 if val is None: val = ''
!                 args = str(val)
              tb = traceback.extract_tb(tb)
+             self.debug("localcall:EXCEPTION: ", mod, name, args, tb)
              return ("EXCEPTION", (mod, name, args, tb))
  
      def remotecall(self, oid, methodname, args, kwargs):
!         self.debug("remotecall:") 
          seq = self.asynccall(oid, methodname, args, kwargs)
!         return self.asyncreturn(seq)
  
      def asynccall(self, oid, methodname, args, kwargs):
          request = ("call", (oid, methodname, args, kwargs))
          seq = self.putrequest(request)
+         self.debug(("asyncall:%d:" % seq), oid, methodname, args, kwargs)
          return seq
  
      def asyncreturn(self, seq):
          response = self.getresponse(seq)
!         self.debug(("asyncreturn:%d:" % seq), response)
          return self.decoderesponse(response)
  
***************
*** 198,201 ****
--- 195,199 ----
              return what
          if how == "EXCEPTION":
+             self.debug("decoderesponse: Internal EXCEPTION:", what)
              mod, name, args, tb = what
              self.traceback = tb
***************
*** 218,221 ****
--- 216,220 ----
              raise name, args
          if how == "ERROR":
+             self.debug("decoderesponse: Internal ERROR:", what)            
              raise RuntimeError, what
          raise SystemError, (how, what)
***************
*** 275,278 ****
--- 274,278 ----
  
      def putmessage(self, message):
+         ##self.debug("putmessage: ", message)
          try:
              s = pickle.dumps(message)
***************
*** 346,349 ****
--- 346,350 ----
              seq, resq = message
              if resq[0] == "call":
+                 self.debug("call_localcall:%d:" % seq)
                  response = self.localcall(resq)
                  self.putmessage((seq, response))
***************
*** 378,382 ****
  class RPCHandler(SocketServer.BaseRequestHandler, SocketIO):
  
!     debugging = 0
  
      def __init__(self, sock, addr, svr):
--- 379,384 ----
  class RPCHandler(SocketServer.BaseRequestHandler, SocketIO):
  
!     debugging = False
!     location = "#S"  # Server
  
      def __init__(self, sock, addr, svr):
***************
*** 393,396 ****
--- 395,401 ----
  
  class RPCClient(SocketIO):
+ 
+     debugging = False
+     location = "#C"  # Client
  
      nextseq = 1 # Requests coming from the client are odd numbered