Lines Matching +full:file +full:- +full:entry +full:- +full:cache
1 """Cache lines from Python source files.
3 This is intended to read lines from modules imported -- hence if a filename
4 is not found, it will look down the module search path for a file by
16 # The cache. Maps filenames to either a thunk which will provide source code,
18 cache = {} variable
22 """Clear the cache entirely."""
23 cache.clear()
27 """Get a line for a Python source file from the cache.
28 Update the cache if it doesn't contain an entry for this file already."""
32 return lines[lineno - 1]
37 """Get the lines for a Python source file from the cache.
38 Update the cache if it doesn't contain an entry for this file already."""
40 if filename in cache:
41 entry = cache[filename]
42 if len(entry) != 1:
43 return cache[filename][2]
53 """Discard cache entries that are out of date.
57 filenames = list(cache.keys())
58 elif filename in cache:
64 entry = cache[filename]
65 if len(entry) == 1:
66 # lazy cache entry, leave it lazy.
68 size, mtime, lines, fullname = entry
70 continue # no-op for files loaded via a __loader__
74 cache.pop(filename, None)
77 cache.pop(filename, None)
81 """Update a cache entry and return its list of lines.
82 If something's wrong, print a message, discard the cache entry,
85 if filename in cache:
86 if len(cache[filename]) != 1:
87 cache.pop(filename, None)
101 data = cache[filename][0]()
109 cache[filename] = (
115 return cache[filename][2]
126 # Not sufficiently string-like to do anything useful with.
140 if lines and not lines[-1].endswith('\n'):
141 lines[-1] += '\n'
143 cache[filename] = size, mtime, lines, fullname
148 """Seed the cache for filename with module_globals.
153 If there is an entry in the cache already, it is not altered.
155 :return: True if a lazy load is registered in the cache,
160 if filename in cache:
161 if len(cache[filename]) == 1:
180 cache[filename] = (get_lines,)