Exemple #1
0
        def wrapper(*args, **kws):
            """The decorator itself, checks arguments with set operations, moves
            args from *args into **kws, and then calls func().

            Args:
              *args, **kws: The arguments passed to the original function.

            Returns:
              The original function's result when it's called with the
              modified arguments.

            Raises:
              TypeError: When there is a mismatch between the supplied
                and expected arguments.

            """
            keys = collections.KeysView(kws)
            # Are all the keyword-only args covered either by a passed
            # argument or a default?
            if not kw_only_args <= keys | args_with_defaults:
                wrong_args(func, signature,
                           kw_only_args - (keys | args_with_defaults),
                           'keyword-only')
            # Are there enough positional args to cover all the
            # arguments not covered by a passed argument or a default?
            if len(args) < len(positional_args - (keys | args_with_defaults)):
                wrong_args(func, signature,
                           positional_args - (keys | args_with_defaults),
                           'positional', len(args))

            args = list(args)
            for index, (name,
                        param) in enumerate(signature.parameters.items()):
                if param.kind is param.VAR_POSITIONAL or param.kind is param.VAR_KEYWORD:
                    break
                if name in kw_only_args or name in keys & positional_args:
                    args.insert(index, kws.pop(name, param.default))
            func(*args, **kws)
Exemple #2
0
 def iterkeys(self):
     return collections.KeysView(self.mapping)
 def viewkeys(self):
     return collections.KeysView(self)
 def keys(self) -> Iterable[KT]:
     return collections.KeysView(self)
Exemple #5
0
 def keys(self):
     keys = set()
     for _headers in self._all_headers:
         for key in _headers.keys():
             keys.add(key)
     return collections.KeysView(keys)
device = {"hostname":"falcon"}
print(device)

device['vendor'] = 'nokia'
print(device)

device['model'] = '7750'
print(device)

device.setdefault('type', 'SR12')
print(device)

print(collections.Counter(device))
print(collections.ItemsView(device))
print(collections.KeysView(device))
print(collections.MappingView(device))


for k,v in device.items():
    print(k,v)

for k,v in sorted(device.items()):
    print(k,v)

for item in collections.ItemsView(device):
    print(item)

device.pop('type')
print(device)
Exemple #7
0
def _viewkeys(instance):
    "Returns a :py:class:`collections.KeysView` of its own keys."
    return collections.KeysView(instance._dict)
Exemple #8
0
 def keys(self) -> KeysView[bytes]:
     return collections.KeysView(self.db.iterator(include_value=False))