From 2c468ae0d5a1e25998373abb72d87b1ee7693816 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Wed, 17 Jun 2015 12:46:58 +0530 Subject: Fix reading of binary data in read() As per the current code, this is the behavior: >>> with v.fopen("/abc", 'r') as f: ... data = f.read(5) >>> print data >>> print data.value hello >>> It's incorrect to return a ctypes internal object back to the user. In Python 2.x, read() always returns a string. It's really upto the consumer to decode this string into whatever encoding it was written with. This patch reverts parts of this old change: Ia2bb47343880cbf7121fed9510e4cfa085fe23bd Change-Id: Ia1d3e5834be2b856776bd3cf8382a17ffd61d5df Signed-off-by: Prashanth Pai --- gluster/gfapi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gluster') diff --git a/gluster/gfapi.py b/gluster/gfapi.py index 96088ff..bd6f240 100755 --- a/gluster/gfapi.py +++ b/gluster/gfapi.py @@ -319,7 +319,10 @@ class File(object): rbuf = ctypes.create_string_buffer(size) ret = api.glfs_read(self.fd, rbuf, size, 0) if ret > 0: - return rbuf + # In python 2.x, read() always returns a string. It's really upto + # the consumer to decode this string into whatever encoding it was + # written with. + return rbuf.value[:ret] elif ret < 0: err = ctypes.get_errno() raise OSError(err, os.strerror(err)) -- cgit