Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: linecache.py
"""Cache lines from Python source files.
[0] Fix | Delete
[1] Fix | Delete
This is intended to read lines from modules imported -- hence if a filename
[2] Fix | Delete
is not found, it will look down the module search path for a file by
[3] Fix | Delete
that name.
[4] Fix | Delete
"""
[5] Fix | Delete
[6] Fix | Delete
import functools
[7] Fix | Delete
import sys
[8] Fix | Delete
import os
[9] Fix | Delete
import tokenize
[10] Fix | Delete
[11] Fix | Delete
__all__ = ["getline", "clearcache", "checkcache"]
[12] Fix | Delete
[13] Fix | Delete
def getline(filename, lineno, module_globals=None):
[14] Fix | Delete
lines = getlines(filename, module_globals)
[15] Fix | Delete
if 1 <= lineno <= len(lines):
[16] Fix | Delete
return lines[lineno-1]
[17] Fix | Delete
else:
[18] Fix | Delete
return ''
[19] Fix | Delete
[20] Fix | Delete
[21] Fix | Delete
# The cache
[22] Fix | Delete
[23] Fix | Delete
# The cache. Maps filenames to either a thunk which will provide source code,
[24] Fix | Delete
# or a tuple (size, mtime, lines, fullname) once loaded.
[25] Fix | Delete
cache = {}
[26] Fix | Delete
[27] Fix | Delete
[28] Fix | Delete
def clearcache():
[29] Fix | Delete
"""Clear the cache entirely."""
[30] Fix | Delete
[31] Fix | Delete
global cache
[32] Fix | Delete
cache = {}
[33] Fix | Delete
[34] Fix | Delete
[35] Fix | Delete
def getlines(filename, module_globals=None):
[36] Fix | Delete
"""Get the lines for a Python source file from the cache.
[37] Fix | Delete
Update the cache if it doesn't contain an entry for this file already."""
[38] Fix | Delete
[39] Fix | Delete
if filename in cache:
[40] Fix | Delete
entry = cache[filename]
[41] Fix | Delete
if len(entry) != 1:
[42] Fix | Delete
return cache[filename][2]
[43] Fix | Delete
[44] Fix | Delete
try:
[45] Fix | Delete
return updatecache(filename, module_globals)
[46] Fix | Delete
except MemoryError:
[47] Fix | Delete
clearcache()
[48] Fix | Delete
return []
[49] Fix | Delete
[50] Fix | Delete
[51] Fix | Delete
def checkcache(filename=None):
[52] Fix | Delete
"""Discard cache entries that are out of date.
[53] Fix | Delete
(This is not checked upon each call!)"""
[54] Fix | Delete
[55] Fix | Delete
if filename is None:
[56] Fix | Delete
filenames = list(cache.keys())
[57] Fix | Delete
else:
[58] Fix | Delete
if filename in cache:
[59] Fix | Delete
filenames = [filename]
[60] Fix | Delete
else:
[61] Fix | Delete
return
[62] Fix | Delete
[63] Fix | Delete
for filename in filenames:
[64] Fix | Delete
entry = cache[filename]
[65] Fix | Delete
if len(entry) == 1:
[66] Fix | Delete
# lazy cache entry, leave it lazy.
[67] Fix | Delete
continue
[68] Fix | Delete
size, mtime, lines, fullname = entry
[69] Fix | Delete
if mtime is None:
[70] Fix | Delete
continue # no-op for files loaded via a __loader__
[71] Fix | Delete
try:
[72] Fix | Delete
stat = os.stat(fullname)
[73] Fix | Delete
except OSError:
[74] Fix | Delete
cache.pop(filename, None)
[75] Fix | Delete
continue
[76] Fix | Delete
if size != stat.st_size or mtime != stat.st_mtime:
[77] Fix | Delete
cache.pop(filename, None)
[78] Fix | Delete
[79] Fix | Delete
[80] Fix | Delete
def updatecache(filename, module_globals=None):
[81] Fix | Delete
"""Update a cache entry and return its list of lines.
[82] Fix | Delete
If something's wrong, print a message, discard the cache entry,
[83] Fix | Delete
and return an empty list."""
[84] Fix | Delete
[85] Fix | Delete
if filename in cache:
[86] Fix | Delete
if len(cache[filename]) != 1:
[87] Fix | Delete
cache.pop(filename, None)
[88] Fix | Delete
if not filename or (filename.startswith('<') and filename.endswith('>')):
[89] Fix | Delete
return []
[90] Fix | Delete
[91] Fix | Delete
fullname = filename
[92] Fix | Delete
try:
[93] Fix | Delete
stat = os.stat(fullname)
[94] Fix | Delete
except OSError:
[95] Fix | Delete
basename = filename
[96] Fix | Delete
[97] Fix | Delete
# Realise a lazy loader based lookup if there is one
[98] Fix | Delete
# otherwise try to lookup right now.
[99] Fix | Delete
if lazycache(filename, module_globals):
[100] Fix | Delete
try:
[101] Fix | Delete
data = cache[filename][0]()
[102] Fix | Delete
except (ImportError, OSError):
[103] Fix | Delete
pass
[104] Fix | Delete
else:
[105] Fix | Delete
if data is None:
[106] Fix | Delete
# No luck, the PEP302 loader cannot find the source
[107] Fix | Delete
# for this module.
[108] Fix | Delete
return []
[109] Fix | Delete
cache[filename] = (
[110] Fix | Delete
len(data), None,
[111] Fix | Delete
[line+'\n' for line in data.splitlines()], fullname
[112] Fix | Delete
)
[113] Fix | Delete
return cache[filename][2]
[114] Fix | Delete
[115] Fix | Delete
# Try looking through the module search path, which is only useful
[116] Fix | Delete
# when handling a relative filename.
[117] Fix | Delete
if os.path.isabs(filename):
[118] Fix | Delete
return []
[119] Fix | Delete
[120] Fix | Delete
for dirname in sys.path:
[121] Fix | Delete
try:
[122] Fix | Delete
fullname = os.path.join(dirname, basename)
[123] Fix | Delete
except (TypeError, AttributeError):
[124] Fix | Delete
# Not sufficiently string-like to do anything useful with.
[125] Fix | Delete
continue
[126] Fix | Delete
try:
[127] Fix | Delete
stat = os.stat(fullname)
[128] Fix | Delete
break
[129] Fix | Delete
except OSError:
[130] Fix | Delete
pass
[131] Fix | Delete
else:
[132] Fix | Delete
return []
[133] Fix | Delete
try:
[134] Fix | Delete
with tokenize.open(fullname) as fp:
[135] Fix | Delete
lines = fp.readlines()
[136] Fix | Delete
except OSError:
[137] Fix | Delete
return []
[138] Fix | Delete
if lines and not lines[-1].endswith('\n'):
[139] Fix | Delete
lines[-1] += '\n'
[140] Fix | Delete
size, mtime = stat.st_size, stat.st_mtime
[141] Fix | Delete
cache[filename] = size, mtime, lines, fullname
[142] Fix | Delete
return lines
[143] Fix | Delete
[144] Fix | Delete
[145] Fix | Delete
def lazycache(filename, module_globals):
[146] Fix | Delete
"""Seed the cache for filename with module_globals.
[147] Fix | Delete
[148] Fix | Delete
The module loader will be asked for the source only when getlines is
[149] Fix | Delete
called, not immediately.
[150] Fix | Delete
[151] Fix | Delete
If there is an entry in the cache already, it is not altered.
[152] Fix | Delete
[153] Fix | Delete
:return: True if a lazy load is registered in the cache,
[154] Fix | Delete
otherwise False. To register such a load a module loader with a
[155] Fix | Delete
get_source method must be found, the filename must be a cachable
[156] Fix | Delete
filename, and the filename must not be already cached.
[157] Fix | Delete
"""
[158] Fix | Delete
if filename in cache:
[159] Fix | Delete
if len(cache[filename]) == 1:
[160] Fix | Delete
return True
[161] Fix | Delete
else:
[162] Fix | Delete
return False
[163] Fix | Delete
if not filename or (filename.startswith('<') and filename.endswith('>')):
[164] Fix | Delete
return False
[165] Fix | Delete
# Try for a __loader__, if available
[166] Fix | Delete
if module_globals and '__loader__' in module_globals:
[167] Fix | Delete
name = module_globals.get('__name__')
[168] Fix | Delete
loader = module_globals['__loader__']
[169] Fix | Delete
get_source = getattr(loader, 'get_source', None)
[170] Fix | Delete
[171] Fix | Delete
if name and get_source:
[172] Fix | Delete
get_lines = functools.partial(get_source, name)
[173] Fix | Delete
cache[filename] = (get_lines,)
[174] Fix | Delete
return True
[175] Fix | Delete
return False
[176] Fix | Delete
[177] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function