当前位置: 首页>>代码示例>>Python>>正文


Python WbResponse.text_stream方法代码示例

本文整理汇总了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)
开发者ID:robertknight,项目名称:pywb,代码行数:32,代码来源:handlers.py

示例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')
开发者ID:chdorner,项目名称:pywb,代码行数:9,代码来源:cdx_api_handler.py

示例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)
开发者ID:jcushman,项目名称:pywb,代码行数:10,代码来源:query_handler.py

示例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
开发者ID:ikreymer,项目名称:perma,代码行数:12,代码来源:pywb_config.py

示例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')
开发者ID:daleathan,项目名称:pywb,代码行数:20,代码来源:cdx_api_handler.py

示例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)
开发者ID:peval,项目名称:pywb,代码行数:5,代码来源:views.py


注:本文中的pywb.framework.wbrequestresponse.WbResponse.text_stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。