Python linecache.lazycache() Examples
The following are 28
code examples of linecache.lazycache().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
linecache
, or try the search function
.
Example #1
Source File: test_linecache.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lazycache_smoke(self): lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) linecache.clearcache() self.assertEqual( True, linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(1, len(linecache.cache[NONEXISTENT_FILENAME])) # Note here that we're looking up a nonexistent filename with no # globals: this would error if the lazy value wasn't resolved. self.assertEqual(lines, linecache.getlines(NONEXISTENT_FILENAME))
Example #2
Source File: test_linecache.py From android_universal with MIT License | 5 votes |
def test_lazycache_already_cached(self): linecache.clearcache() lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) self.assertEqual( False, linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME]))
Example #3
Source File: test_linecache.py From android_universal with MIT License | 5 votes |
def test_lazycache_check(self): linecache.clearcache() linecache.lazycache(NONEXISTENT_FILENAME, globals()) linecache.checkcache()
Example #4
Source File: test_linecache.py From android_universal with MIT License | 5 votes |
def test_lazycache_provide_after_failed_lookup(self): linecache.clearcache() lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) linecache.clearcache() linecache.getlines(NONEXISTENT_FILENAME) linecache.lazycache(NONEXISTENT_FILENAME, globals()) self.assertEqual(lines, linecache.updatecache(NONEXISTENT_FILENAME))
Example #5
Source File: test_linecache.py From android_universal with MIT License | 5 votes |
def test_lazycache_smoke(self): lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) linecache.clearcache() self.assertEqual( True, linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(1, len(linecache.cache[NONEXISTENT_FILENAME])) # Note here that we're looking up a nonexistent filename with no # globals: this would error if the lazy value wasn't resolved. self.assertEqual(lines, linecache.getlines(NONEXISTENT_FILENAME))
Example #6
Source File: test_linecache.py From android_universal with MIT License | 5 votes |
def test_lazycache_no_globals(self): lines = linecache.getlines(FILENAME) linecache.clearcache() self.assertEqual(False, linecache.lazycache(FILENAME, None)) self.assertEqual(lines, linecache.getlines(FILENAME))
Example #7
Source File: test_traceback.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lazy_lines(self): linecache.clearcache() f = traceback.FrameSummary("f", 1, "dummy", lookup_line=False) self.assertEqual(None, f._line) linecache.lazycache("f", globals()) self.assertEqual( '"""Test cases for traceback module"""', f.line)
Example #8
Source File: test_traceback.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_basics(self): linecache.clearcache() linecache.lazycache("f", globals()) f = traceback.FrameSummary("f", 1, "dummy") self.assertEqual(f, ("f", 1, "dummy", '"""Test cases for traceback module"""')) self.assertEqual(tuple(f), ("f", 1, "dummy", '"""Test cases for traceback module"""')) self.assertEqual(f, traceback.FrameSummary("f", 1, "dummy")) self.assertEqual(f, tuple(f)) # Since tuple.__eq__ doesn't support FrameSummary, the equality # operator fallbacks to FrameSummary.__eq__. self.assertEqual(tuple(f), f) self.assertIsNone(f.locals)
Example #9
Source File: test_linecache.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lazycache_already_cached(self): linecache.clearcache() lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) self.assertEqual( False, linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME]))
Example #10
Source File: test_linecache.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lazycache_check(self): linecache.clearcache() linecache.lazycache(NONEXISTENT_FILENAME, globals()) linecache.checkcache()
Example #11
Source File: test_linecache.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lazycache_provide_after_failed_lookup(self): linecache.clearcache() lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) linecache.clearcache() linecache.getlines(NONEXISTENT_FILENAME) linecache.lazycache(NONEXISTENT_FILENAME, globals()) self.assertEqual(lines, linecache.updatecache(NONEXISTENT_FILENAME))
Example #12
Source File: test_linecache.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lazycache_no_globals(self): lines = linecache.getlines(FILENAME) linecache.clearcache() self.assertEqual(False, linecache.lazycache(FILENAME, None)) self.assertEqual(lines, linecache.getlines(FILENAME))
Example #13
Source File: execute.py From reactivepy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run_cell(self, code, name): linecache.lazycache( name, { '__name__': name, '__loader__': self.loader}) exec_result = ExecutionResult() with CapturedIOCtx(exec_result.capture_io), CapturedDisplayCtx(exec_result.displayhook): code_ast = ast.parse(code, filename=name, mode='exec') run_failed, output_name = self._run_ast_nodes(code_ast.body, name) exec_result.has_exception = run_failed exec_result.target_id = output_name return exec_result
Example #14
Source File: executing.py From executing with MIT License | 5 votes |
def lazycache(cls, frame): if hasattr(linecache, 'lazycache'): linecache.lazycache(frame.f_code.co_filename, frame.f_globals)
Example #15
Source File: executing.py From executing with MIT License | 5 votes |
def lazycache(cls, frame): if hasattr(linecache, 'lazycache'): linecache.lazycache(frame.f_code.co_filename, frame.f_globals)
Example #16
Source File: test_traceback.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lazy_lines(self): linecache.clearcache() f = traceback.FrameSummary("f", 1, "dummy", lookup_line=False) self.assertEqual(None, f._line) linecache.lazycache("f", globals()) self.assertEqual( '"""Test cases for traceback module"""', f.line)
Example #17
Source File: test_traceback.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_basics(self): linecache.clearcache() linecache.lazycache("f", globals()) f = traceback.FrameSummary("f", 1, "dummy") self.assertEqual(f, ("f", 1, "dummy", '"""Test cases for traceback module"""')) self.assertEqual(tuple(f), ("f", 1, "dummy", '"""Test cases for traceback module"""')) self.assertEqual(f, traceback.FrameSummary("f", 1, "dummy")) self.assertEqual(f, tuple(f)) # Since tuple.__eq__ doesn't support FrameSummary, the equality # operator fallbacks to FrameSummary.__eq__. self.assertEqual(tuple(f), f) self.assertIsNone(f.locals)
Example #18
Source File: test_linecache.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lazycache_already_cached(self): linecache.clearcache() lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) self.assertEqual( False, linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME]))
Example #19
Source File: test_linecache.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lazycache_check(self): linecache.clearcache() linecache.lazycache(NONEXISTENT_FILENAME, globals()) linecache.checkcache()
Example #20
Source File: test_linecache.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lazycache_provide_after_failed_lookup(self): linecache.clearcache() lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) linecache.clearcache() linecache.getlines(NONEXISTENT_FILENAME) linecache.lazycache(NONEXISTENT_FILENAME, globals()) self.assertEqual(lines, linecache.updatecache(NONEXISTENT_FILENAME))
Example #21
Source File: test_linecache.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lazycache_smoke(self): lines = linecache.getlines(NONEXISTENT_FILENAME, globals()) linecache.clearcache() self.assertEqual( True, linecache.lazycache(NONEXISTENT_FILENAME, globals())) self.assertEqual(1, len(linecache.cache[NONEXISTENT_FILENAME])) # Note here that we're looking up a non existant filename with no # globals: this would error if the lazy value wasn't resolved. self.assertEqual(lines, linecache.getlines(NONEXISTENT_FILENAME))
Example #22
Source File: test_linecache.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lazycache_no_globals(self): lines = linecache.getlines(FILENAME) linecache.clearcache() self.assertEqual(False, linecache.lazycache(FILENAME, None)) self.assertEqual(lines, linecache.getlines(FILENAME))
Example #23
Source File: traceback.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, lineno in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result
Example #24
Source File: traceback.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, lineno in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result
Example #25
Source File: traceback.py From Imogen with MIT License | 4 votes |
def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, lineno in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result
Example #26
Source File: traceback.py From odoo13-x64 with GNU General Public License v3.0 | 4 votes |
def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, lineno in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result
Example #27
Source File: traceback.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, lineno in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result
Example #28
Source File: traceback.py From android_universal with MIT License | 4 votes |
def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples to include in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, lineno in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result