本文整理汇总了Python中pyspider.libs.response.rebuild_response函数的典型用法代码示例。如果您正苦于以下问题:Python rebuild_response函数的具体用法?Python rebuild_response怎么用?Python rebuild_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rebuild_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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,
}
示例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)
示例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)
示例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')
示例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)
示例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)
示例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)
示例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)
示例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')
示例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)
示例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
示例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')
示例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