10
10
import sys
11
11
import time
12
12
from asyncio import ensure_future , sleep , Future , CancelledError , iscoroutine
13
- from threading import RLock
14
-
15
- from six import ensure_binary , ensure_text
16
13
17
14
import libtorrent as lt
18
15
19
- from six import int2byte , text_type
20
16
21
17
from Tribler .Core .Config .download_config import DownloadConfig , get_default_dest_dir
22
18
from Tribler .Core .DownloadState import DownloadState
30
26
from Tribler .Core .osutils import fix_filebasename
31
27
from Tribler .Core .simpledefs import DLMODE_VOD , DLSTATUS_SEEDING , DLSTATUS_STOPPED
32
28
from Tribler .pyipv8 .ipv8 .taskmanager import TaskManager
29
+ from Tribler .pyipv8 .ipv8 .util import int2byte
33
30
34
31
if sys .platform == "win32" :
35
32
try :
@@ -234,7 +231,7 @@ async def create_handle(self, checkpoint_disabled=False, share_mode=False, uploa
234
231
metainfo = self .tdef .get_metainfo ()
235
232
torrentinfo = lt .torrent_info (metainfo )
236
233
237
- self .orig_files = [ensure_text ( file_entry .path ) for file_entry in torrentinfo .files ()]
234
+ self .orig_files = [file_entry .path for file_entry in torrentinfo .files ()]
238
235
is_multifile = len (self .orig_files ) > 1
239
236
commonprefix = os .path .commonprefix (self .orig_files ) if is_multifile else ''
240
237
swarmname = commonprefix .partition (os .path .sep )[0 ]
@@ -254,8 +251,8 @@ async def create_handle(self, checkpoint_disabled=False, share_mode=False, uploa
254
251
if resume_data and isinstance (resume_data , dict ):
255
252
# Rewrite save_path as a global path, if it is given as a relative path
256
253
if b"save_path" in resume_data and not os .path .isabs (resume_data [b"save_path" ]):
257
- resume_data [b"save_path" ] = text_type (
258
- os . path . join ( self . state_dir , ensure_unicode (resume_data [b"save_path" ], 'utf-8' ) ))
254
+ resume_data [b"save_path" ] = os . path . join ( self . state_dir ,
255
+ ensure_unicode (resume_data [b"save_path" ], 'utf-8' ))
259
256
atp ["resume_data" ] = lt .bencode (resume_data )
260
257
else :
261
258
atp ["url" ] = self .tdef .get_url () or "magnet:?xt=urn:btih:" + hexlify (self .tdef .get_infohash ())
@@ -469,8 +466,8 @@ def on_save_resume_data_alert(self, alert):
469
466
if self .state_dir and b'save_path' in resume_data and os .path .abspath (resume_data [b'save_path' ]):
470
467
if self .state_dir == os .path .commonprefix ([ensure_unicode (resume_data [b'save_path' ], 'utf-8' ),
471
468
self .state_dir ]):
472
- resume_data [b'save_path' ] = text_type (
473
- os . path . relpath ( ensure_unicode ( resume_data [ b'save_path' ], 'utf-8' ), self .state_dir ) )
469
+ resume_data [b'save_path' ] = os . path . relpath ( ensure_unicode ( resume_data [ b'save_path' ], 'utf-8' ),
470
+ self .state_dir )
474
471
475
472
metainfo = {
476
473
'infohash' : self .tdef .get_infohash (),
@@ -534,7 +531,7 @@ def on_metadata_received_alert(self, alert):
534
531
535
532
metadata = {b'info' : lt .bdecode (torrent_info .metadata ())}
536
533
537
- trackers = [ensure_binary ( tracker ['url' ]) for tracker in self .handle .trackers ()]
534
+ trackers = [tracker ['url' ]. encode ( 'utf-8' ) for tracker in self .handle .trackers ()]
538
535
if trackers :
539
536
if len (trackers ) > 1 :
540
537
metadata [b"announce-list" ] = [trackers ]
@@ -553,7 +550,7 @@ def on_metadata_received_alert(self, alert):
553
550
self ._logger .warning ("Torrent contains no files!" )
554
551
torrent_files = []
555
552
556
- self .orig_files = [ensure_text ( torrent_file .path ) for torrent_file in torrent_files ]
553
+ self .orig_files = [torrent_file .path for torrent_file in torrent_files ]
557
554
self .set_corrected_infoname ()
558
555
self .set_filepieceranges ()
559
556
self .set_selected_files ()
@@ -695,9 +692,9 @@ def set_selected_files(self, selected_files=None):
695
692
696
693
# as from libtorrent 1.0, files returning file_storage (lazy-iterable)
697
694
if hasattr (lt , 'file_storage' ) and isinstance (torrent_storage , lt .file_storage ):
698
- cur_path = ensure_text ( torrent_storage .at (index ).path )
695
+ cur_path = torrent_storage .at (index ).path
699
696
else :
700
- cur_path = ensure_text ( torrent_storage [index ].path )
697
+ cur_path = torrent_storage [index ].path
701
698
702
699
if cur_path != new_path :
703
700
if not os .path .exists (unwanteddir_abs ) and self .unwanted_directory_name in new_path :
@@ -736,7 +733,7 @@ def get_save_path(self):
736
733
# self.handle.status().save_path to query the save path of a torrent. However, this attribute
737
734
# is only included in libtorrent 1.0.9+
738
735
status = self .handle .status ()
739
- return ensure_text ( status .save_path if hasattr (status , 'save_path' ) else self .handle .save_path () )
736
+ return status .save_path if hasattr (status , 'save_path' ) else self .handle .save_path ()
740
737
741
738
@checkHandle ()
742
739
def force_recheck (self ):
@@ -871,7 +868,7 @@ def get_tracker_status(self):
871
868
for announce_entry in self .handle .trackers ():
872
869
if announce_entry ['url' ] not in self .tracker_status :
873
870
try :
874
- url = ensure_text ( announce_entry ['url' ])
871
+ url = announce_entry ['url' ]
875
872
self .tracker_status [url ] = [0 , 'Not contacted yet' ]
876
873
except UnicodeDecodeError :
877
874
pass
@@ -967,7 +964,7 @@ def get_dest_files(self, exts=None):
967
964
filename = file_entry .path
968
965
ext = os .path .splitext (filename )[1 ].lstrip ('.' )
969
966
if exts is None or ext in exts :
970
- dest_files .append ((filename , os .path .join (self .config .get_dest_dir (), ensure_text ( filename ) )))
967
+ dest_files .append ((filename , os .path .join (self .config .get_dest_dir (), filename )))
971
968
return dest_files
972
969
973
970
def checkpoint (self ):
0 commit comments