home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / linecache.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  2.4 KB  |  94 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import sys
  5. import os
  6. from stat import *
  7. __all__ = [
  8.     'getline',
  9.     'clearcache',
  10.     'checkcache']
  11.  
  12. def getline(filename, lineno):
  13.     lines = getlines(filename)
  14.     if lineno <= lineno:
  15.         pass
  16.     elif lineno <= len(lines):
  17.         return lines[lineno - 1]
  18.     else:
  19.         return ''
  20.  
  21. cache = { }
  22.  
  23. def clearcache():
  24.     global cache
  25.     cache = { }
  26.  
  27.  
  28. def getlines(filename):
  29.     if cache.has_key(filename):
  30.         return cache[filename][2]
  31.     else:
  32.         return updatecache(filename)
  33.  
  34.  
  35. def checkcache():
  36.     for filename in cache.keys():
  37.         (size, mtime, lines, fullname) = cache[filename]
  38.         
  39.         try:
  40.             stat = os.stat(fullname)
  41.         except os.error:
  42.             del cache[filename]
  43.             continue
  44.  
  45.         if size != stat[ST_SIZE] or mtime != stat[ST_MTIME]:
  46.             del cache[filename]
  47.         
  48.     
  49.  
  50.  
  51. def updatecache(filename):
  52.     if cache.has_key(filename):
  53.         del cache[filename]
  54.     
  55.     if not filename or filename[0] + filename[-1] == '<>':
  56.         return []
  57.     
  58.     fullname = filename
  59.     
  60.     try:
  61.         stat = os.stat(fullname)
  62.     except os.error:
  63.         msg = None
  64.         basename = os.path.split(filename)[1]
  65.         for dirname in sys.path:
  66.             
  67.             try:
  68.                 fullname = os.path.join(dirname, basename)
  69.             except (TypeError, AttributeError):
  70.                 pass
  71.  
  72.             
  73.             try:
  74.                 stat = os.stat(fullname)
  75.             except os.error:
  76.                 pass
  77.  
  78.         else:
  79.             return []
  80.  
  81.     
  82.     try:
  83.         fp = open(fullname, 'r')
  84.         lines = fp.readlines()
  85.         fp.close()
  86.     except IOError:
  87.         msg = None
  88.         return []
  89.  
  90.     (size, mtime) = (stat[ST_SIZE], stat[ST_MTIME])
  91.     cache[filename] = (size, mtime, lines, fullname)
  92.     return lines
  93.  
  94.