From 25bf5ebc00fa1c79e6f764a58802cd70a16967bf Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 17 Oct 2012 22:57:09 -0700 Subject: [PATCH] Handle InvalidData from _pkg_str. --- pym/_emerge/create_world_atom.py | 17 +++++++++++++---- pym/_emerge/depgraph.py | 4 ++-- pym/portage/_sets/libs.py | 3 ++- pym/portage/dbapi/vartree.py | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pym/_emerge/create_world_atom.py b/pym/_emerge/create_world_atom.py index 3e05c6d74..ac994cc04 100644 --- a/pym/_emerge/create_world_atom.py +++ b/pym/_emerge/create_world_atom.py @@ -1,7 +1,15 @@ # Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import sys + from portage.dep import _repo_separator +from portage.exception import InvalidData + +if sys.hexversion >= 0x3000000: + _unicode = str +else: + _unicode = unicode def create_world_atom(pkg, args_set, root_config): """Create a new atom for the world file if one does not exist. If the @@ -35,8 +43,8 @@ def create_world_atom(pkg, args_set, root_config): for cpv in portdb.match(cp): for repo in repos: try: - available_slots.add(portdb._pkg_str(cpv, repo).slot) - except KeyError: + available_slots.add(portdb._pkg_str(_unicode(cpv), repo).slot) + except (KeyError, InvalidData): pass slotted = len(available_slots) > 1 or \ @@ -87,8 +95,9 @@ def create_world_atom(pkg, args_set, root_config): for cpv in matches: for repo in repos: try: - matched_slots.add(portdb._pkg_str(cpv, repo).slot) - except KeyError: + matched_slots.add( + portdb._pkg_str(_unicode(cpv), repo).slot) + except (KeyError, InvalidData): pass if len(matched_slots) == 1: diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index ef31d58d1..0722fac78 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -25,7 +25,7 @@ from portage.dep import Atom, best_match_to_list, extract_affecting_use, \ from portage.dep._slot_operator import ignore_built_slot_operator_deps from portage.eapi import eapi_has_strong_blocks, eapi_has_required_use, \ _get_eapi_attrs -from portage.exception import (InvalidAtom, InvalidDependString, +from portage.exception import (InvalidAtom, InvalidData, InvalidDependString, PackageNotFound, PortageException) from portage.output import colorize, create_color_func, \ darkgreen, green @@ -3832,7 +3832,7 @@ class depgraph(object): other_db._pkg_str(_unicode(cpv), None).slot: slot_available = True break - except KeyError: + except (KeyError, InvalidData): pass if not slot_available: continue diff --git a/pym/portage/_sets/libs.py b/pym/portage/_sets/libs.py index 27ef50e71..a6433e855 100644 --- a/pym/portage/_sets/libs.py +++ b/pym/portage/_sets/libs.py @@ -3,6 +3,7 @@ from __future__ import print_function +from portage.exception import InvalidData from portage.localization import _ from portage._sets.base import PackageSet from portage._sets import get_boolean, SetConfigError @@ -22,7 +23,7 @@ class LibraryConsumerSet(PackageSet): for cpv in self.dbapi._linkmap.getOwners(p): try: pkg = self.dbapi._pkg_str(cpv, None) - except KeyError: + except (KeyError, InvalidData): # This is expected for preserved libraries # of packages that have been uninstalled # without replacement. diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 30b6cb17d..46afea572 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -4094,7 +4094,7 @@ class dblink(object): try: slot = self.vartree.dbapi._pkg_str(cpv, None).slot counter = self.vartree.dbapi.cpv_counter(cpv) - except KeyError: + except (KeyError, InvalidData): pass else: has_vdb_entry = True -- 2.26.2