]> granicus.if.org Git - python/commitdiff
Backport 70111: Let configparser use ordered dicts by default.
authorRaymond Hettinger <python@rcn.com>
Tue, 3 Mar 2009 05:00:37 +0000 (05:00 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 3 Mar 2009 05:00:37 +0000 (05:00 +0000)
Doc/library/configparser.rst
Lib/ConfigParser.py
Misc/NEWS

index bab44d45145f40b55d87c7e90b202fc04dc4700b..0c5bb15ba494389cd38644096b1ddbd281f99a87 100644 (file)
@@ -75,6 +75,9 @@ write-back, as will be the keys within each section.
    .. versionchanged:: 2.6
       *dict_type* was added.
 
+   .. versionchanged:: 2.7
+      The default *dict_type* is :class:`collections.OrderedDict`.
+
 
 .. class:: ConfigParser([defaults[, dict_type]])
 
@@ -91,6 +94,14 @@ write-back, as will be the keys within each section.
    option names to lower case), the values ``foo %(bar)s`` and ``foo %(BAR)s`` are
    equivalent.
 
+   .. versionadded:: 2.3
+
+   .. versionchanged:: 2.6
+      *dict_type* was added.
+
+   .. versionchanged:: 2.7
+      The default *dict_type* is :class:`collections.OrderedDict`.
+
 
 .. class:: SafeConfigParser([defaults[, dict_type]])
 
@@ -103,6 +114,12 @@ write-back, as will be the keys within each section.
 
    .. versionadded:: 2.3
 
+   .. versionchanged:: 2.6
+      *dict_type* was added.
+
+   .. versionchanged:: 2.7
+      The default *dict_type* is :class:`collections.OrderedDict`.
+
 
 .. exception:: NoSectionError
 
index b6af6f9bab916a4eb24de35dcddb7f6f60ccdb08..1861b5aff91247e17023a576a8050dcba5027d61 100644 (file)
@@ -87,6 +87,12 @@ ConfigParser -- responsible for parsing a list of
         write the configuration state in .ini format
 """
 
+try:
+    from collections import OrderedDict as _default_dict
+except ImportError:
+    # fallback for setup.py which hasn't yet built _collections
+    _default_dict = dict
+
 import re
 
 __all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError",
@@ -215,7 +221,7 @@ class MissingSectionHeaderError(ParsingError):
 
 
 class RawConfigParser:
-    def __init__(self, defaults=None, dict_type=dict):
+    def __init__(self, defaults=None, dict_type=_default_dict):
         self._dict = dict_type
         self._sections = self._dict()
         self._defaults = self._dict()
index 70160bb43e0f9b870ef3830cf701128608574f49..d91164f4c5120bf4be859f3084b5ae4592303390 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -172,6 +172,8 @@ Library
 
 - The _asdict() for method for namedtuples now returns an OrderedDict().
 
+- The configparser module now defaults to using an ordered dictionary.
+
 - Issue #4308: httplib.IncompleteRead's repr doesn't include all of the data all
   ready received.