Minor cleaning up of the new read code
authorEd Page <eopage@byu.net>
Sat, 25 Apr 2009 03:01:42 +0000 (22:01 -0500)
committerEd Page <eopage@byu.net>
Sat, 25 Apr 2009 03:01:42 +0000 (22:01 -0500)
src/rtm_api.py

index b748b38..a184328 100644 (file)
@@ -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():