Python collections.KeysView() Examples

The following are code examples for showing how to use collections.KeysView(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: oil   Author: oilshell   File: test_dictviews.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 2
Project: python2-tracer   Author: extremecoders-re   File: test_dictviews.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 3
Project: xarray-simlab   Author: benbovy   File: utils.py    (BSD 3-Clause "New" or "Revised" License) View Source Project 5 votes vote down vote up
def keys(self):
        "D.keys() -> a set-like object providing a view on D's keys"
        return KeysView(self) 
Example 4
Project: central   Author: viniciuschiele   File: core.py    (license) View Source Project 5 votes vote down vote up
def keys(self):
        """
        Get all the keys of the configuration.
        :return tuple: The keys of the configuration.
        """
        return KeysView(self) 
Example 5
Project: python-diskcache   Author: grantjenks   File: persistent.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 6
Project: python-diskcache   Author: grantjenks   File: persistent.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 7
Project: zippy   Author: securesystemslab   File: test_collections.py    (license) View Source Project 5 votes vote down vote up
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)]) 
Example 8
Project: Python_Master-the-Art-of-Design-Patterns   Author: PacktPublishing   File: 6_16_dictsorted.py    (license) View Source Project 5 votes vote down vote up
def keys(self):
        return KeysView(self) 
Example 9
Project: Deploy_XXNET_Server   Author: jzp820927   File: request_environment.py    (license) View Source Project 5 votes vote down vote up
def viewkeys(self):
    return collections.KeysView(self) 
Example 10
Project: Python-Journey-from-Novice-to-Expert   Author: PacktPublishing   File: 6_16_dictsorted.py    (license) View Source Project 5 votes vote down vote up
def keys(self):
        return KeysView(self)