def make_socks5(loop, *, addr=None, auth=None, rr=True, dst=None, r=None, ap_factory=None, whiter=None): addr = addr or aiosocks.Socks5Addr('localhost', 1080) auth = auth or aiosocks.Socks5Auth('user', 'pwd') dst = dst or ('python.org', 80) proto = aiosocks.Socks5Protocol(proxy=addr, proxy_auth=auth, dst=dst, remote_resolve=rr, loop=loop, app_protocol_factory=ap_factory, waiter=whiter) proto._stream_writer = mock.Mock() proto._stream_writer.drain = fake_coroutine(True) if not isinstance(r, (list, tuple)): proto.read_response = mock.Mock( side_effect=coro(mock.Mock(return_value=r))) else: proto.read_response = mock.Mock( side_effect=coro(mock.Mock(side_effect=r))) proto._get_dst_addr = mock.Mock( side_effect=coro(mock.Mock(return_value=(socket.AF_INET, '127.0.0.1')))) return proto
def make_socks4(loop, *, addr=None, auth=None, rr=True, dst=None, r=b'', ap_factory=None, whiter=None): addr = addr or aiosocks.Socks4Addr('localhost', 1080) auth = auth or aiosocks.Socks4Auth('user') dst = dst or ('python.org', 80) proto = aiosocks.Socks4Protocol(proxy=addr, proxy_auth=auth, dst=dst, remote_resolve=rr, loop=loop, app_protocol_factory=ap_factory, waiter=whiter) proto._stream_writer = mock.Mock() proto.read_response = mock.Mock(side_effect=coro(mock.Mock( return_value=r))) proto._get_dst_addr = mock.Mock( side_effect=coro(mock.Mock(return_value=(socket.AF_INET, '127.0.0.1')))) return proto
def _py_backwards_async_generator(func): @functools_wraps(func) def wrapper(*args, **kwargs): return AsyncGenerator(coro_func(*args, **kwargs)) coro_func = coro(func) return wrapper
def make_socks4(loop, *, addr=None, auth=None, rr=True, dst=None, r=b'', ap_factory=None, whiter=None): addr = addr or aiosocks.Socks4Addr('localhost', 1080) auth = auth or aiosocks.Socks4Auth('user') dst = dst or ('python.org', 80) proto = aiosocks.Socks4Protocol( proxy=addr, proxy_auth=auth, dst=dst, remote_resolve=rr, loop=loop, app_protocol_factory=ap_factory, waiter=whiter) proto._stream_writer = mock.Mock() proto.read_response = mock.Mock( side_effect=coro(mock.Mock(return_value=r))) proto._get_dst_addr = mock.Mock( side_effect=coro(mock.Mock(return_value=(socket.AF_INET, '127.0.0.1'))) ) return proto
def make_socks5(loop, *, addr=None, auth=None, rr=True, dst=None, r=None, ap_factory=None, whiter=None): addr = addr or aiosocks.Socks5Addr('localhost', 1080) auth = auth or aiosocks.Socks5Auth('user', 'pwd') dst = dst or ('python.org', 80) proto = aiosocks.Socks5Protocol( proxy=addr, proxy_auth=auth, dst=dst, remote_resolve=rr, loop=loop, app_protocol_factory=ap_factory, waiter=whiter) proto._stream_writer = mock.Mock() proto._stream_writer.drain = fake_coroutine(True) if not isinstance(r, (list, tuple)): proto.read_response = mock.Mock( side_effect=coro(mock.Mock(return_value=r))) else: proto.read_response = mock.Mock( side_effect=coro(mock.Mock(side_effect=r))) proto._get_dst_addr = mock.Mock( side_effect=coro(mock.Mock(return_value=(socket.AF_INET, '127.0.0.1'))) ) return proto