guard against linecache non-safety

This commit is contained in:
Mahmoud Hashemi 2015-02-08 19:00:09 -08:00
parent 6c2296283b
commit 75616c7b94
1 changed files with 8 additions and 5 deletions

View File

@ -112,11 +112,14 @@ class _DeferredLine(object):
def __str__(self):
if hasattr(self, '_line'):
return self._line
linecache.checkcache(self.filename)
line = linecache.getline(self.filename,
self.lineno,
self.module_globals)
line = line.rstrip()
try:
linecache.checkcache(self.filename)
line = linecache.getline(self.filename,
self.lineno,
self.module_globals)
line = line.rstrip()
except KeyError:
line = ''
self._line = line
return line