def exhaust_iterator(iterator):
 data = b('')
 try:
  chunk = b(next(iterator))
 except StopIteration:
  chunk = b('')
 while (len(chunk) > 0):
  data += chunk
  try:
   chunk = b(next(iterator))
  except StopIteration:
   chunk = b('')
 return data

def exhaust_iterator ( iterator ) : data = b ( '' ) try : chunk = b ( next ( iterator ) ) except StopIteration : chunk = b ( '' ) while ( len ( chunk ) > 0 ) : data += chunk try : chunk = b ( next ( iterator ) ) except StopIteration : chunk = b ( '' ) return data
exhaust an iterator and return all data returned by it .