def calculate_tree_hash(body):
 chunks = []
 required_chunk_size = (1024 * 1024)
 sha256 = hashlib.sha256
 for chunk in iter((lambda : body.read(required_chunk_size)), ''):
  chunks.append(sha256(chunk).digest())
 if (not chunks):
  return sha256('').hexdigest()
 while (len(chunks) > 1):
  new_chunks = []
  for (first, second) in _in_pairs(chunks):
   if (second is not None):
    new_chunks.append(sha256((first + second)).digest())
   else:
    new_chunks.append(first)
  chunks = new_chunks
 return binascii.hexlify(chunks[0]).decode('ascii')

def calculate_tree_hash ( body ) : chunks = [ ] required_chunk_size = ( 1024 * 1024 ) sha256 = hashlib . sha256 for chunk in iter ( ( lambda : body . read ( required_chunk_size ) ) , '' ) : chunks . append ( sha256 ( chunk ) . digest ( ) ) if ( not chunks ) : return sha256 ( '' ) . hexdigest ( ) while ( len ( chunks ) > 1 ) : new_chunks = [ ] for ( first , second ) in _in_pairs ( chunks ) : if ( second is not None ) : new_chunks . append ( sha256 ( ( first + second ) ) . digest ( ) ) else : new_chunks . append ( first ) chunks = new_chunks return binascii . hexlify ( chunks [ 0 ] ) . decode ( 'ascii' )
calculate a tree hash checksum .