Commit 5a94e38f authored by Fred Drake's avatar Fred Drake

Do not test for sys.exc_info(); it was already present in Python 2.1.
This simplifies code and improves performance (very slightly).

In two places, object type was tested by calling type() on each of two
values and comparing the results (4 dict lookups, 2 Python->C function
calls).  Replace each with an isinstance() call comparing to a saved
type object (3 dict lookups, 1 Python->C function call, more future-proof).
parent a374dd25
...@@ -162,13 +162,15 @@ Examples ...@@ -162,13 +162,15 @@ Examples
s s
$Id: Test.py,v 1.35 1999/09/03 21:43:53 jim Exp $ $Id: Test.py,v 1.36 2001/06/05 20:24:57 fred Exp $
''' '''
__version__='$Revision: 1.35 $'[11:-2] __version__='$Revision: 1.36 $'[11:-2]
import sys, traceback, profile, os, getopt, string import sys, traceback, profile, os, getopt, string
from time import clock from time import clock
repeat_count=100 repeat_count=100
TupleType=type(())
def main(): def main():
import sys, os, getopt, string import sys, os, getopt, string
...@@ -260,13 +262,11 @@ def publish_module(module_name, ...@@ -260,13 +262,11 @@ def publish_module(module_name,
for k, v in extra.items(): request[k]=v for k, v in extra.items(): request[k]=v
response = publish(request, module_name, after_list, debug=debug) response = publish(request, module_name, after_list, debug=debug)
except SystemExit, v: except SystemExit, v:
if hasattr(sys, 'exc_info'): must_die=sys.exc_info() must_die=sys.exc_info()
else: must_die = SystemExit, v, sys.exc_info()[2]
response.exception(must_die) response.exception(must_die)
except ImportError, v: except ImportError, v:
if type(v) is type(()) and len(v)==3: must_die=v if isinstance(v, TupleType) and len(v)==3: must_die=v
elif hasattr(sys, 'exc_info'): must_die=sys.exc_info() else: must_die=sys.exc_info()
else: must_die = SystemExit, v, sys.exc_info()[2]
response.exception(1, v) response.exception(1, v)
except: except:
response.exception() response.exception()
...@@ -411,7 +411,7 @@ def publish(script=None,path_info='/', ...@@ -411,7 +411,7 @@ def publish(script=None,path_info='/',
if b: exec b in dbdata if b: exec b in dbdata
for b in dbdata['breakpoints']: for b in dbdata['breakpoints']:
if type(b) is type(()): if isinstance(b, TupleType):
apply(db.set_break,b) apply(db.set_break,b)
else: else:
fbreak(db,b) fbreak(db,b)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment