def test_AsyncClient_core(self): async_client = AsyncClient(size=20) self.assertEquals(async_client._num_conn, 20) self.assertEquals(async_client._remaining, 0) self.assertEquals(async_client.success_callback, None) self.assertEquals(async_client.fail_callback, None) self.assertEquals(async_client._openers_pool, None) self.assertEquals(async_client._data_queue, []) self.assertEquals(async_client.connections_count, 0) async_client.add_handler(url=build_url("/get"), method="get", params={"get1": "get1 value", "get2": "get2 value"}, success_callback=self.success_callback, fail_callback=self.fail_callback) self.assertEquals(len(async_client._data_queue), 1) self.assertTrue(isinstance(async_client._data_queue[0], dict)) params = self.random_dict(10) async_client.get(url=build_url("/get"), params=params, success_callback=self.success_callback, fail_callback=self.fail_callback) self.assertTrue(isinstance(async_client._data_queue[1], dict)) self.assertEquals(async_client._data_queue[1]['params'], params) self.assertEquals(async_client.connections_count, 2)
def test_add_handler(self): async_client = AsyncClient() data = self.request_params() self.assertRaises(InterfaceError, async_client.add_handler, **data) data['success_callback'] = lambda **kwargs: kwargs data['fail_callback'] = lambda **kwargs: kwargs async_client.add_handler(**data) self.assertEquals(async_client._data_queue[0], data) self.assertEquals(async_client._num_urls, 1) self.assertEquals(async_client._remaining, 1)
# get_ip() url = 'https://blog.csdn.net/fly_zhyu/article/details/76408158' client = AsyncClient(success_callback=success_call, fail_callback=fail_call) # request = Request(network_interface='185.101.107.106',method='GET', url=url) # print(request.response) # request.send() # response = request.response # print(response.content) # print(request.make_response()) # request._network_interface='172.17.35.241' # # # opener = pycurl.Curl() da = { 'network_interface': 'eth0:5', } da = { 'network_interface': '185.101.107.122', } client.add_handler(**da) # client.configure_opener(opener, data=da) client.get(url) client.start() # import lz4 # # egg: http://python-lz4.readthedocs.io/en/stable/quickstart.html#simple-usage # compressed = lz4.frame.compress('10111001110010111010111111010') # decompressed = lz4.frame.decompress(compressed) # print(decompressed)