def _count_blocks(obj):
 block_counts = defaultdict(int)
 block = BytesIO()
 n = 0
 block_write = block.write
 block_seek = block.seek
 block_truncate = block.truncate
 block_getvalue = block.getvalue
 for c in chain(*obj.as_raw_chunks()):
  if (sys.version_info[0] == 3):
   c = c.to_bytes(1, 'big')
  block_write(c)
  n += 1
  if ((c == '\n') or (n == _BLOCK_SIZE)):
   value = block_getvalue()
   block_counts[hash(value)] += len(value)
   block_seek(0)
   block_truncate()
   n = 0
 if (n > 0):
  last_block = block_getvalue()
  block_counts[hash(last_block)] += len(last_block)
 return block_counts

def _count_blocks ( obj ) : block_counts = defaultdict ( int ) block = BytesIO ( ) n = 0 block_write = block . write block_seek = block . seek block_truncate = block . truncate block_getvalue = block . getvalue for c in chain ( * obj . as_raw_chunks ( ) ) : if ( sys . version_info [ 0 ] == 3 ) : c = c . to_bytes ( 1 , 'big' ) block_write ( c ) n += 1 if ( ( c == '\n' ) or ( n == _BLOCK_SIZE ) ) : value = block_getvalue ( ) block_counts [ hash ( value ) ] += len ( value ) block_seek ( 0 ) block_truncate ( ) n = 0 if ( n > 0 ) : last_block = block_getvalue ( ) block_counts [ hash ( last_block ) ] += len ( last_block ) return block_counts
count the blocks in an object .