[kernel] r9190 - people/waldi/dkt/lib/dkt/config
Bastian Blank
waldi at alioth.debian.org
Tue Jul 24 21:58:34 UTC 2007
Author: waldi
Date: Tue Jul 24 21:58:34 2007
New Revision: 9190
Log:
* lib/dkt/config/base.py: Add.
* lib/dkt/config/interfaces.py: Add some methods.
Added:
people/waldi/dkt/lib/dkt/config/base.py
Modified:
people/waldi/dkt/lib/dkt/config/interfaces.py
Added: people/waldi/dkt/lib/dkt/config/base.py
==============================================================================
--- (empty file)
+++ people/waldi/dkt/lib/dkt/config/base.py Tue Jul 24 21:58:34 2007
@@ -0,0 +1,72 @@
+from .interface import *
+from dkt.interface import implements
+
+_marker = object()
+
+class Config(object):
+ implements(IConfig)
+
+ __slots__ = '_data'
+
+ def __init__(self):
+ self._data = {}
+
+ def get(self, section, option, default = _marker):
+ s = self._data.get(section, _marker)
+ if s == _marker:
+ if default == _marker:
+ raise KeyError
+ return default
+ o = s.get(o, _marker)
+ if o == _marker:
+ if default == _marker:
+ raise KeyError
+ return default
+ return o
+
+ def get_section(self, section, default = _marker):
+ s = self._data.get(section, _marker)
+ if s == _marker:
+ if default == _marker:
+ raise KeyError
+ return default
+ return s.copy()
+
+ def iteroptions(self, section):
+ s = self._data.get(section, _marker)
+ if s == _marker:
+ raise KeyError
+ return s.iterkeys()
+
+ def itersections(self):
+ return self._data.iterkeys()
+
+ def options(self, section):
+ s = self._data.get(section, _marker)
+ if s == _marker:
+ raise KeyError
+ return s.keys()
+
+ def sections(self):
+ return self._data.keys()
+
+class MutableConfig(Config):
+ implements(IMutableConfig)
+
+ def add_section(self, section):
+ s = self._data.get(section, _marker)
+ if s == _marker:
+ self._data[section] = {}
+
+ def delete(self, section, option):
+ del self._data[section][option]
+
+ def delete_section(self, section):
+ del self._data[section]
+
+ def set(self, section, option, value):
+ s = self._data.get(section, _marker)
+ if s == _marker:
+ raise KeyError
+ s[option] = value
+
Modified: people/waldi/dkt/lib/dkt/config/interfaces.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/interfaces.py (original)
+++ people/waldi/dkt/lib/dkt/config/interfaces.py Tue Jul 24 21:58:34 2007
@@ -1,7 +1,10 @@
from dkt.interface import Interface
class IConfig(Interface):
- def get(section, option):
+ def get(section, option, default = None):
+ pass
+
+ def get_section(section, default = None):
pass
def iteroptions(section):
@@ -17,7 +20,13 @@
pass
class IMutableConfig(IConfig):
- def pop(section, option):
+ def add_section(section):
+ pass
+
+ def delete(section, option):
+ pass
+
+ def delete_section(section):
pass
def set(section, option, value):
More information about the Kernel-svn-changes
mailing list