Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_user_not_absolute_home():
with pytest.raises(aioftp.errors.PathIsNotAbsolute):
aioftp.User(home_path="foo")
try:
priority, port = self.available_data_ports.get_nowait()
if port in viewed_ports:
raise errors.NoAvailablePort
viewed_ports.add(port)
passive_server = await asyncio.start_server(
handler_callback,
connection.server_host,
port,
ssl=self.ssl,
**self._start_server_extra_arguments,
)
connection.passive_server_port = port
break
except asyncio.QueueEmpty:
raise errors.NoAvailablePort
except OSError as err:
self.available_data_ports.put_nowait((priority + 1, port))
if err.errno != errno.EADDRINUSE:
raise
else:
passive_server = await asyncio.start_server(
handler_callback,
connection.server_host,
connection.passive_server_port,
ssl=self.ssl,
**self._start_server_extra_arguments,
)
return passive_server
host = host_parts.split("/")[0]
path = "/".join(host_parts.split("/")[1:])
try:
digest = None
with async_timeout.timeout(timeout):
fail_mode, digest = await ftp_fetch(host, path, outfile, digest_func)
except asyncio.TimeoutError as e:
fail_mode = "timeout"
continue
except socket.gaierror as e:
fail_mode = "dnsfail"
continue
except OSError:
fail_mode = "refused"
continue
except aioftp.errors.StatusCodeError:
fail_mode = "ftp_code"
continue
except Exception as e:
fail_mode = str(e)
raise
print("Download failure:", fail_mode)
continue
else:
# handle http/https download --
try:
digest = None
with async_timeout.timeout(timeout):
fail_mode, digest = await http_fetch(real_uri, outfile, digest_func)
except asyncio.TimeoutError as e:
fail_mode = "timeout"
continue
self.greeting(connection, ""),
self.response_writer(stream, response_queue),
self.parse_command(stream),
}
self.connections[key] = connection
try:
while True:
done, pending = await asyncio.wait(
pending | connection.extra_workers,
return_when=asyncio.FIRST_COMPLETED,
)
connection.extra_workers -= done
for task in done:
try:
result = task.result()
except errors.PathIOError:
connection.response("451", "file system error")
continue
# this is "command" result
if isinstance(result, bool):
if not result:
await response_queue.join()
return
# this is parse_command result
elif isinstance(result, tuple):
pending.add(self.parse_command(stream))
cmd, rest = result
if cmd == "pass":
# is there a better solution?
cmd = "pass_"
if hasattr(self, cmd):
pending.add(getattr(self, cmd)(connection, rest))
async def wrapper(*args, **kwargs):
try:
return await coro(*args, **kwargs)
except (asyncio.CancelledError, NotImplementedError,
StopAsyncIteration):
raise
except Exception:
raise errors.PathIOError(reason=sys.exc_info())
login=None,
password=None, *,
base_path=pathlib.Path("."),
home_path=pathlib.PurePosixPath("/"),
permissions=None,
maximum_connections=None,
read_speed_limit=None,
write_speed_limit=None,
read_speed_limit_per_connection=None,
write_speed_limit_per_connection=None):
self.login = login
self.password = password
self.base_path = pathlib.Path(base_path)
self.home_path = pathlib.PurePosixPath(home_path)
if not self.home_path.is_absolute():
raise errors.PathIsNotAbsolute(home_path)
self.permissions = permissions or [Permission()]
self.maximum_connections = maximum_connections
self.read_speed_limit = read_speed_limit
self.write_speed_limit = write_speed_limit
self.read_speed_limit_per_connection = read_speed_limit_per_connection
# damn 80 symbols
self.write_speed_limit_per_connection = \
write_speed_limit_per_connection