• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python response.rebuild_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyspider.libs.response.rebuild_response函数的典型用法代码示例。如果您正苦于以下问题:Python rebuild_response函数的具体用法?Python rebuild_response怎么用?Python rebuild_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_a200_robots_txt

    def test_a200_robots_txt(self):
        request = copy.deepcopy(self.sample_task_http)
        request['fetch']['robots_txt'] = False
        request['url'] = self.httpbin+'/deny'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)

        request['fetch']['robots_txt'] = True
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 403, result)
开发者ID:eromoe,项目名称:pyspider,代码行数:14,代码来源:test_fetcher.py


示例2: test_a200_robots_txt

    def test_a200_robots_txt(self):
        request = copy.deepcopy(self.sample_task_http)
        request["fetch"]["robots_txt"] = False
        request["url"] = self.httpbin + "/deny"
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)

        request["fetch"]["robots_txt"] = True
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 403, result)
开发者ID:appleboy1977,项目名称:pyspider,代码行数:14,代码来源:test_fetcher.py


示例3: run

def run(project):
    task = json.loads(request.form['task'])
    project_info = {
            'name': project,
            'status': 'DEBUG',
            'script': request.form['script'],
            }

    fetch_result = {}
    start_time = time.time()
    try:
        fetch_result = app.config['fetch'](task)
        response = rebuild_response(fetch_result)
        module = build_module(project_info, {
            'debugger': True
            })
        ret = module['instance'].run(module['module'], task, response)
    except Exception, e:
        type, value, tb = sys.exc_info()
        tb = hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
                'fetch_result': fetch_result,
                'logs': logs,
                'follows': [],
                'messages': [],
                'result': None,
                'time': time.time() - start_time,
                }
开发者ID:BCriswell,项目名称:pyspider,代码行数:29,代码来源:debug.py


示例4: test_a180_max_redirects

    def test_a180_max_redirects(self):
        request = copy.deepcopy(self.sample_task_http)
        request["fetch"]["max_redirects"] = 10
        request["url"] = self.httpbin + "/redirect/10"
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
开发者ID:appleboy1977,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例5: test_a170_validate_cert

    def test_a170_validate_cert(self):
        request = copy.deepcopy(self.sample_task_http)
        request["fetch"]["validate_cert"] = False
        request["url"] = self.httpbin + "/get"
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
开发者ID:appleboy1977,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例6: test_20_dataurl_get

    def test_20_dataurl_get(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = 'data:,hello'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.text, 'hello')
开发者ID:eromoe,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例7: test_a150_too_much_redirect

    def test_a150_too_much_redirect(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = self.httpbin+'/redirect/10'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 599, result)
        self.assertIn('redirects followed', response.error)
开发者ID:eromoe,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例8: test_a180_max_redirects

    def test_a180_max_redirects(self):
        request = copy.deepcopy(self.sample_task_http)
        request['fetch']['max_redirects'] = 10
        request['url'] = self.httpbin+'/redirect/10'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
开发者ID:eromoe,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例9: test_a160_cookie

    def test_a160_cookie(self):
        request = copy.deepcopy(self.sample_task_http)
        request["url"] = self.httpbin + "/cookies/set?k1=v1&k2=v2"
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
        self.assertEqual(response.cookies, {"a": "b", "k1": "v1", "k2": "v2", "c": "d"}, result)
开发者ID:appleboy1977,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例10: test_a170_validate_cert

    def test_a170_validate_cert(self):
        request = copy.deepcopy(self.sample_task_http)
        request['fetch']['validate_cert'] = False
        request['url'] = self.httpbin+'/get'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
开发者ID:eromoe,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例11: test_40_with_rpc

    def test_40_with_rpc(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = 'data:,hello'
        result = umsgpack.unpackb(self.rpc.fetch(request).data)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.text, 'hello')
开发者ID:eromoe,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例12: test_a160_cookie

    def test_a160_cookie(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = self.httpbin+'/cookies/set?k1=v1&k2=v2'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
        self.assertEqual(response.cookies, {'a': 'b', 'k1': 'v1', 'k2': 'v2', 'c': 'd'}, result)
开发者ID:eromoe,项目名称:pyspider,代码行数:8,代码来源:test_fetcher.py


示例13: get

 def get(self, url, **kwargs):
     if not url.startswith('http://'):
         url = self.httpbin + url
     request = copy.deepcopy(self.sample_task_http)
     request['url'] = url
     request.update(kwargs)
     result = self.fetcher.fetch(request)
     response = rebuild_response(result)
     return response
开发者ID:Dmitry-Kucher,项目名称:pyspider,代码行数:9,代码来源:test_response.py


示例14: test_a140_redirect

    def test_a140_redirect(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = self.httpbin+'/redirect-to?url=/get'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200, result)
        self.assertEqual(response.orig_url, request['url'])
        self.assertEqual(response.url, self.httpbin+'/get')
开发者ID:eromoe,项目名称:pyspider,代码行数:9,代码来源:test_fetcher.py


示例15: test_a120_http_get_with_proxy_fail

    def test_a120_http_get_with_proxy_fail(self):
        self.fetcher.proxy = self.proxy
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = self.httpbin+'/get'
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 403, result)
        self.fetcher.proxy = None
开发者ID:eromoe,项目名称:pyspider,代码行数:9,代码来源:test_fetcher.py


示例16: test_65_418

    def test_65_418(self):
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = self.httpbin+'/status/418'
        self.inqueue.put(request)
        task, result = self.outqueue.get()
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 418)
        self.assertIn('teapot', response.text)
开发者ID:eromoe,项目名称:pyspider,代码行数:9,代码来源:test_fetcher.py


示例17: test_30_with_queue

    def test_30_with_queue(self):
        request= copy.deepcopy(self.sample_task_http)
        request['url'] = 'data:,hello'
        self.inqueue.put(request)
        task, result = self.outqueue.get()
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.text, 'hello')
开发者ID:eromoe,项目名称:pyspider,代码行数:9,代码来源:test_fetcher.py


示例18: test_75_splash_robots

    def test_75_splash_robots(self):
        request = self.sample_task_http
        request['url'] = self.httpbin + '/deny'
        request['fetch']['fetch_type'] = 'splash'
        request['fetch']['robots_txt'] = True
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 403, result)
开发者ID:eromoe,项目名称:pyspider,代码行数:9,代码来源:test_fetcher.py


示例19: run

def run(project):
    task = utils.decode_unicode_obj(json.loads(request.form['task']))
    project_info = {
        'name': project,
        'status': 'DEBUG',
        'script': request.form['script'],
    }

    fetch_result = {}
    start_time = time.time()
    try:
        fetch_result = app.config['fetch'](task)
        response = rebuild_response(fetch_result)
        module = build_module(project_info, {
            'debugger': True
        })
        ret = module['instance'].run(module['module'], task, response)
    except Exception:
        type, value, tb = sys.exc_info()
        tb = utils.hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
            'fetch_result': fetch_result,
            'logs': logs,
            'follows': [],
            'messages': [],
            'result': None,
            'time': time.time() - start_time,
        }
    else:
        result = {
            'fetch_result': fetch_result,
            'logs': ret.logstr(),
            'follows': ret.follows,
            'messages': ret.messages,
            'result': ret.result,
            'time': time.time() - start_time,
        }
        result['fetch_result']['content'] = response.text

    try:
        # binary data can't encode to JSON, encode result as unicode obj
        # before send it to frontend
        return json.dumps(utils.unicode_obj(result)), 200, {'Content-Type': 'application/json'}
    except Exception:
        type, value, tb = sys.exc_info()
        tb = utils.hide_me(tb, globals())
        logs = ''.join(traceback.format_exception(type, value, tb))
        result = {
            'fetch_result': "",
            'logs': logs,
            'follows': [],
            'messages': [],
            'result': None,
            'time': time.time() - start_time,
        }
        return json.dumps(utils.unicode_obj(result)), 200, {'Content-Type': 'application/json'}
开发者ID:7472741,项目名称:pyspider,代码行数:57,代码来源:debug.py


示例20: test_75_phantomjs_robots

    def test_75_phantomjs_robots(self):
        if not self.phantomjs:
            raise unittest.SkipTest('no phantomjs')
        request = copy.deepcopy(self.sample_task_http)
        request['url'] = self.httpbin + '/deny'
        request['fetch']['fetch_type'] = 'phantomjs'
        request['fetch']['robots_txt'] = True
        result = self.fetcher.sync_fetch(request)
        response = rebuild_response(result)

        self.assertEqual(response.status_code, 403, result)
开发者ID:eromoe,项目名称:pyspider,代码行数:11,代码来源:test_fetcher.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.md5string函数代码示例发布时间:2022-05-27
下一篇:
Python multiprocessing_queue.Queue类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap