mirror of
https://github.com/python/cpython.git
synced 2025-11-02 06:31:29 +00:00
Renamed ConfigParser to configparser.
Merged revisions 63247-63248 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63247 | georg.brandl | 2008-05-14 18:30:31 -0400 (Wed, 14 May 2008) | 2 lines Update configparser docs for lowercasing rename. ........ r63248 | alexandre.vassalotti | 2008-05-14 18:44:22 -0400 (Wed, 14 May 2008) | 8 lines Updated import statements to use the new `configparser` module name. Updated the documentation to use the new name. Revert addition of the stub entry for the old name. Georg, I am reverting your changes since this commit should propagate to py3k. ........
This commit is contained in:
parent
84726faf41
commit
1d1eaa45c9
11 changed files with 61 additions and 58 deletions
|
|
@ -1,15 +1,14 @@
|
||||||
|
:mod:`configparser` --- Configuration file parser
|
||||||
:mod:`ConfigParser` --- Configuration file parser
|
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
.. module:: ConfigParser
|
.. module:: configparser
|
||||||
:synopsis: Configuration file parser.
|
:synopsis: Configuration file parser.
|
||||||
|
|
||||||
.. moduleauthor:: Ken Manheimer <klm@zope.com>
|
.. moduleauthor:: Ken Manheimer <klm@zope.com>
|
||||||
.. moduleauthor:: Barry Warsaw <bwarsaw@python.org>
|
.. moduleauthor:: Barry Warsaw <bwarsaw@python.org>
|
||||||
.. moduleauthor:: Eric S. Raymond <esr@thyrsus.com>
|
.. moduleauthor:: Eric S. Raymond <esr@thyrsus.com>
|
||||||
.. sectionauthor:: Christopher G. Petrilli <petrilli@amber.org>
|
.. sectionauthor:: Christopher G. Petrilli <petrilli@amber.org>
|
||||||
|
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
pair: .ini; file
|
pair: .ini; file
|
||||||
pair: configuration; file
|
pair: configuration; file
|
||||||
|
|
@ -213,9 +212,9 @@ RawConfigParser Objects
|
||||||
load the required file or files using :meth:`readfp` before calling :meth:`read`
|
load the required file or files using :meth:`readfp` before calling :meth:`read`
|
||||||
for any optional files::
|
for any optional files::
|
||||||
|
|
||||||
import ConfigParser, os
|
import configparser, os
|
||||||
|
|
||||||
config = ConfigParser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.readfp(open('defaults.cfg'))
|
config.readfp(open('defaults.cfg'))
|
||||||
config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
|
config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
|
||||||
|
|
||||||
|
|
@ -342,9 +341,9 @@ Examples
|
||||||
|
|
||||||
An example of writing to a configuration file::
|
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
|
# When adding sections or items, add them in the reverse order of
|
||||||
# how you want them to be displayed in the actual file.
|
# how you want them to be displayed in the actual file.
|
||||||
|
|
@ -367,9 +366,9 @@ An example of writing to a configuration file::
|
||||||
|
|
||||||
An example of reading the configuration file again::
|
An example of reading the configuration file again::
|
||||||
|
|
||||||
import ConfigParser
|
import configparser
|
||||||
|
|
||||||
config = ConfigParser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.read('example.cfg')
|
config.read('example.cfg')
|
||||||
|
|
||||||
# getfloat() raises an exception if the value is not a float
|
# getfloat() raises an exception if the value is not a float
|
||||||
|
|
@ -386,9 +385,9 @@ An example of reading the configuration file again::
|
||||||
To get interpolation, you will need to use a :class:`ConfigParser` or
|
To get interpolation, you will need to use a :class:`ConfigParser` or
|
||||||
:class:`SafeConfigParser`::
|
:class:`SafeConfigParser`::
|
||||||
|
|
||||||
import ConfigParser
|
import configparser
|
||||||
|
|
||||||
config = ConfigParser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('example.cfg')
|
config.read('example.cfg')
|
||||||
|
|
||||||
# Set the third, optional argument of get to 1 if you wish to use raw mode.
|
# Set the third, optional argument of get to 1 if you wish to use raw mode.
|
||||||
|
|
@ -403,10 +402,10 @@ To get interpolation, you will need to use a :class:`ConfigParser` or
|
||||||
Defaults are available in all three types of ConfigParsers. They are used in
|
Defaults are available in all three types of ConfigParsers. They are used in
|
||||||
interpolation if an option used is not defined elsewhere. ::
|
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
|
# 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')
|
config.read('example.cfg')
|
||||||
|
|
||||||
print(config.get('Section1', 'foo')) # -> "Python is fun!"
|
print(config.get('Section1', 'foo')) # -> "Python is fun!"
|
||||||
|
|
@ -419,7 +418,7 @@ The function ``opt_move`` below can be used to move options between sections::
|
||||||
def opt_move(config, section1, section2, option):
|
def opt_move(config, section1, section2, option):
|
||||||
try:
|
try:
|
||||||
config.set(section2, option, config.get(section1, option, 1))
|
config.set(section2, option, config.get(section1, option, 1))
|
||||||
except ConfigParser.NoSectionError:
|
except configparser.NoSectionError:
|
||||||
# Create non-existent section
|
# Create non-existent section
|
||||||
config.add_section(section2)
|
config.add_section(section2)
|
||||||
opt_move(config, section1, section2, option)
|
opt_move(config, section1, section2, option)
|
||||||
|
|
|
||||||
|
|
@ -2202,12 +2202,12 @@ in :mod:`logging` itself) and defining handlers which are declared either in
|
||||||
|
|
||||||
.. function:: fileConfig(fname[, defaults])
|
.. function:: fileConfig(fname[, defaults])
|
||||||
|
|
||||||
Reads the logging configuration from a ConfigParser-format file named *fname*.
|
Reads the logging configuration from a :mod:`configparser`\-format file named
|
||||||
This function can be called several times from an application, allowing an end
|
*fname*. This function can be called several times from an application,
|
||||||
user the ability to select from various pre-canned configurations (if the
|
allowing an end user the ability to select from various pre-canned
|
||||||
developer provides a mechanism to present the choices and load the chosen
|
configurations (if the developer provides a mechanism to present the choices
|
||||||
configuration). Defaults to be passed to ConfigParser can be specified in the
|
and load the chosen configuration). Defaults to be passed to the ConfigParser
|
||||||
*defaults* argument.
|
can be specified in the *defaults* argument.
|
||||||
|
|
||||||
|
|
||||||
.. function:: listen([port])
|
.. function:: listen([port])
|
||||||
|
|
@ -2237,18 +2237,20 @@ in :mod:`logging` itself) and defining handlers which are declared either in
|
||||||
Configuration file format
|
Configuration file format
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
The configuration file format understood by :func:`fileConfig` is based on
|
The configuration file format understood by :func:`fileConfig` is
|
||||||
ConfigParser functionality. The file must contain sections called ``[loggers]``,
|
based on :mod:`configparser` functionality. The file must contain
|
||||||
``[handlers]`` and ``[formatters]`` which identify by name the entities of each
|
sections called ``[loggers]``, ``[handlers]`` and ``[formatters]``
|
||||||
type which are defined in the file. For each such entity, there is a separate
|
which identify by name the entities of each type which are defined in
|
||||||
section which identified how that entity is configured. Thus, for a logger named
|
the file. For each such entity, there is a separate section which
|
||||||
``log01`` in the ``[loggers]`` section, the relevant configuration details are
|
identified how that entity is configured. Thus, for a logger named
|
||||||
held in a section ``[logger_log01]``. Similarly, a handler called ``hand01`` in
|
``log01`` in the ``[loggers]`` section, the relevant configuration
|
||||||
the ``[handlers]`` section will have its configuration held in a section called
|
details are held in a section ``[logger_log01]``. Similarly, a handler
|
||||||
``[handler_hand01]``, while a formatter called ``form01`` in the
|
called ``hand01`` in the ``[handlers]`` section will have its
|
||||||
``[formatters]`` section will have its configuration specified in a section
|
configuration held in a section called ``[handler_hand01]``, while a
|
||||||
called ``[formatter_form01]``. The root logger configuration must be specified
|
formatter called ``form01`` in the ``[formatters]`` section will have
|
||||||
in a section called ``[logger_root]``.
|
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. ::
|
Examples of these sections in the file are given below. ::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ The :mod:`shlex` module defines the following class:
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
Module :mod:`ConfigParser`
|
Module :mod:`configparser`
|
||||||
Parser for configuration files similar to the Windows :file:`.ini` files.
|
Parser for configuration files similar to the Windows :file:`.ini` files.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import platform
|
import platform
|
||||||
import ConfigParser
|
import configparser
|
||||||
import httplib
|
import httplib
|
||||||
import base64
|
import base64
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ def find_config_files (self):
|
||||||
|
|
||||||
def parse_config_files (self, filenames=None):
|
def parse_config_files (self, filenames=None):
|
||||||
|
|
||||||
from ConfigParser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
if filenames is None:
|
if filenames is None:
|
||||||
filenames = self.find_config_files()
|
filenames = self.find_config_files()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from idlelib import macosxSupport
|
from idlelib import macosxSupport
|
||||||
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
|
from configparser import ConfigParser, NoOptionError, NoSectionError
|
||||||
|
|
||||||
class InvalidConfigType(Exception): pass
|
class InvalidConfigType(Exception): pass
|
||||||
class InvalidConfigSet(Exception): pass
|
class InvalidConfigSet(Exception): pass
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,9 @@ def fileConfig(fname, defaults=None):
|
||||||
rather than a filename, in which case the file-like object will be read
|
rather than a filename, in which case the file-like object will be read
|
||||||
using readfp.
|
using readfp.
|
||||||
"""
|
"""
|
||||||
import ConfigParser
|
import configparser
|
||||||
|
|
||||||
cp = ConfigParser.ConfigParser(defaults)
|
cp = configparser.ConfigParser(defaults)
|
||||||
if hasattr(cp, 'readfp') and hasattr(fname, 'readline'):
|
if hasattr(cp, 'readfp') and hasattr(fname, 'readline'):
|
||||||
cp.readfp(fname)
|
cp.readfp(fname)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ def test_all(self):
|
||||||
|
|
||||||
self.check_all("BaseHTTPServer")
|
self.check_all("BaseHTTPServer")
|
||||||
self.check_all("CGIHTTPServer")
|
self.check_all("CGIHTTPServer")
|
||||||
self.check_all("ConfigParser")
|
self.check_all("configparser")
|
||||||
self.check_all("Cookie")
|
self.check_all("Cookie")
|
||||||
self.check_all("Queue")
|
self.check_all("Queue")
|
||||||
self.check_all("SimpleHTTPServer")
|
self.check_all("SimpleHTTPServer")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import ConfigParser
|
import configparser
|
||||||
import io
|
import io
|
||||||
import unittest
|
import unittest
|
||||||
import collections
|
import collections
|
||||||
|
|
@ -89,7 +89,7 @@ def test_basic(self):
|
||||||
"remove_option() failed to report non-existance of option"
|
"remove_option() failed to report non-existance of option"
|
||||||
" that was removed")
|
" that was removed")
|
||||||
|
|
||||||
self.assertRaises(ConfigParser.NoSectionError,
|
self.assertRaises(configparser.NoSectionError,
|
||||||
cf.remove_option, 'No Such Section', 'foo')
|
cf.remove_option, 'No Such Section', 'foo')
|
||||||
|
|
||||||
eq(cf.get('Long Line', 'foo'),
|
eq(cf.get('Long Line', 'foo'),
|
||||||
|
|
@ -142,17 +142,17 @@ def test_default_case_sensitivity(self):
|
||||||
|
|
||||||
def test_parse_errors(self):
|
def test_parse_errors(self):
|
||||||
self.newconfig()
|
self.newconfig()
|
||||||
self.parse_error(ConfigParser.ParsingError,
|
self.parse_error(configparser.ParsingError,
|
||||||
"[Foo]\n extra-spaces: splat\n")
|
"[Foo]\n extra-spaces: splat\n")
|
||||||
self.parse_error(ConfigParser.ParsingError,
|
self.parse_error(configparser.ParsingError,
|
||||||
"[Foo]\n extra-spaces= splat\n")
|
"[Foo]\n extra-spaces= splat\n")
|
||||||
self.parse_error(ConfigParser.ParsingError,
|
self.parse_error(configparser.ParsingError,
|
||||||
"[Foo]\noption-without-value\n")
|
"[Foo]\noption-without-value\n")
|
||||||
self.parse_error(ConfigParser.ParsingError,
|
self.parse_error(configparser.ParsingError,
|
||||||
"[Foo]\n:value-without-option-name\n")
|
"[Foo]\n:value-without-option-name\n")
|
||||||
self.parse_error(ConfigParser.ParsingError,
|
self.parse_error(configparser.ParsingError,
|
||||||
"[Foo]\n=value-without-option-name\n")
|
"[Foo]\n=value-without-option-name\n")
|
||||||
self.parse_error(ConfigParser.MissingSectionHeaderError,
|
self.parse_error(configparser.MissingSectionHeaderError,
|
||||||
"No Section!\n")
|
"No Section!\n")
|
||||||
|
|
||||||
def parse_error(self, exc, src):
|
def parse_error(self, exc, src):
|
||||||
|
|
@ -165,13 +165,13 @@ def test_query_errors(self):
|
||||||
"new ConfigParser should have no defined sections")
|
"new ConfigParser should have no defined sections")
|
||||||
self.failIf(cf.has_section("Foo"),
|
self.failIf(cf.has_section("Foo"),
|
||||||
"new ConfigParser should have no acknowledged sections")
|
"new ConfigParser should have no acknowledged sections")
|
||||||
self.assertRaises(ConfigParser.NoSectionError,
|
self.assertRaises(configparser.NoSectionError,
|
||||||
cf.options, "Foo")
|
cf.options, "Foo")
|
||||||
self.assertRaises(ConfigParser.NoSectionError,
|
self.assertRaises(configparser.NoSectionError,
|
||||||
cf.set, "foo", "bar", "value")
|
cf.set, "foo", "bar", "value")
|
||||||
self.get_error(ConfigParser.NoSectionError, "foo", "bar")
|
self.get_error(configparser.NoSectionError, "foo", "bar")
|
||||||
cf.add_section("foo")
|
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):
|
def get_error(self, exc, section, option):
|
||||||
try:
|
try:
|
||||||
|
|
@ -210,7 +210,7 @@ def test_boolean(self):
|
||||||
def test_weird_errors(self):
|
def test_weird_errors(self):
|
||||||
cf = self.newconfig()
|
cf = self.newconfig()
|
||||||
cf.add_section("Foo")
|
cf.add_section("Foo")
|
||||||
self.assertRaises(ConfigParser.DuplicateSectionError,
|
self.assertRaises(configparser.DuplicateSectionError,
|
||||||
cf.add_section, "Foo")
|
cf.add_section, "Foo")
|
||||||
|
|
||||||
def test_write(self):
|
def test_write(self):
|
||||||
|
|
@ -314,7 +314,7 @@ def check_items_config(self, expected):
|
||||||
|
|
||||||
|
|
||||||
class ConfigParserTestCase(TestCaseBase):
|
class ConfigParserTestCase(TestCaseBase):
|
||||||
config_class = ConfigParser.ConfigParser
|
config_class = configparser.ConfigParser
|
||||||
|
|
||||||
def test_interpolation(self):
|
def test_interpolation(self):
|
||||||
cf = self.get_interpolation_config()
|
cf = self.get_interpolation_config()
|
||||||
|
|
@ -325,11 +325,11 @@ def test_interpolation(self):
|
||||||
"something with lots of interpolation (9 steps)")
|
"something with lots of interpolation (9 steps)")
|
||||||
eq(cf.get("Foo", "bar10"),
|
eq(cf.get("Foo", "bar10"),
|
||||||
"something with lots of interpolation (10 steps)")
|
"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):
|
def test_interpolation_missing_value(self):
|
||||||
cf = self.get_interpolation_config()
|
cf = self.get_interpolation_config()
|
||||||
e = self.get_error(ConfigParser.InterpolationError,
|
e = self.get_error(configparser.InterpolationError,
|
||||||
"Interpolation Error", "name")
|
"Interpolation Error", "name")
|
||||||
self.assertEqual(e.reference, "reference")
|
self.assertEqual(e.reference, "reference")
|
||||||
self.assertEqual(e.section, "Interpolation Error")
|
self.assertEqual(e.section, "Interpolation Error")
|
||||||
|
|
@ -365,7 +365,7 @@ def test_set_nonstring_types(self):
|
||||||
|
|
||||||
|
|
||||||
class RawConfigParserTestCase(TestCaseBase):
|
class RawConfigParserTestCase(TestCaseBase):
|
||||||
config_class = ConfigParser.RawConfigParser
|
config_class = configparser.RawConfigParser
|
||||||
|
|
||||||
def test_interpolation(self):
|
def test_interpolation(self):
|
||||||
cf = self.get_interpolation_config()
|
cf = self.get_interpolation_config()
|
||||||
|
|
@ -400,7 +400,7 @@ def test_set_nonstring_types(self):
|
||||||
|
|
||||||
|
|
||||||
class SafeConfigParserTestCase(ConfigParserTestCase):
|
class SafeConfigParserTestCase(ConfigParserTestCase):
|
||||||
config_class = ConfigParser.SafeConfigParser
|
config_class = configparser.SafeConfigParser
|
||||||
|
|
||||||
def test_safe_interpolation(self):
|
def test_safe_interpolation(self):
|
||||||
# See http://www.python.org/sf/511737
|
# See http://www.python.org/sf/511737
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- The ConfigParser module has been renamed to configparser.
|
||||||
|
|
||||||
- Issue 2865: webbrowser.open() works again in a KDE environment.
|
- Issue 2865: webbrowser.open() works again in a KDE environment.
|
||||||
|
|
||||||
- The multifile module has been removed.
|
- The multifile module has been removed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue