本文整理汇总了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
示例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
示例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()
示例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
#
示例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
示例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():
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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,
示例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
""")