view MoinMoin/datastruct/dicts/backends/ @ 4825:8db07c73e972

Groups2009: The datastruct.dicts module is refactored to be similar to the groups module. The events.wikidictsrescan was removed.
author Dmitrijs Milajevs <>
date Fri, 26 Jun 2009 20:06:12 +0200
parents e5ef9d9f9eaa
children 9bee7b3e9235
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - MoinMoin.datastruct.dicts.backends.

    @copyright: 2009 by MoinMoin:DmitrijsMilajevs
    @license: GNU GPL, see COPYING for details.

class DictDoesNotExistError(Exception):
    Raised when a dict name is not found in the backend.

class BaseDict(object):
    def __init__(self, request, name, backend):
        Initialize a dict.

        @param request
        @param name: moin dict name
        @backend: backend object which created this object

        self.request = request = name
        self._backend = backend
        self._dict = self._load_dict()

    def __iter__(self):
        return self._dict.__iter__()

    def __len__(self):
        return self._dict.__len__()

    def __getitem__(self, *kargs):
        return self._dict.__getitem__(*kargs)

    def get(self, *kargs):
        return self._dict.get(*kargs)

    def _load_dict(self):
        Retrieve dict data from the backend.
        return self._backend._retrieve_members(

    def __repr__(self):
        return "<%r name=%r items=%r>" % (self.__class__,, self._dict.items())

class BaseDictBackend(object):

    def __init__(self, request):
        self.request = request
        self.page_dict_regex = request.cfg.cache.page_dict_regexact

    def is_dict_name(self, name):
        return self.page_dict_regex.match(name)

    def __contains__(self, dict_name):
        Check if a dict called <dict_name> is available in this backend.
        raise NotImplementedError()

    def __getitem__(self, dict_name):
        Get a dict by its moin dict name.
        raise NotImplementedError()

    def _retrieve_members(self, dict_name):
        raise NotImplementedError()