Did I find the right examples for you? yes no

All Samples(15)  |  Call(15)  |  Derive(0)  |  Import(0)
Serve the first application that does not response with 404 Not Found.

If no application serves content, will respond with generic 404 Not Found.

Args:
  apps: List of WSGI applications to search through.  Will serve the content
    of the first of these that does not return a 404 Not Found.  Applications
    in this list must not modify the environment or any objects in it if they
    do not match.  Applications that do not obey this restriction can create
    unpredictable results.(more...)

        def first_found(apps):
  """Serve the first application that does not response with 404 Not Found.

  If no application serves content, will respond with generic 404 Not Found.

  Args:
    apps: List of WSGI applications to search through.  Will serve the content
      of the first of these that does not return a 404 Not Found.  Applications
      in this list must not modify the environment or any objects in it if they
      do not match.  Applications that do not obey this restriction can create
      unpredictable results.

  Returns:
    Compound application that serves the contents of the first application that
    does not response with 404 Not Found.
  """
  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 = {}  # Used in absence of Python local scoping.

    def first_found_start_response(status, response_headers):
      """Replacement for start_response as passed in to first_found_app.

      Called by each application in apps instead of the real start response.
      Checks the response status, and if anything other than 404, sets 'status'
      and 'response_headers' in final_result.
      """
      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
        


src/c/a/canteen-0.1-alpha/canteen/rpc/__init__.py   canteen(Download)
        pregistry.RegistryService.new_factory(registry_map), registry_path, protocols=protocols))
 
    return pwsgi_util.first_found(final_mapping)
 
 

src/p/r/protorpc-0.9.1/protorpc/wsgi/util_test.py   protorpc(Download)
  def testEmptyConfiguration(self):
    self.ResetServer(wsgi_util.first_found([]))
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.NOT_FOUND, status)
    self.assertEquals(httplib.responses[httplib.NOT_FOUND], status_text)
  def testOneApp(self):
    self.ResetServer(wsgi_util.first_found([APP1]))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)
  def testIterator(self):
    self.ResetServer(wsgi_util.first_found(iter([APP1])))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)
  def testTwoApps(self):
    self.ResetServer(wsgi_util.first_found([APP1, APP2]))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)
  def testFirstNotFound(self):
    self.ResetServer(wsgi_util.first_found([NOT_FOUND, APP2]))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)

src/p/r/protorpc-standalone-0.9.1/protorpc/wsgi/util_test.py   protorpc-standalone(Download)
  def testEmptyConfiguration(self):
    self.ResetServer(wsgi_util.first_found([]))
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.NOT_FOUND, status)
    self.assertEquals(httplib.responses[httplib.NOT_FOUND], status_text)
  def testOneApp(self):
    self.ResetServer(wsgi_util.first_found([APP1]))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)
  def testIterator(self):
    self.ResetServer(wsgi_util.first_found(iter([APP1])))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)
  def testTwoApps(self):
    self.ResetServer(wsgi_util.first_found([APP1, APP2]))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)
  def testFirstNotFound(self):
    self.ResetServer(wsgi_util.first_found([NOT_FOUND, APP2]))
 
    status, status_text, content, headers = self.DoHttpRequest('/')
    self.assertEquals(httplib.OK, status)

src/p/r/protorpc-0.9.1/protorpc/wsgi/service_test.py   protorpc(Download)
      protocols=self.protocols)
 
    return util.first_found([my_service, my_other_service])
 
  def testAlternateProtocols(self):

src/p/r/protorpc-standalone-0.9.1/protorpc/wsgi/service_test.py   protorpc-standalone(Download)
      protocols=self.protocols)
 
    return util.first_found([my_service, my_other_service])
 
  def testAlternateProtocols(self):