[Pkg-gnupg-commit] [gpgme] 94/412: python: Raise exceptions on write errors.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Thu Sep 22 21:26:23 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gpgme.
commit c5d118b2a76e9528df780d11da9566ff7c22e4f5
Author: Justus Winter <justus at gnupg.org>
Date: Thu May 12 18:00:16 2016 +0200
python: Raise exceptions on write errors.
* lang/python/pyme/core.py (Data.write): Handle errors.
* lang/python/pyme/errors.py (GPGMEError.fromSyserror): New function.
Signed-off-by: Justus Winter <justus at gnupg.org>
---
lang/python/pyme/core.py | 5 ++++-
lang/python/pyme/errors.py | 4 ++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index dafbd9b..1d6e384 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -394,7 +394,10 @@ class Data(GpgmeWrapper):
"""Write buffer given as string or bytes.
If a string is given, it is implicitly encoded using UTF-8."""
- return pygpgme.gpgme_data_write(self.wrapped, buffer)
+ written = pygpgme.gpgme_data_write(self.wrapped, buffer)
+ if written < 0:
+ raise GPGMEError.fromSyserror()
+ return written
def read(self, size = -1):
"""Read at most size bytes, returned as bytes.
diff --git a/lang/python/pyme/errors.py b/lang/python/pyme/errors.py
index 37d0fe6..5c8f922 100644
--- a/lang/python/pyme/errors.py
+++ b/lang/python/pyme/errors.py
@@ -23,6 +23,10 @@ class GPGMEError(Exception):
self.error = error
self.message = message
+ @classmethod
+ def fromSyserror(cls):
+ return cls(pygpgme.gpgme_err_code_from_syserror())
+
def getstring(self):
message = "%s: %s" % (pygpgme.gpgme_strsource(self.error),
pygpgme.gpgme_strerror(self.error))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list