source: trunk/essentials/dev-lang/python/Lib/linecache.py@ 3393

Last change on this file since 3393 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 4.0 KB
Line 
1"""Cache lines from files.
2
3This is intended to read lines from modules imported -- hence if a filename
4is not found, it will look down the module search path for a file by
5that name.
6"""
7
8import sys
9import os
10
11__all__ = ["getline", "clearcache", "checkcache"]
12
13def getline(filename, lineno, module_globals=None):
14 lines = getlines(filename, module_globals)
15 if 1 <= lineno <= len(lines):
16 return lines[lineno-1]
17 else:
18 return ''
19
20
21# The cache
22
23cache = {} # The cache
24
25
26def clearcache():
27 """Clear the cache entirely."""
28
29 global cache
30 cache = {}
31
32
33def getlines(filename, module_globals=None):
34 """Get the lines for a file from the cache.
35 Update the cache if it doesn't contain an entry for this file already."""
36
37 if filename in cache: