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

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

项目: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)
项目:xarray-simlab    作者:benbovy    | 项目源码 | 文件源码
def keys(self):
        "D.keys() -> a set-like object providing a view on D's keys"
        return KeysView(self)
项目:central    作者:viniciuschiele    | 项目源码 | 文件源码
def keys(self):
        """
        Get all the keys of the configuration.
        :return tuple: The keys of the configuration.
        """
        return KeysView(self)
项目:python-diskcache    作者:grantjenks    | 项目源码 | 文件源码
def viewkeys(self):
            """Set-like object providing a view of index keys.

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

            :return: keys view

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

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

            :return: keys view

            """
            return KeysView(self)
项目:Python_Master-the-Art-of-Design-Patterns    作者:PacktPublishing    | 项目源码 | 文件源码
def keys(self):
        return KeysView(self)
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
def viewkeys(self):
    return collections.KeysView(self)
项目:Python-Journey-from-Novice-to-Expert    作者:PacktPublishing    | 项目源码 | 文件源码
def keys(self):
        return KeysView(self)