def first_found(apps):
 apps = tuple(apps)
 not_found = error(httplib.NOT_FOUND)
 def first_found_app(environ, start_response):
  'Compound application returned from the first_found function.'
  final_result = {}
  def first_found_start_response(status, response_headers):
   "Replacement for start_response as passed in to first_found_app.\n\n      Called by each application in apps instead of the real start response.\n      Checks the response status, and if anything other than 404, sets 'status'\n      and 'response_headers' in final_result.\n      "
   status_match = _STATUS_PATTERN.match(status)
   assert status_match, ('Status must be a string beginning with 3 digit number. Found: %s' % status)
   status_code = status_match.group(0)
   if (int(status_code) == httplib.NOT_FOUND):
    return
   final_result['status'] = status
   final_result['response_headers'] = response_headers
  for app in apps:
   response = app(environ, first_found_start_response)
   if final_result:
    start_response(final_result['status'], final_result['response_headers'])
    return response
  return not_found(environ, start_response)
 return first_found_app

def first_found ( apps ) : apps = tuple ( apps ) not_found = error ( httplib . NOT_FOUND ) def first_found_app ( environ , start_response ) : final_result = { } def first_found_start_response ( status , response_headers ) : status_match = _STATUS_PATTERN . match ( status ) assert status_match , ( 'Status must be a string beginning with 3 digit number. Found: %s' % status ) status_code = status_match . group ( 0 ) if ( int ( status_code ) == httplib . NOT_FOUND ) : return final_result [ 'status' ] = status final_result [ 'response_headers' ] = response_headers for app in apps : response = app ( environ , first_found_start_response ) if final_result : start_response ( final_result [ 'status' ] , final_result [ 'response_headers' ] ) return response return not_found ( environ , start_response ) return first_found_app
serve the first application that does not response with 404 not found .