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


Python Request.matchdict方法代码示例

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


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

示例1: __call__

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import matchdict [as 别名]
    def __call__(self, environ, start_response):
        request = Request(environ)
        path_info = request.path_info
        route_match = routing.mapping.match(path_info)

        if route_match is None:
            # If there's an equivalent URL that ends with /, redirect
            # to that.
            if not path_info.endswith('/') \
                    and request.method == 'GET' \
                    and routing.mapping.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)

            # Return a 404
            response = util.generate_404_response(
                request, routing, environ, self.staticdirector)
            return response(environ, start_response)

        controller = load_controller(route_match['controller'])
        request.start_response = start_response

        request.matchdict = route_match
        request.urlgen = routes.URLGenerator(routing.mapping, environ)
        request.staticdirect = self.staticdirector

        return controller(request)(environ, start_response)
开发者ID:BIGGANI,项目名称:creativecommons.org,代码行数:33,代码来源:app.py

示例2: pick_lang

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import matchdict [as 别名]
 def pick_lang(langs=[], form_lang=None):
     """Shorthand helper function thing."""
     environ = {"REQUEST_METHOD": "GET", "PATH_INFO": "/", "HTTP_ACCEPT_LANGUAGE": ", ".join(langs)}
     if form_lang:
         environ["QUERY_STRING"] = "lang=" + form_lang
     req = Request(environ)
     req.matchdict = {}
     return util.get_target_lang_from_request(req, default_locale="default")
开发者ID:vthunder,项目名称:cc.engine,代码行数:10,代码来源:test_util.py

示例3: __call__

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import matchdict [as 别名]
    def __call__(self, environ, start_response):
        request = Request(environ)
        path_info = request.path_info

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

        # 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!
            return exc.HTTPNotFound()(environ, start_response)

        controller = util.import_component(route_match['controller'])
        request.start_response = start_response

        ## 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 = util.get_locale_from_request(request)
            
        request.template_env = util.get_jinja_env(
            self.template_loader, request.locale)
        request.db = self.db
        request.staticdirect = self.staticdirector

        util.setup_user_in_request(request)

        return controller(request)(environ, start_response)
开发者ID:OpenSourceInternetV2,项目名称:mediagoblin,代码行数:47,代码来源:app.py

示例4: __call__

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import matchdict [as 别名]
    def __call__(self, environ, start_response):
        req = Request(environ)
        path_info_parts = req.path_info.strip('/').split('/')
        action_name = path_info_parts[0]

        req.matchdict = {'action': action_name}
        try:
            req.matchdict['key'] = path_info_parts[1]
            req.matchdict['value'] = path_info_parts[2]
        except IndexError:
            pass

        # Options passed to ``Session.get()``, et al
        req.options = {k: bool(int(v)) for k, v in req.params.items()}

        action = getattr(self, action_name)
        sess = req.environ['gimlet.session']

        resp = action(req, sess)
        if isinstance(resp, basestring):
            resp = Response(resp)
        resp.content_type = 'text/plain'
        return resp(environ, start_response)
开发者ID:wylee,项目名称:gimlet,代码行数:25,代码来源:test_middleware.py


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