pdk.DataClasses.ShelfClasses ($Date: 2002/12/04 10:16:54 $)
index
pdk/DataClasses/ShelfClasses.py

Specialized shelf classes.

FOG 04.2001

 
Classes
            
RegistryError
SafeShelf
TreeShelf
Registry
pdk.ErrorClasses.pdkError(exceptions.StandardError)
SafeShelfError
TreeShelfError
 
class TreeShelf(SafeShelf)
     
Purpose:wrapper around a shelf file that allows access with tuple keys (of strings) and records modification times for the keys
Detail:

this class is called "TreeShelf" because it is meant to be used with hierarchical data. Each node in the tree is specified by a n-ary tuple and the sub-tree rooted in each node can be retrieved by passing this tuple to __getitem__.

Example: given the list of keys in the tree shelf

[("car","porsche"),("car","dodge"),("animal","bird")]

a call to __getitem__ with argument ("car,") will return a list of the values associated with the keys

("car","porsche") and ("car","dodge").

 
   Methods defined here:
__delitem__(self, key)
__getitem__(self, key)
__init__(self, shelfFileName, flags='c', separator=None)
__setitem__(self, key, value)
getKeyMTime(self, keyT)
returns the modification time for the shelf key keyT or 0, if this key is not found.
hasKey(self, key)
keys(self, match=None)

returns a list of available tuple keys. With match, a tuple key can be passed that will select only the matching keys from the list of available tuple keys. "Matching" means all keys <key> for which

<key>[:len(`match`)] == `match`

i.e., this implements globbing on tuple keys.

rebuildKeyMTimes(self)
force a rebuild of the shelf key modification times.
reopen(self)

Data and non-method functions defined here:
KEYSEPARATORCHAR = ' '
 
class TreeShelfError(SafeShelfError)
       
  
Method resolution order:
TreeShelfError
SafeShelfError
pdk.ErrorClasses.pdkError
exceptions.StandardError
exceptions.Exception

Data and non-method functions defined here:
CODES = {}
DOMAIN = 'compound key shelf'
 
class Registry(TreeShelf)
     
Purpose:a key:value registry based on compound key shelf files
Detail:Eventually, this should be a class used by all applications to store app-specific configurations etc.. Under Windows, we could optionally use the system registry via an Adapter for this generic registry class.

 
  
Method resolution order:
Registry
TreeShelf
SafeShelf

Methods defined here:
loadKey = __getitem__(self, key)
removeKey = __delitem__(self, key)
storeKey = __setitem__(self, key, value)
 
class RegistryError
     
Purpose: specialized error class for Registry instances

 
   Data and non-method functions defined here:
DOMAIN = 'Registry'
 
class SafeShelf
     
Purpose:wrapper around a shelf file, adding some attributes and controlled error handling
Detail:opens a shelf file in a controlled fashion (i.e., a meaningful error is raised in case of a failure).

 
   Methods defined here:
__del__ = close(self)
__delitem__(self, item)
__getitem__(self, item)
__init__(self, shelfFileName, flags='c')
Parameters:
  • shelfFileName: the name of the shelf file to open
  • flags: one of the following (cf. anydbm documentation) * "n": "always create new" * "c": "create if it does not exist" * "w": "read and write access to existing" * "r": "read only access to existing"
__setitem__(self, item, value)
close(self)
getShelfFile(self)
getShelfFileName(self)
hasKey(self, key)
isClosed(self)
isOpen(self)
keys(self)
reopen(self)
 
class SafeShelfError(pdk.ErrorClasses.pdkError)
       
  
Method resolution order:
SafeShelfError
pdk.ErrorClasses.pdkError
exceptions.StandardError
exceptions.Exception

Data and non-method functions defined here:
CODES = {'file_exists': ('Trying to overwrite an existing shelf file without permission', ''), 'file_locked': ('Trying to open a locked shelf file', ''), 'file_not_found': ('Trying to re-open a non-existing shelf file', ''), 'key_not_found': ('Key not found in shelf file', ''), 'read_only': ('Trying to update a shelf file that was opened in read-only mode', ''), 'unknown_file_type': ('Type of shelf file could not be determined', '')}
DOMAIN = 'Safe Shelf'
 
Functions
            
shelf_factory(shelfSource, shelfClass)
a factory function that tries to convert shelfSource into a shelf of class shelfClass. shelfSource can be a string pointing to a shelf file or already an instance of shelfClass. Raises a ValueError if the argument can`t be converted to a shelf.
 
Author
            
$Author: gathmann $