'computes the authentication, raises error if unsuccessful'

def compute(self, ha1, username, response, method, path, nonce, nc, cnonce, qop):

    if (not ha1):
        return self.build_authentication()
    content = ('%s:%s' % (method, path))
    if six.PY3:
        content = content.encode('utf8')
    ha2 = md5(content).hexdigest()
    if qop:
        chk = ('%s:%s:%s:%s:%s:%s' % (ha1, nonce, nc, cnonce, qop, ha2))
    else:
        chk = ('%s:%s:%s' % (ha1, nonce, ha2))
    if six.PY3:
        chk = chk.encode('utf8')
    if (response != md5(chk).hexdigest()):
        if (nonce in self.nonce):
            del self.nonce[nonce]
        return self.build_authentication()
    pnc = self.nonce.get(nonce, '00000000')
    if ((pnc is not None) and (nc <= pnc)):
        if (nonce in self.nonce):
            del self.nonce[nonce]
        return self.build_authentication(stale=True)
    self.nonce[nonce] = nc
    return username
