本文整理汇总了Python中context.Context.response方法的典型用法代码示例。如果您正苦于以下问题:Python Context.response方法的具体用法?Python Context.response怎么用?Python Context.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context.Context
的用法示例。
在下文中一共展示了Context.response方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import response [as 别名]
def __call__(self, environ, start_response):
if (self._controllers == None
or len(self._controllers) == 0
or self.mapper == None):
raise NotInitializedProperly('Missing controller to execute.')
else:
context = Context(environ=environ, worker = self, match_callback = self.mapper.routematch,
generator_callback = URLGenerator(self.mapper, environ))
try:
context.match()
if context.match_dict is None:
req = context.request.copy()
if req.path_info.endswith('/'):
req.path_info = req.path_info.rstrip('/')
route = context.matcher(environ=req.environ)
else:
req.path_info = req.path_info + '/'
route = context.matcher(environ=req.environ)
if route is not None:
raise HTTPFound('Try add/remove trailing slash.', location = req.url)
else:
raise HTTPNotFound('Requested route %s cannot be matched.' % context.request.path_url)
except RoutesException:
raise HTTPNotFound('Requested route %s cannot be matched.' % context.request.path_url, exc_info = True)
ctrl = self._controllers.get(context.match_dict.get('controller'))
# TODO: test if callable and raise ControllerNotInitializedProperly respectively
ctrl(context)
return context.response(environ, start_response) # context.return_response()