MCPcopy Create free account
hub / github.com/SecurityInnovation/PGPy / load

Method load

pgpy/pgp.py:2788–2817  ·  view source on GitHub ↗

r""" Load all keys provided into this keyring object. :param \*args: Each arg in ``args`` can be any of the formats supported by :py:meth:`PGPKey.from_file` and :py:meth:`PGPKey.from_blob` or a :py:class:`PGPKey` instance, or a ``list`` or ``tuple`` of these.

(self, *args)

Source from the content-addressed store, hash-verified

2786 self._add_key(subkey)
2787
2788 def load(self, *args):
2789 r"""
2790 Load all keys provided into this keyring object.
2791
2792 :param \*args: Each arg in ``args`` can be any of the formats supported by :py:meth:`PGPKey.from_file` and
2793 :py:meth:`PGPKey.from_blob` or a :py:class:`PGPKey` instance, or a ``list`` or ``tuple`` of these.
2794 :type \*args: ``list``, ``tuple``, ``str``, ``unicode``, ``bytes``, ``bytearray``
2795 :returns: a ``set`` containing the unique fingerprints of all of the keys that were loaded during this operation.
2796 """
2797 def _preiter(first, iterable):
2798 yield first
2799 for item in iterable:
2800 yield item
2801
2802 loaded = set()
2803 for key in iter(item for ilist in iter(ilist if isinstance(ilist, (tuple, list)) else [ilist] for ilist in args)
2804 for item in ilist):
2805 keys = {}
2806 if isinstance(key, PGPKey):
2807 _key = key
2808 elif os.path.isfile(key):
2809 _key, keys = PGPKey.from_file(key)
2810 else:
2811 _key, keys = PGPKey.from_blob(key)
2812
2813 for ik in _preiter(_key, keys.values()):
2814 self._add_key(ik)
2815 loaded |= {ik.fingerprint} | {isk.fingerprint for isk in ik.subkeys.values()}
2816
2817 return list(loaded)
2818
2819 @contextlib.contextmanager
2820 def key(self, identifier):

Callers 3

__init__Method · 0.95
test_loadMethod · 0.80

Calls 3

_add_keyMethod · 0.95
from_fileMethod · 0.80
from_blobMethod · 0.80

Tested by 2

test_loadMethod · 0.64