write PythonUtil.describeException

This commit is contained in:
David Rose 2003-07-17 13:09:25 +00:00
parent d9d36d9a8e
commit c0ace4ee5d
2 changed files with 34 additions and 0 deletions

View File

@ -238,6 +238,11 @@ class ConnectionRepository(DirectObject.DirectObject):
return 1
return 0
def flush(self):
# Ensure the latest has been sent to the server.
if self.tcpConn:
self.tcpConn.flush()
def ensureValidConnection(self):
# Was the connection reset?
if self.connectHttp:

View File

@ -687,6 +687,34 @@ def findPythonModule(module):
return None
def describeException(backTrace = 4):
# When called in an exception handler, returns a string describing
# the current exception.
infoArr = sys.exc_info()
exception = infoArr[0]
exceptionName = getattr(exception, '__name__', None)
extraInfo = infoArr[1]
trace = infoArr[2]
stack = []
while trace.tb_next:
module = trace.tb_frame.f_globals.get('__name__', None)
lineno = trace.tb_lineno
stack.append("%s:%s, " % (module, lineno))
trace = trace.tb_next
module = trace.tb_frame.f_globals.get('__name__', None)
lineno = trace.tb_lineno
stack.append("%s:%s, " % (module, lineno))
description = ""
for i in range(len(stack) - 1, max(len(stack) - backTrace, 0) - 1, -1):
description += stack[i]
description += "%s: %s" % (exceptionName, extraInfo)
return description
class PureVirtual:
""" Python classes that want to have C++-style pure-virtual functions
can derive from this class and call 'derivedMustOverride' from their
@ -698,3 +726,4 @@ class PureVirtual:
and are not meant to be chained down to. This simulates C++
pure-virtual methods. """
raise 'error: derived class must implement %s' % callerInfo()[2]