From e558d14d1c3f82647a67c399805420d5e55fd1ca Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 24 Apr 2009 22:01:42 -0500 Subject: [PATCH] Minor cleaning up of the new read code --- src/rtm_api.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/rtm_api.py b/src/rtm_api.py index b748b38..a184328 100644 --- a/src/rtm_api.py +++ b/src/rtm_api.py @@ -103,16 +103,17 @@ class RTMapi(object): actuallyRead = 0 chunks = [] + chunk = connection.read() - while 0 < timeout: - actuallyRead += len(chunk) - if actuallyRead == specifiedLength: - break - chunks.append(chunk) + actuallyRead += len(chunk) + chunks.append(chunk) + while 0 < timeout and actuallyRead < specifiedLength: time.sleep(1) timeout -= 1 chunk = connection.read() - chunks.append(chunk) + actuallyRead += len(chunk) + chunks.append(chunk) + json = "".join(chunks) if "Content-Length" in connection.info(): @@ -131,13 +132,15 @@ class RTMapi(object): # to grab data. chunks = [] + chunk = connection.read() + chunks.append(chunk) while chunk and 0 < timeout: - chunks.append(chunk) time.sleep(1) timeout -= 1 chunk = connection.read() - chunks.append(chunk) + chunks.append(chunk) + json = "".join(chunks) if "Content-Length" in connection.info(): -- 1.7.9.5