[Zope-Checkins] CVS: Packages/ZConfig - Config.py:1.3
Fred L. Drake, Jr.
fdrake@acm.org
Mon, 21 Oct 2002 15:00:25 -0400
Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv18107
Modified Files:
Config.py
Log Message:
Added getlist(), has_key(), and __getitem__(), and related tests and
documentation.
=== Packages/ZConfig/Config.py 1.2 => 1.3 ===
--- Packages/ZConfig/Config.py:1.2 Wed Oct 9 00:33:38 2002
+++ Packages/ZConfig/Config.py Mon Oct 21 14:59:54 2002
@@ -87,6 +87,15 @@
key = key.lower()
self._data[key] = value
+ def has_key(self, key):
+ key = key.lower()
+ if self._data.has_key(key):
+ return True
+ elif self.delegate:
+ return self.delegate.has_key(key)
+ else:
+ return False
+
def items(self):
"""Returns a list of key-value pairs for this section.
@@ -116,6 +125,18 @@
L2.append(k)
return L2
+ def __getitem__(self, key):
+ k = key.lower()
+ if self._data.has_key(k):
+ return self._data[k]
+ elif self.delegate:
+ v = self.delegate.get(k)
+ if v is None:
+ raise KeyError(key)
+ return v
+ else:
+ raise KeyError(key)
+
def get(self, key, default=None):
key = key.lower()
try:
@@ -166,6 +187,14 @@
if max is not None and x > max:
raise ValueError("value for %s must be no more than %s, found %s"
% (repr(key), max, x))
+
+ def getlist(self, key, default=None):
+ missing = []
+ s = self.get(key, missing)
+ if s is missing:
+ return default
+ else:
+ return s.split()
class ImportingConfiguration(Configuration):