def www_authenticate(realm, key, algorithm='MD5', nonce=None, qop=qop_auth, stale=False):
 if (qop not in valid_qops):
  raise ValueError(("Unsupported value for qop: '%s'" % qop))
 if (algorithm not in valid_algorithms):
  raise ValueError(("Unsupported value for algorithm: '%s'" % algorithm))
 if (nonce is None):
  nonce = synthesize_nonce(realm, key)
 s = ('Digest realm="%s", nonce="%s", algorithm="%s", qop="%s"' % (realm, nonce, algorithm, qop))
 if stale:
  s += ', stale="true"'
 return s

def www_authenticate ( realm , key , algorithm = 'MD5' , nonce = None , qop = qop_auth , stale = False ) : if ( qop not in valid_qops ) : raise ValueError ( ( "Unsupported value for qop: '%s'" % qop ) ) if ( algorithm not in valid_algorithms ) : raise ValueError ( ( "Unsupported value for algorithm: '%s'" % algorithm ) ) if ( nonce is None ) : nonce = synthesize_nonce ( realm , key ) s = ( 'Digest realm="%s", nonce="%s", algorithm="%s", qop="%s"' % ( realm , nonce , algorithm , qop ) ) if stale : s += ', stale="true"' return s
constructs a www-authenticate header for digest authentication .