当前位置: 首页>>代码示例>>Python>>正文


Python Request.accept_language方法代码示例

本文整理汇总了Python中werkzeug.wrappers.Request.accept_language方法的典型用法代码示例。如果您正苦于以下问题:Python Request.accept_language方法的具体用法?Python Request.accept_language怎么用?Python Request.accept_language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.wrappers.Request的用法示例。


在下文中一共展示了Request.accept_language方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: call_backend

# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import accept_language [as 别名]
    def call_backend(self, environ, start_response):
        request = Request(environ)

        ## Compatibility webob -> werkzeug
        request.GET = request.args
        request.accept_language = request.accept_languages
        request.accept = request.accept_mimetypes

        ## Routing / controller loading stuff
        path_info = request.path
        route_match = self.routing.match(path_info)

        # By using fcgi, mediagoblin can run under a base path
        # like /mediagoblin/. request.path_info contains the
        # path inside mediagoblin. If the something needs the
        # full path of the current page, that should include
        # the basepath.
        # Note: urlgen and routes are fine!
        request.full_path = environ["SCRIPT_NAME"] + request.path
        # python-routes uses SCRIPT_NAME. So let's use that too.
        # The other option would be:
        # request.full_path = environ["SCRIPT_URL"]

        # Fix up environ for urlgen
        # See bug: https://bitbucket.org/bbangert/routes/issue/55/cache_hostinfo-breaks-on-https-off
        if environ.get('HTTPS', '').lower() == 'off':
            environ.pop('HTTPS')

        ## Attach utilities to the request object
        request.matchdict = route_match
        request.urlgen = routes.URLGenerator(self.routing, environ)
        # Do we really want to load this via middleware?  Maybe?
        request.session = request.environ['beaker.session']
        # Attach self as request.app
        # Also attach a few utilities from request.app for convenience?
        request.app = self
        request.locale = translate.get_locale_from_request(request)

        request.template_env = template.get_jinja_env(
            self.template_loader, request.locale)
        request.db = self.db
        request.staticdirect = self.staticdirector

        mg_request.setup_user_in_request(request)

        # No matching page?
        if route_match is None:
            # Try to do see if we have a match with a trailing slash
            # added and if so, redirect
            if not path_info.endswith('/') \
                    and request.method == 'GET' \
                    and self.routing.match(path_info + '/'):
                new_path_info = path_info + '/'
                if request.GET:
                    new_path_info = '%s?%s' % (
                        new_path_info, urllib.urlencode(request.GET))
                redirect = exc.HTTPFound(location=new_path_info)
                return request.get_response(redirect)(environ, start_response)

            # Okay, no matches.  404 time!
            request.matchdict = {}  # in case our template expects it
            return render_404(request)(environ, start_response)

        # import the controller, or if it's already a callable, call that
        route_controller = route_match['controller']
        if isinstance(route_controller, unicode) \
                or isinstance(route_controller, str):
            controller = common.import_component(route_match['controller'])
        else:
            controller = route_match['controller']

        # pass the request through our meddleware classes
        for m in self.meddleware:
            response = m.process_request(request, controller)
            if response is not None:
                return response(environ, start_response)

        request.start_response = start_response

        # get the response from the controller
        response = controller(request)

        # pass the response through the meddleware
        for m in self.meddleware[::-1]:
            m.process_response(request, response)

        return response(environ, start_response)
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:89,代码来源:app.py


注:本文中的werkzeug.wrappers.Request.accept_language方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。