示例#1
0
 def _convert(self, collection):
     # TODO We could check if the objects' type is correct.
     type_ = util.duck_type_collection(collection)
     if type_ is dict:
         for key, value in util.dictlike_iteritems(collection):
             if key != self.keyfunc(value):
                 raise TypeError("Found incompatible key '%r' for value '%r'" % (key, value))
             yield value
     elif type_ in (list, set):
         for value in collection:
             yield value
     else:
         raise TypeError("Object '%r' is not dict-like nor iterable" % collection)
示例#2
0
 def _convert(self, coll):
     # TODO We could check if the objects' type is correct.
     type_ = util.duck_type_collection(coll)
     if type_ is dict:
         for key, value in util.dictlike_iteritems(coll):
             if key != self.keyfunc(value):
                 raise TypeError(
                     "Found incompatible key '%r' for value '%r'" %
                     (key, value))
             yield value
     elif type_ in (list, set):
         for value in coll:
             yield value
     else:
         raise TypeError("Object '%r' is not dict-like nor iterable" % coll)
示例#3
0
    def _convert(self, dictlike):
        """Validate and convert a dict-like object into values for set()ing.

        This is called behind the scenes when a MappedCollection is replaced
        entirely by another collection, as in::

          myobj.mappedcollection = {'a':obj1, 'b': obj2} # ...

        Raises a TypeError if the key in any (key, value) pair in the dictlike
        object does not match the key that this collection's keyfunc would
        have assigned for that value.
        """

        for incoming_key, value in sautil.dictlike_iteritems(dictlike):
            new_key = self.keyfunc(value)
            if incoming_key != new_key:
                raise TypeError(
                    "Found incompatible key %r for value %r; this collection's "
                    "keying function requires a key of %r for this value." %
                    (incoming_key, value, new_key))
            yield value
示例#4
0
    def _convert(self, dictlike):
        """Validate and convert a dict-like object into values for set()ing.

        This is called behind the scenes when a MappedCollection is replaced
        entirely by another collection, as in::

          myobj.mappedcollection = {'a':obj1, 'b': obj2} # ...

        Raises a TypeError if the key in any (key, value) pair in the dictlike
        object does not match the key that this collection's keyfunc would
        have assigned for that value.

        """
        for incoming_key, value in util.dictlike_iteritems(dictlike):
            new_key = self.keyfunc(value)
            if incoming_key != new_key:
                raise TypeError(
                    "Found incompatible key %r for value %r; this collection's "
                    "keying function requires a key of %r for this value." % (
                    incoming_key, value, new_key))
            yield value
示例#5
0
 def _ok(self, instance):
     iterator = util.dictlike_iteritems(instance)
     eq_(set(iterator), self.baseline)
示例#6
0
 def _ok(self, instance):
     iterator = util.dictlike_iteritems(instance)
     eq_(set(iterator), self.baseline)
示例#7
0
 def _ok(self, instance):
     iterator = util.dictlike_iteritems(instance)
     self.assertEquals(set(iterator), self.baseline)