[kernel] r9397 - in people/waldi/dkt/lib/dkt/config: . test

Bastian Blank waldi at alioth.debian.org
Tue Aug 28 19:17:32 UTC 2007


Author: waldi
Date: Tue Aug 28 19:17:32 2007
New Revision: 9397

Log:
lib/dkt/config: Update.


Modified:
   people/waldi/dkt/lib/dkt/config/base.py
   people/waldi/dkt/lib/dkt/config/file.py
   people/waldi/dkt/lib/dkt/config/test/test_base.py

Modified: people/waldi/dkt/lib/dkt/config/base.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/base.py	(original)
+++ people/waldi/dkt/lib/dkt/config/base.py	Tue Aug 28 19:17:32 2007
@@ -6,69 +6,64 @@
 class Config(object):
     implements(interfaces.IConfig)
 
-    __slots__ = '_data'
+    __slots__ = '_sections'
 
     def __init__(self):
-        self._data = {}
+        from dkt.support.ordered_dict import OrderedDict
+        self._sections = OrderedDict()
 
     def __iter__(self):
-        return self._data.iterkeys()
+        return self._sections.iterkeys()
 
     def get(self, section, option, default = _marker):
-        s = self._data.get(section, _marker)
-        if s == _marker:
-            if default == _marker:
+        s = self._sections.get(section, _marker)
+        if s is _marker:
+            if default is _marker:
                 raise KeyError(section)
             return default
         o = s.get(option, _marker)
-        if o == _marker:
-            if default == _marker:
+        if o is _marker:
+            if default is _marker:
                 raise KeyError(option)
             return default
         return o
 
     def get_section(self, section, default = _marker):
-        s = self._data.get(section, _marker)
-        if s == _marker:
-            if default == _marker:
+        s = self._sections.get(section, _marker)
+        if s is _marker:
+            if default is _marker:
                 raise KeyError(section)
             return default
         return s.copy()
 
     def iteroptions(self, section):
-        s = self._data.get(section, _marker)
-        if s == _marker:
-            raise KeyError(section)
-        return s.iterkeys()
+        return self._sections[section].iterkeys()
 
     def itersections(self):
-        return self._data.iterkeys()
+        return self._sections.iterkeys()
 
     def options(self, section):
-        s = self._data.get(section, _marker)
-        if s == _marker:
-            raise KeyError(section)
-        return s.keys()
+        return self._sections[section].keys()
 
     def sections(self):
-        return self._data.keys()
+        return self._sections.keys()
 
 class MutableConfig(Config):
     implements(interfaces.IMutableConfig)
 
     def add_section(self, section):
-        s = self._data.get(section, _marker)
+        s = self._sections.get(section, _marker)
         if s == _marker:
-            self._data[section] = {}
+            self._sections[section] = {}
 
     def delete(self, section, option):
-        del self._data[section][option]
+        del self._sections[section][option]
 
     def delete_section(self, section):
-        del self._data[section]
+        del self._sections[section]
 
     def set(self, section, option, value):
-        s = self._data.get(section, _marker)
+        s = self._sections.get(section, _marker)
         if s == _marker:
             raise KeyError(section)
         s[option] = value

Modified: people/waldi/dkt/lib/dkt/config/file.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/file.py	(original)
+++ people/waldi/dkt/lib/dkt/config/file.py	Tue Aug 28 19:17:32 2007
@@ -3,8 +3,7 @@
 
 class Config(base.Config):
     def __init__(self, fp):
-        from dkt.support.ordered_dict import OrderedDict
-        self._sections = OrderedDict()
+        super(Config, self).__init__()
         self._read(fp)
 
     _rules = r"""

Modified: people/waldi/dkt/lib/dkt/config/test/test_base.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/test/test_base.py	(original)
+++ people/waldi/dkt/lib/dkt/config/test/test_base.py	Tue Aug 28 19:17:32 2007
@@ -3,7 +3,7 @@
 
 def test_get():
     c = Config()
-    c._data = {'a': {'a': 'a'}}
+    c._sections = {'a': {'a': 'a'}}
 
     assert c.get('a', 'a') == 'a'
 
@@ -15,7 +15,7 @@
 
 def test_get_section():
     c = Config()
-    c._data = {'a': {'a': 'a'}}
+    c._sections = {'a': {'a': 'a'}}
 
     assert c.get_section('a') == {'a': 'a'}
 
@@ -24,27 +24,27 @@
 
 def test_options():
     c = Config()
-    c._data = {'a': {'a': 'a'}}
+    c._sections = {'a': {'a': 'a'}}
 
     assert c.options('a') == ['a']
     py.test.raises(KeyError, c.options, 'b')
 
 def test_sections():
     c = Config()
-    c._data = {'a': {'a': 'a'}}
+    c._sections = {'a': {'a': 'a'}}
 
     assert c.sections() == ['a']
 
 def test_add_section():
     c = MutableConfig()
-    c._data = {}
+    c._sections = {}
 
     c.add_section('a')
     assert c.get_section('a') == {}
 
 def test_delete():
     c = MutableConfig()
-    c._data = {'a': {'a': 'a'}}
+    c._sections = {'a': {'a': 'a'}}
 
     c.delete('a', 'a')
     assert c.get_section('a') == {}
@@ -52,14 +52,14 @@
 
 def test_delete_section():
     c = MutableConfig()
-    c._data = {'a': {}}
+    c._sections = {'a': {}}
 
     c.delete_section('a')
     py.test.raises(KeyError, c.get_section, 'a')
 
 def test_set():
     c = MutableConfig()
-    c._data = {'a': {}}
+    c._sections = {'a': {}}
 
     c.set('a', 'a', 'a')
     assert c.get('a', 'a') == 'a'



More information about the Kernel-svn-changes mailing list