icache.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » Demo » stdwin » ibrowse » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » Demo » stdwin » ibrowse » icache.py
# Cache management for info file processing.
# The function get_node() is the standard interface;
# its signature is the same as ifile.get_node() but it uses
# the cache and supports indirect tag tables.


import string
import ifile
from ifile import NoSuchNode,NoSuchFile
import itags


# Special hack to save the cache when using reload().
# This can just be "cache = {}" in a production version.
#
try:
  dummy = cache
  del dummy
except NameError:
  cache = {}


# Clear the entire cache.
#
def resetcache():
  for key in cache.keys():
    del cache[key]


# Clear the node info from the cache (the most voluminous data).
#
def resetnodecache():
  for key in cache.keys():
    tags, nodes = cache[key]
    cache[key] = tags, {}


# Get a node.
#
def get_node(curfile, ref):
  file, node = ifile.parse_ref(curfile, ref)
  file = string.lower(file)
  node = string.lower(node)
  if node == '*':
    # Don't cache whole file references;
    # reading the data is faster than displaying it anyway.
    return ifile.get_whole_file(file) # May raise NoSuchFile
  if not cache.has_key(file):
    cache[file] = get_tags(file), {} # May raise NoSuchFile
  tags, nodes = cache[file]
  if not nodes.has_key(node):
    if not tags.has_key(node):
      raise NoSuchNode, ref
    file1, offset, line = tags[node]
    if not file1:
      file1 = file
    file1, node1, header, menu, footnotes, text = \
      ifile.get_file_node(file1, offset, node)
    nodes[node] = file, node1, header, menu, footnotes, text
  return nodes[node]


# Get the tag table for a file.
# Either construct one or get the one found in the file.
# Raise NoSuchFile if the file isn't found.
#
def get_tags(file):
  f = ifile.try_open(file) # May raise NoSuchFile
  tags = itags.get_tags(f)
  if not tags:
    ###print 'Scanning file...'
    f.seek(0)
    tags = ifile.make_tags(f)
  return tags
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.