diff --git a/.sonar/analyse.py b/.sonar/analyse.py index 34253533fd0..9a25120723b 100644 --- a/.sonar/analyse.py +++ b/.sonar/analyse.py @@ -13,7 +13,7 @@ # These env varialble should be set by Jenkins. SERVER_URL = os.environ.get('SONAR_SERVER_URL', "https://sonarcloud.io") PROJECT_KEY = os.environ.get('PROJECT_KEY', "org.sonarqube:tribler") -PR_COMMIT = os.environ.get('ghprbActualCommit', u'') +PR_COMMIT = os.environ.get('ghprbActualCommit', '') TASK_PATH = os.path.join(os.environ.get('WORKSPACE', os.getcwd()), '.scannerwork', 'report-task.txt') task_status_url = None @@ -56,12 +56,12 @@ json_response = requests.get(pr_analysis_url) data = json.loads(json_response.text) - for pull_request in data[u'pullRequests']: - print("Matching analysis:", pull_request[u'key'], PR_COMMIT, pull_request[u'key'] == PR_COMMIT) + for pull_request in data['pullRequests']: + print("Matching analysis:", pull_request['key'], PR_COMMIT, pull_request['key'] == PR_COMMIT) # If there is analysis result for the PR commit with status OK, then exit with success status (0) - if pull_request[u'key'] == PR_COMMIT: - print("Quality Gate:", pull_request[u'status']) - if pull_request[u'status'][u'qualityGateStatus'] == u'OK': + if pull_request['key'] == PR_COMMIT: + print("Quality Gate:", pull_request['status']) + if pull_request['status']['qualityGateStatus'] == 'OK': print("Status: OK") break else: diff --git a/doc/conf.py b/doc/conf.py index 46f37a5aefc..ec18fa0b5ea 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -26,6 +26,14 @@ # root_dir = Path(__file__).parent.parent +def _add_root_endpoint(add_endpoint): + def _add_endpoint(self, path, ep): + if path in ['/ipv8', '/market', '/wallets']: + return None + return add_endpoint(self, path, ep) + + return _add_endpoint + root_dir = os.path.abspath(os.path.join(os.path.dirname(__name__), '..')) tribler_source_dirs = [ os.path.join(root_dir, "src"), @@ -49,8 +57,7 @@ from tribler.core.components.restapi.rest.root_endpoint import RootEndpoint add_endpoint = RootEndpoint.add_endpoint - RootEndpoint.add_endpoint = lambda self, path, ep: add_endpoint(self, path, ep) \ - if path not in ['/ipv8', '/market', '/wallets'] else None + RootEndpoint.add_endpoint = _add_root_endpoint(add_endpoint=add_endpoint) # Extract Swagger docs from extract_swagger import extract_swagger @@ -93,18 +100,18 @@ master_doc = 'index' # General information about the project. -project = u'Tribler' -copyright = u'2020, Tribler devs' -author = u'Tribler devs' +project = 'Tribler' +copyright = '2020, Tribler devs' +author = 'Tribler devs' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'7.5' +version = '7.5' # The full version, including alpha/beta/rc tags. -release = u'7.5.0' +release = '7.5.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -177,7 +184,7 @@ # The name for this set of Sphinx documents. # " v documentation" by default. # -# html_title = u'Tribler v6.6' +# html_title = 'Tribler v6.6' # A shorter title for the navigation bar. Default is the same as html_title. # @@ -303,8 +310,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'Tribler.tex', u'Tribler Documentation', - u'Tribler devs', 'manual'), + (master_doc, 'Tribler.tex', 'Tribler Documentation', + 'Tribler devs', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -339,7 +346,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'tribler', u'Tribler Documentation', + (master_doc, 'tribler', 'Tribler Documentation', [author], 1) ] @@ -354,7 +361,7 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'Tribler', u'Tribler Documentation', + (master_doc, 'Tribler', 'Tribler Documentation', author, 'Tribler', 'One line description of project.', 'Miscellaneous'), ] diff --git a/requirements-build.txt b/requirements-build.txt index 1774335a82a..f69876dd512 100644 --- a/requirements-build.txt +++ b/requirements-build.txt @@ -8,4 +8,4 @@ text-unidecode==1.3; sys_platform == 'darwin' defusedxml==0.7.1; sys_platform == 'linux2' or sys_platform == 'linux' markupsafe==2.0.1; sys_platform == 'linux2' or sys_platform == 'linux' -requests==2.25.1 \ No newline at end of file +requests==2.31.0 \ No newline at end of file diff --git a/src/tribler/core/components/gigachannel/community/gigachannel_community.py b/src/tribler/core/components/gigachannel/community/gigachannel_community.py index 06bd7f74899..936570e0654 100644 --- a/src/tribler/core/components/gigachannel/community/gigachannel_community.py +++ b/src/tribler/core/components/gigachannel/community/gigachannel_community.py @@ -1,3 +1,4 @@ +import operator import uuid from binascii import unhexlify from collections import defaultdict @@ -47,7 +48,7 @@ def add(self, peer: Peer, channel_pk: bytes, channel_id: int): self._peers_channels[peer].add(id_tuple) if len(channel_peers) > self.max_peers_per_channel: - removed_peer = min(channel_peers, key=lambda x: x.last_response) + removed_peer = min(channel_peers, key=operator.attrgetter("last_response")) channel_peers.remove(removed_peer) # Maintain the reverse mapping self._peers_channels[removed_peer].remove(id_tuple) @@ -64,7 +65,10 @@ def remove_peer(self, peer): def get_last_seen_peers_for_channel(self, channel_pk: bytes, channel_id: int, limit=None): id_tuple = (channel_pk, channel_id) channel_peers = self._channels_dict.get(id_tuple, []) - return sorted(channel_peers, key=lambda x: x.last_response, reverse=True)[0:limit] + last_seen_peers = ( + sorted(channel_peers, key=operator.attrgetter("last_response"), reverse=True) + ) + return last_seen_peers[0:limit] class GigaChannelCommunity(RemoteQueryCommunity): diff --git a/src/tribler/core/components/libtorrent/download_manager/download_manager.py b/src/tribler/core/components/libtorrent/download_manager/download_manager.py index d150bc092e5..857723629fb 100644 --- a/src/tribler/core/components/libtorrent/download_manager/download_manager.py +++ b/src/tribler/core/components/libtorrent/download_manager/download_manager.py @@ -248,11 +248,11 @@ def create_session(self, hops=0, store_listen_port=True): self._logger.info(f'Dummy mode: {self.dummy_mode}. Hops: {hops}.') # Elric: Strip out the -rcX, -beta, -whatever tail on the version string. - fingerprint = ['TL'] + [int(x) for x in version_id.split('-')[0].split('.')] + [0] + fingerprint = ['TL', *map(int, version_id.split('-')[0].split('.')), 0] if self.dummy_mode: from unittest.mock import Mock ltsession = Mock() - ltsession.pop_alerts = lambda: {} + ltsession.pop_alerts = dict ltsession.listen_port = lambda: 123 ltsession.get_settings = lambda: {"peer_fingerprint": "000"} else: @@ -268,10 +268,10 @@ def create_session(self, hops=0, store_listen_port=True): settings['enable_incoming_utp'] = enable_utp settings['prefer_rc4'] = True - settings["listen_interfaces"] = "0.0.0.0:%d" % libtorrent_port + settings["listen_interfaces"] = f"0.0.0.0:{libtorrent_port}" settings['peer_fingerprint'] = self.peer_mid - settings['handshake_client_version'] = 'Tribler/' + version_id + '/' + hexlify(self.peer_mid) + settings['handshake_client_version'] = f"Tribler/{version_id}/{hexlify(self.peer_mid)}" else: settings['enable_outgoing_utp'] = True settings['enable_incoming_utp'] = True @@ -281,7 +281,7 @@ def create_session(self, hops=0, store_listen_port=True): settings['force_proxy'] = True # Anon listen port is never used anywhere, so we let Libtorrent set it - # settings["listen_interfaces"] = "0.0.0.0:%d" % anon_port + # settings["listen_interfaces"] = f"0.0.0.0:{anon_port}" # By default block all IPs except 1.1.1.1 (which is used to ensure libtorrent makes a connection to us) self.update_ip_filter(ltsession, ['1.1.1.1']) @@ -363,7 +363,8 @@ def set_max_connections(self, conns, hops=None): def set_upload_rate_limit(self, rate, hops=None): # Rate conversion due to the fact that we had a different system with Swift # and the old python BitTorrent core: unlimited == 0, stop == -1, else rate in kbytes - libtorrent_rate = int(-1 if rate == 0 else (1 if rate == -1 else rate * 1024)) + torrent_rate = {0: -1, -1: 1} + libtorrent_rate = torrent_rate.get(rate, rate * 1024) # Pass outgoing_port and num_outgoing_ports to dict due to bug in libtorrent 0.16.18 settings_dict = {'upload_rate_limit': libtorrent_rate, 'outgoing_port': 0, 'num_outgoing_ports': 1} @@ -374,10 +375,12 @@ def get_upload_rate_limit(self, hops=None): # Rate conversion due to the fact that we had a different system with Swift # and the old python BitTorrent core: unlimited == 0, stop == -1, else rate in kbytes libtorrent_rate = self.get_session(hops).upload_rate_limit() - return 0 if libtorrent_rate == -1 else (-1 if libtorrent_rate == 1 else libtorrent_rate / 1024) + torrent_rate = {-1: 0, 1: -1} + return torrent_rate.get(libtorrent_rate, libtorrent_rate // 1024) def set_download_rate_limit(self, rate, hops=None): - libtorrent_rate = int(-1 if rate == 0 else (1 if rate == -1 else rate * 1024)) + torrent_rate = {0: -1, -1: 1} + libtorrent_rate = torrent_rate.get(rate, rate * 1024) # Pass outgoing_port and num_outgoing_ports to dict due to bug in libtorrent 0.16.18 settings_dict = {'download_rate_limit': libtorrent_rate} @@ -386,7 +389,8 @@ def set_download_rate_limit(self, rate, hops=None): def get_download_rate_limit(self, hops=0): libtorrent_rate = self.get_session(hops).download_rate_limit() - return 0 if libtorrent_rate == -1 else (-1 if libtorrent_rate == 1 else libtorrent_rate / 1024) + torrent_rate = {-1: 0, 1: -1} + return torrent_rate.get(libtorrent_rate, libtorrent_rate // 1024) def process_alert(self, alert, hops=0): alert_type = alert.__class__.__name__ @@ -780,7 +784,7 @@ def update_trackers(self, infohash, trackers): old_def = download.get_def() old_trackers = old_def.get_trackers() new_trackers = list(set(trackers) - old_trackers) - all_trackers = list(old_trackers) + new_trackers + all_trackers = [*old_trackers, *new_trackers] if new_trackers: # Add new trackers to the download diff --git a/src/tribler/core/components/libtorrent/tests/test_download_manager.py b/src/tribler/core/components/libtorrent/tests/test_download_manager.py index 2834c5668f6..59be9560ba7 100644 --- a/src/tribler/core/components/libtorrent/tests/test_download_manager.py +++ b/src/tribler/core/components/libtorrent/tests/test_download_manager.py @@ -1,4 +1,5 @@ import asyncio +import functools from asyncio import Future, gather, get_event_loop, sleep from unittest.mock import MagicMock @@ -27,9 +28,10 @@ def create_fake_download_and_state(): fake_download.get_def().get_name_as_unicode = lambda: "test.iso" fake_download.get_peerlist = lambda: [fake_peer] fake_download.hidden = False - fake_download.checkpoint = lambda: succeed(None) - fake_download.stop = lambda: succeed(None) - fake_download.shutdown = lambda: succeed(None) + succeed_none = functools.partial(succeed, None) + fake_download.checkpoint = succeed_none + fake_download.stop = succeed_none + fake_download.shutdown = succeed_none dl_state = MagicMock() dl_state.get_infohash = lambda: b'aaaa' dl_state.get_status = lambda: DownloadStatus.SEEDING @@ -138,9 +140,10 @@ async def test_get_metainfo_with_already_added_torrent(fake_dlmgr): download_impl = MagicMock() download_impl.future_metainfo = succeed(bencode(torrent_def.get_metainfo())) - download_impl.checkpoint = lambda: succeed(None) - download_impl.stop = lambda: succeed(None) - download_impl.shutdown = lambda: succeed(None) + succeed_none = functools.partial(succeed, None) + download_impl.checkpoint = succeed_none + download_impl.stop = succeed_none + download_impl.shutdown = succeed_none fake_dlmgr.initialize() fake_dlmgr.downloads[torrent_def.infohash] = download_impl @@ -155,10 +158,10 @@ async def test_start_download_while_getting_metainfo(fake_dlmgr): infohash = b"a" * 20 metainfo_session = MagicMock() - metainfo_session.get_torrents = lambda: [] + metainfo_session.get_torrents = list metainfo_dl = MagicMock() - metainfo_dl.get_def = lambda: MagicMock(get_infohash=lambda: infohash) + metainfo_dl.get_def = functools.partial(MagicMock, get_infohash=lambda: infohash) fake_dlmgr.initialize() fake_dlmgr.get_session = lambda *_: metainfo_session @@ -181,7 +184,7 @@ async def test_start_download(fake_dlmgr): infohash = b'a' * 20 mock_handle = MagicMock() - mock_handle.info_hash = lambda: hexlify(infohash) + mock_handle.info_hash = functools.partial(hexlify, infohash) mock_handle.is_valid = lambda: True mock_error = MagicMock() @@ -192,7 +195,7 @@ async def test_start_download(fake_dlmgr): category=lambda _: None))() mock_ltsession = MagicMock() - mock_ltsession.get_torrents = lambda: [] + mock_ltsession.get_torrents = list mock_ltsession.async_add_torrent = lambda _: fake_dlmgr.register_task('post_alert', fake_dlmgr.process_alert, mock_alert, delay=0.1) @@ -241,7 +244,7 @@ async def test_start_download_existing_handle(fake_dlmgr): infohash = b'a' * 20 mock_handle = MagicMock() - mock_handle.info_hash = lambda: hexlify(infohash) + mock_handle.info_hash = functools.partial(hexlify, infohash) mock_handle.is_valid = lambda: True mock_ltsession = MagicMock() @@ -319,7 +322,7 @@ def on_set_settings(settings): assert settings['proxy_hostnames'] mock_lt_session = MagicMock() - mock_lt_session.get_settings = lambda: {} + mock_lt_session.get_settings = dict mock_lt_session.set_settings = on_set_settings mock_lt_session.set_proxy = on_proxy_set # Libtorrent < 1.1.0 uses set_proxy to set proxy settings fake_dlmgr.set_proxy_settings(mock_lt_session, 0, ('a', "1234"), ('abc', 'def')) @@ -406,7 +409,7 @@ def mocked_load_checkpoint(filename): mocked_load_checkpoint.called = True mocked_load_checkpoint.called = False - fake_dlmgr.get_checkpoint_dir = lambda: Path(tmpdir) + fake_dlmgr.get_checkpoint_dir = functools.partial(Path, tmpdir) with open(fake_dlmgr.get_checkpoint_dir() / 'abcd.conf', 'wb') as state_file: state_file.write(b"hi") diff --git a/src/tribler/core/components/libtorrent/torrentdef.py b/src/tribler/core/components/libtorrent/torrentdef.py index 952792bc1db..90013c876c2 100644 --- a/src/tribler/core/components/libtorrent/torrentdef.py +++ b/src/tribler/core/components/libtorrent/torrentdef.py @@ -35,7 +35,7 @@ def escape_as_utf8(string, encoding='utf8'): # latin1 and hope for the best (minor corruption). return string.decode('latin1').encode('utf8', 'ignore').decode('utf8') except (TypeError, ValueError): - # This is a very nasty string (e.g. u'\u266b'), remove the illegal entries. + # This is a very nasty string (e.g. '\u266b'), remove the illegal entries. return string.encode('utf8', 'ignore').decode('utf8') diff --git a/src/tribler/core/components/metadata_store/restapi/search_endpoint.py b/src/tribler/core/components/metadata_store/restapi/search_endpoint.py index dfbaef20d45..c992009af3d 100644 --- a/src/tribler/core/components/metadata_store/restapi/search_endpoint.py +++ b/src/tribler/core/components/metadata_store/restapi/search_endpoint.py @@ -1,3 +1,4 @@ +import operator import time from collections import defaultdict from typing import Dict, List @@ -57,7 +58,7 @@ def build_snippets(self, search_results: List[Dict]) -> List[Dict]: # Sort the search results within each snippet by the number of seeders for torrents_list in content_to_torrents.values(): - torrents_list.sort(key=lambda x: x["num_seeders"], reverse=True) + torrents_list.sort(key=operator.itemgetter("num_seeders"), reverse=True) # Determine the most popular content items - this is the one we show sorted_content_info = list(content_to_torrents.items()) diff --git a/src/tribler/core/components/reporter/reported_error.py b/src/tribler/core/components/reporter/reported_error.py index 3968f8c0aff..f0c449409f4 100644 --- a/src/tribler/core/components/reporter/reported_error.py +++ b/src/tribler/core/components/reporter/reported_error.py @@ -7,7 +7,7 @@ class ReportedError: type: str text: str event: dict = field(repr=False) - additional_information: dict = field(default_factory=lambda: {}, repr=False) + additional_information: dict = field(default_factory=dict, repr=False) long_text: str = field(default='', repr=False) context: str = field(default='', repr=False) diff --git a/src/tribler/core/components/tunnel/community/dispatcher.py b/src/tribler/core/components/tunnel/community/dispatcher.py index d7a3b2cb135..244aeacbe53 100644 --- a/src/tribler/core/components/tunnel/community/dispatcher.py +++ b/src/tribler/core/components/tunnel/community/dispatcher.py @@ -1,3 +1,4 @@ +import functools import random from collections import defaultdict @@ -97,6 +98,11 @@ async def on_socks5_tcp_data(self, tcp_connection, destination, request): tcp_connection.transport.write(response) tcp_connection.transport.close() + def _add_data_if_result(self, result_func, connection, request): + if not result_func.result(): + return None + return self.on_socks5_udp_data(connection, request) + def select_circuit(self, connection, request): if request.destination[1] == CIRCUIT_ID_PORT: circuit = self.tunnels.circuits.get(self.tunnels.ip_to_circuit_id(request.destination[0])) @@ -120,8 +126,13 @@ def select_circuit(self, connection, request): return None self._logger.debug("Creating circuit for data to %s. Retrying later..", request.destination) self.cid_to_con[circuit.circuit_id] = connection - circuit.ready.add_done_callback(lambda f, c=connection.udp_connection, r=request: - self.on_socks5_udp_data(c, r) if f.result() else None) + circuit.ready.add_done_callback( + functools.partial( + self._add_data_if_result, + connection=connection.udp_connection, + request=request + ) + ) return None circuit = random.choice(options) diff --git a/src/tribler/core/components/tunnel/community/tunnel_community.py b/src/tribler/core/components/tunnel/community/tunnel_community.py index c9896ec31fa..9b0aa0fe111 100644 --- a/src/tribler/core/components/tunnel/community/tunnel_community.py +++ b/src/tribler/core/components/tunnel/community/tunnel_community.py @@ -1,3 +1,4 @@ +import functools import hashlib import math import sys @@ -503,7 +504,7 @@ def monitor_downloads(self, dslist): if state_changed and new_state in active: if old_state != DownloadStatus.METADATA or new_state != DownloadStatus.DOWNLOADING: self.join_swarm(info_hash, hops[info_hash], seeding=new_state == DownloadStatus.SEEDING, - callback=lambda addr, ih=info_hash: self.on_e2e_finished(addr, ih)) + callback=functools.partial(self.on_e2e_finished, info_hash=info_hash)) elif state_changed and new_state in [DownloadStatus.STOPPED, None]: self.leave_swarm(info_hash) diff --git a/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388a67997fd4.state b/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388a67997fd4.state index 3bc90e77e0d..25a62fa1ed0 100644 --- a/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388a67997fd4.state +++ b/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388a67997fd4.state @@ -14,4 +14,4 @@ channel_download = True version = 5 metainfo = {'creation date': 1562337604, 'info': {'files': [{'path': ['1562337581003.mdblob.lz4'], 'length': 295}], 'piece length': 16384, 'name': '5263ec553e7a062ac4f75eb6f7bf26f7400b800d74b575f6', 'pieces': '\x17\x18u\xcd\xae\xa2\xc9f*g3\x13u\xda{c\xab\xbc\xae\xc8'}} dlstate = {'status': 1, 'progress': 0, 'swarmcache': None} -engineresumedata = {'active_time': 0, 'num_incomplete': 16777215, 'announce_to_lsd': 1, 'seed_mode': 0, 'paused': 0, 'seeding_time': 0, 'info-hash': '>\xfb~\x91W\x11\x0e\x1a%\x9d: t\x038\x8ag\x99\x7f\xd4', 'upload_rate_limit': -1, 'max_uploads': 16777215, 'max_connections': 16777215, 'unfinished': [], 'num_downloaded': 16777215, 'total_downloaded': 0, 'file-format': 'libtorrent resume file', 'peers6': '', 'added_time': 1562337604, 'banned_peers6': '', 'file_priority': [1], 'last_seen_complete': 0, 'total_uploaded': 0, 'file-version': 1, 'auto_managed': 0, 'save_path': u'channels', 'peers': '', 'completed_time': 0, 'blocks per piece': 1, 'download_rate_limit': -1, 'libtorrent-version': '1.1.5.0', 'banned_peers': '', 'sequential_download': 0, 'announce_to_trackers': 1, 'num_complete': 16777215, 'finished_time': 0, 'announce_to_dht': 1, 'trackers': [[]], 'super_seeding': 0} +engineresumedata = {'active_time': 0, 'num_incomplete': 16777215, 'announce_to_lsd': 1, 'seed_mode': 0, 'paused': 0, 'seeding_time': 0, 'info-hash': '>\xfb~\x91W\x11\x0e\x1a%\x9d: t\x038\x8ag\x99\x7f\xd4', 'upload_rate_limit': -1, 'max_uploads': 16777215, 'max_connections': 16777215, 'unfinished': [], 'num_downloaded': 16777215, 'total_downloaded': 0, 'file-format': 'libtorrent resume file', 'peers6': '', 'added_time': 1562337604, 'banned_peers6': '', 'file_priority': [1], 'last_seen_complete': 0, 'total_uploaded': 0, 'file-version': 1, 'auto_managed': 0, 'save_path': 'channels', 'peers': '', 'completed_time': 0, 'blocks per piece': 1, 'download_rate_limit': -1, 'libtorrent-version': '1.1.5.0', 'banned_peers': '', 'sequential_download': 0, 'announce_to_trackers': 1, 'num_complete': 16777215, 'finished_time': 0, 'announce_to_dht': 1, 'trackers': [[]], 'super_seeding': 0} diff --git a/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388fffffffff.state b/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388fffffffff.state index a163cd17558..40940222b25 100644 --- a/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388fffffffff.state +++ b/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/3efb7e9157110e1a259d3a207403388fffffffff.state @@ -14,4 +14,4 @@ channel_download = True version = 5 metainfo = {'creation date': 1562337604, 'info': {'files': [{'path': ['1562337581003.mdblob.lz4'], 'length': 295}], 'piece length': 16384, 'name': '5263ec553e7a062ac4f75eb6f7bf26f7400b800d74b575f6', 'pieces': '\x17\x18u\xcd\xae\xa2\xc9f*g3\x13u\xda{c\xab\xbc\xae\xc8'}} dlstate = {'status': 1, 'progress': 0, 'swarmcache': None} -engineresumedata = {'active_time': 0, 'num_incomplete': 16777215, 'announce_to_lsd': 1, 'seed_mode': 0, 'paused': 0, 'seeding_time': 0, 'info-hash': '>\xfb~\x91W\x11\x0e\x1a%\x9d: t\x038\x8ag\x99\x7f\xd4', 'upload_rate_limit': -1, 'max_uploads': 16777215, 'max_connections': 16777215, 'unfinished': [], 'num_downloaded': 16777215, 'total_downloaded': 0, 'file-format': 'libtorrent resume file', 'peers6': '', 'added_time': 1562337604, 'banned_peers6': '', 'file_priority': [1], 'last_seen_complete': 0, 'total_uploaded': 0, 'file-version': 1, 'auto_managed': 0, 'save_path': u'channels', 'peers': '', 'completed_time': 0, 'blocks per piece': 1, 'download_rate_limit': -1, 'libtorrent-version': '1.1.5.0', 'banned_peers': '', 'sequential_download': 0, 'announce_to_trackers': 1, 'num_complete': 16777215, 'finished_time': 0, 'announce_to_dht': 1, 'trackers': [[]], 'super_seeding': 0} +engineresumedata = {'active_time': 0, 'num_incomplete': 16777215, 'announce_to_lsd': 1, 'seed_mode': 0, 'paused': 0, 'seeding_time': 0, 'info-hash': '>\xfb~\x91W\x11\x0e\x1a%\x9d: t\x038\x8ag\x99\x7f\xd4', 'upload_rate_limit': -1, 'max_uploads': 16777215, 'max_connections': 16777215, 'unfinished': [], 'num_downloaded': 16777215, 'total_downloaded': 0, 'file-format': 'libtorrent resume file', 'peers6': '', 'added_time': 1562337604, 'banned_peers6': '', 'file_priority': [1], 'last_seen_complete': 0, 'total_uploaded': 0, 'file-version': 1, 'auto_managed': 0, 'save_path': 'channels', 'peers': '', 'completed_time': 0, 'blocks per piece': 1, 'download_rate_limit': -1, 'libtorrent-version': '1.1.5.0', 'banned_peers': '', 'sequential_download': 0, 'announce_to_trackers': 1, 'num_complete': 16777215, 'finished_time': 0, 'announce_to_dht': 1, 'trackers': [[]], 'super_seeding': 0} diff --git a/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/811c1c033474e6a07e42f3f90f3f31dcad7dccc1.state b/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/811c1c033474e6a07e42f3f90f3f31dcad7dccc1.state index bfb4784de27..eb3f9470660 100644 --- a/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/811c1c033474e6a07e42f3f90f3f31dcad7dccc1.state +++ b/src/tribler/core/tests/tools/data/noncompliant_state_dir/dlcheckpoints/811c1c033474e6a07e42f3f90f3f31dcad7dccc1.state @@ -14,4 +14,4 @@ channel_download = True version = 5 metainfo = {'creation date': 1562337893, 'info': {'files': [{'path': ['1562337481003.mdblob.lz4'], 'length': 306}, {'path': ['1562337581005.mdblob.lz4'], 'length': 270}], 'piece length': 16384, 'name': '5263ec553e7a062ac4f75eb6f7bf26f7', 'pieces': '\xc7\xd7\xdf\xcf/x$D\xd3UQ\xcc\x90\x13\xa2\x1c\x82c\x13Y'}} dlstate = {'status': 4, 'progress': 1.0, 'swarmcache': None} -engineresumedata = {'active_time': 10, 'num_incomplete': 16777215, 'announce_to_lsd': 1, 'seed_mode': 0, 'pieces': '\x01', 'paused': 0, 'seeding_time': 10, 'info-hash': '\x81\x1c\x1c\x034t\xe6\xa0~B\xf3\xf9\x0f?1\xdc\xad}\xcc\xc1', 'upload_rate_limit': -1, 'max_uploads': 16777215, 'max_connections': 16777215, 'num_downloaded': 16777215, 'total_downloaded': 0, 'file-format': 'libtorrent resume file', 'peers6': '', 'added_time': 1562337893, 'banned_peers6': '', 'file_priority': [1, 1], 'last_seen_complete': 0, 'total_uploaded': 0, 'file-version': 1, 'auto_managed': 0, 'save_path': u'channels', 'peers': '', 'completed_time': 1562337894, 'blocks per piece': 1, 'download_rate_limit': -1, 'libtorrent-version': '1.1.5.0', 'banned_peers': '', 'sequential_download': 0, 'announce_to_trackers': 1, 'num_complete': 16777215, 'finished_time': 10, 'announce_to_dht': 1, 'trackers': [[]], 'super_seeding': 0, 'file sizes': [[306, 1562337511], [270, 1562337893]]} +engineresumedata = {'active_time': 10, 'num_incomplete': 16777215, 'announce_to_lsd': 1, 'seed_mode': 0, 'pieces': '\x01', 'paused': 0, 'seeding_time': 10, 'info-hash': '\x81\x1c\x1c\x034t\xe6\xa0~B\xf3\xf9\x0f?1\xdc\xad}\xcc\xc1', 'upload_rate_limit': -1, 'max_uploads': 16777215, 'max_connections': 16777215, 'num_downloaded': 16777215, 'total_downloaded': 0, 'file-format': 'libtorrent resume file', 'peers6': '', 'added_time': 1562337893, 'banned_peers6': '', 'file_priority': [1, 1], 'last_seen_complete': 0, 'total_uploaded': 0, 'file-version': 1, 'auto_managed': 0, 'save_path': 'channels', 'peers': '', 'completed_time': 1562337894, 'blocks per piece': 1, 'download_rate_limit': -1, 'libtorrent-version': '1.1.5.0', 'banned_peers': '', 'sequential_download': 0, 'announce_to_trackers': 1, 'num_complete': 16777215, 'finished_time': 10, 'announce_to_dht': 1, 'trackers': [[]], 'super_seeding': 0, 'file sizes': [[306, 1562337511], [270, 1562337893]]} diff --git a/src/tribler/gui/dialogs/feedbackdialog.py b/src/tribler/gui/dialogs/feedbackdialog.py index 767810695df..ef8549b8fd3 100644 --- a/src/tribler/gui/dialogs/feedbackdialog.py +++ b/src/tribler/gui/dialogs/feedbackdialog.py @@ -129,8 +129,7 @@ def on_cancel_clicked(self, checked): def on_send_clicked(self, checked): self.send_report_button.setEnabled(False) self.send_report_button.setText(tr("SENDING...")) - - sys_info = defaultdict(lambda: []) + sys_info = defaultdict(list) for ind in range(self.env_variables_list.topLevelItemCount()): item = self.env_variables_list.topLevelItem(ind) key = item.text(0) diff --git a/src/tribler/gui/utilities.py b/src/tribler/gui/utilities.py index e9c2e1d7af7..0d79997b5c2 100644 --- a/src/tribler/gui/utilities.py +++ b/src/tribler/gui/utilities.py @@ -72,7 +72,7 @@ def tr(key): def data_item2uri(data_item): - return f"magnet:?xt=urn:btih:{data_item[u'infohash']}&dn={data_item[u'name']}" + return f"magnet:?xt=urn:btih:{data_item['infohash']}&dn={data_item['name']}" def index2uri(index): diff --git a/src/tribler/gui/widgets/downloadsdetailstabwidget.py b/src/tribler/gui/widgets/downloadsdetailstabwidget.py index 702fd2b4362..29cbd398725 100644 --- a/src/tribler/gui/widgets/downloadsdetailstabwidget.py +++ b/src/tribler/gui/widgets/downloadsdetailstabwidget.py @@ -1,3 +1,4 @@ +import operator from enum import IntEnum from pathlib import PurePosixPath from typing import Dict, Optional @@ -27,7 +28,7 @@ class DownloadDetailsTabs(IntEnum): def convert_to_files_tree_format(download_info): files = download_info['files'] out = [] - for file in sorted(files, key=lambda x: x['index']): + for file in sorted(files, key=operator.itemgetter("index")): file_path_parts = PurePosixPath(file['name']).parts file_path = [download_info['name'], *file_path_parts] if len(files) == 1: diff --git a/src/tribler/gui/widgets/graphs/timeseriesplot.py b/src/tribler/gui/widgets/graphs/timeseriesplot.py index 4bbc563dc73..a907e3d2153 100644 --- a/src/tribler/gui/widgets/graphs/timeseriesplot.py +++ b/src/tribler/gui/widgets/graphs/timeseriesplot.py @@ -1,3 +1,4 @@ +import operator import time import numpy as np @@ -45,7 +46,7 @@ def add_data(self, timestamp, data): def render_plot(self): # Sort the plot data before rendering via plot.setData() to prevent loops and extra lines in the graph. - self.plot_data = dict(sorted(self.plot_data.items(), key=lambda x: x[0])) + self.plot_data = dict(sorted(self.plot_data.items(), key=operator.itemgetter(0))) for i, plot in enumerate(self.plots): plot.setData(