diff --git a/apns.py b/apns.py index 2a281ce..e41eab0 100644 --- a/apns.py +++ b/apns.py @@ -432,20 +432,13 @@ def items(self): A generator that yields (token_hex, fail_time) pairs retrieved from the APNs feedback server """ - buff = b'' + buff = bytearray() for chunk in self._chunks(): - buff += chunk - - # Quit if there's no more data to read - if not buff: - break - - # Sanity check: after a socket read we should always have at least - # 6 bytes in the buffer - if len(buff) < 6: + if not chunk: break + buff.extend(chunk) - while len(buff) > 6: + while len(buff) >= 6: token_length = APNs.unpacked_ushort_big_endian(buff[4:6]) bytes_to_read = 6 + token_length if len(buff) >= bytes_to_read: @@ -458,7 +451,7 @@ def items(self): yield (token, fail_time) # Remove data for current token from buffer - buff = buff[bytes_to_read:] + del buff[:bytes_to_read] else: # break out of inner while loop - i.e. go and fetch # some more data and append to buffer