當前位置: 首頁>>代碼示例>>Python>>正文


Python linecache.checkcache方法代碼示例

本文整理匯總了Python中linecache.checkcache方法的典型用法代碼示例。如果您正苦於以下問題:Python linecache.checkcache方法的具體用法?Python linecache.checkcache怎麽用?Python linecache.checkcache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在linecache的用法示例。


在下文中一共展示了linecache.checkcache方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extract_tb

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def extract_tb(tb, limit=None):
    """This implementation is stolen from traceback module but respects __traceback_hide__."""
    if limit is None:
        if hasattr(sys, "tracebacklimit"):
            limit = sys.tracebacklimit
    tb_list = []
    n = 0
    while tb is not None and (limit is None or n < limit):
        f = tb.tb_frame
        if not _should_skip_frame(f):
            lineno = tb.tb_lineno
            co = f.f_code
            filename = co.co_filename
            name = co.co_name
            linecache.checkcache(filename)
            line = linecache.getline(filename, lineno, f.f_globals)
            if line:
                line = line.strip()
            else:
                line = None
            tb_list.append((filename, lineno, name, line))
        tb = tb.tb_next
        n = n + 1
    return tb_list 
開發者ID:quora,項目名稱:asynq,代碼行數:26,代碼來源:debug.py

示例2: _install_linecache_wrapper

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def _install_linecache_wrapper(self):
        """Disable linecache.checkcache to not invalidate caches.

        This gets installed permanently to also bypass e.g. pytest using
        `inspect.getsource`, which would invalidate it outside of the
        interaction them.
        """
        if not hasattr(self, "_orig_linecache_checkcache"):
            import linecache

            # Save it, although not used really (can be useful for debugging).
            self._orig_linecache_checkcache = linecache.checkcache

            def _linecache_checkcache(*args, **kwargs):
                return

            linecache.checkcache = _linecache_checkcache 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:19,代碼來源:pdbpp.py

示例3: setup_myfile

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def setup_myfile(self, testdir):
        testdir.makepyfile(
            myfile="""
            from pdbpp import set_trace

            def rewrite_file():
                with open(__file__, "w") as f:
                    f.write("something completely different")

            def after_settrace():
                import linecache
                linecache.checkcache()

            def fn():
                set_trace()
                after_settrace()
                set_trace()
                a = 3
            """)
        testdir.monkeypatch.setenv("PDBPP_COLORS", "0")
        testdir.syspathinsert() 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:23,代碼來源:test_pdb.py

示例4: SaveFile

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def SaveFile(self, fileName):
		if isRichText:
			view = self.GetFirstView()
			view.SaveTextFile(fileName)
		else: # Old style edit view window.
			self.GetFirstView().SaveFile(fileName)
		try:
			# Make sure line cache has updated info about me!
			import linecache
			linecache.checkcache()
		except:
			pass

	#
	# Color state stuff
	# 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:editor.py

示例5: _convert_stack

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def _convert_stack(stack):
  """Converts a stack extracted using _extract_stack() to a traceback stack.

  Args:
    stack: A list of n 4-tuples, (filename, lineno, name, frame_globals).

  Returns:
    A list of n 4-tuples (filename, lineno, name, code), where the code tuple
    element is calculated from the corresponding elements of the input tuple.
  """
  ret = []
  for filename, lineno, name, frame_globals in stack:
    linecache.checkcache(filename)
    line = linecache.getline(filename, lineno, frame_globals)
    if line:
      line = line.strip()
    else:
      line = None
    ret.append((filename, lineno, name, line))
  return ret


# pylint: disable=line-too-long 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:25,代碼來源:ops.py

示例6: extended_linecache_checkcache

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def extended_linecache_checkcache(filename=None,
                                  orig_checkcache=linecache.checkcache):
    """Extend linecache.checkcache to preserve the <pyshell#...> entries

    Rather than repeating the linecache code, patch it to save the
    <pyshell#...> entries, call the original linecache.checkcache()
    (skipping them), and then restore the saved entries.

    orig_checkcache is bound at definition time to the original
    method, allowing it to be patched.
    """
    cache = linecache.cache
    save = {}
    for key in list(cache):
        if key[:1] + key[-1:] == '<>':
            save[key] = cache.pop(key)
    orig_checkcache(filename)
    cache.update(save)

# Patch linecache.checkcache(): 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:22,代碼來源:PyShell.py

示例7: __init__

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def __init__(self):
        codeop.Compile.__init__(self)
        
        # This is ugly, but it must be done this way to allow multiple
        # simultaneous ipython instances to coexist.  Since Python itself
        # directly accesses the data structures in the linecache module, and
        # the cache therein is global, we must work with that data structure.
        # We must hold a reference to the original checkcache routine and call
        # that in our own check_cache() below, but the special IPython cache
        # must also be shared by all IPython instances.  If we were to hold
        # separate caches (one in each CachingCompiler instance), any call made
        # by Python itself to linecache.checkcache() would obliterate the
        # cached data from the other IPython instances.
        if not hasattr(linecache, '_ipython_cache'):
            linecache._ipython_cache = {}
        if not hasattr(linecache, '_checkcache_ori'):
            linecache._checkcache_ori = linecache.checkcache
        # Now, we must monkeypatch the linecache directly so that parts of the
        # stdlib that call it outside our control go through our codepath
        # (otherwise we'd lose our tracebacks).
        linecache.checkcache = check_linecache_ipython 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:compilerop.py

示例8: __init__

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def __init__(self,color_scheme = 'Linux', call_pdb=False, ostream=None,
                 tb_offset=0, long_header=False, include_vars=True,
                 check_cache=None):
        """Specify traceback offset, headers and color scheme.

        Define how many frames to drop from the tracebacks. Calling it with
        tb_offset=1 allows use of this handler in interpreters which will have
        their own code at the top of the traceback (VerboseTB will first
        remove that frame before printing the traceback info)."""
        TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb,
                         ostream=ostream)
        self.tb_offset = tb_offset
        self.long_header = long_header
        self.include_vars = include_vars
        # By default we use linecache.checkcache, but the user can provide a
        # different check_cache implementation.  This is used by the IPython
        # kernel to provide tracebacks for interactive code that is cached,
        # by a compiler instance that flushes the linecache but preserves its
        # own code cache.
        if check_cache is None:
            check_cache = linecache.checkcache
        self.check_cache = check_cache 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:24,代碼來源:ultratb.py

示例9: _format_stack

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def _format_stack(task, coro, complete=False):
    '''
    Formats a traceback from a stack of coroutines/generators
    '''
    dirname = os.path.dirname(__file__)
    extracted_list = []
    checked = set()
    for f in _get_stack(coro):
        lineno = f.f_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        if not complete and os.path.dirname(filename) == dirname:
            continue
        if filename not in checked:
            checked.add(filename)
            linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        extracted_list.append((filename, lineno, name, line))
    if not extracted_list:
        resp = 'No stack for %r' % task
    else:
        resp = 'Stack for %r (most recent call last):\n' % task
        resp += ''.join(traceback.format_list(extracted_list))
    return resp 
開發者ID:anyant,項目名稱:rssant,代碼行數:27,代碼來源:asyncio_tools.py

示例10: PrintException

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def PrintException(msg,web=False):
    try:
        LOGPATH=settings.LOG_DIR
    except:
        LOGPATH = os.path.join(settings.BASE_DIR,"logs/")
    if not os.path.exists(LOGPATH):
        os.makedirs(LOGPATH)
    exc_type, exc_obj, tb = sys.exc_info()
    f = tb.tb_frame
    lineno = tb.tb_lineno
    filename = f.f_code.co_filename
    linecache.checkcache(filename)
    line = linecache.getline(filename, lineno, f.f_globals)
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    dat= '\n['+st+']\n'+msg+' ({0}, LINE {1} "{2}"): {3}'.format(filename, lineno, line.strip(), exc_obj)
    if platform.system()=="Windows":
        print dat
    else:
        if web:
            print Color.BOLD + Color.ORANGE + dat + Color.END
        else:
            print Color.BOLD + Color.RED + dat + Color.END
    with open(LOGPATH + 'MobSF.log','a') as f:
        f.write(dat) 
開發者ID:HackingLab,項目名稱:MobileSF,代碼行數:27,代碼來源:utils.py

示例11: _extract_tb_or_stack_iter

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def _extract_tb_or_stack_iter(curr, limit, extractor):
    if limit is None:
        limit = getattr(sys, 'tracebacklimit', None)

    n = 0
    while curr is not None and (limit is None or n < limit):
        f, lineno, next_item = extractor(curr)
        co = f.f_code
        filename = co.co_filename
        name = co.co_name

        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)

        if line:
            line = line.strip()
        else:
            line = None

        yield (filename, lineno, name, line)
        curr = next_item
        n += 1 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:24,代碼來源:traceback.py

示例12: _format_stack

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def _format_stack(task: 'asyncio.Task[Any]') -> str:
    extracted_list = []
    checked = set()  # type: Set[str]
    for f in _get_stack(task):
        lineno = f.f_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        if filename not in checked:
            checked.add(filename)
            linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        extracted_list.append((filename, lineno, name, line))
    if not extracted_list:
        resp = 'No stack for %r' % task
    else:
        resp = 'Stack for %r (most recent call last):\n' % task
        resp += ''.join(traceback.format_list(extracted_list))  # type: ignore
    return resp 
開發者ID:aio-libs,項目名稱:aiomonitor,代碼行數:21,代碼來源:utils.py

示例13: for_filename

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def for_filename(cls, filename, module_globals=None, use_cache=True):
        source_cache = cls._class_local('__source_cache', {})
        if use_cache:
            try:
                return source_cache[filename]
            except KeyError:
                pass

        if isinstance(filename, Path):
            filename = str(filename)

        if not use_cache:
            linecache.checkcache(filename)

        lines = tuple(linecache.getlines(filename, module_globals))
        result = source_cache[filename] = cls._for_filename_and_lines(filename, lines)
        return result 
開發者ID:alexmojaki,項目名稱:executing,代碼行數:19,代碼來源:executing.py

示例14: print_exception

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def print_exception():
    import linecache
    linecache.checkcache()
    flush_stdout()
    efile = sys.stderr
    typ, val, tb = excinfo = sys.exc_info()
    sys.last_type, sys.last_value, sys.last_traceback = excinfo
    tbe = traceback.extract_tb(tb)
    print>>efile, '\nTraceback (most recent call last):'
    exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
               "RemoteDebugger.py", "bdb.py")
    cleanup_traceback(tbe, exclude)
    traceback.print_list(tbe, file=efile)
    lines = traceback.format_exception_only(typ, val)
    for line in lines:
        print>>efile, line, 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:18,代碼來源:run.py

示例15: test_list_with_changed_source

# 需要導入模塊: import linecache [as 別名]
# 或者: from linecache import checkcache [as 別名]
def test_list_with_changed_source(self):
        from myfile import fn

        check(fn, r"""
    [NUM] > .*fn()
    -> after_settrace()
       5 frames hidden (try 'help hidden_frames')
    (Pdb++) l
    NUM  \t    import linecache$
    NUM  \t    linecache.checkcache()$
    NUM  \t$
    NUM  \tdef fn():
    NUM  \t    set_trace()
    NUM  ->\t    after_settrace()
    NUM  \t    set_trace()
    NUM  \t    a = 3
    [EOF]
    (Pdb++) rewrite_file()
    (Pdb++) c
    [NUM] > .*fn()
    -> a = 3
       5 frames hidden (try 'help hidden_frames')
    (Pdb++) l
    NUM  \t
    NUM  \tdef fn():
    NUM  \t    set_trace()
    NUM  \t    after_settrace()
    NUM  \t    set_trace()
    NUM  ->\t    a = 3
    [EOF]
    (Pdb++) c
    """) 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:34,代碼來源:test_pdb.py


注:本文中的linecache.checkcache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。