1 # Cache management for info file processing.
2 # The function get_node() is the standard interface;
3 # its signature is the same as ifile.get_node() but it uses
4 # the cache and supports indirect tag tables.
9 from ifile
import NoSuchNode
, NoSuchFile
13 # Special hack to save the cache when using reload().
14 # This can just be "cache = {}" in a production version.
23 # Clear the entire cache.
26 for key
in cache
.keys():
30 # Clear the node info from the cache (the most voluminous data).
33 for key
in cache
.keys():
34 tags
, nodes
= cache
[key
]
40 def get_node(curfile
, ref
):
41 file, node
= ifile
.parse_ref(curfile
, ref
)
42 file = string
.lower(file)
43 node
= string
.lower(node
)
45 # Don't cache whole file references;
46 # reading the data is faster than displaying it anyway.
47 return ifile
.get_whole_file(file) # May raise NoSuchFile
48 if not cache
.has_key(file):
49 cache
[file] = get_tags(file), {} # May raise NoSuchFile
50 tags
, nodes
= cache
[file]
51 if not nodes
.has_key(node
):
52 if not tags
.has_key(node
):
54 file1
, offset
, line
= tags
[node
]
57 file1
, node1
, header
, menu
, footnotes
, text
= \
58 ifile
.get_file_node(file1
, offset
, node
)
59 nodes
[node
] = file, node1
, header
, menu
, footnotes
, text
63 # Get the tag table for a file.
64 # Either construct one or get the one found in the file.
65 # Raise NoSuchFile if the file isn't found.
68 f
= ifile
.try_open(file) # May raise NoSuchFile
69 tags
= itags
.get_tags(f
)
71 ###print 'Scanning file...'
73 tags
= ifile
.make_tags(f
)