aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/src/errors.py
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-08-10 01:25:01 +0000
committerBen McGinnes <[email protected]>2018-08-10 01:25:01 +0000
commit94bf13e78e65e1d1bc2e5d6b2311f9c9657bfe5f (patch)
treeea23101d276096ece7c4eb656fe1c70611953c6d /lang/python/src/errors.py
parentLink fixes (diff)
downloadgpgme-94bf13e78e65e1d1bc2e5d6b2311f9c9657bfe5f.tar.gz
gpgme-94bf13e78e65e1d1bc2e5d6b2311f9c9657bfe5f.zip
PEP8 compliance and other code fixes
* Ran all the .py files in src/ and below through Yapf. * Included some manual edits of core.py, this time successfully making two notorious sections a bit more pythonic than scheming. * Left the module imports as is. * This will be committed if it passes the most essential test: compiling, installing and running it. Signed-off-by: Ben McGinnes <[email protected]>
Diffstat (limited to 'lang/python/src/errors.py')
-rw-r--r--lang/python/src/errors.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/lang/python/src/errors.py b/lang/python/src/errors.py
index c41ac692..45157c5e 100644
--- a/lang/python/src/errors.py
+++ b/lang/python/src/errors.py
@@ -30,6 +30,7 @@ EOF = None
util.process_constants('GPG_ERR_', globals())
del util
+
class GpgError(Exception):
"""A GPG Error
@@ -55,6 +56,7 @@ class GpgError(Exception):
exception objects.
"""
+
def __init__(self, error=None, context=None, results=None):
self.error = error
self.context = context
@@ -93,6 +95,7 @@ class GpgError(Exception):
msgs.append(self.code_str)
return ': '.join(msgs)
+
class GPGMEError(GpgError):
'''Generic error
@@ -101,24 +104,30 @@ class GPGMEError(GpgError):
returns an error. This is the error that was used in PyME.
'''
+
@classmethod
def fromSyserror(cls):
return cls(gpgme.gpgme_err_code_from_syserror())
+
@property
def message(self):
return self.context
+
def getstring(self):
return str(self)
+
def getcode(self):
return self.code
+
def getsource(self):
return self.source
-def errorcheck(retval, extradata = None):
+def errorcheck(retval, extradata=None):
if retval:
raise GPGMEError(retval, extradata)
+
class KeyNotFound(GPGMEError, KeyError):
"""Raised if a key was not found
@@ -127,63 +136,76 @@ class KeyNotFound(GPGMEError, KeyError):
indicating EOF, and a KeyError.
"""
+
def __init__(self, keystr):
self.keystr = keystr
GPGMEError.__init__(self, EOF)
+
def __str__(self):
return self.keystr
+
# These errors are raised in the idiomatic interface code.
+
class EncryptionError(GpgError):
pass
+
class InvalidRecipients(EncryptionError):
def __init__(self, recipients, **kwargs):
EncryptionError.__init__(self, **kwargs)
self.recipients = recipients
+
def __str__(self):
- return ", ".join("{}: {}".format(r.fpr,
- gpgme.gpgme_strerror(r.reason))
+ return ", ".join("{}: {}".format(r.fpr, gpgme.gpgme_strerror(r.reason))
for r in self.recipients)
+
class DeryptionError(GpgError):
pass
+
class UnsupportedAlgorithm(DeryptionError):
def __init__(self, algorithm, **kwargs):
DeryptionError.__init__(self, **kwargs)
self.algorithm = algorithm
+
def __str__(self):
return self.algorithm
+
class SigningError(GpgError):
pass
+
class InvalidSigners(SigningError):
def __init__(self, signers, **kwargs):
SigningError.__init__(self, **kwargs)
self.signers = signers
+
def __str__(self):
- return ", ".join("{}: {}".format(s.fpr,
- gpgme.gpgme_strerror(s.reason))
+ return ", ".join("{}: {}".format(s.fpr, gpgme.gpgme_strerror(s.reason))
for s in self.signers)
+
class VerificationError(GpgError):
def __init__(self, result, **kwargs):
GpgError.__init__(self, **kwargs)
self.result = result
+
class BadSignatures(VerificationError):
def __str__(self):
- return ", ".join("{}: {}".format(s.fpr,
- gpgme.gpgme_strerror(s.status))
+ return ", ".join("{}: {}".format(s.fpr, gpgme.gpgme_strerror(s.status))
for s in self.result.signatures
if s.status != NO_ERROR)
+
class MissingSignatures(VerificationError):
def __init__(self, result, missing, **kwargs):
VerificationError.__init__(self, result, **kwargs)
self.missing = missing
+
def __str__(self):
return ", ".join(k.subkeys[0].fpr for k in self.missing)