Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Lib/trace.py

    r2 r388  
    5353import re
    5454import sys
    55 import threading
    5655import time
    5756import token
    5857import tokenize
    59 import types
     58import inspect
    6059import gc
    61 
     60import dis
    6261try:
    6362    import cPickle
     
    6564except ImportError:
    6665    import pickle
     66
     67try:
     68    import threading
     69except ImportError:
     70    _settrace = sys.settrace
     71
     72    def _unsettrace():
     73        sys.settrace(None)
     74else:
     75    def _settrace(func):
     76        threading.settrace(func)
     77        sys.settrace(func)
     78
     79    def _unsettrace():
     80        sys.settrace(None)
     81        threading.settrace(None)
    6782
    6883def usage(outfile):
     
    125140
    126141    def names(self, filename, modulename):
    127         if self._ignore.has_key(modulename):
     142        if modulename in self._ignore:
    128143            return self._ignore[modulename]
    129144
     
    196211    else:
    197212        base = path
     213    # the drive letter is never part of the module name
     214    drive, base = os.path.splitdrive(base)
    198215    base = base.replace(os.sep, ".")
    199216    if os.altsep:
    200217        base = base.replace(os.altsep, ".")
    201218    filename, ext = os.path.splitext(base)
    202     return filename
     219    return filename.lstrip(".")
    203220
    204221class CoverageResults:
     
    319336
    320337            if summary and n_lines:
    321                 percent = int(100 * n_hits / n_lines)
     338                percent = 100 * n_hits // n_lines
    322339                sums[modulename] = n_lines, percent, modulename, filename
    323340
     
    378395    linenos = {}
    379396
    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):
    387398        if lineno not in strs:
    388399            linenos[lineno] = 1
     
    397408    # and check the constants for references to other code objects
    398409    for c in code.co_consts:
    399         if isinstance(c, types.CodeType):
     410        if inspect.iscode(c):
    400411            # find another code object, so recurse into it
    401412            linenos.update(find_lines(c, strs))
     
    492503        import __main__
    493504        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)
    503506
    504507    def runctx(self, cmd, globals=None, locals=None):
     
    506509        if locals is None: locals = {}
    507510        if not self.donothing:
    508             sys.settrace(self.globaltrace)
    509             threading.settrace(self.globaltrace)
     511            _settrace(self.globaltrace)
    510512        try:
    511513            exec cmd in globals, locals
    512514        finally:
    513515            if not self.donothing:
    514                 sys.settrace(None)
    515                 threading.settrace(None)
     516                _unsettrace()
    516517
    517518    def runfunc(self, func, *args, **kw):
     
    544545            # all functions which refer to this code object
    545546            funcs = [f for f in gc.get_referrers(code)
    546                          if hasattr(f, "func_doc")]
     547                         if inspect.isfunction(f)]
    547548            # require len(func) == 1 to avoid ambiguity caused by calls to
    548549            # new.function(): "In the face of ambiguity, refuse the
     
    556557                    if len(classes) == 1:
    557558                        # ditto for new.classobj()
    558                         clsname = str(classes[0])
     559                        clsname = classes[0].__name__
    559560                        # cache the result - assumption is that new.* is
    560561                        # not called later to disturb this relationship
     
    563564                        self._caller_cache[code] = clsname
    564565        if clsname is not None:
    565             # final hack - module name shows up in str(cls), but we've already
    566             # computed module name, so remove it
    567             clsname = clsname.split(".")[1:]
    568             clsname = ".".join(clsname)
    569566            funcname = "%s.%s" % (clsname, funcname)
    570567
     
    799796                  outfile=counts_file, timing=timing)
    800797        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)
    802808        except IOError, err:
    803809            _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
Note: See TracChangeset for help on using the changeset viewer.