Merge branch 'fix/81-import-indempotence' into develop

fix/67-hidden-encrypt
Isis Lovecruft 2014-11-27 01:01:25 +00:00
commit 09a0af7b41
No known key found for this signature in database
GPG Key ID: 18C16EC5F9F1D673
1 changed files with 44 additions and 34 deletions

View File

@ -1026,12 +1026,19 @@ class ListKeys(list):
class ImportResult(object): class ImportResult(object):
"""Parse GnuPG status messages for key import operations. """Parse GnuPG status messages for key import operations."""
def __init__(self, gpg):
"""Start parsing the results of a key import operation.
:type gpg: :class:`gnupg.GPG` :type gpg: :class:`gnupg.GPG`
:param gpg: An instance of :class:`gnupg.GPG`. :param gpg: An instance of :class:`gnupg.GPG`.
""" """
_ok_reason = {'0': 'Not actually changed', self._gpg = gpg
#: A map from GnuPG codes shown with the ``IMPORT_OK`` status message
#: to their human-meaningful English equivalents.
self._ok_reason = {'0': 'Not actually changed',
'1': 'Entirely new key', '1': 'Entirely new key',
'2': 'New user IDs', '2': 'New user IDs',
'4': 'New signatures', '4': 'New signatures',
@ -1039,29 +1046,32 @@ class ImportResult(object):
'16': 'Contains private key', '16': 'Contains private key',
'17': 'Contains private key',} '17': 'Contains private key',}
_problem_reason = { '0': 'No specific reason given', #: A map from GnuPG codes shown with the ``IMPORT_PROBLEM`` status
#: message to their human-meaningful English equivalents.
self._problem_reason = { '0': 'No specific reason given',
'1': 'Invalid Certificate', '1': 'Invalid Certificate',
'2': 'Issuer Certificate missing', '2': 'Issuer Certificate missing',
'3': 'Certificate Chain too long', '3': 'Certificate Chain too long',
'4': 'Error storing certificate', } '4': 'Error storing certificate', }
_fields = '''count no_user_id imported imported_rsa unchanged #: All the possible status messages pertaining to actions taken while
#: importing a key.
self._fields = '''count no_user_id imported imported_rsa unchanged
n_uids n_subk n_sigs n_revoc sec_read sec_imported sec_dups n_uids n_subk n_sigs n_revoc sec_read sec_imported sec_dups
not_imported'''.split() not_imported'''.split()
_counts = OrderedDict(
zip(_fields, [int(0) for x in range(len(_fields))]) ) #: Counts of all the status message results, :data:`_fields` which
#: have appeared.
self.counts = OrderedDict(
zip(self._fields, [int(0) for x in range(len(self._fields))]))
#: A list of strings containing the fingerprints of the GnuPG keyIDs #: A list of strings containing the fingerprints of the GnuPG keyIDs
#: imported. #: imported.
fingerprints = list() self.fingerprints = list()
#: A list containing dictionaries with information gathered on keys #: A list containing dictionaries with information gathered on keys
#: imported. #: imported.
results = list() self.results = list()
def __init__(self, gpg):
self._gpg = gpg
self.counts = self._counts
def __nonzero__(self): def __nonzero__(self):
"""Override the determination for truthfulness evaluation. """Override the determination for truthfulness evaluation.
@ -1077,7 +1087,7 @@ class ImportResult(object):
def _handle_status(self, key, value): def _handle_status(self, key, value):
"""Parse a status code from the attached GnuPG process. """Parse a status code from the attached GnuPG process.
:raises: :exc:`~exceptions.ValueError` if the status message is unknown. :raises ValueError: if the status message is unknown.
""" """
if key == "IMPORTED": if key == "IMPORTED":
# this duplicates info we already see in import_ok & import_problem # this duplicates info we already see in import_ok & import_problem