From d60deb8a127fb35c01acc729f33b014840af0e7b Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 12 May 2016 11:21:58 +0200 Subject: python: Fix type translation. * lang/python/gpgme.i: Adjust to Python3's string type being 'Unicode', not 'bytes'. Fix type checking. * lang/python/core.py (Data.write): Add docstring mentioning the expected type of parameter 'buffer'. (Data.read): Adjust read loop. Also, use a saner chunk size, and join all chunks at the end instead of adding them. * lang/python/examples/simple.py: Adjust example. Signed-off-by: Justus Winter --- lang/python/pyme/core.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lang/python/pyme/core.py') diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py index 09f0fa88..fd4802ec 100644 --- a/lang/python/pyme/core.py +++ b/lang/python/pyme/core.py @@ -377,10 +377,11 @@ class Data(GpgmeWrapper): self.new_from_fd(file) def write(self, buffer): + """Write buffer given as bytes.""" errorcheck(pygpgme.gpgme_data_write(self.wrapped, buffer, len(buffer))) def read(self, size = -1): - """Read at most size bytes, returned as a string. + """Read at most size bytes, returned as bytes. If the size argument is negative or omitted, read until EOF is reached. @@ -393,13 +394,13 @@ class Data(GpgmeWrapper): if size > 0: return pygpgme.gpgme_data_read(self.wrapped, size) else: - retval = '' + chunks = [] while 1: - result = pygpgme.gpgme_data_read(self.wrapped, 10240) + result = pygpgme.gpgme_data_read(self.wrapped, 4096) if len(result) == 0: break - retval += result - return retval + chunks.append(result) + return b''.join(chunks) def pubkey_algo_name(algo): return pygpgme.gpgme_pubkey_algo_name(algo) -- cgit v1.2.3