本文整理汇总了Python中pywb.framework.wbrequestresponse.WbResponse.redir_response方法的典型用法代码示例。如果您正苦于以下问题:Python WbResponse.redir_response方法的具体用法?Python WbResponse.redir_response怎么用?Python WbResponse.redir_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywb.framework.wbrequestresponse.WbResponse
的用法示例。
在下文中一共展示了WbResponse.redir_response方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def __call__(self, wbrequest):
"""
If someone requests a bare GUID url like /warc/1234-5678/, forward them to the submitted_url playback for that GUID.
"""
if wbrequest.wb_url_str == '/':
return WbResponse.redir_response("%s/%s/%s" % (settings.WARC_ROUTE, wbrequest.custom_params['guid'], wbrequest.custom_params['url']), status='301 Moved Permanently')
return super(PermaGUIDHandler, self).__call__(wbrequest)
示例2: test_resp_3
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def test_resp_3():
resp = vars(WbResponse.redir_response('http://example.com/otherfile'))
expected = {'body': [], 'status_headers': StatusAndHeaders(protocol = '', statusline = '302 Redirect',
headers = [('Location', 'http://example.com/otherfile'), ('Content-Length', '0')])}
assert(resp == expected)
示例3: make_redir_response
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def make_redir_response(self, url, headers=None):
if not headers:
headers = []
if self.extra_headers:
for name, value in six.iteritems(self.extra_headers):
headers.append((name, value))
return WbResponse.redir_response(url, headers=headers)
示例4: _make_response
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def _make_response(self, wbrequest, status_headers, gen, is_rewritten):
# only redirect for non-identity and non-embeds
if not wbrequest.wb_url.is_embed and not wbrequest.wb_url.is_identity:
content_type = status_headers.get_header('Content-Type')
redir = self.redirects.get(content_type)
if redir:
return WbResponse.redir_response(redir.format(wbrequest.wb_url.url))
return super(CustomRedirHandler, self)._make_response(wbrequest,
status_headers,
gen,
is_rewritten)
示例5: _make_response
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def _make_response(self, wbrequest, status_headers, gen, is_rewritten):
# only redirect for non-identity and non-embeds
if not wbrequest.wb_url.is_embed and not wbrequest.wb_url.is_identity:
content_type = status_headers.get_header('Content-Type')
redir = self.redirects.get(content_type)
# safe is used so output matches JavaScript's encodeURIComponent()
url = urllib.quote(unicode(wbrequest.wb_url.url).encode('utf-8'),
safe='~()*!.\'')
if redir:
return WbResponse.redir_response(redir.format(url))
return super(CustomRedirHandler, self)._make_response(wbrequest,
status_headers,
gen,
is_rewritten)
示例6: handle_request
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def handle_request(self, wbrequest):
if wbrequest.wb_url.is_query():
type_ = wbrequest.wb_url.LATEST_REPLAY
url = wbrequest.urlrewriter.get_new_url(type=type_, timestamp='')
return WbResponse.redir_response(url)
try:
return self.render_content(wbrequest)
except Exception as exc:
import traceback
err_details = traceback.format_exc(exc)
print err_details
url = wbrequest.wb_url.url
msg = 'Could not load the url from the live web: ' + url
raise LiveResourceException(msg=msg, url=url)
示例7: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def __call__(self, wbrequest):
if wbrequest.wb_url_str == '/':
wbrequest.wb_url_str = ''
return WbResponse.redir_response(self.redir_path + wbrequest.wb_url_str,
self.status)
示例8: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def __call__(self, env, the_router):
referrer = env.get('HTTP_REFERER')
routes = the_router.routes
# ensure there is a referrer
if referrer is None:
return None
# get referrer path name
ref_split = urlsplit(referrer)
# require that referrer starts with current Host, if any
curr_host = env.get('HTTP_HOST')
if curr_host and curr_host != ref_split.netloc:
return None
path = ref_split.path
app_path = env.get('SCRIPT_NAME', '')
if app_path:
# must start with current app name, if not root
if not path.startswith(app_path):
return None
path = path[len(app_path):]
ref_route = None
ref_request = None
for route in routes:
matcher, coll = route.is_handling(path)
if matcher:
ref_request = the_router.parse_request(route, env,
matcher, coll, path)
ref_route = route
break
# must have matched one of the routes with a urlrewriter
if not ref_request or not ref_request.urlrewriter:
return None
rewriter = ref_request.urlrewriter
rel_request_uri = env['REL_REQUEST_URI']
timestamp_path = '/' + rewriter.wburl.timestamp + '/'
# check if timestamp is already part of the path
if rel_request_uri.startswith(timestamp_path):
# remove timestamp but leave / to make host relative url
# 2013/path.html -> /path.html
rel_request_uri = rel_request_uri[len(timestamp_path) - 1:]
rewritten_url = rewriter.rewrite(rel_request_uri)
# if post, can't redirect as that would lost the post data
# (can't use 307 because FF will show confirmation warning)
if ref_request.method == 'POST':
new_wb_url = WbUrl(rewritten_url[len(rewriter.prefix):])
ref_request.wb_url.url = new_wb_url.url
return ref_route.handler(ref_request)
final_url = urlunsplit((ref_split.scheme,
ref_split.netloc,
rewritten_url,
'',
''))
return WbResponse.redir_response(final_url, status='302 Temp Redirect')
示例9: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import redir_response [as 别名]
def __call__(self, wbrequest):
return WbResponse.redir_response(self.redir_path + wbrequest.wb_url_str)