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@gnupg.org>
This commit is contained in:
parent
f7094d8358
commit
c5d118b2a7
@ -394,7 +394,10 @@ class Data(GpgmeWrapper):
|
|||||||
"""Write buffer given as string or bytes.
|
"""Write buffer given as string or bytes.
|
||||||
|
|
||||||
If a string is given, it is implicitly encoded using UTF-8."""
|
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):
|
def read(self, size = -1):
|
||||||
"""Read at most size bytes, returned as bytes.
|
"""Read at most size bytes, returned as bytes.
|
||||||
|
@ -23,6 +23,10 @@ class GPGMEError(Exception):
|
|||||||
self.error = error
|
self.error = error
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def fromSyserror(cls):
|
||||||
|
return cls(pygpgme.gpgme_err_code_from_syserror())
|
||||||
|
|
||||||
def getstring(self):
|
def getstring(self):
|
||||||
message = "%s: %s" % (pygpgme.gpgme_strsource(self.error),
|
message = "%s: %s" % (pygpgme.gpgme_strsource(self.error),
|
||||||
pygpgme.gpgme_strerror(self.error))
|
pygpgme.gpgme_strerror(self.error))
|
||||||
|
Loading…
Reference in New Issue
Block a user