Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_method(self):
self.bitfield = (
"9e7ef5fbdefdffffdfffffffffffffdf7fff5dfefff7feffefffdff7fffffffbfeffbffddf7de9f7eefffffffeffe77bb"
"f8fdbdcffef7fffffbefad7ffffffbf55bff7edfedfeff7ffff7ffffff3ffff7d3ffbfffddddffe7ffffffffffdedf7fd"
"fef62fbdfffffbffbffdcfaffffafebeff3ebff7d5fffbbb2bafef77ffaffe7d37fbffffffb6dfffffffedfebbecbbffe"
"bdefffffffff977f7ffdffee7fffffffdfeb3f67dddffeedfffffbfffffdaffbfeedfadef6dfd9d2df9fb7f689ffcff3f"
"fbfebbfdbd7fcddfa77dfddffdfe327fdcbf77fad87ffff6ff7ffebfefdfbbffdefdafeefed7fefffe7ffad9ffdcffefc"
"ffbbf3c07ef7fc0"
)
self.download = Download(
API(),
{
"bitfield": self.bitfield,
"bittorrent": {},
"completedLength": "889592532",
"connections": "44",
"dir": "/home/pawamoy/Downloads/torrents/tmp",
"downloadSpeed": "745509",
"files": [
{
"completedLength": "58132",
"index": "1",
"length": "58132",
"path": "/home/pawamoy/Downloads/torrents/tmp/dl/logo.jpg",
"selected": "true",
"uris": [],
def test_get_downloads_method():
with Aria2Server(port=7105, session=SESSIONS_DIR / "dl-2-aria2.txt") as server:
downloads = server.api.get_downloads()
assert len(downloads) == 2
assert isinstance(downloads[0], Download)
assert downloads[0].gid == "2089b05ecca3d829"
do_all (bool): pause all downloads if True.
Returns:
int: 0 if all success, 1 if one failure.
"""
print(
"Deprecation warning: command 'purge' is deprecated in favor of command 'remove', "
"and will be removed in version 0.7.0.",
file=sys.stderr,
)
if do_all:
if api.purge_all():
return 0
return 1
downloads = [Download(api, {"gid": gid}) for gid in gids]
result = api.purge(downloads)
if all(result):
return 0
for item in result:
if isinstance(item, ClientException):
print(item, file=sys.stderr)
return 1
api (API): the API instance to use.
gids (list of str): the GIDs of the downloads to pause.
do_all (bool): pause all downloads if True.
force (bool): force pause or not (see API.pause).
Returns:
int: 0 if all success, 1 if one failure.
"""
if do_all:
if api.pause_all(force=force):
return 0
return 1
# FIXME: could break if API.resume needs more info than just gid
# See how we do that in subcommand_remove
downloads = [Download(api, {"gid": gid}) for gid in gids]
result = api.pause(downloads, force=force)
if all(result):
return 0
for item in result:
if isinstance(item, ClientException):
print(item, file=sys.stderr)
return 1
Args:
api (API): the API instance to use.
gids (list of str): the GIDs of the downloads to resume.
do_all (bool): pause all downloads if True.
Returns:
int: 0 if all success, 1 if one failure.
"""
if do_all:
if api.resume_all():
return 0
return 1
# FIXME: could break if API.resume needs more info than just gid
# See how we do that in subcommand_remove
downloads = [Download(api, {"gid": gid}) for gid in gids]
result = api.resume(downloads)
if all(result):
return 0
for item in result:
if isinstance(item, ClientException):
print(item, file=sys.stderr)
return 1