Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sbahling/osc
Browse files Browse the repository at this point in the history
Use configparser.ConfigParser instead of configparser.SafeConfigParser,
since the latter will be removed in future python versions. No functional
changes because SafeConfigParser is a ConfigParser except that its __init__
prints a DeprecationWarning.
  • Loading branch information
marcus-h committed Feb 9, 2020
2 parents 32859d6 + b9adde9 commit 9b0dcf3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions osc/OscConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

if sys.version_info >= ( 3, ):
import configparser
ConfigParser = configparser.ConfigParser
else:
#python 2.x
import ConfigParser as configparser
ConfigParser = configparser.SafeConfigParser

import re

Expand Down Expand Up @@ -188,7 +190,7 @@ def __init__(self, optname, line):
self.format(line)

def format(self, line):
mo = configparser.ConfigParser.OPTCRE.match(line.strip())
mo = ConfigParser.OPTCRE.match(line.strip())
key, val = mo.group('option', 'value')
self.frmt = line.replace(key.strip(), '%s', 1)
pos = val.find(' ;')
Expand All @@ -201,7 +203,7 @@ def __str__(self):
return self.value


class OscConfigParser(configparser.SafeConfigParser):
class OscConfigParser(ConfigParser):
"""
OscConfigParser() behaves like a normal ConfigParser() object. The
only differences is that it preserves the order+format of configuration entries
Expand All @@ -210,7 +212,7 @@ class OscConfigParser(configparser.SafeConfigParser):
class.
"""
def __init__(self, defaults={}):
configparser.SafeConfigParser.__init__(self, defaults)
ConfigParser.__init__(self, defaults)
self._sections = ConfigLineOrder()

# XXX: unfortunately we have to override the _read() method from the ConfigParser()
Expand Down Expand Up @@ -319,7 +321,7 @@ def write(self, fp, comments = False):
fp.write(str(self))
fp.write('\n')
else:
configparser.SafeConfigParser.write(self, fp)
ConfigParser.write(self, fp)

def has_option(self, section, option, proper=False, **kwargs):
"""
Expand All @@ -329,7 +331,7 @@ def has_option(self, section, option, proper=False, **kwargs):
"""
if proper:
return self.optionxform(option) in self._sections[section].keys()
return configparser.SafeConfigParser.has_option(self, section, option, **kwargs)
return ConfigParser.has_option(self, section, option, **kwargs)

# XXX: simplify!
def __str__(self):
Expand Down

0 comments on commit 9b0dcf3

Please sign in to comment.