mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update linecache from v3.14.2
This commit is contained in:
committed by
Jeong, YunWon
parent
ac2729511f
commit
dbbd921a53
24
Lib/linecache.py
vendored
24
Lib/linecache.py
vendored
@@ -63,6 +63,16 @@ def _getlines_from_code(code):
|
||||
return []
|
||||
|
||||
|
||||
def _source_unavailable(filename):
|
||||
"""Return True if the source code is unavailable for such file name."""
|
||||
return (
|
||||
not filename
|
||||
or (filename.startswith('<')
|
||||
and filename.endswith('>')
|
||||
and not filename.startswith('<frozen '))
|
||||
)
|
||||
|
||||
|
||||
def checkcache(filename=None):
|
||||
"""Discard cache entries that are out of date.
|
||||
(This is not checked upon each call!)"""
|
||||
@@ -118,10 +128,20 @@ def updatecache(filename, module_globals=None):
|
||||
if filename in cache:
|
||||
if len(cache[filename]) != 1:
|
||||
cache.pop(filename, None)
|
||||
if not filename or (filename.startswith('<') and filename.endswith('>')):
|
||||
if _source_unavailable(filename):
|
||||
return []
|
||||
|
||||
fullname = filename
|
||||
if filename.startswith('<frozen '):
|
||||
# This is a frozen module, so we need to use the filename
|
||||
# from the module globals.
|
||||
if module_globals is None:
|
||||
return []
|
||||
|
||||
fullname = module_globals.get('__file__')
|
||||
if fullname is None:
|
||||
return []
|
||||
else:
|
||||
fullname = filename
|
||||
try:
|
||||
stat = os.stat(fullname)
|
||||
except OSError:
|
||||
|
||||
13
Lib/test/test_linecache.py
vendored
13
Lib/test/test_linecache.py
vendored
@@ -281,6 +281,19 @@ class LineCacheTests(unittest.TestCase):
|
||||
self.assertEqual(linecache.getlines(filename, module_globals),
|
||||
['source for x.y.z\n'])
|
||||
|
||||
def test_frozen(self):
|
||||
filename = '<frozen fakemodule>'
|
||||
module_globals = {'__file__': FILENAME}
|
||||
empty = linecache.getlines(filename)
|
||||
self.assertEqual(empty, [])
|
||||
lines = linecache.getlines(filename, module_globals)
|
||||
self.assertGreater(len(lines), 0)
|
||||
lines_cached = linecache.getlines(filename)
|
||||
self.assertEqual(lines, lines_cached)
|
||||
linecache.clearcache()
|
||||
empty = linecache.getlines(filename)
|
||||
self.assertEqual(empty, [])
|
||||
|
||||
def test_invalid_names(self):
|
||||
for name, desc in [
|
||||
('\x00', 'NUL bytes filename'),
|
||||
|
||||
Reference in New Issue
Block a user