[Python-checkins] r88326 - python/branches/release31-maint/Lib/configparser.py
raymond.hettinger
python-checkins at python.org
Wed Feb 2 23:17:35 CET 2011
Author: raymond.hettinger
Date: Wed Feb 2 23:17:34 2011
New Revision: 88326
Log:
collections.Mapping is not available for setup.py. Remove the dependency the old-fashioned way (copy and paste).
Modified:
python/branches/release31-maint/Lib/configparser.py
Modified: python/branches/release31-maint/Lib/configparser.py
==============================================================================
--- python/branches/release31-maint/Lib/configparser.py (original)
+++ python/branches/release31-maint/Lib/configparser.py Wed Feb 2 23:17:34 2011
@@ -88,7 +88,7 @@
"""
try:
- from collections import Mapping, OrderedDict as _default_dict
+ from collections import OrderedDict as _default_dict
except ImportError:
# fallback for setup.py which hasn't yet built _collections
_default_dict = dict
@@ -515,7 +515,7 @@
if e:
raise e
-class _Chainmap(Mapping):
+class _Chainmap:
"""Combine multiple mappings for successive lookups.
For example, to emulate Python's normal lookup sequence:
@@ -548,6 +548,36 @@
s.update(*self.maps)
return len(s)
+ def get(self, key, default=None):
+ try:
+ return self[key]
+ except KeyError:
+ return default
+
+ def __contains__(self, key):
+ try:
+ self[key]
+ except KeyError:
+ return False
+ else:
+ return True
+
+ def keys(self):
+ return list(self)
+
+ def items(self):
+ return [(k, self[k]) for k in self]
+
+ def values(self):
+ return [self[k] for k in self]
+
+ def __eq__(self, other):
+ return dict(self.items()) == dict(other.items())
+
+ def __ne__(self, other):
+ return not (self == other)
+
+
class ConfigParser(RawConfigParser):
def get(self, section, option, raw=False, vars=None):
More information about the Python-checkins
mailing list