From cde46b372b6fa08174714f3b3443767528d3cd9c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 28 Jul 2008 05:34:07 +0000 Subject: Create a SlotDict constructor which can take an optional positional arg that is passed to the update() method (similar to the dict constructor), and also pass keyword arguments into the update() method if any are given. This makes it possible to use the constructor similarly to the way that the _emerge.SlotObject constructor is used. svn path=/main/trunk/; revision=11230 --- pym/portage/cache/mappings.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index d0ca487f0..75f97d6ae 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -142,6 +142,19 @@ def slot_dict_class(keys, prefix="_val_"): __slots__ = ("__weakref__",) + \ tuple(prefix + k for k in allowed_keys) + def __init__(self, *args, **kwargs): + + if len(args) > 1: + raise TypeError( + "expected at most 1 positional argument, got " + \ + repr(1 + len(args))) + + if args: + self.update(args[0]) + + if kwargs: + self.update(kwargs) + def __iter__(self): for k, v in self.iteritems(): yield k -- cgit v1.2.3-1-g7c22