diff --git a/deluge/maketorrent.py b/deluge/maketorrent.py index 2e91ca723..b2c297c32 100644 --- a/deluge/maketorrent.py +++ b/deluge/maketorrent.py @@ -147,17 +147,17 @@ class TorrentMetadata(object): fs = [] pieces = [] # Create the piece hashes - buf = '' + buf = b'' for size, path in files: - path = [s.decode(sys.getfilesystemencoding()).encode('UTF-8') for s in path] - fs.append({'length': size, 'path': path}) - if path[-1].startswith('_____padding_file_'): - buf += '\0' * size + path = [s.encode('UTF-8') for s in path] + fs.append({b'length': size, b'path': path}) + if path[-1].startswith(b'_____padding_file_'): + buf += b'\0' * size pieces.append(sha(buf).digest()) - buf = '' - fs[-1]['attr'] = 'p' + buf = b'' + fs[-1][b'attr'] = b'p' else: - with open(os.path.join(self.data_path, *path), 'rb') as _file: + with open(os.path.join(self.data_path.encode('utf8'), *path), 'rb') as _file: r = _file.read(piece_size - len(buf)) while r: buf += r @@ -166,7 +166,7 @@ class TorrentMetadata(object): # Run the progress function if necessary if progress: progress(len(pieces), num_pieces) - buf = '' + buf = b'' else: break r = _file.read(piece_size - len(buf)) diff --git a/deluge/tests/test_maketorrent.py b/deluge/tests/test_maketorrent.py index 01ce4ee1f..da008e876 100644 --- a/deluge/tests/test_maketorrent.py +++ b/deluge/tests/test_maketorrent.py @@ -72,11 +72,11 @@ class MakeTorrentTestCase(unittest.TestCase): # Create a temporary folder for torrent creation tmp_path = tempfile.mkdtemp() with open(os.path.join(tmp_path, 'file_A'), 'wb') as _file: - _file.write('a' * (312 * 1024)) + _file.write(b'a' * (312 * 1024)) with open(os.path.join(tmp_path, 'file_B'), 'wb') as _file: - _file.write('b' * (2354 * 1024)) + _file.write(b'b' * (2354 * 1024)) with open(os.path.join(tmp_path, 'file_C'), 'wb') as _file: - _file.write('c' * (11 * 1024)) + _file.write(b'c' * (11 * 1024)) t = maketorrent.TorrentMetadata() t.data_path = tmp_path diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 02eed51f5..b9866d21c 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -222,7 +222,7 @@ class TorrentInfo(object): encoding = self._metainfo_dict.get(b'encoding', None) codepage = self._metainfo_dict.get(b'codepage', None) if not encoding: - encoding = codepage if codepage else 'UTF-8' + encoding = codepage if codepage else b'UTF-8' # Decode 'name' with encoding unless 'name.utf-8' found. if b'name.utf-8' in info_dict: