From d41cfc0cb16b90a41f22d3f41fb27bccd245fc29 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 2 Nov 2016 19:47:31 -0500 Subject: [PATCH] Use BytesIO on py3 in HTTPUploaderData --- speedtest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/speedtest.py b/speedtest.py index 1dd32c8..5ac3129 100755 --- a/speedtest.py +++ b/speedtest.py @@ -491,8 +491,12 @@ class HTTPUploaderData(object): def _create_data(self): chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' multiplier = int(round(int(self.length) / 36.0)) - self._data = StringIO('content1=%s' % - (chars * multiplier)[0:int(self.length) - 9]) + IO = BytesIO or StringIO + self._data = IO( + ('content1=%s' % + (chars * multiplier)[0:int(self.length) - 9] + ).encode() + ) @property def data(self): @@ -503,7 +507,7 @@ class HTTPUploaderData(object): def read(self, n=10240): if ((timeit.default_timer() - self.start) <= self.timeout and not SHUTDOWN_EVENT.isSet()): - chunk = self.data.read(n).encode() + chunk = self.data.read(n) self.total.append(len(chunk)) return chunk else: