diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-03-11 05:55:40 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-03-11 05:55:40 +0000 |
commit | 2c47365aa4b8ebd4271a415b48842027704e4cdc (patch) | |
tree | 69f916edba0e3cb9269074396984a9da732237dc /pym | |
parent | 74e4618d558a7d06522ea2e941b1812f864c4a7a (diff) | |
download | portage-2c47365aa4b8ebd4271a415b48842027704e4cdc.tar.gz portage-2c47365aa4b8ebd4271a415b48842027704e4cdc.tar.bz2 portage-2c47365aa4b8ebd4271a415b48842027704e4cdc.zip |
Fix update() methods to work with python-3.0. (trunk r12647)
svn path=/main/branches/2.1.6/; revision=12918
Diffstat (limited to 'pym')
-rw-r--r-- | pym/portage/cache/mappings.py | 32 |
1 files 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: |