changeset 4835:cf3c81f67862

Missing file were added
author Dmitrijs Milajevs <dimazest@gmail.com>
date Sat, 04 Jul 2009 14:14:30 +0100
parents f8cc357576c3
children 8be26b0ebc96
files MoinMoin/datastruct/backends/_tests/test_composite_dicts.py MoinMoin/datastruct/backends/composite_dicts.py
diffstat 2 files changed, 87 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/datastruct/backends/_tests/test_composite_dicts.py	Sat Jul 04 14:14:30 2009 +0100
@@ -0,0 +1,38 @@
+# -*- coding: iso-8859-1 -*-
+
+"""
+MoinMoin.datastruct.backends.composite_dicts test
+
+@copyright: 2009 MoinMoin:DmitrijsMilajevs
+            2008 MoinMoin: MelitaMihaljevic
+@license: GPL, see COPYING for details
+"""
+
+from py.test import raises
+
+from MoinMoin.datastruct.backends._tests import DictsBackendTest
+from MoinMoin.datastruct import ConfigDicts, CompositeDicts, DictDoesNotExistError
+from MoinMoin._tests import wikiconfig
+from MoinMoin import security
+
+
+class TestCompositeDict(DictsBackendTest):
+
+    class Config(wikiconfig.Config):
+
+        one_dict = {u'SomeTestDict': {u'First': u'first item',
+                                      u'text with spaces': u'second item',
+                                      u'Empty string': u'',
+                                      u'Last': u'last item'}}
+
+        other_dict = {u'SomeOtherTestDict': {u'One': '1',
+                                             u'Two': '2'}}
+
+
+        def dict_manager_init(self, request):
+            return CompositeDicts(request,
+                                  CompositeDicts(request, self.one_dict),
+                                  CompositeDicts(request, self.other_dict))
+
+
+coverage_modules = ['MoinMoin.datastruct.backends.composite_dicts']
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/datastruct/backends/composite_dicts.py	Sat Jul 04 14:14:30 2009 +0100
@@ -0,0 +1,49 @@
+# -*- coding: iso-8859-1 -*-
+"""
+MoinMoin - dict access via various backends.
+
+@copyright: 2009 DmitrijsMilajevs
+@license: GPL, see COPYING for details
+"""
+
+from MoinMoin.datastruct.backends import BaseDictsBackend, DictDoesNotExistError
+
+
+class CompositeDicts(BaseDictsBackend):
+    """
+    Manage several dicts backends.
+    """
+
+    def __init__(self, request, *backends):
+        """
+        @param backends: list of group backends which are used to get
+                         access to the group definitions.
+        """
+        super(CompositeDicts, self).__init__(request)
+        self._backends = backends
+
+    def __getitem__(self, dict_name):
+        """
+        Get a group by its name. First match counts.
+
+        @param group_name: name of the group [unicode]
+        """
+        for backend in self._backends:
+            if dict_name in backend:
+                return backend[dict_name]
+        raise DictDoesNotExistError(dict_name)
+
+    def __contains__(self, dict_name):
+        """
+        Check if a dict called dict_name is available in any of the backends.
+
+        @param dict_name: name of the dict [unicode]
+        """
+        for backend in self._backends:
+            if dict_name in backend:
+                return True
+        return False
+
+    def __repr__(self):
+        return "<%s backends=%s>" % (self.__class__, self._backends)
+