Changeset 388 for python/vendor/current/Lib/trace.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/trace.py
r2 r388 53 53 import re 54 54 import sys 55 import threading56 55 import time 57 56 import token 58 57 import tokenize 59 import types58 import inspect 60 59 import gc 61 60 import dis 62 61 try: 63 62 import cPickle … … 65 64 except ImportError: 66 65 import pickle 66 67 try: 68 import threading 69 except ImportError: 70 _settrace = sys.settrace 71 72 def _unsettrace(): 73 sys.settrace(None) 74 else: 75 def _settrace(func): 76 threading.settrace(func) 77 sys.settrace(func) 78 79 def _unsettrace(): 80 sys.settrace(None) 81 threading.settrace(None) 67 82 68 83 def usage(outfile): … … 125 140 126 141 def names(self, filename, modulename): 127 if self._ignore.has_key(modulename):142 if modulename in self._ignore: 128 143 return self._ignore[modulename] 129 144 … … 196 211 else: 197 212 base = path 213 # the drive letter is never part of the module name 214 drive, base = os.path.splitdrive(base) 198 215 base = base.replace(os.sep, ".") 199 216 if os.altsep: 200 217 base = base.replace(os.altsep, ".") 201 218 filename, ext = os.path.splitext(base) 202 return filename 219 return filename.lstrip(".") 203 220 204 221 class CoverageResults: … … 319 336 320 337 if summary and n_lines: 321 percent = int(100 * n_hits / n_lines)338 percent = 100 * n_hits // n_lines 322 339 sums[modulename] = n_lines, percent, modulename, filename 323 340 … … 378 395 linenos = {} 379 396 380 line_increments = [ord(c) for c in code.co_lnotab[1::2]] 381 table_length = len(line_increments) 382 docstring = False 383 384 lineno = code.co_firstlineno 385 for li in line_increments: 386 lineno += li 397 for _, lineno in dis.findlinestarts(code): 387 398 if lineno not in strs: 388 399 linenos[lineno] = 1 … … 397 408 # and check the constants for references to other code objects 398 409 for c in code.co_consts: 399 if i sinstance(c, types.CodeType):410 if inspect.iscode(c): 400 411 # find another code object, so recurse into it 401 412 linenos.update(find_lines(c, strs)) … … 492 503 import __main__ 493 504 dict = __main__.__dict__ 494 if not self.donothing: 495 sys.settrace(self.globaltrace) 496 threading.settrace(self.globaltrace) 497 try: 498 exec cmd in dict, dict 499 finally: 500 if not self.donothing: 501 sys.settrace(None) 502 threading.settrace(None) 505 self.runctx(cmd, dict, dict) 503 506 504 507 def runctx(self, cmd, globals=None, locals=None): … … 506 509 if locals is None: locals = {} 507 510 if not self.donothing: 508 sys.settrace(self.globaltrace) 509 threading.settrace(self.globaltrace) 511 _settrace(self.globaltrace) 510 512 try: 511 513 exec cmd in globals, locals 512 514 finally: 513 515 if not self.donothing: 514 sys.settrace(None) 515 threading.settrace(None) 516 _unsettrace() 516 517 517 518 def runfunc(self, func, *args, **kw): … … 544 545 # all functions which refer to this code object 545 546 funcs = [f for f in gc.get_referrers(code) 546 if hasattr(f, "func_doc")]547 if inspect.isfunction(f)] 547 548 # require len(func) == 1 to avoid ambiguity caused by calls to 548 549 # new.function(): "In the face of ambiguity, refuse the … … 556 557 if len(classes) == 1: 557 558 # ditto for new.classobj() 558 clsname = str(classes[0])559 clsname = classes[0].__name__ 559 560 # cache the result - assumption is that new.* is 560 561 # not called later to disturb this relationship … … 563 564 self._caller_cache[code] = clsname 564 565 if clsname is not None: 565 # final hack - module name shows up in str(cls), but we've already566 # computed module name, so remove it567 clsname = clsname.split(".")[1:]568 clsname = ".".join(clsname)569 566 funcname = "%s.%s" % (clsname, funcname) 570 567 … … 799 796 outfile=counts_file, timing=timing) 800 797 try: 801 t.run('execfile(%r)' % (progname,)) 798 with open(progname) as fp: 799 code = compile(fp.read(), progname, 'exec') 800 # try to emulate __main__ namespace as much as possible 801 globs = { 802 '__file__': progname, 803 '__name__': '__main__', 804 '__package__': None, 805 '__cached__': None, 806 } 807 t.runctx(code, globs, globs) 802 808 except IOError, err: 803 809 _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
Note:
See TracChangeset
for help on using the changeset viewer.