Skip to content

Commit

Permalink
Fix TorrentDefNoMetainfo.get_name_utf8() to return string instead of …
Browse files Browse the repository at this point in the history
…bytes
  • Loading branch information
xoriole committed Jan 22, 2024
1 parent 76de562 commit 94dfae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ def test_load_from_dict():


def test_torrent_no_metainfo():
tdef = TorrentDefNoMetainfo(b"12345678901234567890", VIDEO_FILE_NAME, "http://google.com")
assert tdef.get_name() == VIDEO_FILE_NAME
video_file_name_bytes = VIDEO_FILE_NAME.encode('utf-8')
tdef = TorrentDefNoMetainfo(b"12345678901234567890", video_file_name_bytes, "http://google.com")
assert tdef.get_name() == video_file_name_bytes
assert tdef.get_infohash() == b"12345678901234567890"
assert tdef.get_length() == 0 # there are no files
assert not tdef.get_metainfo()
Expand All @@ -223,13 +224,13 @@ def test_torrent_no_metainfo():
assert tdef.get_files_with_length() == []
assert len(tdef.get_trackers()) == 0
assert not tdef.is_private()
assert tdef.get_name_utf8() == "video.avi"
assert tdef.get_name_utf8() == VIDEO_FILE_NAME
assert tdef.get_nr_pieces() == 0
assert tdef.torrent_info is None
tdef.load_torrent_info()
assert tdef.torrent_info is None

torrent2 = TorrentDefNoMetainfo(b"12345678901234567890", VIDEO_FILE_NAME, "magnet:")
torrent2 = TorrentDefNoMetainfo(b"12345678901234567890", video_file_name_bytes, "magnet:")
assert len(torrent2.get_trackers()) == 0


Expand Down
9 changes: 3 additions & 6 deletions src/tribler/core/components/libtorrent/torrentdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_metainfo(self) -> Dict:
"""
return self.metainfo

def get_name(self) -> str:
def get_name(self) -> bytes:
"""
Returns the name as raw string of bytes.
"""
Expand All @@ -325,7 +325,7 @@ def get_name_utf8(self) -> str:
"""
return escape_as_utf8(self.get_name(), self.get_encoding())

def set_name(self, name: str) -> None:
def set_name(self, name: bytes) -> None:
"""
Set the name of this torrent.
:param name: The new name of the torrent
Expand Down Expand Up @@ -554,8 +554,5 @@ def torrent_info(self) -> lt.torrent_info | None:
def load_torrent_info(self) -> None:
pass

def get_name_utf8(self):
return self.get_name()

def get_name_as_unicode(self):
return self.get_name()
return self.get_name_utf8()

0 comments on commit 94dfae1

Please sign in to comment.