From 8f1e383d68405c97bfccb6319bfc93b8c41413b9 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 22 Jan 2024 16:07:00 +0100 Subject: [PATCH] Make name field binary in torrentdef references and in tests --- .../libtorrent/download_manager/download_manager.py | 2 +- .../components/libtorrent/tests/test_download_manager.py | 8 ++++---- src/tribler/core/components/libtorrent/torrentdef.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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 1f422157b04..1edb4a42104 100644 --- a/src/tribler/core/components/libtorrent/download_manager/download_manager.py +++ b/src/tribler/core/components/libtorrent/download_manager/download_manager.py @@ -590,7 +590,7 @@ async def start_download_from_uri(self, uri, config=None): tdef = TorrentDef.load_from_dict(self.metainfo_cache[infohash]['meta_info']) else: self._logger.info('Metainfo not found in cache') - tdef = TorrentDefNoMetainfo(infohash, "Unknown name" if not name else name, url=uri) + tdef = TorrentDefNoMetainfo(infohash, b"Unknown name" if not name else name, url=uri) return await self.start_download(tdef=tdef, config=config) if scheme == FILE_SCHEME: self._logger.info('File scheme detected') 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 ee0c2d57522..bc13726af07 100644 --- a/src/tribler/core/components/libtorrent/tests/test_download_manager.py +++ b/src/tribler/core/components/libtorrent/tests/test_download_manager.py @@ -179,7 +179,7 @@ async def test_start_download_while_getting_metainfo(fake_dlmgr): fake_dlmgr.remove_download = AsyncMock(return_value=succeed(None)) tdef = TorrentDefNoMetainfo( - infohash, "name", f"magnet:?xt=urn:btih:{hexlify(infohash)}&" + infohash, b"name", f"magnet:?xt=urn:btih:{hexlify(infohash)}&" ) download = await fake_dlmgr.start_download(tdef=tdef, checkpoint_disabled=True) assert metainfo_dl != download @@ -222,7 +222,7 @@ async def test_start_download(fake_dlmgr): fake_dlmgr.get_session = MagicMock(return_value=mock_ltsession) download = await fake_dlmgr.start_download( - tdef=TorrentDefNoMetainfo(infohash, ""), checkpoint_disabled=True + tdef=TorrentDefNoMetainfo(infohash, b""), checkpoint_disabled=True ) handle = await download.get_handle() assert handle == mock_handle @@ -273,7 +273,7 @@ async def test_start_download_existing_handle(fake_dlmgr): fake_dlmgr.get_session = MagicMock(return_value=mock_ltsession) download = await fake_dlmgr.start_download( - tdef=TorrentDefNoMetainfo(infohash, "name"), checkpoint_disabled=True + tdef=TorrentDefNoMetainfo(infohash, b"name"), checkpoint_disabled=True ) handle = await download.get_handle() assert handle == mock_handle @@ -508,7 +508,7 @@ async def test_start_download_from_magnet_no_name(fake_dlmgr: DownloadManager): # Test whether a download is started with `Unknown name` name when the magnet has no name magnet = f'magnet:?xt=urn:btih:{"A" * 40}' download = await fake_dlmgr.start_download_from_uri(magnet) - assert download.tdef.get_name() == 'Unknown name' + assert download.tdef.get_name() == b'Unknown name' def test_update_trackers(fake_dlmgr) -> None: diff --git a/src/tribler/core/components/libtorrent/torrentdef.py b/src/tribler/core/components/libtorrent/torrentdef.py index 2cdb6ac34fc..7cd68a8d6cf 100644 --- a/src/tribler/core/components/libtorrent/torrentdef.py +++ b/src/tribler/core/components/libtorrent/torrentdef.py @@ -554,5 +554,5 @@ def torrent_info(self) -> lt.torrent_info | None: def load_torrent_info(self) -> None: pass - def get_name_as_unicode(self): + def get_name_as_unicode(self) -> str: return self.get_name_utf8()