home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2005 June
/
PCWorld_2005-06_cd.bin
/
software
/
vyzkuste
/
firewally
/
firewally.exe
/
framework-2.3.exe
/
linecache.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2004-02-22
|
3KB
|
111 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.3)
'''Cache lines from files.
This is intended to read lines from modules imported -- hence if a filename
is not found, it will look down the module search path for a file by
that name.
'''
import sys
import os
__all__ = [
'getline',
'clearcache',
'checkcache']
def getline(filename, lineno):
lines = getlines(filename)
if lineno <= lineno:
pass
elif lineno <= len(lines):
return lines[lineno - 1]
else:
return ''
cache = { }
def clearcache():
'''Clear the cache entirely.'''
global cache
cache = { }
def getlines(filename):
"""Get the lines for a file from the cache.
Update the cache if it doesn't contain an entry for this file already."""
if filename in cache:
return cache[filename][2]
else:
return updatecache(filename)
def checkcache():
'''Discard cache entries that are out of date.
(This is not checked upon each call!)'''
for filename in cache.keys():
(size, mtime, lines, fullname) = cache[filename]
try:
stat = os.stat(fullname)
except os.error:
del cache[filename]
continue
if size != stat.st_size or mtime != stat.st_mtime:
del cache[filename]
continue
def updatecache(filename):
"""Update a cache entry and return its list of lines.
If something's wrong, print a message, discard the cache entry,
and return an empty list."""
if filename in cache:
del cache[filename]
if not filename or filename[0] + filename[-1] == '<>':
return []
fullname = filename
try:
stat = os.stat(fullname)
except os.error:
msg = None
basename = os.path.split(filename)[1]
for dirname in sys.path:
try:
fullname = os.path.join(dirname, basename)
except (TypeError, AttributeError):
continue
try:
stat = os.stat(fullname)
continue
except os.error:
continue
else:
return []
except:
None<EXCEPTION MATCH>os.error
try:
fp = open(fullname, 'rU')
lines = fp.readlines()
fp.close()
except IOError:
msg = None
return []
(size, mtime) = (stat.st_size, stat.st_mtime)
cache[filename] = (size, mtime, lines, fullname)
return lines