Skip to content

Commit

Permalink
Use Python 3 compatible except syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Jun 4, 2014
1 parent 7837944 commit bf9bdb7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pykg-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def main(argv):
parser = setup_option_parser()
try:
options, args = parser.parse_args()
except OptionError, e:
except OptionError as e:
print 'OptionError: ' + str (e)
sys.exit(1)

Expand Down Expand Up @@ -297,10 +297,10 @@ def main(argv):
Options().set_option('search_string', search)
result = PkgCfgResult(global_variables)
result.find_packages(search, True)
except NoOpenableFilesError, e:
except NoOpenableFilesError as e:
ErrorPrinter().verbose_error(str(e))
sys.exit(1)
except PackageNotFoundError, e:
except PackageNotFoundError as e:
if not Options().get_option('short_errors'):
ErrorPrinter().verbose_error('''Package {0} was not found in the \
pkg-config search path.
Expand All @@ -312,7 +312,7 @@ def main(argv):
print >>Options().get_option('error_dest'), \
'Must specify package names on the command line'
sys.exit(1)
except UndefinedVarError, e:
except UndefinedVarError as e:
ErrorPrinter().error("Variable '{0}' not defined in '{1}'".format(
e.variable, e.pkgfile))
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pykg_config/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _process_props(self, global_variables):
if props['version']:
try:
self.properties['version'] = Version(props['version'])
except BadVersionFormatError, e:
except BadVersionFormatError as e:
raise BadVersionFormatError(e.versionstring, props['name'])
self.properties['requires'] = \
parse_package_spec_list(props['requires'])
Expand Down
14 changes: 7 additions & 7 deletions pykg_config/pkgsearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def search_for_package(self, dep, globals):
for pcfile in pcfiles:
try:
pkgs.append(Package(pcfile, globals))
except IOError, e:
except IOError as e:
ErrorPrinter().verbose_error("Failed to open '{0}': \
{1}".format(pcfile, e.strerror))
continue
except UndefinedVarError, e:
except UndefinedVarError as e:
raise UndefinedVarError(e.variable, pcfile)
if not pkgs and pcfiles:
# Raise an error indicating that all pc files we could try were
Expand Down Expand Up @@ -186,11 +186,11 @@ def known_packages_list(self):
# Use the highest-priority version of the package
try:
pkg = Package(self._known_pkgs[pkgname][0])
except IOError, e:
except IOError as e:
ErrorPrinter().verbose_error("Failed to open '{0}': \
{1}".format(self._known_pkgs[pkgname][0], e.strerror))
continue
except UndefinedVarError, e:
except UndefinedVarError as e:
errors.append("Variable '{0}' not defined in '{1}'".format(e,
self._known_pkgs[pkgname][0]))
continue
Expand Down Expand Up @@ -227,7 +227,7 @@ def _init_search_dirs(self):
(_winreg.HKEY_LOCAL_MACHINE, 'HKEY_LOCAL_MACHINE')):
try:
key = _winreg.OpenKey(root[0], key_path)
except WindowsError, e:
except WindowsError as e:
ErrorPrinter().debug_print('Failed to add paths from \
{0}\\{1}: {2}'.format(root[1], key_path, e))
continue
Expand All @@ -237,7 +237,7 @@ def _init_search_dirs(self):
name, val, type = _winreg.EnumValue(key, ii)
if type == _winreg.REG_SZ:
self._append_packages(val)
except WindowsError, e:
except WindowsError as e:
ErrorPrinter().debug_print('Failed to add paths from \
{0}\\{1}: {2}'.format(root[1], key_path, e))
finally:
Expand Down Expand Up @@ -270,7 +270,7 @@ def _split_char(self):
def _can_open_file(self, filename):
try:
result = open(filename, 'r')
except IOError, e:
except IOError as e:
ErrorPrinter().debug_print('Could not open {0}'.format(filename))
search_string = Options().get_option('search_string').split()
if (not search_string and \
Expand Down

0 comments on commit bf9bdb7

Please sign in to comment.