Skip to content

Commit

Permalink
Config: Catch specific exceptions when wrapping ConfigParser methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-savola authored and jamesls committed Apr 1, 2016
1 parent 1570934 commit 14a9f2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion boto/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@
# StandardError was removed, so use the base exception type instead
StandardError = Exception
long_type = int
from configparser import ConfigParser
from configparser import ConfigParser, NoOptionError, NoSectionError
unquote_str = unquote_plus
else:
StandardError = StandardError
long_type = long
from ConfigParser import SafeConfigParser as ConfigParser
from ConfigParser import NoOptionError, NoSectionError

def unquote_str(value, encoding='utf-8'):
# In python2, unquote() gives us a string back that has the urldecoded
Expand Down
14 changes: 7 additions & 7 deletions boto/pyami/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import boto

from boto.compat import expanduser, ConfigParser, StringIO
from boto.compat import expanduser, ConfigParser, NoOptionError, NoSectionError, StringIO


# By default we use two locations for the boto configurations,
Expand Down Expand Up @@ -128,21 +128,21 @@ def save_system_option(self, section, option, value):
def get_instance(self, name, default=None):
try:
val = self.get('Instance', name)
except:
except (NoOptionError, NoSectionError):
val = default
return val

def get_user(self, name, default=None):
try:
val = self.get('User', name)
except:
except (NoOptionError, NoSectionError):
val = default
return val

def getint_user(self, name, default=0):
try:
val = self.getint('User', name)
except:
except (NoOptionError, NoSectionError):
val = default
return val

Expand All @@ -156,7 +156,7 @@ def get(self, section, name, default=None):
return default
try:
return impl.get(section, name)
except:
except (NoOptionError, NoSectionError):
return default

def getint(self, section, name, default=0):
Expand All @@ -166,7 +166,7 @@ def getint(self, section, name, default=0):
return int(default)
try:
return impl.getint(section, name)
except:
except (NoOptionError, NoSectionError):
return int(default)

def getfloat(self, section, name, default=0.0):
Expand All @@ -176,7 +176,7 @@ def getfloat(self, section, name, default=0.0):
return float(default)
try:
return impl.getfloat(section, name)
except:
except (NoOptionError, NoSectionError):
return float(default)

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

0 comments on commit 14a9f2c

Please sign in to comment.