def fetcher(self): request = Get(self.url, headers=self.headers, auth=self.auth, attempts=self.attempts) self.task.add(request, ResponseHandle.ERROR, ResponseHandle.DONE) request.add_map('200', self.handle_success) return request
class TestGet2(unittest.TestCase): def setUp(self): self.url = 'https://httpbin.org/get?e=1&u=2' auth = TokenAuth('fooobar') self.request = Get(self.url, auth=auth) self.request.add_map(ResponseHandle.DONE, self.handle_done) def handle_done(self, request, response): response_data = response.content() response_data = json.loads(response_data) self.assertEqual(self.url, response_data['url']) die() def test_get(self): core.gear.mainloop()
class TestGet0(unittest.TestCase): def setUp(self): url = 'http://httpbin.org/get' self.args = {'key0': 'value0', 'key1': 'value2'} self.request = Get(url, args=self.args) self.request.add_map(ResponseHandle.DONE, self.handle_done) def handle_done(self, request, response): response_data = json.loads(response.content()) self.assertTrue(response_data['args'], self.args) die() def test_get(self): core.gear.mainloop()
class TestGet1(unittest.TestCase): def setUp(self): url = 'https://httpbin.org/get' auth = BasicAuth('username', 'foobar') self.request = Get(url, auth=auth) self.request.add_map(ResponseHandle.DONE, self.handle_done) def handle_done(self, request, response): response_data = response.content() response_data = json.loads(response_data) authorization = response_data['headers']['Authorization'] self.assertEqual(authorization, request.headers['authorization']) die() def test_get(self): core.gear.mainloop()
""" """ from websnake import Get, ResponseHandle, core, RequestPool, die def handle_done(request, response): print('Headers:', response.headers) print('Code:', response.code) print('Version:', response.version) print('Reason:', response.reason) def handle_empty(pool): print('All requests done!') die('Stopping...') if __name__ == '__main__': urls = ('https://en.wikipedia.org/wiki/Leonhard_Euler', 'https://www.google.com.br','https://facebook.com/') pool = RequestPool() pool.add_map(RequestPool.EMPTY, handle_empty) for ind in urls: Get(ind, pool=pool).add_map(ResponseHandle.DONE, handle_done) core.gear.mainloop()
def setUp(self): url = 'http://httpbin.org/get' self.args = {'key0': 'value0', 'key1': 'value2'} self.request = Get(url, args=self.args) self.request.add_map(ResponseHandle.DONE, self.handle_done)
def setUp(self): self.url = 'https://httpbin.org/get?e=1&u=2' auth = TokenAuth('fooobar') self.request = Get(self.url, auth=auth) self.request.add_map(ResponseHandle.DONE, self.handle_done)
def setUp(self): url = 'https://httpbin.org/get' auth = BasicAuth('username', 'foobar') self.request = Get(url, auth=auth) self.request.add_map(ResponseHandle.DONE, self.handle_done)
from websnake import Get, ResponseHandle, core, die def handle_done(request, response): print('Headers:', response.headers) print('Code:', response.code) print('Version:', response.version) print('Reason:', response.reason) print('Data:', response.content()) die('Request done.') if __name__ == '__main__': request = Get('https://www.google.com.br/') request.add_map('200', handle_done) core.gear.mainloop()
from websnake import Get, BasicAuth, ResponseHandle, core, die def handle_response(request, response): print('Headers:', response.headers) print('Code:', response.code) print('Version:', response.version) print('Reason:', response.reason) if __name__ == '__main__': request = Get('http://httpbin.org/get', auth=BasicAuth('foo', 'bar')) request.add_map(ResponseHandle.RESPONSE, handle_response) request.add_map(ResponseHandle.DONE, lambda req, resp: die('Bye!')) core.gear.mainloop()
from websnake import Get, ResponseHandle, core, die def on_response(request, response): print('Headers:', response.headers) print('Code:', response.code) print('Version:', response.version) print('Reason:', response.reason) print('Data:', response.fd.read()) die('Request done.') if __name__ == '__main__': request = Get('http://codepad.org/') request.add_map(ResponseHandle.RESPONSE, on_response) core.gear.mainloop()
from websnake import Get, ResponseHandle, core, die def handle_response(request, response): print('Headers:', response.headers) print('Code:', response.code) print('Version:', response.version) print('Reason:', response.reason) if __name__ == '__main__': request = Get('https://facebook.com/') request.add_map(ResponseHandle.RESPONSE, handle_response) request.add_map(ResponseHandle.DONE, lambda req, resp: die('Bye!')) core.gear.mainloop()