From 8be1a1f81066241318ee5be858285ff14500884f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 19 Feb 2009 12:27:28 +0000 Subject: [PATCH] Fix update() methods to work with python-3.0. svn path=/main/trunk/; revision=12647 --- pym/portage/cache/mappings.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index 5fe836daa..a632ce61d 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -115,7 +115,12 @@ class MutableMapping(Mapping): if other is None: pass elif hasattr(other, 'iteritems'): - for k, v in other.iteritems(): + # Use getattr to avoid interference from 2to3. + for k, v in getattr(other, 'iteritems')(): + self[k] = v + elif hasattr(other, 'items'): + # Use getattr to avoid interference from 2to3. + for k, v in getattr(other, 'items')(): self[k] = v elif hasattr(other, 'keys'): for k in other.keys(): @@ -358,14 +363,25 @@ def slot_dict_class(keys, prefix="_val_"): self[key] = default return default - def update(self, d): - i = getattr(d, "iteritems", None) - if i is None: - i = d + def update(self, other=None, **kwargs): + if other is None: + pass + elif hasattr(other, 'iteritems'): + # Use getattr to avoid interference from 2to3. + for k, v in getattr(other, 'iteritems')(): + self[k] = v + elif hasattr(other, 'items'): + # Use getattr to avoid interference from 2to3. + for k, v in getattr(other, 'items')(): + self[k] = v + elif hasattr(other, 'keys'): + for k in other.keys(): + self[k] = other[k] else: - i = i() - for k, v in i: - self[k] = v + for k, v in other: + self[k] = v + if kwargs: + self.update(kwargs) def __getitem__(self, k): try: -- 2.26.2