Skip to content

Commit

Permalink
Config: Don't inherit from ConfigParser
Browse files Browse the repository at this point in the history
Closes boto#3474
  • Loading branch information
tt-savola authored and jamesls committed Apr 1, 2016
1 parent 1d75b6d commit 1570934
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions boto/pyami/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@
BotoConfigLocations.append(expanduser(path))


class Config(ConfigParser):
class Config(object):

def __init__(self, path=None, fp=None, do_load=True):
# We don't use ``super`` here, because ``ConfigParser`` still uses
# old-style classes.
ConfigParser.__init__(self, {'working_dir': '/mnt/pyami',
self._impl = ConfigParser({'working_dir': '/mnt/pyami',
'debug': '0'})
if do_load:
if path:
Expand All @@ -70,6 +68,20 @@ def __init__(self, path=None, fp=None, do_load=True):
except IOError:
warnings.warn('Unable to load AWS_CREDENTIAL_FILE (%s)' % full_path)

def __getattr__(self, name):
try:
impl = self.__dict__['_impl']
except KeyError:
raise AttributeError(name)
return getattr(impl, name)

def has_option(self, *args, **kwargs):
try:
impl = self.__dict__['_impl']
except KeyError:
return False
return impl.has_option(*args, **kwargs)

def load_credential_file(self, path):
"""Load a credential file as is setup like the Java utilities"""
c_data = StringIO()
Expand Down Expand Up @@ -139,24 +151,33 @@ def get_value(self, section, name, default=None):

def get(self, section, name, default=None):
try:
val = ConfigParser.get(self, section, name)
impl = self.__dict__['_impl']
except KeyError:
return default
try:
return impl.get(section, name)
except:
val = default
return val
return default

def getint(self, section, name, default=0):
try:
val = ConfigParser.getint(self, section, name)
impl = self.__dict__['_impl']
except KeyError:
return int(default)
try:
return impl.getint(section, name)
except:
val = int(default)
return val
return int(default)

def getfloat(self, section, name, default=0.0):
try:
val = ConfigParser.getfloat(self, section, name)
impl = self.__dict__['_impl']
except KeyError:
return float(default)
try:
return impl.getfloat(section, name)
except:
val = float(default)
return val
return float(default)

def getbool(self, section, name, default=False):
if self.has_option(section, name):
Expand Down

0 comments on commit 1570934

Please sign in to comment.