Back to index

moin  1.9.0~rc2
config_dicts.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - config dict backend
00004 
00005 The config group backend enables you to define dicts in a configuration file.
00006 
00007 @copyright: 2009 MoinMoin:DmitrijsMilajevs
00008 @license: GPL, see COPYING for details
00009 """
00010 
00011 from MoinMoin.datastruct.backends import BaseDict, BaseDictsBackend, DictDoesNotExistError
00012 
00013 
00014 class ConfigDict(BaseDict):
00015     pass
00016 
00017 
00018 class ConfigDicts(BaseDictsBackend):
00019 
00020     def __init__(self, request, dicts):
00021         super(ConfigDicts, self).__init__(request)
00022 
00023         self._dicts = dicts
00024 
00025     def __contains__(self, dict_name):
00026         return self.is_dict_name(dict_name) and dict_name in self._dicts
00027 
00028     def __iter__(self):
00029         return self._dicts.iterkeys()
00030 
00031     def __getitem__(self, dict_name):
00032         return ConfigDict(request=self.request, name=dict_name, backend=self)
00033 
00034     def _retrieve_items(self, dict_name):
00035         try:
00036             return self._dicts[dict_name]
00037         except KeyError:
00038             raise DictDoesNotExistError(dict_name)
00039