home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.2)
-
- import sys
- import os
- from stat import *
- __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():
- global cache
- cache = { }
-
-
- def getlines(filename):
- if cache.has_key(filename):
- return cache[filename][2]
- else:
- return updatecache(filename)
-
-
- def checkcache():
- 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]
-
-
-
-
- def updatecache(filename):
- if cache.has_key(filename):
- 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):
- pass
-
-
- try:
- stat = os.stat(fullname)
- except os.error:
- pass
-
- else:
- return []
-
-
- try:
- fp = open(fullname, 'r')
- 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
-
-