From 2c47365aa4b8ebd4271a415b48842027704e4cdc Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 11 Mar 2009 05:55:40 +0000 Subject: Fix update() methods to work with python-3.0. (trunk r12647) svn path=/main/branches/2.1.6/; revision=12918 --- 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: -- cgit v1.2.3-1-g7c22