Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
linecache Namespace Reference

Functions

def getline
 
def clearcache
 
def getlines
 
def checkcache
 
def updatecache
 

Variables

list __all__ = ["getline","clearcache","checkcache"]
 
dictionary cache = {}
 
tuple fp = open(fullname, 'r')
 print '*** Cannot stat', filename, ':', msg More...
 
tuple lines = fp.readlines()
 

Detailed Description

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.

Function Documentation

def linecache.checkcache ( )
Discard cache entries that are out of date.
(This is not checked upon each call!)

Definition at line 44 of file linecache.py.

44 
45 def checkcache():
46  """Discard cache entries that are out of date.
47  (This is not checked upon each call!)"""
48 
49  for filename in cache.keys():
50  size, mtime, lines, fullname = cache[filename]
51  try:
52  stat = os.stat(fullname)
53  except os.error:
54  del cache[filename]
55  continue
56  if size != stat[ST_SIZE] or mtime != stat[ST_MTIME]:
57  del cache[filename]
58 
def linecache.clearcache ( )
Clear the cache entirely.

Definition at line 27 of file linecache.py.

27 
28 def clearcache():
29  """Clear the cache entirely."""
30 
31  global cache
32  cache = {}
33 
def linecache.getline (   filename,
  lineno 
)

Definition at line 14 of file linecache.py.

References getlines().

14 
15 def getline(filename, lineno):
16  lines = getlines(filename)
17  if 1 <= lineno <= len(lines):
18  return lines[lineno-1]
19  else:
20  return ''
21 
22 
23 # The cache
def linecache.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.

Definition at line 34 of file linecache.py.

References updatecache().

34 
35 def getlines(filename):
36  """Get the lines for a file from the cache.
37  Update the cache if it doesn't contain an entry for this file already."""
38 
39  if cache.has_key(filename):
40  return cache[filename][2]
41  else:
42  return updatecache(filename)
43 
def linecache.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.

Definition at line 59 of file linecache.py.

59 
60 def updatecache(filename):
61  """Update a cache entry and return its list of lines.
62  If something's wrong, print a message, discard the cache entry,
63  and return an empty list."""
64 
65  if cache.has_key(filename):
66  del cache[filename]
67  if not filename or filename[0] + filename[-1] == '<>':
68  return []
69  fullname = filename
70  try:
71  stat = os.stat(fullname)
72  except os.error, msg:
73  # Try looking through the module search path.
74  basename = os.path.split(filename)[1]
75  for dirname in sys.path:
76  # When using imputil, sys.path may contain things other than
77  # strings; ignore them when it happens.
78  try:
79  fullname = os.path.join(dirname, basename)
80  except (TypeError, AttributeError):
81  # Not sufficiently string-like to do anything useful with.
82  pass
83  else:
84  try:
85  stat = os.stat(fullname)
86  break
87  except os.error:
88  pass
89  else:
# No luck

Variable Documentation

list __all__ = ["getline","clearcache","checkcache"]

Definition at line 12 of file linecache.py.

dictionary cache = {}

Definition at line 24 of file linecache.py.

tuple fp = open(fullname, 'r')

print '*** Cannot stat', filename, ':', msg

Definition at line 93 of file linecache.py.

tuple lines = fp.readlines()

Definition at line 94 of file linecache.py.