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


Python WbResponse.text_response方法代码示例

本文整理汇总了Python中pywb.framework.wbrequestresponse.WbResponse.text_response方法的典型用法代码示例。如果您正苦于以下问题:Python WbResponse.text_response方法的具体用法?Python WbResponse.text_response怎么用?Python WbResponse.text_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pywb.framework.wbrequestresponse.WbResponse的用法示例。


在下文中一共展示了WbResponse.text_response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_cert_install

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [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 = ''
            with open(self.ca.ca_file, 'rb') as fh:
                buff = fh.read()

            content_type = 'application/x-x509-ca-cert'

            return WbResponse.text_response(buff,
                                            content_type=content_type)

        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'

            return WbResponse.text_response(buff,
                                            content_type=content_type)
开发者ID:robertknight,项目名称:pywb,代码行数:35,代码来源:proxy.py

示例2: _get_video_info

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
    def _get_video_info(self, wbrequest, info_url=None, video_url=None):
        if not video_url:
            video_url = wbrequest.wb_url.url

        if not info_url:
            info_url = wbrequest.wb_url.url

        cache_key = None
        if self.recording:
            cache_key = self._get_cache_key('v:', video_url)

        info = self.live_fetcher.get_video_info(video_url)
        if info is None:  #pragma: no cover
            msg = ('youtube-dl is not installed, pip install youtube-dl to ' +
                   'enable improved video proxy')

            return WbResponse.text_response(text=msg, status='404 Not Found')

        #if info and info.formats and len(info.formats) == 1:

        content_type = self.YT_DL_TYPE
        metadata = json.dumps(info)

        if (self.recording and cache_key):
            headers = self._live_request_headers(wbrequest)
            headers['Content-Type'] = content_type

            if info_url.startswith('https://'):
                info_url = info_url.replace('https', 'http', 1)

            response = self.live_fetcher.add_metadata(info_url, headers, metadata)

            self._cache[cache_key] = '1'

        return WbResponse.text_response(metadata, content_type=content_type)
开发者ID:Orbiter,项目名称:pywb,代码行数:37,代码来源:live_rewrite_handler.py

示例3: render_response

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
 def render_response(self, status='200 OK', content_type='text/html; charset=utf-8', **template_kwargs):
     template_context = dict(
         template_kwargs,
         status=status,
         content_type=content_type)
     template_result = loader.render_to_string(self.filename, template_context, request=self.fake_request)
     return WbResponse.text_response(unicode(template_result), status=status, content_type=content_type)
开发者ID:ikreymer,项目名称:perma,代码行数:9,代码来源:pywb_config.py

示例4: render_response

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
 def render_response(self, **kwargs):
     template_result = self.render_to_string(**kwargs)
     status = kwargs.get('status', '200 OK')
     content_type = kwargs.get('content_type', 'text/html; charset=utf-8')
     return WbResponse.text_response(template_result,
                                     status=status,
                                     content_type=content_type)
开发者ID:chdorner,项目名称:pywb,代码行数:9,代码来源:views.py

示例5: render_search_page

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
 def render_search_page(self, wbrequest, **kwargs):
     if self.search_view:
         return self.search_view.render_response(wbrequest=wbrequest,
                                                 prefix=wbrequest.wb_prefix,
                                                 **kwargs)
     else:
         return WbResponse.text_response('No Lookup Url Specified')
开发者ID:jasonliw93,项目名称:recon,代码行数:9,代码来源:handlers.py

示例6: render_response

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
 def render_response(self, **kwargs):
     template_result = self.render_to_string(**dict(kwargs,
                                                  STATIC_URL=settings.STATIC_URL,
                                                  DEBUG=settings.DEBUG))
     status = kwargs.get('status', '200 OK')
     content_type = kwargs.get('content_type', 'text/html; charset=utf-8')
     return WbResponse.text_response(template_result.encode('utf-8'), status=status, content_type=content_type)
开发者ID:allmende,项目名称:perma,代码行数:9,代码来源:pywb_config.py

示例7: test_resp_1

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
def test_resp_1():
    resp = vars(WbResponse.text_response('Test'))

    expected = {'body': [b'Test'], 'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK',
                headers = [('Content-Type', 'text/plain; charset=utf-8'), ('Content-Length', '4')])}

    assert(resp == expected)
开发者ID:chdorner,项目名称:pywb,代码行数:9,代码来源:test_wbrequestresponse.py

示例8: __call__

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
    def __call__(self, wbrequest):
        wb_url = wbrequest.wb_url

        res = redis_client.get_all_embeds(wb_url)

        return WbResponse.text_response(json.dumps(res),
                                        content_type='application/json')
开发者ID:theletterf,项目名称:memento-reconstruct,代码行数:9,代码来源:mementohandler.py

示例9: test_resp_4

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
def test_resp_4():
    resp = vars(WbResponse.text_response('Test').add_range(10, 4, 100))

    expected = {'body': [b'Test'], 'status_headers': StatusAndHeaders(protocol = '', statusline = '206 Partial Content',
                headers = [ ('Content-Type', 'text/plain; charset=utf-8'),
                  ('Content-Length', '4'),
                  ('Content-Range', 'bytes 10-13/100'),
                  ('Accept-Ranges', 'bytes')])}

    assert(resp == expected)
开发者ID:chdorner,项目名称:pywb,代码行数:12,代码来源:test_wbrequestresponse.py

示例10: _get_video_info

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
    def _get_video_info(self, wbrequest, info_url=None, video_url=None):
        if not self.youtubedl:
            self.youtubedl = YoutubeDLWrapper()

        if not video_url:
            video_url = wbrequest.wb_url.url

        if not info_url:
            info_url = wbrequest.wb_url.url

        cache_key = None
        if self.proxies:
            cache_key = self._get_cache_key('v:', video_url)

        info = self.youtubedl.extract_info(video_url)
        if info is None:  #pragma: no cover
            msg = ('youtube-dl is not installed, pip install youtube-dl to ' +
                   'enable improved video proxy')

            return WbResponse.text_response(text=msg, status='404 Not Found')

        #if info and info.formats and len(info.formats) == 1:

        content_type = self.YT_DL_TYPE
        metadata = json.dumps(info)

        if (self.proxies and cache_key):
            headers = self._live_request_headers(wbrequest)
            headers['Content-Type'] = content_type

            info_url = HttpsUrlRewriter.remove_https(info_url)

            response = requests.request(method='PUTMETA',
                                        url=info_url,
                                        data=metadata,
                                        headers=headers,
                                        proxies=self.proxies,
                                        verify=False)

            self._cache[cache_key] = '1'

        return WbResponse.text_response(metadata, content_type=content_type)
开发者ID:robertknight,项目名称:pywb,代码行数:44,代码来源:live_rewrite_handler.py

示例11: check_single_url

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
    def check_single_url(self, wbrequest, perms_checker):
        urlkey = self.url_canon(wbrequest.wb_url.url)

        if not perms_checker.allow_url_lookup(urlkey):
            response_text = BLOCK
        else:
            response_text = ALLOW

        #TODO: other types of checking
        return WbResponse.text_response(response_text,
                                        content_type=RESPONSE_TYPE)
开发者ID:Orbiter,项目名称:pywb,代码行数:13,代码来源:perms_handler.py

示例12: _make_response

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_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")
            tpl_name = self.templates.get(content_type)

            if tpl_name is not None:
                tpl = env.get_template(tpl_name)
                result = tpl.render(url=wbrequest.wb_url.url)
                return WbResponse.text_response(result.encode("utf-8-sig"), content_type="text/html")

        return super(TemplateRewriteHandler, self)._make_response(wbrequest, status_headers, gen, is_rewritten)
开发者ID:robertknight,项目名称:via,代码行数:14,代码来源:rewriter.py

示例13: handle_exception

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [as 别名]
    def handle_exception(self, env, exc, print_trace):
        error_view = None

        if hasattr(self.wb_router, 'error_view'):
            error_view = self.wb_router.error_view

        if hasattr(exc, 'status'):
            status = exc.status()
        else:
            status = '500 Internal Server Error'

        if hasattr(exc, 'url'):
            err_url = exc.url
        else:
            err_url = None

        if len(exc.args):
            err_msg = exc.args[0]

        if print_trace:
            import traceback
            err_details = traceback.format_exc()
            print(err_details)
        else:
            logging.info(err_msg)
            err_details = None

        if error_view:
            if err_url and isinstance(err_url, str):
                err_url = to_native_str(err_url, 'utf-8')
            if err_msg and isinstance(err_msg, str):
                err_msg = to_native_str(err_msg, 'utf-8')

            return error_view.render_response(exc_type=type(exc).__name__,
                                              err_msg=err_msg,
                                              err_details=err_details,
                                              status=status,
                                              env=env,
                                              err_url=err_url)
        else:
            msg = status + ' Error: '
            if err_msg:
                msg += err_msg

            #msg = msg.encode('utf-8', 'ignore')
            return WbResponse.text_response(msg,
                                           status=status)
开发者ID:flinkt,项目名称:pywb,代码行数:49,代码来源:wsgi_wrappers.py

示例14: __call__

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_response [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

示例15: _make_response

# 需要导入模块: from pywb.framework.wbrequestresponse import WbResponse [as 别名]
# 或者: from pywb.framework.wbrequestresponse.WbResponse import text_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")
            cleaned_content_type = _lookup_key(content_type)
            tpl_name = self.templates.get(cleaned_content_type)

            if tpl_name is not None:
                tpl = env.get_template(tpl_name)
                tpl_params = {"url": wbrequest.wb_url.url}
                tpl_params.update(wbrequest.env.get("pywb.template_params", {}))
                result = tpl.render(**tpl_params)
                return WbResponse.text_response(
                    result.encode("utf-8-sig"), content_type=b"text/html; charset=utf-8"
                )

        return super(TemplateRewriteHandler, self)._make_response(
            wbrequest, status_headers, gen, is_rewritten
        )
开发者ID:hypothesis,项目名称:via,代码行数:21,代码来源:rewriter.py


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