本文整理汇总了Python中pywb.framework.wbrequestresponse.WbResponse.bin_stream方法的典型用法代码示例。如果您正苦于以下问题:Python WbResponse.bin_stream方法的具体用法?Python WbResponse.bin_stream怎么用?Python WbResponse.bin_stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywb.framework.wbrequestresponse.WbResponse
的用法示例。
在下文中一共展示了WbResponse.bin_stream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import bin_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(), b'')
content_type = 'application/octet-stream'
guessed = mimetypes.guess_type(full_path)
if guessed[0]:
content_type = guessed[0]
return WbResponse.bin_stream(reader,
content_type=content_type,
headers=headers)
except IOError:
raise NotFoundException('Static File Not Found: ' +
wbrequest.wb_url_str)
示例2: test_resp_2
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import bin_stream [as 别名]
def test_resp_2():
resp = vars(WbResponse.bin_stream([b'Test', b'Another'], content_type='text/plain; charset=utf-8', status='404'))
expected = {'body': [b'Test', b'Another'], 'status_headers': StatusAndHeaders(protocol = '', statusline = '404',
headers = [('Content-Type', 'text/plain; charset=utf-8')])}
assert(resp == expected)
示例3: handle_cert_install
# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import bin_stream [as 别名]
def handle_cert_install(self, env):
if env['pywb.proxy_req_uri'] in ('/', '/index.html', '/index.html'):
available = (self.ca is not None)
if self.proxy_cert_dl_view:
return (self.proxy_cert_dl_view.
render_response(available=available,
pem_path=self.CERT_DL_PEM,
p12_path=self.CERT_DL_P12))
elif env['pywb.proxy_req_uri'] == self.CERT_DL_PEM:
if not self.ca:
return None
buff = b''
with open(self.ca.ca_file, 'rb') as fh:
buff = fh.read()
content_type = 'application/x-x509-ca-cert'
headers = [('Content-Length', str(len(buff)))]
return WbResponse.bin_stream([buff],
content_type=content_type,
headers=headers)
elif env['pywb.proxy_req_uri'] == self.CERT_DL_P12:
if not self.ca:
return None
buff = self.ca.get_root_PKCS12()
content_type = 'application/x-pkcs12'
headers = [('Content-Length', str(len(buff)))]
return WbResponse.bin_stream([buff],
content_type=content_type,
headers=headers)