mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-06 00:18:39 +00:00
[Py2to3] Further maketorrent fixes
This commit is contained in:
parent
ad20ec62f2
commit
1cce6a297c
3 changed files with 13 additions and 13 deletions
|
@ -147,17 +147,17 @@ class TorrentMetadata(object):
|
||||||
fs = []
|
fs = []
|
||||||
pieces = []
|
pieces = []
|
||||||
# Create the piece hashes
|
# Create the piece hashes
|
||||||
buf = ''
|
buf = b''
|
||||||
for size, path in files:
|
for size, path in files:
|
||||||
path = [s.decode(sys.getfilesystemencoding()).encode('UTF-8') for s in path]
|
path = [s.encode('UTF-8') for s in path]
|
||||||
fs.append({'length': size, 'path': path})
|
fs.append({b'length': size, b'path': path})
|
||||||
if path[-1].startswith('_____padding_file_'):
|
if path[-1].startswith(b'_____padding_file_'):
|
||||||
buf += '\0' * size
|
buf += b'\0' * size
|
||||||
pieces.append(sha(buf).digest())
|
pieces.append(sha(buf).digest())
|
||||||
buf = ''
|
buf = b''
|
||||||
fs[-1]['attr'] = 'p'
|
fs[-1][b'attr'] = b'p'
|
||||||
else:
|
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))
|
r = _file.read(piece_size - len(buf))
|
||||||
while r:
|
while r:
|
||||||
buf += r
|
buf += r
|
||||||
|
@ -166,7 +166,7 @@ class TorrentMetadata(object):
|
||||||
# Run the progress function if necessary
|
# Run the progress function if necessary
|
||||||
if progress:
|
if progress:
|
||||||
progress(len(pieces), num_pieces)
|
progress(len(pieces), num_pieces)
|
||||||
buf = ''
|
buf = b''
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
r = _file.read(piece_size - len(buf))
|
r = _file.read(piece_size - len(buf))
|
||||||
|
|
|
@ -72,11 +72,11 @@ class MakeTorrentTestCase(unittest.TestCase):
|
||||||
# Create a temporary folder for torrent creation
|
# Create a temporary folder for torrent creation
|
||||||
tmp_path = tempfile.mkdtemp()
|
tmp_path = tempfile.mkdtemp()
|
||||||
with open(os.path.join(tmp_path, 'file_A'), 'wb') as _file:
|
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:
|
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:
|
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 = maketorrent.TorrentMetadata()
|
||||||
t.data_path = tmp_path
|
t.data_path = tmp_path
|
||||||
|
|
|
@ -222,7 +222,7 @@ class TorrentInfo(object):
|
||||||
encoding = self._metainfo_dict.get(b'encoding', None)
|
encoding = self._metainfo_dict.get(b'encoding', None)
|
||||||
codepage = self._metainfo_dict.get(b'codepage', None)
|
codepage = self._metainfo_dict.get(b'codepage', None)
|
||||||
if not encoding:
|
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.
|
# Decode 'name' with encoding unless 'name.utf-8' found.
|
||||||
if b'name.utf-8' in info_dict:
|
if b'name.utf-8' in info_dict:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue