diff options
author | Justus Winter <[email protected]> | 2016-05-12 09:21:58 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-05-12 09:49:17 +0000 |
commit | d60deb8a127fb35c01acc729f33b014840af0e7b (patch) | |
tree | d5188d0cc07273b80e6728b1e95fc757c7630e5d /lang/python/pyme/core.py | |
parent | python: Fix simple example. (diff) | |
download | gpgme-d60deb8a127fb35c01acc729f33b014840af0e7b.tar.gz gpgme-d60deb8a127fb35c01acc729f33b014840af0e7b.zip |
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 <[email protected]>
Diffstat (limited to 'lang/python/pyme/core.py')
-rw-r--r-- | lang/python/pyme/core.py | 11 |
1 files changed, 6 insertions, 5 deletions
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) |