WIP: python3
This commit is contained in:
Executable → Regular
+19
-19
@@ -12,19 +12,22 @@ The underlying INIConfig object can be accessed as cfg.data
|
||||
"""
|
||||
|
||||
import re
|
||||
from ConfigParser import DuplicateSectionError, \
|
||||
NoSectionError, NoOptionError, \
|
||||
InterpolationMissingOptionError, \
|
||||
InterpolationDepthError, \
|
||||
InterpolationSyntaxError, \
|
||||
DEFAULTSECT, MAX_INTERPOLATION_DEPTH
|
||||
from .configparser import DuplicateSectionError, \
|
||||
NoSectionError, NoOptionError, \
|
||||
InterpolationMissingOptionError, \
|
||||
InterpolationDepthError, \
|
||||
InterpolationSyntaxError, \
|
||||
DEFAULTSECT, MAX_INTERPOLATION_DEPTH
|
||||
|
||||
# These are imported only for compatiability.
|
||||
# The code below does not reference them directly.
|
||||
from ConfigParser import Error, InterpolationError, \
|
||||
MissingSectionHeaderError, ParsingError
|
||||
from .configparser import Error, InterpolationError, \
|
||||
MissingSectionHeaderError, ParsingError
|
||||
|
||||
import six
|
||||
|
||||
from . import ini
|
||||
|
||||
import ini
|
||||
|
||||
class RawConfigParser(object):
|
||||
def __init__(self, defaults=None, dict_type=dict):
|
||||
@@ -56,7 +59,7 @@ class RawConfigParser(object):
|
||||
# The default section is the only one that gets the case-insensitive
|
||||
# treatment - so it is special-cased here.
|
||||
if section.lower() == "default":
|
||||
raise ValueError, 'Invalid section name: %s' % section
|
||||
raise ValueError('Invalid section name: %s' % section)
|
||||
|
||||
if self.has_section(section):
|
||||
raise DuplicateSectionError(section)
|
||||
@@ -68,7 +71,7 @@ class RawConfigParser(object):
|
||||
|
||||
The DEFAULT section is not acknowledged.
|
||||
"""
|
||||
return (section in self.data)
|
||||
return section in self.data
|
||||
|
||||
def options(self, section):
|
||||
"""Return a list of option names for the given section name."""
|
||||
@@ -88,7 +91,7 @@ class RawConfigParser(object):
|
||||
filename may also be given.
|
||||
"""
|
||||
files_read = []
|
||||
if isinstance(filenames, basestring):
|
||||
if isinstance(filenames, six.string_types):
|
||||
filenames = [filenames]
|
||||
for filename in filenames:
|
||||
try:
|
||||
@@ -113,8 +116,6 @@ class RawConfigParser(object):
|
||||
def get(self, section, option, vars=None):
|
||||
if not self.has_section(section):
|
||||
raise NoSectionError(section)
|
||||
if vars is not None and option in vars:
|
||||
value = vars[option]
|
||||
|
||||
sec = self.data[section]
|
||||
if option in sec:
|
||||
@@ -143,7 +144,7 @@ class RawConfigParser(object):
|
||||
def getboolean(self, section, option):
|
||||
v = self.get(section, option)
|
||||
if v.lower() not in self._boolean_states:
|
||||
raise ValueError, 'Not a boolean: %s' % v
|
||||
raise ValueError('Not a boolean: %s' % v)
|
||||
return self._boolean_states[v.lower()]
|
||||
|
||||
def has_option(self, section, option):
|
||||
@@ -234,7 +235,7 @@ class ConfigParser(RawConfigParser):
|
||||
if "%(" in value:
|
||||
try:
|
||||
value = value % vars
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
raise InterpolationMissingOptionError(
|
||||
option, section, rawval, e.args[0])
|
||||
else:
|
||||
@@ -283,7 +284,7 @@ class SafeConfigParser(ConfigParser):
|
||||
_badpercent_re = re.compile(r"%[^%]|%$")
|
||||
|
||||
def set(self, section, option, value):
|
||||
if not isinstance(value, basestring):
|
||||
if not isinstance(value, six.string_types):
|
||||
raise TypeError("option values must be strings")
|
||||
# check for bad percent signs:
|
||||
# first, replace all "good" interpolations
|
||||
@@ -323,8 +324,7 @@ class SafeConfigParser(ConfigParser):
|
||||
elif c == "(":
|
||||
m = self._interpvar_match(rest)
|
||||
if m is None:
|
||||
raise InterpolationSyntaxError(option, section,
|
||||
"bad interpolation variable reference %r" % rest)
|
||||
raise InterpolationSyntaxError(option, section, "bad interpolation variable reference %r" % rest)
|
||||
var = m.group(1)
|
||||
rest = rest[m.end():]
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user