Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
writer.write(b)
await writer.drain()
await client.command(None, "2xx", "1xx")
await client.quit()
with f.open("rb") as fin:
rb = fin.read()
f.unlink()
nose.tools.eq_(b, rb)
class SlowServer(aioftp.Server):
async def dispatcher(self, reader, writer):
await asyncio.sleep(10, loop=self.loop)
@nose.tools.raises(asyncio.TimeoutError)
def test_client_socket_timeout():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
server = SlowServer(loop=loop)
client = aioftp.Client(loop=loop, socket_timeout=1)
async def coro():
try:
await server.start(None, 8888)
def test_user_manager_timeout():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
server = aioftp.Server(SlowUserManager(None, timeout=1, loop=loop),
loop=loop)
client = aioftp.Client(loop=loop)
async def coro():
try:
await server.start(None, 8888)
await client.connect("127.0.0.1", 8888)
await client.login()
finally:
await server.close()
loop.run_until_complete(coro())
class MyClient(aioftp.Client):
async def collect(self, count):
collected = []
async with self.get_stream("COLL " + str(count), "1xx") as stream:
async for line in stream.iter_by_line():
collected.append(line)
return collected
class MyServer(aioftp.Server):
@aioftp.ConnectionConditions(
aioftp.ConnectionConditions.login_required,
aioftp.ConnectionConditions.passive_server_started)
async def coll(self, connection, rest):
@aioftp.ConnectionConditions(
aioftp.ConnectionConditions.data_connection_made,
wait=True,
fail_code="425",
fail_info="Can't open data connection")
@aioftp.server.worker
async def coll_worker(self, connection, rest):
stream = connection.data_connection
del connection.data_connection
def run_in_loop(s_args, s_kwargs, c_args, c_kwargs, s_ssl=None, c_ssl=None):
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(name)s] %(message)s",
datefmt="[%H:%M:%S]:",
)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)
server = aioftp.Server(*s_args, loop=loop, ssl=s_ssl, **s_kwargs)
client = aioftp.Client(*c_args, loop=loop, ssl=c_ssl, **c_kwargs)
try:
loop.run_until_complete(f(loop, client, server))
finally:
if hasattr(server, "server"):
loop.run_until_complete(server.close())
if hasattr(client, "writer"):
client.close()
loop.close()
def test_server_mtime_build():
now = datetime.datetime(year=2002, month=1, day=1).timestamp()
past = datetime.datetime(year=2001, month=1, day=1).timestamp()
b = aioftp.Server.build_list_mtime
assert b(now, now) == "Jan 1 00:00"
assert b(past, now) == "Jan 1 2001"
)
if args.memory:
user = aioftp.User(args.login, args.password, base_path="/")
path_io_factory = aioftp.MemoryPathIO
else:
if args.home:
user = aioftp.User(args.login, args.password, base_path=args.home)
else:
user = aioftp.User(args.login, args.password)
path_io_factory = aioftp.PathIO
family = {
"ipv4": socket.AF_INET,
"ipv6": socket.AF_INET6,
"auto": socket.AF_UNSPEC,
}[args.family]
server = aioftp.Server([user], path_io_factory=path_io_factory)
loop = asyncio.get_event_loop()
loop.run_until_complete(server.start(args.host, args.port, family=family))
try:
loop.run_forever()
except KeyboardInterrupt:
loop.run_until_complete(server.close())
loop.close()