def read_in_chunks(iterator, chunk_size=None, fill_size=False, yield_empty=False):
 chunk_size = (chunk_size or CHUNK_SIZE)
 if isinstance(iterator, (file, httplib.HTTPResponse)):
  get_data = iterator.read
  args = (chunk_size,)
 else:
  get_data = next
  args = (iterator,)
 data = b('')
 empty = False
 while ((not empty) or (len(data) > 0)):
  if (not empty):
   try:
    chunk = b(get_data(*args))
    if (len(chunk) > 0):
     data += chunk
    else:
     empty = True
   except StopIteration:
    empty = True
  if (len(data) == 0):
   if (empty and yield_empty):
    (yield b(''))
   raise StopIteration
  if fill_size:
   if (empty or (len(data) >= chunk_size)):
    (yield data[:chunk_size])
    data = data[chunk_size:]
  else:
   (yield data)
   data = b('')

def read_in_chunks ( iterator , chunk_size = None , fill_size = False , yield_empty = False ) : chunk_size = ( chunk_size or CHUNK_SIZE ) if isinstance ( iterator , ( file , httplib . HTTPResponse ) ) : get_data = iterator . read args = ( chunk_size , ) else : get_data = next args = ( iterator , ) data = b ( '' ) empty = False while ( ( not empty ) or ( len ( data ) > 0 ) ) : if ( not empty ) : try : chunk = b ( get_data ( * args ) ) if ( len ( chunk ) > 0 ) : data += chunk else : empty = True except StopIteration : empty = True if ( len ( data ) == 0 ) : if ( empty and yield_empty ) : ( yield b ( '' ) ) raise StopIteration if fill_size : if ( empty or ( len ( data ) >= chunk_size ) ) : ( yield data [ : chunk_size ] ) data = data [ chunk_size : ] else : ( yield data ) data = b ( '' )
return a generator which yields data in chunks .