本文整理汇总了Python中trac.web.api.Request.redirect方法的典型用法代码示例。如果您正苦于以下问题:Python Request.redirect方法的具体用法?Python Request.redirect怎么用?Python Request.redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.web.api.Request
的用法示例。
在下文中一共展示了Request.redirect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: my_redirect
# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import redirect [as 别名]
def my_redirect(*args, **kwords):
# Munge the cookie path
if 'trac_auth' in req.outcookie:
assert not self.uri_root.startswith('http'), 'The tracforge uri_root must be set to relative path'
req.outcookie['trac_auth']['path'] = self.uri_root
# Check to see if we should refer back to sibling Trac
referer = req.args.get('referer')
self.log.debug('TracForgeCookieMunger: Got referer as %r'%referer)
if referer:
parts = urlsplit(referer or '')
self.log.debug('TracForgeCookieMunger: parts=%s name=%r'%(parts,req.server_name))
if parts[2].startswith(self.uri_root) and (not parts[1] or parts[1] == req.server_name):
Request.redirect(req, referer)
old_redirect(req, *args, **kwords)
示例2: dummy_request
# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import redirect [as 别名]
def dummy_request(env, cookies_from=None, query=None):
environ = {
'trac.base_url': env.base_url,
'wsgi.url_scheme': 'http',
'wsgi.input': BytesIO(),
'SCRIPT_NAME': '/trac.cgi',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': 'example.org',
'SERVER_PORT': '80',
'HTTP_HOST': 'example.org',
}
if query:
environ['QUERY_STRING'] = urlencode(query)
if cookies_from:
outcookie = cookies_from.outcookie
cookie = '; '.join('%s=%s' % (name, morsel.value)
for name, morsel in outcookie.items())
environ['HTTP_COOKIE'] = cookie
start_response = mock.Mock(name='start_response')
req = Request(environ, start_response)
req.session = {}
req.chrome = {'warnings': [], 'notices': []}
req.redirect = mock.Mock(name='req.redirect', spec=())
req.authname = 'anonymous'
return req
示例3: dummy_request
# 需要导入模块: from trac.web.api import Request [as 别名]
# 或者: from trac.web.api.Request import redirect [as 别名]
def dummy_request(env, uname=None):
environ = {}
setup_testing_defaults(environ)
environ.update({
'REQUEST_METHOD' : 'GET',
'SCRIPT_NAME' : urlparse(str(env._abs_href())).path,
'trac.base_url' : str(env._abs_href()),
})
req = Request(environ, lambda *args, **kwds: None)
# Intercept redirection
req.redirect = lambda *args, **kwds: None
# Setup user information
if uname is not None :
environ['REMOTE_USER'] = req.authname = uname
rd = RequestDispatcher(env)
chrome = Chrome(env)
req.callbacks.update({
'authname': rd.authenticate,
'chrome': chrome.prepare_request,
'hdf': getattr(rd, '_get_hdf', None),
'lc_time': rd._get_lc_time,
'locale' : getattr(rd, '_get_locale', None),
'perm': rd._get_perm,
'session': rd._get_session,
'tz': rd._get_timezone,
'form_token': rd._get_form_token
})
return req