def compare_checksum(info, f):
    """Return True if the checksum values in the info dictionary match the
    computed checksum values of file content.
    """
    pieces = info['pieces']

    def getchunks(f, size):
        while True:
            chunk = f.read(size)
            if chunk == '':
                break
            yield hashlib.sha1(chunk).digest()

    calc = getchunks(f, info['piece length'])
    ref = (pieces[i:i + 20] for i in xrange(0, len(pieces), 20))
    for expected, actual in itertools.izip(calc, ref):
        if expected != actual:
            return False
    return ensure_empty(calc) and ensure_empty(ref)
def compare_checksum ( info , f ) : pieces = info [ 'pieces' ] def getchunks ( f , size ) : while True : chunk = f . read ( size ) if chunk == '' : break yield hashlib . sha1 ( chunk ) . digest ( ) calc = getchunks ( f , info [ 'piece length' ] ) ref = ( pieces [ i : i + 20 ] for i in xrange ( 0 , len ( pieces ) , 20 ) ) for expected , actual in itertools . izip ( calc , ref ) : if expected != actual : return False return ensure_empty ( calc ) and ensure_empty ( ref )
Return True if the checksum values in the info dictionary match the
    computed checksum values of file content.