Index: Doc/library/configparser.rst =================================================================== --- Doc/library/configparser.rst (revision 63597) +++ Doc/library/configparser.rst (working copy) @@ -1,10 +1,7 @@ -:mod:`configparser` --- Configuration file parser +:mod:`ConfigParser` --- Configuration file parser ================================================= .. module:: ConfigParser - :synopsis: Old name for the configparser module. - -.. module:: configparser :synopsis: Configuration file parser. .. moduleauthor:: Ken Manheimer @@ -13,10 +10,11 @@ .. sectionauthor:: Christopher G. Petrilli .. note:: - The :mod:`ConfigParser` module has been renamed to :mod:`configparser` in - Python 3.0. It is importable under both names in Python 2.6 and the rest of - the 2.x series. + The :mod:`ConfigParser` module has been renamed to `configparser` in + Python 3.0. The :term:`2to3` tool will automatically adapt imports when + converting your sources to 3.0. + .. index:: pair: .ini; file pair: configuration; file @@ -233,9 +231,9 @@ load the required file or files using :meth:`readfp` before calling :meth:`read` for any optional files:: - import configparser, os + import ConfigParser, os - config = configparser.ConfigParser() + config = ConfigParser.ConfigParser() config.readfp(open('defaults.cfg')) config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')]) @@ -375,9 +373,9 @@ An example of writing to a configuration file:: - import configparser + import ConfigParser - config = configparser.RawConfigParser() + config = ConfigParser.RawConfigParser() # When adding sections or items, add them in the reverse order of # how you want them to be displayed in the actual file. @@ -400,9 +398,9 @@ An example of reading the configuration file again:: - import configparser + import ConfigParser - config = configparser.RawConfigParser() + config = ConfigParser.RawConfigParser() config.read('example.cfg') # getfloat() raises an exception if the value is not a float @@ -419,9 +417,9 @@ To get interpolation, you will need to use a :class:`ConfigParser` or :class:`SafeConfigParser`:: - import configparser + import ConfigParser - config = configparser.ConfigParser() + config = ConfigParser.ConfigParser() config.read('example.cfg') # Set the third, optional argument of get to 1 if you wish to use raw mode. @@ -436,10 +434,10 @@ Defaults are available in all three types of ConfigParsers. They are used in interpolation if an option used is not defined elsewhere. :: - import configparser + import ConfigParser # New instance with 'bar' and 'baz' defaulting to 'Life' and 'hard' each - config = configparser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'}) + config = ConfigParser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'}) config.read('example.cfg') print config.get('Section1', 'foo') # -> "Python is fun!" @@ -452,7 +450,7 @@ def opt_move(config, section1, section2, option): try: config.set(section2, option, config.get(section1, option, 1)) - except configparser.NoSectionError: + except ConfigParser.NoSectionError: # Create non-existent section config.add_section(section2) opt_move(config, section1, section2, option) Index: Doc/library/logging.rst =================================================================== --- Doc/library/logging.rst (revision 63597) +++ Doc/library/logging.rst (working copy) @@ -2240,12 +2240,12 @@ .. function:: fileConfig(fname[, defaults]) - Reads the logging configuration from a :mod:`configparser`\-format file named - *fname*. This function can be called several times from an application, - allowing an end user the ability to select from various pre-canned - configurations (if the developer provides a mechanism to present the choices - and load the chosen configuration). Defaults to be passed to the ConfigParser - can be specified in the *defaults* argument. + Reads the logging configuration from a ConfigParser-format file named *fname*. + This function can be called several times from an application, allowing an end + user the ability to select from various pre-canned configurations (if the + developer provides a mechanism to present the choices and load the chosen + configuration). Defaults to be passed to ConfigParser can be specified in the + *defaults* argument. .. function:: listen([port]) @@ -2275,20 +2275,18 @@ Configuration file format ^^^^^^^^^^^^^^^^^^^^^^^^^ -The configuration file format understood by :func:`fileConfig` is -based on :mod:`configparser` functionality. The file must contain -sections called ``[loggers]``, ``[handlers]`` and ``[formatters]`` -which identify by name the entities of each type which are defined in -the file. For each such entity, there is a separate section which -identified how that entity is configured. Thus, for a logger named -``log01`` in the ``[loggers]`` section, the relevant configuration -details are held in a section ``[logger_log01]``. Similarly, a handler -called ``hand01`` in the ``[handlers]`` section will have its -configuration held in a section called ``[handler_hand01]``, while a -formatter called ``form01`` in the ``[formatters]`` section will have -its configuration specified in a section called -``[formatter_form01]``. The root logger configuration must be -specified in a section called ``[logger_root]``. +The configuration file format understood by :func:`fileConfig` is based on +ConfigParser functionality. The file must contain sections called ``[loggers]``, +``[handlers]`` and ``[formatters]`` which identify by name the entities of each +type which are defined in the file. For each such entity, there is a separate +section which identified how that entity is configured. Thus, for a logger named +``log01`` in the ``[loggers]`` section, the relevant configuration details are +held in a section ``[logger_log01]``. Similarly, a handler called ``hand01`` in +the ``[handlers]`` section will have its configuration held in a section called +``[handler_hand01]``, while a formatter called ``form01`` in the +``[formatters]`` section will have its configuration specified in a section +called ``[formatter_form01]``. The root logger configuration must be specified +in a section called ``[logger_root]``. Examples of these sections in the file are given below. :: Index: Doc/library/shlex.rst =================================================================== --- Doc/library/shlex.rst (revision 63597) +++ Doc/library/shlex.rst (working copy) @@ -63,7 +63,7 @@ .. seealso:: - Module :mod:`configparser` + Module :mod:`ConfigParser` Parser for configuration files similar to the Windows :file:`.ini` files. Index: Lib/idlelib/configHandler.py =================================================================== --- Lib/idlelib/configHandler.py (revision 63597) +++ Lib/idlelib/configHandler.py (working copy) @@ -21,7 +21,7 @@ import sys import string import macosxSupport -from configparser import ConfigParser, NoOptionError, NoSectionError +from ConfigParser import ConfigParser, NoOptionError, NoSectionError class InvalidConfigType(Exception): pass class InvalidConfigSet(Exception): pass Index: Lib/distutils/command/upload.py =================================================================== --- Lib/distutils/command/upload.py (revision 63597) +++ Lib/distutils/command/upload.py (working copy) @@ -14,11 +14,7 @@ import base64 import urlparse import cStringIO as StringIO -try: - from configparser import ConfigParser -except ImportError: - # For backward-compatibility with Python versions < 2.6. - from ConfigParser import ConfigParser +from ConfigParser import ConfigParser class upload(PyPIRCCommand): Index: Lib/lib-old/ConfigParser.py =================================================================== --- Lib/lib-old/ConfigParser.py (revision 63597) +++ Lib/lib-old/ConfigParser.py (working copy) @@ -1,8 +0,0 @@ -import sys -from warnings import warnpy3k - -warnpy3k("the ConfigParser module has been renamed " - "to 'configparser' in Python 3.0", stacklevel=2) - -import configparser -sys.modules[__name__] = configparser Index: Lib/logging/config.py =================================================================== --- Lib/logging/config.py (revision 63597) +++ Lib/logging/config.py (working copy) @@ -65,9 +65,9 @@ rather than a filename, in which case the file-like object will be read using readfp. """ - import configparser + import ConfigParser - cp = configparser.ConfigParser(defaults) + cp = ConfigParser.ConfigParser(defaults) if hasattr(cp, 'readfp') and hasattr(fname, 'readline'): cp.readfp(fname) else: Index: Lib/test/test_py3kwarn.py =================================================================== --- Lib/test/test_py3kwarn.py (revision 63597) +++ Lib/test/test_py3kwarn.py (working copy) @@ -216,7 +216,6 @@ class TestStdlibRenames(unittest.TestCase): renames = {'Queue': 'queue', - 'ConfigParser': 'configparser', } def check_rename(self, module_name, new_module_name): Index: Lib/test/test_cfgparser.py =================================================================== --- Lib/test/test_cfgparser.py (revision 63597) +++ Lib/test/test_cfgparser.py (working copy) @@ -1,4 +1,4 @@ -import configparser +import ConfigParser import StringIO import unittest import UserDict @@ -94,7 +94,7 @@ "remove_option() failed to report non-existance of option" " that was removed") - self.assertRaises(configparser.NoSectionError, + self.assertRaises(ConfigParser.NoSectionError, cf.remove_option, 'No Such Section', 'foo') eq(cf.get('Long Line', 'foo'), @@ -147,17 +147,17 @@ def test_parse_errors(self): self.newconfig() - self.parse_error(configparser.ParsingError, + self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") - self.parse_error(configparser.ParsingError, + self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") - self.parse_error(configparser.ParsingError, + self.parse_error(ConfigParser.ParsingError, "[Foo]\noption-without-value\n") - self.parse_error(configparser.ParsingError, + self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") - self.parse_error(configparser.ParsingError, + self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") - self.parse_error(configparser.MissingSectionHeaderError, + self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n") def parse_error(self, exc, src): @@ -170,13 +170,13 @@ "new ConfigParser should have no defined sections") self.failIf(cf.has_section("Foo"), "new ConfigParser should have no acknowledged sections") - self.assertRaises(configparser.NoSectionError, + self.assertRaises(ConfigParser.NoSectionError, cf.options, "Foo") - self.assertRaises(configparser.NoSectionError, + self.assertRaises(ConfigParser.NoSectionError, cf.set, "foo", "bar", "value") - self.get_error(configparser.NoSectionError, "foo", "bar") + self.get_error(ConfigParser.NoSectionError, "foo", "bar") cf.add_section("foo") - self.get_error(configparser.NoOptionError, "foo", "bar") + self.get_error(ConfigParser.NoOptionError, "foo", "bar") def get_error(self, exc, section, option): try: @@ -215,7 +215,7 @@ def test_weird_errors(self): cf = self.newconfig() cf.add_section("Foo") - self.assertRaises(configparser.DuplicateSectionError, + self.assertRaises(ConfigParser.DuplicateSectionError, cf.add_section, "Foo") def test_write(self): @@ -324,7 +324,7 @@ class ConfigParserTestCase(TestCaseBase): - config_class = configparser.ConfigParser + config_class = ConfigParser.ConfigParser def test_interpolation(self): cf = self.get_interpolation_config() @@ -335,11 +335,11 @@ "something with lots of interpolation (9 steps)") eq(cf.get("Foo", "bar10"), "something with lots of interpolation (10 steps)") - self.get_error(configparser.InterpolationDepthError, "Foo", "bar11") + self.get_error(ConfigParser.InterpolationDepthError, "Foo", "bar11") def test_interpolation_missing_value(self): cf = self.get_interpolation_config() - e = self.get_error(configparser.InterpolationError, + e = self.get_error(ConfigParser.InterpolationError, "Interpolation Error", "name") self.assertEqual(e.reference, "reference") self.assertEqual(e.section, "Interpolation Error") @@ -375,7 +375,7 @@ class RawConfigParserTestCase(TestCaseBase): - config_class = configparser.RawConfigParser + config_class = ConfigParser.RawConfigParser def test_interpolation(self): cf = self.get_interpolation_config() @@ -410,7 +410,7 @@ class SafeConfigParserTestCase(ConfigParserTestCase): - config_class = configparser.SafeConfigParser + config_class = ConfigParser.SafeConfigParser def test_safe_interpolation(self): # See http://www.python.org/sf/511737 Index: Lib/test/test___all__.py =================================================================== --- Lib/test/test___all__.py (revision 63597) +++ Lib/test/test___all__.py (working copy) @@ -37,7 +37,7 @@ self.check_all("BaseHTTPServer") self.check_all("Bastion") self.check_all("CGIHTTPServer") - self.check_all("configparser") + self.check_all("ConfigParser") self.check_all("Cookie") self.check_all("MimeWriter") self.check_all("queue")