def get_response(self, request):
    global translations_cache
    if self.app_settings.USE_I18N:
      from kay.i18n import load_translations
      from kay.i18n import get_language_from_request
      lang = get_language_from_request(request)
      if not lang:
        lang = self.app_settings.DEFAULT_LANG
      translations = translations_cache.get("trans:%s:%s" %
                                            (self.app_settings.APP_NAME, lang),
                                            None)
      if translations is None:
        translations = load_translations(lang)
        translations_cache["trans:%s:%s" %
                     (self.app_settings.APP_NAME, lang)] = translations
      self.active_translations = translations
    else:
      from kay.i18n import KayNullTranslations
      lang = None
      self.active_translations = KayNullTranslations()
    request.lang = lang

    if self._request_middleware is None:
      self.load_middleware()
    try:
      try:
        endpoint, values = local.url_adapter.match()
      except RequestRedirect, e:
        if request.args:
          e.new_url += '?' + url_encode(request.args)
        raise e
      if self.app_settings.IS_MARKETPLACE_APP:
        if values.has_key(settings.MARKETPLACE_DOMAIN_NAME_KEY):
          setattr(request, settings.MARKETPLACE_DOMAIN_NAME_KEY,
                  values[settings.MARKETPLACE_DOMAIN_NAME_KEY])
      # apply request middleware
      for mw_method in self._request_middleware:
        response = mw_method(request)
        if response:
          return response
      view_func = self.views.get(endpoint, None)
      try:
        if isinstance(view_func, tuple):
          view_classname, args, kwargs = view_func
          view_cls = import_string(view_classname)
          view_func = view_cls(*args, **kwargs)
        elif isinstance(view_func, basestring):
          view_func = import_string(view_func)
        assert(callable(view_func))
      except StandardError, e:
          logging.error(self._get_traceback(sys.exc_info()))
          raise InternalServerError(e)
      for mw_method in self._view_middleware:
        response = mw_method(request, view_func, **values)
        if response:
          return response
      try:
        response = view_func(request, **values)
      except Exception, e:
        # If the view raised an exception, run it through exception
        # middleware, and if the exception middleware returns a
        # response, use that. Otherwise, reraise the exception.
        for middleware_method in self._exception_middleware:
          response = middleware_method(request, e)
          if response:
            return response
        raise
    except RequestRedirect, e:
      response = e.get_response(None)
    except HTTPException, e:
      logging.warning(e)
      response = render_error(e)
    except __HOLE__:
      # Allow sys.exit() to actually exit.
      raise
    except CapabilityDisabledError, e:
      from kay.i18n import gettext as _
      logging.error(e)
      # Saving session will also fail.
      if hasattr(request, 'session'):
        del(request.session)
      return Response(
        render_to_string(
          "_internal/maintenance.html",
          {"message": _('Appengine might be under maintenance.')}),
        content_type="text/html; charset=utf-8",
        status=503)
    except Exception:
      # Handle everything else, including SuspiciousOperation, etc.
      # Get the exception info now, in case another exception is thrown later.
      exc_info = sys.exc_info()
      return self.handle_uncaught_exception(request, exc_info)
    return response
dataset/ETHPy150Open IanLewis/kay/kay/app.py/KayApp.get_response