Package configshell :: Module prefs :: Class Prefs

[hide private]
[frames] | no frames]

# Class Prefs

    object --+
             |
            Prefs

This is a preferences backend object used to:

- Hold the ConfigShell preferences
- Handle persistent storage and retrieval of these preferences
- Share the preferences between the ConfigShell and ConfigNode objects

As it is inherently destined to be shared between objects, this is a Borg.

Instance Methods | [hide private]

__init__(self, filename=None) Instanciates the ConfigShell preferences object. |

n/a

__getitem__(self, key) Proxies dict-like references to prefs. |

__setitem__(self, key, value) Proxies dict-like references to prefs. |

__contains__(self, key) Do the preferences contain key ? |

__delitem__(self, key) Deletes a preference key. |

__iter__(self) Generic iterator for the preferences. |

list

keys(self) Returns: Returns the list of keys in preferences. |

list of (key, value) tuples

items(self) Returns: Returns the list of items in preferences. |

yields items that are (key, value) pairs

iteritems(self) Returns: Iterates on the items in preferences. |

save(self, filename=None) Saves the preferences to disk. |

load(self, filename=None) Loads the preferences from file. |

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Class Variables | [hide private]

| _prefs = `{}`
| filename = `None`
| autosave = `False`
| __borg_state = `{}`

Properties | [hide private]

Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, filename=None)
(Constructor)

Instanciates the ConfigShell preferences object.

Parameters:
  - `filename` (str) - File to store the preferencces to.
Overrides: object.__init__

### __getitem__(self, key)
(Indexing operator)

Proxies dict-like references to prefs. One specific behavior, though, is that if the key does not exists, we will return None instead of raising an exception.

Parameters:
  - `key` (any valid dict key) - The preferences dictionnary key to get.
Returns: n/a
  The key value

### __setitem__(self, key, value)
(Index assignment operator)

Proxies dict-like references to prefs.

Parameters:
  - `key` (any valid dict key) - The preferences dictionnary key to set.

### __contains__(self, key)
(In operator)

Do the preferences contain key ?

Parameters:
  - `key` (any valid dict key) - The preferences dictionnary key to check.

### __delitem__(self, key)
(Index deletion operator)

Deletes a preference key.

Parameters:
  - `key` (any valid dict key) - The preference to delete.

### keys(self)

Returns: list
  Returns the list of keys in preferences.

### items(self)

Returns: list of (key, value) tuples
  Returns the list of items in preferences.

### iteritems(self)

Returns: yields items that are (key, value) pairs
  Iterates on the items in preferences.

### save(self, filename=None)

Saves the preferences to disk. If filename is not specified, use the default one if it is set, else do nothing.

Parameters:
  - `filename` (str) - Optional alternate file to use.

### load(self, filename=None)

Loads the preferences from file. Use either the supplied filename, or the default one if set. Else, do nothing.