diff options
| author | Justus Winter <[email protected]> | 2016-10-13 11:13:23 +0000 | 
|---|---|---|
| committer | Justus Winter <[email protected]> | 2016-10-13 11:19:49 +0000 | 
| commit | f526d0e22e8b881ccbca66b46a0e1b68bbc4cd6b (patch) | |
| tree | 7deb5fc787f22e6104d830ca3ab4a0b72b1a07d6 /lang/python/pyme/errors.py | |
| parent | python: Return public keys by default. (diff) | |
| download | gpgme-f526d0e22e8b881ccbca66b46a0e1b68bbc4cd6b.tar.gz gpgme-f526d0e22e8b881ccbca66b46a0e1b68bbc4cd6b.zip  | |
python: Make 'get_key' more idiomatic.
* lang/python/pyme/core.py (Context.get_key): Raise errors.KeyNotFound
if the key is not found.  This error is both a KeyError for idiomatic
error handling as well as a GPGMEError so we don't break existing
code.
* lang/python/pyme/errors.py (KeyNotFound): New class.
* lang/python/tests/support.py (no_such_key): New variable.
* lang/python/tests/t-keylist.py: Test the new behavior.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/pyme/errors.py')
| -rw-r--r-- | lang/python/pyme/errors.py | 22 | 
1 files changed, 19 insertions, 3 deletions
diff --git a/lang/python/pyme/errors.py b/lang/python/pyme/errors.py index e26c7476..0fd85efa 100644 --- a/lang/python/pyme/errors.py +++ b/lang/python/pyme/errors.py @@ -21,10 +21,12 @@ del absolute_import, print_function, unicode_literals  from . import gpgme  from . import util -util.process_constants('GPG_ERR_', globals()) +# To appease static analysis tools, we define some constants here. +# They are overwritten with the proper values by process_constants. +NO_ERROR = None +EOF = None -# To appease static analysis tools, we define some constants here: -NO_ERROR = 0 +util.process_constants('GPG_ERR_', globals())  class PymeError(Exception):      pass @@ -58,6 +60,20 @@ def errorcheck(retval, extradata = None):      if retval:          raise GPGMEError(retval, extradata) +class KeyNotFound(GPGMEError, KeyError): +    """Raised if a key was not found + +    GPGME indicates this condition with EOF, which is not very +    idiomatic.  We raise this error that is both a GPGMEError +    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(PymeError):  | 
