예제 #1
0
    def update(self, *args, **kwargs):

        if len(args) > 1:
            raise TypeError("update() takes at most 1 positional "
                            "arguments ({} given)".format(len(args)))
        if len(args) >= 1:
            other = args[0]
            if isinstance(other, KeyedList):
                # Merge
                for key, value in other.all_items():
                    self[key] = value
            else:
                MutableMapping.update(self, other)

        for key, value in kwargs.items():
            if isinstance(value, KeyedList):
                try:
                    nestedlist = self[key]
                except KeyError:
                    nestedlist = KeyedList()
                    self[key] = nestedlist
                else:
                    if not isinstance(nestedlist, KeyedList):
                        raise KeyError(
                            'target key "%s" is a value, cannot '
                            'update value against another keyed list' %
                            (key, ))
                nestedlist.update(value)
            else:
                self[key] = value
예제 #2
0
    def update(self, *args, **kw):
        if args:
            lst = args[0]

            if len(lst) != len(dict(lst)):
                # this does not catch the cases where we overwrite existing
                # keys, but those would produce too many warning
                msg = (
                    "Behavior of MultiDict.update() has changed "
                    "and overwrites duplicate keys. Consider using .extend()"
                )
                warnings.warn(msg, UserWarning, stacklevel=2)
        MutableMapping.update(self, *args, **kw)