[Py2to3] Further maketorrent fixes

This commit is contained in:
Calum Lind 2018-07-28 17:44:13 +01:00
parent ad20ec62f2
commit 1cce6a297c
3 changed files with 13 additions and 13 deletions

View File

@ -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))

View File

@ -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

View File

@ -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: