def digest_auth(realm, get_ha1, key, debug=False):
 request = cherrypy.serving.request
 auth_header = request.headers.get('authorization')
 nonce_is_stale = False
 if (auth_header is not None):
  with cherrypy.HTTPError.handle(ValueError, 400, 'The Authorization header could not be parsed.'):
   auth = HttpDigestAuthorization(auth_header, request.method, debug=debug)
  if debug:
   TRACE(str(auth))
  if auth.validate_nonce(realm, key):
   ha1 = get_ha1(realm, auth.username)
   if (ha1 is not None):
    digest = auth.request_digest(ha1, entity_body=request.body)
    if (digest == auth.response):
     if debug:
      TRACE('digest matches auth.response')
     nonce_is_stale = auth.is_nonce_stale(max_age_seconds=600)
     if (not nonce_is_stale):
      request.login = auth.username
      if debug:
       TRACE(('authentication of %s successful' % auth.username))
      return
 header = www_authenticate(realm, key, stale=nonce_is_stale)
 if debug:
  TRACE(header)
 cherrypy.serving.response.headers['WWW-Authenticate'] = header
 raise cherrypy.HTTPError(401, 'You are not authorized to access that resource')

def digest_auth ( realm , get_ha1 , key , debug = False ) : request = cherrypy . serving . request auth_header = request . headers . get ( 'authorization' ) nonce_is_stale = False if ( auth_header is not None ) : with cherrypy . HTTPError . handle ( ValueError , 400 , 'The Authorization header could not be parsed.' ) : auth = HttpDigestAuthorization ( auth_header , request . method , debug = debug ) if debug : TRACE ( str ( auth ) ) if auth . validate_nonce ( realm , key ) : ha1 = get_ha1 ( realm , auth . username ) if ( ha1 is not None ) : digest = auth . request_digest ( ha1 , entity_body = request . body ) if ( digest == auth . response ) : if debug : TRACE ( 'digest matches auth.response' ) nonce_is_stale = auth . is_nonce_stale ( max_age_seconds = 600 ) if ( not nonce_is_stale ) : request . login = auth . username if debug : TRACE ( ( 'authentication of %s successful' % auth . username ) ) return header = www_authenticate ( realm , key , stale = nonce_is_stale ) if debug : TRACE ( header ) cherrypy . serving . response . headers [ 'WWW-Authenticate' ] = header raise cherrypy . HTTPError ( 401 , 'You are not authorized to access that resource' )
if auth fails .