本文整理汇总了Python中pywb.framework.wbrequestresponse.WbResponse.text_stream方法的典型用法代码示例。如果您正苦于以下问题:Python WbResponse.text_stream方法的具体用法?Python WbResponse.text_stream怎么用?Python WbResponse.text_stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywb.framework.wbrequestresponse.WbResponse
的用法示例。
在下文中一共展示了WbResponse.text_stream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_stream [as 别名]
def __call__(self, wbrequest):
url = wbrequest.wb_url_str.split('?')[0]
full_path = self.static_path + url
try:
data = self.block_loader.load(full_path)
data.seek(0, 2)
size = data.tell()
data.seek(0)
headers = [('Content-Length', str(size))]
if 'wsgi.file_wrapper' in wbrequest.env:
reader = wbrequest.env['wsgi.file_wrapper'](data)
else:
reader = iter(lambda: data.read(), '')
content_type = 'application/octet-stream'
guessed = mimetypes.guess_type(full_path)
if guessed[0]:
content_type = guessed[0]
return WbResponse.text_stream(reader,
content_type=content_type,
headers=headers)
except IOError:
raise NotFoundException('Static File Not Found: ' +
wbrequest.wb_url_str)
示例2: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_stream [as 别名]
def __call__(self, wbrequest):
params = self.extract_params_from_wsgi_env(wbrequest.env)
cdx_iter = self.index_handler.load_cdx(wbrequest, params)
return WbResponse.text_stream(cdx_iter,
content_type='text/plain')
示例3: make_cdx_response
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_stream [as 别名]
def make_cdx_response(self, wbrequest, cdx_iter, output, **kwargs):
# if not text, the iterator is assumed to be CDXObjects
if output and output != 'text':
view = self.views.get(output)
if view:
return view.render_response(wbrequest, cdx_iter, **kwargs)
return WbResponse.text_stream(cdx_iter)
示例4: render_response
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_stream [as 别名]
def render_response(self, wbrequest, cdx_lines, **kwargs):
memento_lines = make_timemap(wbrequest, cdx_lines)
new_memento_lines = self.fix_timegate_line(memento_lines)
response = WbResponse.text_stream(new_memento_lines, content_type=LINK_FORMAT, )
response.status_headers.headers.append(('Cache-Control',
'max-age={}'.format(settings.CACHE_MAX_AGES['timemap'])))
return response
示例5: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_stream [as 别名]
def __call__(self, wbrequest):
params = self.extract_params_from_wsgi_env(wbrequest.env)
try:
cdx_iter = self.index_handler.load_cdx(wbrequest, params)
except NotFoundException:
msg = 'No Captures found for: ' + params.get('url')
if params.get('output') == 'json':
msg = json.dumps(dict(error=msg))
content_type='application/json'
else:
content_type='text/plain'
return WbResponse.text_response(msg, content_type=content_type,
status='404 Not Found')
return WbResponse.text_stream(cdx_iter,
content_type='text/plain')
示例6: render_response
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_stream [as 别名]
def render_response(self, wbrequest, cdx_lines, **kwargs):
memento_lines = make_timemap(wbrequest, cdx_lines)
return WbResponse.text_stream(memento_lines, content_type=LINK_FORMAT)