Python collections 模块,ItemsView() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用collections.ItemsView()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_MutableMapping_subclass(self):
        # Test issue 9214
        mymap = UserDict()
        mymap['red'] = 5
        self.assertIsInstance(mymap.keys(), Set)
        self.assertIsInstance(mymap.keys(), KeysView)
        self.assertIsInstance(mymap.items(), Set)
        self.assertIsInstance(mymap.items(), ItemsView)

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.keys() | {'orange'}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), ['orange', 'red'])

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.items() | {('orange', 3)}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), [('orange', 3), ('red', 5)])
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_abc_registry(self):
        d = dict(a=1)

        self.assertIsInstance(d.viewkeys(), collections.KeysView)
        self.assertIsInstance(d.viewkeys(), collections.MappingView)
        self.assertIsInstance(d.viewkeys(), collections.Set)
        self.assertIsInstance(d.viewkeys(), collections.Sized)
        self.assertIsInstance(d.viewkeys(), collections.Iterable)
        self.assertIsInstance(d.viewkeys(), collections.Container)

        self.assertIsInstance(d.viewvalues(), collections.ValuesView)
        self.assertIsInstance(d.viewvalues(), collections.MappingView)
        self.assertIsInstance(d.viewvalues(), collections.Sized)

        self.assertIsInstance(d.viewitems(), collections.ItemsView)
        self.assertIsInstance(d.viewitems(), collections.MappingView)
        self.assertIsInstance(d.viewitems(), collections.Set)
        self.assertIsInstance(d.viewitems(), collections.Sized)
        self.assertIsInstance(d.viewitems(), collections.Iterable)
        self.assertIsInstance(d.viewitems(), collections.Container)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_abc_registry(self):
        d = dict(a=1)

        self.assertIsInstance(d.viewkeys(), collections.KeysView)
        self.assertIsInstance(d.viewkeys(), collections.MappingView)
        self.assertIsInstance(d.viewkeys(), collections.Set)
        self.assertIsInstance(d.viewkeys(), collections.Sized)
        self.assertIsInstance(d.viewkeys(), collections.Iterable)
        self.assertIsInstance(d.viewkeys(), collections.Container)

        self.assertIsInstance(d.viewvalues(), collections.ValuesView)
        self.assertIsInstance(d.viewvalues(), collections.MappingView)
        self.assertIsInstance(d.viewvalues(), collections.Sized)

        self.assertIsInstance(d.viewitems(), collections.ItemsView)
        self.assertIsInstance(d.viewitems(), collections.MappingView)
        self.assertIsInstance(d.viewitems(), collections.Set)
        self.assertIsInstance(d.viewitems(), collections.Sized)
        self.assertIsInstance(d.viewitems(), collections.Iterable)
        self.assertIsInstance(d.viewitems(), collections.Container)
项目:Python_Master-the-Art-of-Design-Patterns    作者:PacktPublishing    | 项目源码 | 文件源码
def items(self):
        return ItemsView(self)
项目:xarray-simlab    作者:benbovy    | 项目源码 | 文件源码
def items(self):
        "D.items() -> a set-like object providing a view on D's items"
        return ItemsView(self)
项目:KidTasks    作者:jima80525    | 项目源码 | 文件源码
def sort(value):
    """ The filter to return the sorted order of a list """
    if isinstance(value, (ItemsView, list)):
        return sorted(value)
    return value
项目:central    作者:viniciuschiele    | 项目源码 | 文件源码
def items(self):
        """
        Get all the items of the configuration (key/value pairs).
        :return tuple: The items of the configuration.
        """
        return ItemsView(self)
项目:python-diskcache    作者:grantjenks    | 项目源码 | 文件源码
def viewitems(self):
            """Set-like object providing a view of index items.

            >>> index = Index('/tmp/diskcache/index')
            >>> index.clear()
            >>> index.update({'a': 1, 'b': 2, 'c': 3})
            >>> items_view = index.viewitems()
            >>> ('b', 2) in items_view
            True

            :return: items view

            """
            return ItemsView(self)
项目:python-diskcache    作者:grantjenks    | 项目源码 | 文件源码
def items(self):
            """Set-like object providing a view of index items.

            >>> index = Index('/tmp/diskcache/index')
            >>> index.clear()
            >>> index.update({'a': 1, 'b': 2, 'c': 3})
            >>> items_view = index.items()
            >>> ('b', 2) in items_view
            True

            :return: items view

            """
            return ItemsView(self)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def viewitems(self):
    return collections.ItemsView(self)
项目:venom    作者:biosustain    | 项目源码 | 文件源码
def __eq__(self, other):
        if not isinstance(other, (Message, Mapping)):
            return NotImplemented
        return dict(ItemsView(self)) == dict(ItemsView(other))
项目:venom    作者:biosustain    | 项目源码 | 文件源码
def items(message: Message) -> ItemsView:
    return ItemsView(message)
项目:Python-Journey-from-Novice-to-Expert    作者:PacktPublishing    | 项目源码 | 文件源码
def items(self):
        return ItemsView(self)
项目:toshi-services-lib    作者:toshiapp    | 项目源码 | 文件源码
def update(self, tablename, update_args, query_args=None):
        """Very simple "generic" update helper.
        will generate the update statement, converting the `update_args`
        dict into "key = value, key = value" statements, and converting
        the `query_args` dict into "key = value AND key = value"
        statements. string values will be wrapped in 'quotes', while
        other types will be left as their python representation.
        """

        if not self.transaction:
            raise DatabaseError("No transaction in progress")

        query = "UPDATE {} SET ".format(tablename)
        arglist = []
        qnum = 1
        if isinstance(update_args, dict):
            update_args = update_args.items()
        if isinstance(update_args, (list, tuple, ItemsView)):
            setstmts = []
            for k, v in update_args:
                setstmts.append("{} = ${}".format(k, qnum))
                qnum += 1
                arglist.append(v)
            query += ', '.join(setstmts)
        else:
            raise DatabaseError("expected dict or list for update_args")
        if isinstance(query_args, dict):
            query_args = query_args.items()
        if isinstance(query_args, (list, tuple, ItemsView)):
            query += " WHERE "
            wherestmts = []
            # TODO: support OR somehow?
            for k, v in query_args:
                wherestmts.append("{} = ${}".format(k, qnum))
                qnum += 1
                arglist.append(v)
            query += ' AND '.join(wherestmts)
        elif query_args is not None:
            raise DatabaseError("expected dict or list or None for query_args")

        resp = await self.connection.execute(query, *arglist)

        if resp and resp[0].startswith("ERROR:"):
            raise DatabaseError(resp)
        return resp