Skip to content

Commit 4c901bb

Browse files
committed
Removed six
1 parent 585aa15 commit 4c901bb

File tree

95 files changed

+234
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+234
-483
lines changed

.sonar/analyse.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import requests
1212

13-
from six.moves import xrange
14-
1513
# These env varialble should be set by Jenkins.
1614
SERVER_URL = os.environ.get('SONAR_SERVER_URL', "https://sonarcloud.io")
1715
PROJECT_KEY = os.environ.get('PROJECT_KEY', "org.sonarqube:tribler")
@@ -34,7 +32,7 @@
3432

3533
print("Task status URL: %s" % task_status_url)
3634

37-
for _ in xrange(0, 30):
35+
for _ in range(0, 30):
3836
print("Fetching task status...")
3937
json_response = requests.get(task_status_url)
4038
data = json.loads(json_response.text)

Tribler/Core/APIImplementation/LaunchManyCore.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
from ipv8_service import IPv8
2929

30-
from six import text_type
31-
3230
from Tribler.Core.Config.download_config import DownloadConfig
3331
from Tribler.Core.Modules.MetadataStore.store import MetadataStore
3432
from Tribler.Core.Modules.gigachannel_manager import GigaChannelManager
@@ -505,7 +503,7 @@ async def sesscb_states_callback(self, states_list):
505503
infohash) == self.session.config.get_bootstrap_infohash() and self.trustchain_community:
506504
if download.future_flushed.done():
507505
with open(self.bootstrap.bootstrap_file, 'r') as f:
508-
sql_dumb = text_type(f.read())
506+
sql_dumb = f.read()
509507
self._logger.info("Executing script for trustchain bootstrap")
510508
self.trustchain_community.persistence.executescript(sql_dumb)
511509
self.trustchain_community.persistence.commit()
@@ -581,7 +579,7 @@ def resume_download(self, filename, setupDelay=0):
581579
tdef = (TorrentDefNoMetainfo(metainfo[b'infohash'], metainfo[b'name'], url)
582580
if b'infohash' in metainfo else TorrentDef.load_from_dict(metainfo))
583581
except ValueError as e:
584-
self._logger.exception("tlm: could not restore tdef from metainfo dict: %s %s ", e, text_type(metainfo))
582+
self._logger.exception("tlm: could not restore tdef from metainfo dict: %s %s ", e, metainfo)
585583
return
586584

587585
if config.get_bootstrap_download():

Tribler/Core/Category/FamilyFilter.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import os
88
import re
99

10-
from six.moves import xrange
11-
1210
from Tribler.Core.Utilities.install_dir import get_lib_path
1311

1412
WORDS_REGEXP = re.compile('[a-zA-Z0-9]+')
@@ -77,7 +75,7 @@ def isXXX(self, s, isFilename=True, nonXXXFormat=False):
7775
if not self.isAudio(s) and self.foundXXXTerm(s):
7876
return True
7977
words = self._getWords(s)
80-
words2 = [' '.join(words[i:i + 2]) for i in xrange(0, len(words) - 1)]
78+
words2 = [' '.join(words[i:i + 2]) for i in range(0, len(words) - 1)]
8179
num_xxx = len([w for w in words + words2 if self.isXXXTerm(w, s)])
8280
if nonXXXFormat or (isFilename and self.isAudio(s)):
8381
return num_xxx > 2 # almost never classify mp3 as porn

Tribler/Core/Category/init_category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Author(s): Yuan Yuan
55
"""
6-
from six.moves import configparser
6+
import configparser
77

88

99
def __split_list(string):

Tribler/Core/Config/download_config.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
import libtorrent as lt
77

8-
from six import string_types
9-
108
from validate import Validator
119

1210
from Tribler.Core.Utilities.install_dir import get_lib_path
@@ -61,7 +59,7 @@ def set_dest_dir(self, path):
6159
base_path = self.state_dir
6260
if base_path == os.path.commonprefix([path, base_path]):
6361
path = os.path.relpath(path, base_path)
64-
assert isinstance(path, string_types), path
62+
assert isinstance(path, str), path
6563
self.config['download_defaults']['saveas'] = path
6664

6765
def get_dest_dir(self):

Tribler/Core/Config/tribler_config.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from configobj import ConfigObj
88

9-
from six import text_type
10-
119
from validate import Validator
1210

1311
from Tribler.Core.Config.download_config import get_default_dest_dir
@@ -493,7 +491,7 @@ def set_tunnel_community_socks5_listen_ports(self, ports):
493491
def get_tunnel_community_socks5_listen_ports(self):
494492
ports = self.config['tunnel_community']['socks5_listen_ports']
495493
path = u'tunnel_community~socks5_listen_ports~'
496-
return [self._get_random_port(path + text_type(index))
494+
return [self._get_random_port(path + str(index))
497495
if int(port) < 0 else int(port) for index, port in enumerate(ports)]
498496

499497
def set_tunnel_community_exitnode_enabled(self, value):

Tribler/Core/CreditMining/CreditMiningManager.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import psutil
1111

12-
from six import string_types
13-
1412
from Tribler.Core.Config.download_config import DownloadConfig
1513
from Tribler.Core.CreditMining.CreditMiningPolicy import InvestmentPolicy, MB
1614
from Tribler.Core.CreditMining.CreditMiningSource import ChannelSource
@@ -156,7 +154,7 @@ def add_source(self, source_str):
156154
if source_str not in self.sources:
157155
num_torrents = len(self.torrents)
158156

159-
if isinstance(source_str, string_types):
157+
if isinstance(source_str, str):
160158
source = ChannelSource(self.session, unhexlify(source_str), self.on_torrent_insert)
161159
else:
162160
self._logger.error('Cannot add unknown source %s', source_str)

Tribler/Core/CreditMining/CreditMiningPolicy.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import random
77
import time
88

9-
from six.moves import xrange
10-
119
from Tribler.Core.simpledefs import DLSTATUS_DOWNLOADING, DLSTATUS_SEEDING, DLSTATUS_STOPPED, \
1210
DLSTATUS_STOPPED_ON_ERROR, DOWNLOAD, UPLOAD
1311

@@ -159,7 +157,7 @@ def get_default_investment_states():
159157
"""
160158
investment = 5
161159
states = {}
162-
for level in xrange(10):
160+
for level in range(10):
163161
download_state = 2 * level
164162
upload_state = download_state + 1
165163
states[download_state] = InvestmentState(download_state, download_state % 2, investment * MB)

Tribler/Core/DownloadState.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import logging
77

88
from ipv8.messaging.anonymization.tunnel import PEER_FLAG_EXIT_ANY
9-
from six import ensure_text
109

1110
from Tribler.Core.simpledefs import (DLSTATUS_ALLOCATING_DISKSPACE, DLSTATUS_CIRCUITS, DLSTATUS_DOWNLOADING,
1211
DLSTATUS_EXIT_NODES, DLSTATUS_HASHCHECKING, DLSTATUS_METADATA, DLSTATUS_SEEDING,
@@ -74,8 +73,7 @@ def get_error(self):
7473
""" Returns the Exception that caused the download to be moved to DLSTATUS_STOPPED_ON_ERROR status.
7574
@return An error message
7675
"""
77-
return self.error or \
78-
(ensure_text(self.lt_status.error) if self.lt_status and self.lt_status.error else None)
76+
return self.error or (self.lt_status.error if self.lt_status and self.lt_status.error else None)
7977

8078
def get_current_speed(self, direct):
8179
"""

Tribler/Core/Libtorrent/LibtorrentDownloadImpl.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@
1010
import sys
1111
import time
1212
from asyncio import ensure_future, sleep, Future, CancelledError, iscoroutine
13-
from threading import RLock
14-
15-
from six import ensure_binary, ensure_text
1613

1714
import libtorrent as lt
1815

19-
from six import int2byte, text_type
2016

2117
from Tribler.Core.Config.download_config import DownloadConfig, get_default_dest_dir
2218
from Tribler.Core.DownloadState import DownloadState
@@ -30,6 +26,7 @@
3026
from Tribler.Core.osutils import fix_filebasename
3127
from Tribler.Core.simpledefs import DLMODE_VOD, DLSTATUS_SEEDING, DLSTATUS_STOPPED
3228
from Tribler.pyipv8.ipv8.taskmanager import TaskManager
29+
from Tribler.pyipv8.ipv8.util import int2byte
3330

3431
if sys.platform == "win32":
3532
try:
@@ -234,7 +231,7 @@ async def create_handle(self, checkpoint_disabled=False, share_mode=False, uploa
234231
metainfo = self.tdef.get_metainfo()
235232
torrentinfo = lt.torrent_info(metainfo)
236233

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()]
238235
is_multifile = len(self.orig_files) > 1
239236
commonprefix = os.path.commonprefix(self.orig_files) if is_multifile else ''
240237
swarmname = commonprefix.partition(os.path.sep)[0]
@@ -254,8 +251,8 @@ async def create_handle(self, checkpoint_disabled=False, share_mode=False, uploa
254251
if resume_data and isinstance(resume_data, dict):
255252
# Rewrite save_path as a global path, if it is given as a relative path
256253
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'))
259256
atp["resume_data"] = lt.bencode(resume_data)
260257
else:
261258
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):
469466
if self.state_dir and b'save_path' in resume_data and os.path.abspath(resume_data[b'save_path']):
470467
if self.state_dir == os.path.commonprefix([ensure_unicode(resume_data[b'save_path'], 'utf-8'),
471468
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)
474471

475472
metainfo = {
476473
'infohash': self.tdef.get_infohash(),
@@ -534,7 +531,7 @@ def on_metadata_received_alert(self, alert):
534531

535532
metadata = {b'info': lt.bdecode(torrent_info.metadata())}
536533

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()]
538535
if trackers:
539536
if len(trackers) > 1:
540537
metadata[b"announce-list"] = [trackers]
@@ -553,7 +550,7 @@ def on_metadata_received_alert(self, alert):
553550
self._logger.warning("Torrent contains no files!")
554551
torrent_files = []
555552

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]
557554
self.set_corrected_infoname()
558555
self.set_filepieceranges()
559556
self.set_selected_files()
@@ -695,9 +692,9 @@ def set_selected_files(self, selected_files=None):
695692

696693
# as from libtorrent 1.0, files returning file_storage (lazy-iterable)
697694
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
699696
else:
700-
cur_path = ensure_text(torrent_storage[index].path)
697+
cur_path = torrent_storage[index].path
701698

702699
if cur_path != new_path:
703700
if not os.path.exists(unwanteddir_abs) and self.unwanted_directory_name in new_path:
@@ -736,7 +733,7 @@ def get_save_path(self):
736733
# self.handle.status().save_path to query the save path of a torrent. However, this attribute
737734
# is only included in libtorrent 1.0.9+
738735
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()
740737

741738
@checkHandle()
742739
def force_recheck(self):
@@ -871,7 +868,7 @@ def get_tracker_status(self):
871868
for announce_entry in self.handle.trackers():
872869
if announce_entry['url'] not in self.tracker_status:
873870
try:
874-
url = ensure_text(announce_entry['url'])
871+
url = announce_entry['url']
875872
self.tracker_status[url] = [0, 'Not contacted yet']
876873
except UnicodeDecodeError:
877874
pass
@@ -967,7 +964,7 @@ def get_dest_files(self, exts=None):
967964
filename = file_entry.path
968965
ext = os.path.splitext(filename)[1].lstrip('.')
969966
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)))
971968
return dest_files
972969

973970
def checkpoint(self):

Tribler/Core/Libtorrent/LibtorrentMgr.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
from binascii import unhexlify
1313
from distutils.version import LooseVersion
1414
from shutil import rmtree
15+
from urllib.request import url2pathname
1516

1617
from ipv8.taskmanager import TaskManager
1718

1819
import libtorrent as lt
1920
from libtorrent import bdecode, torrent_handle
2021

21-
from six import text_type
22-
from six.moves.urllib.request import url2pathname
23-
2422
from Tribler.Core.Config.download_config import DownloadConfig
2523
from Tribler.Core.Modules.dht_health_manager import DHTHealthManager
2624
from Tribler.Core.TorrentDef import TorrentDef, TorrentDefNoMetainfo
@@ -696,6 +694,6 @@ def post_session_stats(self, hops=None):
696694

697695
def encode_atp(atp):
698696
for k, v in atp.items():
699-
if isinstance(v, text_type):
697+
if isinstance(v, str):
700698
atp[k] = v.encode('utf-8')
701699
return atp

Tribler/Core/Modules/MetadataStore/OrmBindings/torrent_metadata.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from pony import orm
77
from pony.orm import db_session
88

9-
from six import text_type
10-
119
from Tribler.Core.Category.Category import default_category_filter
1210
from Tribler.Core.Category.FamilyFilter import default_xxx_filter
1311
from Tribler.Core.Modules.MetadataStore.OrmBindings.channel_node import COMMITTED, LEGACY_ENTRY
@@ -157,7 +155,7 @@ def metadata_conflicting(self, b):
157155
# WARNING! This does NOT check the INFOHASH
158156
a = self.to_dict()
159157
for comp in ["title", "size", "tags", "torrent_date", "tracker_info"]:
160-
if (comp not in b) or (text_type(a[comp]) == text_type(b[comp])):
158+
if (comp not in b) or (str(a[comp]) == str(b[comp])):
161159
continue
162160
return True
163161
return False

Tribler/Core/Modules/process_checker.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import psutil
44

5-
from six import text_type
6-
75
from Tribler.Core.Config.tribler_config import TriblerConfig
86

97

@@ -64,7 +62,7 @@ def create_lock_file(self):
6462
self.remove_lock_file()
6563

6664
with open(self.lock_file_path, 'wb') as lock_file:
67-
lock_file.write(text_type(os.getpid()).encode())
65+
lock_file.write(str(os.getpid()).encode())
6866

6967
def remove_lock_file(self):
7068
"""

Tribler/Core/Modules/restapi/debug_endpoint.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
import logging
33
import os
44
import sys
5+
from io import StringIO
56

67
from aiohttp import web
78

89
import psutil
910

10-
from six import StringIO
11-
1211
from Tribler.Core.Utilities.instrumentation import WatchDog
1312
from Tribler.Core.Modules.restapi.rest_endpoint import RESTEndpoint, RESTResponse
1413

Tribler/Core/Modules/restapi/downloads_endpoint.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import json
22
import os
33
from binascii import unhexlify
4+
from urllib.parse import unquote_plus
5+
from urllib.request import url2pathname
46

57
from aiohttp import web
68
from libtorrent import bencode, create_torrent
79

810
from pony.orm import db_session
911

10-
from six import unichr # pylint: disable=redefined-builtin
11-
from six.moves.urllib.parse import unquote_plus
12-
from six.moves.urllib.request import url2pathname
13-
1412
from Tribler.Core.Config.download_config import DownloadConfig
1513
from Tribler.Core.Modules.MetadataStore.serialization import CHANNEL_TORRENT
1614
from Tribler.Core.Modules.MetadataStore.store import UNKNOWN_CHANNEL, UPDATED_OUR_VERSION
@@ -41,7 +39,7 @@ def _safe_extended_peer_info(ext_peer_info):
4139
return ext_peer_info
4240
except UnicodeDecodeError:
4341
# We might have some special unicode characters in here
44-
return u''.join([unichr(ord(c)) for c in ext_peer_info])
42+
return u''.join([chr(ord(c)) for c in ext_peer_info])
4543

4644

4745
class DownloadsEndpoint(RESTEndpoint):

Tribler/Core/Modules/restapi/shutdown_endpoint.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ async def shutdown(self, request):
4242

4343
async def shutdown():
4444
try:
45-
await self.session.shutdown()
45+
keep_loop_running = await self.session.shutdown()
4646
except Exception as e:
4747
self._logger.error(e)
4848

4949
self.process_checker.remove_lock_file()
5050
# Flush the logs to the file before exiting
5151
for handler in logging.getLogger().handlers:
5252
handler.flush()
53-
get_event_loop().stop()
53+
if not keep_loop_running:
54+
get_event_loop().stop()
5455

5556
ensure_future(shutdown())
5657
return RESTResponse({"shutdown": True})

0 commit comments

Comments
 (0)