Remove all Python 2 support

* Removed all __future__ imports from code
* Removed all six dependencies
* Removed all future_builtins imports
* Removed all Python 2 related code

Closes: deluge-torrent/deluge#325
This commit is contained in:
DjLegolas 2021-12-25 14:34:49 +02:00 committed by Calum Lind
parent ff309ea4c5
commit 897955f0a1
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
259 changed files with 86 additions and 817 deletions

View File

@ -289,7 +289,7 @@ callbacks=cb_,_cb
# List of qualified module names which can have objects that can redefine # List of qualified module names which can have objects that can redefine
# builtins. # builtins.
redefining-builtins-modules=six.moves,future.builtins,future_builtins redefining-builtins-modules=
[TYPECHECK] [TYPECHECK]
@ -359,11 +359,6 @@ known-standard-library=
# Force import order to recognize a module as part of a third party library. # Force import order to recognize a module as part of a third party library.
known-third-party=enchant known-third-party=enchant
# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
analyse-fallback-blocks=no
[DESIGN] [DESIGN]

View File

@ -1,6 +1,8 @@
# Changelog # Changelog
## 2.0.6 (WIP) ## 2.1.0 (WIP)
- Removed Python 2 support.
## 2.0.5 (2021-12-15) ## 2.0.5 (2021-12-15)

View File

@ -23,7 +23,6 @@ All modules will require the [common](#common) section dependencies.
- [rencode] _>= 1.0.2_ - Encoding library. - [rencode] _>= 1.0.2_ - Encoding library.
- [PyXDG] - Access freedesktop.org standards for \*nix. - [PyXDG] - Access freedesktop.org standards for \*nix.
- [xdg-utils] - Provides xdg-open for \*nix. - [xdg-utils] - Provides xdg-open for \*nix.
- [six]
- [zope.interface] - [zope.interface]
- [chardet] - Optional: Encoding detection. - [chardet] - Optional: Encoding detection.
- [setproctitle] - Optional: Renaming processes. - [setproctitle] - Optional: Renaming processes.
@ -81,14 +80,12 @@ All modules will require the [common](#common) section dependencies.
[distro]: https://github.com/nir0s/distro [distro]: https://github.com/nir0s/distro
[pywin32]: https://github.com/mhammond/pywin32 [pywin32]: https://github.com/mhammond/pywin32
[certifi]: https://pypi.org/project/certifi/ [certifi]: https://pypi.org/project/certifi/
[py2-ipaddress]: https://pypi.org/project/py2-ipaddress/
[dbus-python]: https://pypi.org/project/dbus-python/ [dbus-python]: https://pypi.org/project/dbus-python/
[setproctitle]: https://pypi.org/project/setproctitle/ [setproctitle]: https://pypi.org/project/setproctitle/
[gtkosxapplication]: https://github.com/jralls/gtk-mac-integration [gtkosxapplication]: https://github.com/jralls/gtk-mac-integration
[chardet]: https://chardet.github.io/ [chardet]: https://chardet.github.io/
[rencode]: https://github.com/aresch/rencode [rencode]: https://github.com/aresch/rencode
[pyxdg]: https://www.freedesktop.org/wiki/Software/pyxdg/ [pyxdg]: https://www.freedesktop.org/wiki/Software/pyxdg/
[six]: https://pythonhosted.org/six/
[xdg-utils]: https://www.freedesktop.org/wiki/Software/xdg-utils/ [xdg-utils]: https://www.freedesktop.org/wiki/Software/xdg-utils/
[gtk+]: https://www.gtk.org/ [gtk+]: https://www.gtk.org/
[pycairo]: https://cairographics.org/pycairo/ [pycairo]: https://cairographics.org/pycairo/

View File

@ -15,8 +15,6 @@ Example:
>>> from deluge._libtorrent import lt >>> from deluge._libtorrent import lt
""" """
from __future__ import unicode_literals
from deluge.common import VersionSplit, get_version from deluge.common import VersionSplit, get_version
from deluge.error import LibtorrentImportError from deluge.error import LibtorrentImportError

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import argparse import argparse
import logging import logging
import os import os

View File

@ -9,13 +9,7 @@
# License. # License.
# Written by Petru Paler # Written by Petru Paler
# Updated by Calum Lind to support both Python 2 and Python 3. # Updated by Calum Lind to support Python 3.
from __future__ import unicode_literals
from sys import version_info
PY2 = version_info.major == 2
class BTFailure(Exception): class BTFailure(Exception):
@ -146,10 +140,6 @@ encode_func[dict] = encode_dict
encode_func[bool] = encode_bool encode_func[bool] = encode_bool
encode_func[str] = encode_string encode_func[str] = encode_string
encode_func[bytes] = encode_bytes encode_func[bytes] = encode_bytes
if PY2:
encode_func[long] = encode_int # noqa: F821
encode_func[str] = encode_bytes
encode_func[unicode] = encode_string # noqa: F821
def bencode(x): def bencode(x):

View File

@ -8,8 +8,6 @@
# #
"""Common functions for various parts of Deluge to use.""" """Common functions for various parts of Deluge to use."""
from __future__ import division, print_function, unicode_literals
import base64 import base64
import binascii import binascii
import functools import functools
@ -27,6 +25,8 @@ import time
from contextlib import closing from contextlib import closing
from datetime import datetime from datetime import datetime
from io import BytesIO, open from io import BytesIO, open
from urllib.parse import unquote_plus, urljoin
from urllib.request import pathname2url
import pkg_resources import pkg_resources
@ -38,14 +38,6 @@ try:
except ImportError: except ImportError:
chardet = None chardet = None
try:
from urllib.parse import unquote_plus, urljoin
from urllib.request import pathname2url
except ImportError:
# PY2 fallback
from urllib import pathname2url, unquote_plus # pylint: disable=ungrouped-imports
from urlparse import urljoin # pylint: disable=ungrouped-imports
# Windows workaround for HTTPS requests requiring certificate authority bundle. # Windows workaround for HTTPS requests requiring certificate authority bundle.
# see: https://twistedmatrix.com/trac/ticket/9209 # see: https://twistedmatrix.com/trac/ticket/9209
if platform.system() in ('Windows', 'Microsoft'): if platform.system() in ('Windows', 'Microsoft'):
@ -84,8 +76,6 @@ JSON_FORMAT = {'indent': 4, 'sort_keys': True, 'ensure_ascii': False}
DBUS_FM_ID = 'org.freedesktop.FileManager1' DBUS_FM_ID = 'org.freedesktop.FileManager1'
DBUS_FM_PATH = '/org/freedesktop/FileManager1' DBUS_FM_PATH = '/org/freedesktop/FileManager1'
PY2 = sys.version_info.major == 2
def get_version(): def get_version():
"""The program version from the egg metadata. """The program version from the egg metadata.
@ -111,10 +101,8 @@ def get_default_config_dir(filename=None):
def save_config_path(resource): def save_config_path(resource):
app_data_path = os.environ.get('APPDATA') app_data_path = os.environ.get('APPDATA')
if not app_data_path: if not app_data_path:
try:
import winreg import winreg
except ImportError:
import _winreg as winreg # For Python 2.
hkey = winreg.OpenKey( hkey = winreg.OpenKey(
winreg.HKEY_CURRENT_USER, winreg.HKEY_CURRENT_USER,
'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders', 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders',
@ -178,8 +166,8 @@ def archive_files(arc_name, filepaths, message=None, rotate=10):
from deluge.configmanager import get_config_dir from deluge.configmanager import get_config_dir
# Set archive compression to lzma with bz2 fallback. # Set archive compression to lzma
arc_comp = 'xz' if not PY2 else 'bz2' arc_comp = 'xz'
archive_dir = os.path.join(get_config_dir(), 'archive') archive_dir = os.path.join(get_config_dir(), 'archive')
timestamp = datetime.now().replace(microsecond=0).isoformat().replace(':', '-') timestamp = datetime.now().replace(microsecond=0).isoformat().replace(':', '-')
@ -1239,11 +1227,7 @@ def set_env_variable(name, value):
http://sourceforge.net/p/gramps/code/HEAD/tree/branches/maintenance/gramps32/src/TransUtils.py http://sourceforge.net/p/gramps/code/HEAD/tree/branches/maintenance/gramps32/src/TransUtils.py
""" """
# Update Python's copy of the environment variables # Update Python's copy of the environment variables
try:
os.environ[name] = value os.environ[name] = value
except UnicodeEncodeError:
# Python 2
os.environ[name] = value.encode('utf8')
if windows_check(): if windows_check():
from ctypes import cdll, windll from ctypes import cdll, windll
@ -1271,30 +1255,7 @@ def set_env_variable(name, value):
def unicode_argv(): def unicode_argv():
""" Gets sys.argv as list of unicode objects on any platform.""" """ Gets sys.argv as list of unicode objects on any platform."""
if windows_check(): # On platforms other than Windows, we have to find the likely encoding of the args and decode
# Versions 2.x of Python don't support Unicode in sys.argv on
# Windows, with the underlying Windows API instead replacing multi-byte
# characters with '?'.
from ctypes import POINTER, byref, c_int, cdll, windll
from ctypes.wintypes import LPCWSTR, LPWSTR
get_cmd_linew = cdll.kernel32.GetCommandLineW
get_cmd_linew.argtypes = []
get_cmd_linew.restype = LPCWSTR
cmdline_to_argvw = windll.shell32.CommandLineToArgvW
cmdline_to_argvw.argtypes = [LPCWSTR, POINTER(c_int)]
cmdline_to_argvw.restype = POINTER(LPWSTR)
cmd = get_cmd_linew()
argc = c_int(0)
argv = cmdline_to_argvw(cmd, byref(argc))
if argc.value > 0:
# Remove Python executable and commands if present
start = argc.value - len(sys.argv)
return [argv[i] for i in range(start, argc.value)]
else:
# On other platforms, we have to find the likely encoding of the args and decode
# First check if sys.stdout or stdin have encoding set # First check if sys.stdout or stdin have encoding set
encoding = getattr(sys.stdout, 'encoding') or getattr(sys.stdin, 'encoding') encoding = getattr(sys.stdout, 'encoding') or getattr(sys.stdin, 'encoding')
# If that fails, check what the locale is set to # If that fails, check what the locale is set to

View File

@ -7,13 +7,10 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import traceback import traceback
from collections import defaultdict from collections import defaultdict
from six import string_types
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet.defer import DeferredList, fail, maybeDeferred, succeed from twisted.internet.defer import DeferredList, fail, maybeDeferred, succeed
from twisted.internet.task import LoopingCall, deferLater from twisted.internet.task import LoopingCall, deferLater
@ -325,7 +322,7 @@ class ComponentRegistry(object):
# Start all the components if names is empty # Start all the components if names is empty
if not names: if not names:
names = list(self.components) names = list(self.components)
elif isinstance(names, string_types): elif isinstance(names, str):
names = [names] names = [names]
def on_depends_started(result, name): def on_depends_started(result, name):
@ -359,7 +356,7 @@ class ComponentRegistry(object):
""" """
if not names: if not names:
names = list(self.components) names = list(self.components)
elif isinstance(names, string_types): elif isinstance(names, str):
names = [names] names = [names]
def on_dependents_stopped(result, name): def on_dependents_stopped(result, name):
@ -399,7 +396,7 @@ class ComponentRegistry(object):
""" """
if not names: if not names:
names = list(self.components) names = list(self.components)
elif isinstance(names, string_types): elif isinstance(names, str):
names = [names] names = [names]
deferreds = [] deferreds = []
@ -425,7 +422,7 @@ class ComponentRegistry(object):
""" """
if not names: if not names:
names = list(self.components) names = list(self.components)
elif isinstance(names, string_types): elif isinstance(names, str):
names = [names] names = [names]
deferreds = [] deferreds = []

View File

@ -39,18 +39,15 @@ this can only be done for the 'config file version' and not for the 'format'
version as this will be done internally. version as this will be done internally.
""" """
from __future__ import unicode_literals
import json import json
import logging import logging
import os import os
import pickle
import shutil import shutil
from codecs import getwriter from codecs import getwriter
from io import open from io import open
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
import six.moves.cPickle as pickle # noqa: N813
from deluge.common import JSON_FORMAT, get_default_config_dir from deluge.common import JSON_FORMAT, get_default_config_dir
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import os import os

View File

@ -15,10 +15,8 @@ This should typically only be used by the Core. Plugins should utilize the
`:mod:EventManager` for similar functionality. `:mod:EventManager` for similar functionality.
""" """
from __future__ import unicode_literals
import logging import logging
import types from types import SimpleNamespace
from twisted.internet import reactor from twisted.internet import reactor
@ -28,14 +26,6 @@ from deluge.common import decode_bytes
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
try:
SimpleNamespace = types.SimpleNamespace # Python 3.3+
except AttributeError:
class SimpleNamespace(object): # Python 2.7
def __init__(self, **attr):
self.__dict__.update(attr)
class AlertManager(component.Component): class AlertManager(component.Component):
"""AlertManager fetches and processes libtorrent alerts""" """AlertManager fetches and processes libtorrent alerts"""

View File

@ -8,8 +8,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import os import os
import shutil import shutil

View File

@ -8,8 +8,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import glob import glob
import logging import logging
import os import os
@ -17,8 +15,8 @@ import shutil
import tempfile import tempfile
import threading import threading
from base64 import b64decode, b64encode from base64 import b64decode, b64encode
from urllib.request import URLError, urlopen
from six import string_types
from twisted.internet import defer, reactor, task from twisted.internet import defer, reactor, task
from twisted.web.client import Agent, readBody from twisted.web.client import Agent, readBody
@ -56,12 +54,6 @@ from deluge.event import (
) )
from deluge.httpdownloader import download_file from deluge.httpdownloader import download_file
try:
from urllib.request import URLError, urlopen
except ImportError:
# PY2 fallback
from urllib2 import URLError, urlopen
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
DEPR_SESSION_STATUS_KEYS = { DEPR_SESSION_STATUS_KEYS = {
@ -666,7 +658,7 @@ class Core(component.Component):
def pause_torrent(self, torrent_id): def pause_torrent(self, torrent_id):
"""Pauses a torrent""" """Pauses a torrent"""
log.debug('Pausing: %s', torrent_id) log.debug('Pausing: %s', torrent_id)
if not isinstance(torrent_id, string_types): if not isinstance(torrent_id, str):
self.pause_torrents(torrent_id) self.pause_torrents(torrent_id)
else: else:
self.torrentmanager[torrent_id].pause() self.torrentmanager[torrent_id].pause()
@ -717,7 +709,7 @@ class Core(component.Component):
def resume_torrent(self, torrent_id): def resume_torrent(self, torrent_id):
"""Resumes a torrent""" """Resumes a torrent"""
log.debug('Resuming: %s', torrent_id) log.debug('Resuming: %s', torrent_id)
if not isinstance(torrent_id, string_types): if not isinstance(torrent_id, str):
self.resume_torrents(torrent_id) self.resume_torrents(torrent_id)
else: else:
self.torrentmanager[torrent_id].resume() self.torrentmanager[torrent_id].resume()
@ -901,7 +893,7 @@ class Core(component.Component):
if 'owner' in options and not self.authmanager.has_account(options['owner']): if 'owner' in options and not self.authmanager.has_account(options['owner']):
raise DelugeError('Username "%s" is not known.' % options['owner']) raise DelugeError('Username "%s" is not known.' % options['owner'])
if isinstance(torrent_ids, string_types): if isinstance(torrent_ids, str):
torrent_ids = [torrent_ids] torrent_ids = [torrent_ids]
for torrent_id in torrent_ids: for torrent_id in torrent_ids:

View File

@ -8,8 +8,6 @@
# #
"""The Deluge daemon""" """The Deluge daemon"""
from __future__ import unicode_literals
import logging import logging
import os import os
import socket import socket

View File

@ -7,8 +7,6 @@
# the additional special exception to link portions of this program with the OpenSSL library. # the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import print_function, unicode_literals
import os import os
import sys import sys
from logging import DEBUG, FileHandler, getLogger from logging import DEBUG, FileHandler, getLogger

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import deluge.component as component import deluge.component as component

View File

@ -7,12 +7,8 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from six import string_types
import deluge.component as component import deluge.component as component
from deluge.common import TORRENT_STATE from deluge.common import TORRENT_STATE
@ -136,7 +132,7 @@ class FilterManager(component.Component):
# Sanitize input: filter-value must be a list of strings # Sanitize input: filter-value must be a list of strings
for key, value in filter_dict.items(): for key, value in filter_dict.items():
if isinstance(value, string_types): if isinstance(value, str):
filter_dict[key] = [value] filter_dict[key] = [value]
# Optimized filter for id # Optimized filter for id

View File

@ -9,8 +9,6 @@
"""PluginManager for Core""" """PluginManager for Core"""
from __future__ import unicode_literals
import logging import logging
from twisted.internet import defer from twisted.internet import defer

View File

@ -8,13 +8,13 @@
# #
from __future__ import unicode_literals
import logging import logging
import os import os
import platform import platform
import random import random
import threading import threading
from urllib.parse import quote_plus
from urllib.request import urlopen
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
@ -29,13 +29,6 @@ try:
except ImportError: except ImportError:
GeoIP = None GeoIP = None
try:
from urllib.parse import quote_plus
from urllib.request import urlopen
except ImportError:
from urllib import quote_plus
from urllib2 import urlopen
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
DEFAULT_PREFS = { DEFAULT_PREFS = {

View File

@ -8,8 +8,6 @@
# #
"""RPCServer Module""" """RPCServer Module"""
from __future__ import unicode_literals
import logging import logging
import os import os
import sys import sys

View File

@ -14,11 +14,10 @@ Attributes:
""" """
from __future__ import division, unicode_literals
import logging import logging
import os import os
import socket import socket
from urllib.parse import urlparse
from twisted.internet.defer import Deferred, DeferredList from twisted.internet.defer import Deferred, DeferredList
@ -34,18 +33,6 @@ from deluge.event import (
TorrentTrackerStatusEvent, TorrentTrackerStatusEvent,
) )
try:
from urllib.parse import urlparse
except ImportError:
# PY2 fallback
from urlparse import urlparse # pylint: disable=ungrouped-imports
try:
from future_builtins import zip
except ImportError:
# Ignore on Py3.
pass
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
LT_TORRENT_STATE_MAP = { LT_TORRENT_STATE_MAP = {

View File

@ -8,17 +8,15 @@
# #
"""TorrentManager handles Torrent objects""" """TorrentManager handles Torrent objects"""
from __future__ import unicode_literals
import datetime import datetime
import logging import logging
import operator import operator
import os import os
import pickle
import time import time
from collections import namedtuple from collections import namedtuple
from tempfile import gettempdir from tempfile import gettempdir
import six.moves.cPickle as pickle # noqa: N813
from twisted.internet import defer, error, reactor, threads from twisted.internet import defer, error, reactor, threads
from twisted.internet.defer import Deferred, DeferredList from twisted.internet.defer import Deferred, DeferredList
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
@ -26,7 +24,6 @@ from twisted.internet.task import LoopingCall
import deluge.component as component import deluge.component as component
from deluge._libtorrent import LT_VERSION, lt from deluge._libtorrent import LT_VERSION, lt
from deluge.common import ( from deluge.common import (
PY2,
VersionSplit, VersionSplit,
archive_files, archive_files,
decode_bytes, decode_bytes,
@ -821,9 +818,6 @@ class TorrentManager(component.Component):
try: try:
with open(filepath, 'rb') as _file: with open(filepath, 'rb') as _file:
if PY2:
state = pickle.load(_file)
else:
state = pickle.load(_file, encoding='utf8') state = pickle.load(_file, encoding='utf8')
except (IOError, EOFError, pickle.UnpicklingError) as ex: except (IOError, EOFError, pickle.UnpicklingError) as ex:
message = 'Unable to load {}: {}'.format(filepath, ex) message = 'Unable to load {}: {}'.format(filepath, ex)

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, print_function, unicode_literals
import os import os
import stat import stat
@ -105,9 +103,7 @@ def generate_ssl_keys():
""" """
This method generates a new SSL key/cert. This method generates a new SSL key/cert.
""" """
from deluge.common import PY2 digest = 'sha256'
digest = 'sha256' if not PY2 else b'sha256'
# Generate key pair # Generate key pair
pkey = crypto.PKey() pkey = crypto.PKey()

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import inspect import inspect
import re import re
import warnings import warnings

View File

@ -9,9 +9,6 @@
# #
from __future__ import unicode_literals
class DelugeError(Exception): class DelugeError(Exception):
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
inst = super(DelugeError, cls).__new__(cls, *args, **kwargs) inst = super(DelugeError, cls).__new__(cls, *args, **kwargs)

View File

@ -14,10 +14,6 @@ This module describes the types of events that can be generated by the daemon
and subsequently emitted to the clients. and subsequently emitted to the clients.
""" """
from __future__ import unicode_literals
import six
known_events = {} known_events = {}
@ -32,7 +28,7 @@ class DelugeEventMetaClass(type):
known_events[name] = cls known_events[name] = cls
class DelugeEvent(six.with_metaclass(DelugeEventMetaClass, object)): class DelugeEvent(metaclass=DelugeEventMetaClass):
""" """
The base class for all events. The base class for all events.

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import cgi import cgi
import logging import logging
import os.path import os.path

View File

@ -3,8 +3,6 @@
# This file is public domain. # This file is public domain.
# #
from __future__ import unicode_literals
# Language code for this installation. All choices can be found here: # Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html # http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'

View File

@ -7,8 +7,7 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals import builtins
import ctypes import ctypes
import gettext import gettext
import locale import locale
@ -17,8 +16,6 @@ import os
import sys import sys
from glob import glob from glob import glob
from six.moves import builtins
import deluge.common import deluge.common
from .languages import LANGUAGES from .languages import LANGUAGES
@ -113,10 +110,7 @@ def setup_translation():
gettext.bindtextdomain(I18N_DOMAIN, translations_path) gettext.bindtextdomain(I18N_DOMAIN, translations_path)
gettext.textdomain(I18N_DOMAIN) gettext.textdomain(I18N_DOMAIN)
# Workaround for Python 2 unicode gettext (keyword removed in Py3). gettext.install(I18N_DOMAIN, translations_path, names=['ngettext'])
kwargs = {} if not deluge.common.PY2 else {'unicode': True}
gettext.install(I18N_DOMAIN, translations_path, names=['ngettext'], **kwargs)
builtins.__dict__['_n'] = builtins.__dict__['ngettext'] builtins.__dict__['_n'] = builtins.__dict__['ngettext']
def load_libintl(libintls): def load_libintl(libintls):

View File

@ -9,8 +9,6 @@
# #
"""Logging functions""" """Logging functions"""
from __future__ import unicode_literals
import inspect import inspect
import logging import logging
import logging.handlers import logging.handlers
@ -102,9 +100,6 @@ class Logging(LoggingLoggerClass):
continue continue
rv = (co.co_filename, f.f_lineno, co.co_name, None) rv = (co.co_filename, f.f_lineno, co.co_name, None)
break break
if common.PY2:
return rv[:-1]
else:
return rv return rv

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import os import os
from hashlib import sha1 as sha from hashlib import sha1 as sha

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import logging import logging
import os.path import os.path
import time import time

View File

@ -8,12 +8,8 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os import os
from deluge.common import PY2
def is_hidden(filepath): def is_hidden(filepath):
def has_hidden_attribute(filepath): def has_hidden_attribute(filepath):
@ -54,9 +50,6 @@ def get_completion_paths(args):
def get_subdirs(dirname): def get_subdirs(dirname):
try: try:
if PY2:
return os.walk(dirname).__next__[1]
else:
return next(os.walk(dirname))[1] return next(os.walk(dirname))[1]
except StopIteration: except StopIteration:
# Invalid dirname # Invalid dirname

View File

@ -9,8 +9,6 @@
"""PluginManagerBase""" """PluginManagerBase"""
from __future__ import unicode_literals
import logging import logging
import os.path import os.path

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -13,8 +13,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import os import os
import shutil import shutil

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import os import os

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,13 +12,10 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from functools import wraps from functools import wraps
from sys import exc_info from sys import exc_info
import six
from pkg_resources import resource_filename from pkg_resources import resource_filename
@ -47,7 +44,7 @@ def raises_errors_as(error):
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
except Exception: except Exception:
(value, tb) = exc_info()[1:] (value, tb) = exc_info()[1:]
six.reraise(error, value, tb) raise error(value).with_traceback(tb) from None
return wrapper return wrapper

View File

@ -8,14 +8,13 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import logging import logging
import os import os
import shutil import shutil
import time import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from email.utils import formatdate from email.utils import formatdate
from urllib.parse import urljoin
from twisted.internet import defer, threads from twisted.internet import defer, threads
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
@ -32,12 +31,6 @@ from .common import IP, BadIP
from .detect import UnknownFormatError, create_reader, detect_compression, detect_format from .detect import UnknownFormatError, create_reader, detect_compression, detect_format
from .readers import ReaderParseError from .readers import ReaderParseError
try:
from urllib.parse import urljoin
except ImportError:
# PY2 fallback
from urlparse import urljoin # pylint: disable=ungrouped-imports
# TODO: check return values for deferred callbacks # TODO: check return values for deferred callbacks
# TODO: review class attributes for redundancy # TODO: review class attributes for redundancy

View File

@ -8,8 +8,6 @@
# #
# pylint: disable=redefined-builtin # pylint: disable=redefined-builtin
from __future__ import unicode_literals
import bz2 import bz2
import gzip import gzip
import zipfile import zipfile

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from .decompressers import BZipped2, GZipped, Zipped from .decompressers import BZipped2, GZipped, Zipped
from .readers import EmuleReader, PeerGuardianReader, SafePeerReader from .readers import EmuleReader, PeerGuardianReader, SafePeerReader

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from datetime import datetime from datetime import datetime

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import gzip import gzip
import logging import logging
import socket import socket
@ -65,8 +63,5 @@ class PGReader(object):
return (start, end) return (start, end)
# Python 2 compatibility
next = __next__
def close(self): def close(self):
self.fd.close() self.fd.close()

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import re import re

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import hashlib import hashlib
import logging import logging
import os import os

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import gi # isort:skip (Required before Gtk import). import gi # isort:skip (Required before Gtk import).

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import errno import errno
import logging import logging
import os import os
@ -37,10 +35,7 @@ if windows_check():
'C:\\Program Files (x86)\\7-Zip\\7z.exe', 'C:\\Program Files (x86)\\7-Zip\\7z.exe',
] ]
try:
import winreg import winreg
except ImportError:
import _winreg as winreg # For Python 2.
try: try:
hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Software\\7-Zip') hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Software\\7-Zip')

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import gi # isort:skip (Required before Gtk import). import gi # isort:skip (Required before Gtk import).

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -15,8 +15,6 @@
torrent-label core plugin. torrent-label core plugin.
adds a status field for tracker. adds a status field for tracker.
""" """
from __future__ import unicode_literals
import logging import logging
import re import re

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge import component # for systray from deluge import component # for systray

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from gi.repository.Gtk import Builder from gi.repository.Gtk import Builder

View File

@ -8,8 +8,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import gi # isort:skip (Required before Gtk import). import gi # isort:skip (Required before Gtk import).

View File

@ -8,8 +8,6 @@
# #
from __future__ import unicode_literals
import logging import logging
from gi.repository.Gtk import Menu, MenuItem from gi.repository.Gtk import Menu, MenuItem

View File

@ -10,8 +10,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import print_function, unicode_literals
from deluge.ui.client import sclient from deluge.ui.client import sclient
sclient.set_core_uri() sclient.set_core_uri()

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import os.path import os.path

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import smtplib import smtplib
from email.utils import formatdate from email.utils import formatdate
@ -119,7 +117,6 @@ Date: %(date)s
message = '\r\n'.join((headers + message).splitlines()) message = '\r\n'.join((headers + message).splitlines())
try: try:
# Python 2.6
server = smtplib.SMTP( server = smtplib.SMTP(
self.config['smtp_host'], self.config['smtp_port'], timeout=60 self.config['smtp_host'], self.config['smtp_port'], timeout=60
) )

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from os.path import basename from os.path import basename

View File

@ -6,8 +6,6 @@
# License: BSD - Please view the LICENSE file for additional information. # License: BSD - Please view the LICENSE file for additional information.
# ============================================================================== # ==============================================================================
from __future__ import unicode_literals
import logging import logging
from twisted.internet import task from twisted.internet import task

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import time import time

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import logging import logging
from gi.repository import Gdk, Gtk from gi.repository import Gdk, Gtk

View File

@ -10,8 +10,6 @@
# the additional special exception to link portions of this program with the OpenSSL library. # the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -10,8 +10,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import logging import logging
import time import time

View File

@ -14,8 +14,6 @@
port of old plugin by markybob. port of old plugin by markybob.
""" """
from __future__ import division, unicode_literals
import logging import logging
import math import math
import time import time

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import division, unicode_literals
import logging import logging
from gi.repository import Gtk from gi.repository import Gtk

View File

@ -4,8 +4,6 @@
# the additional special exception to link portions of this program with the OpenSSL library. # the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import print_function, unicode_literals
import pytest import pytest
from twisted.internet import defer from twisted.internet import defer
from twisted.trial import unittest from twisted.trial import unittest

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import deluge.component as component import deluge.component as component

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import deluge.component as component import deluge.component as component

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from deluge.plugins.pluginbase import WebPluginBase from deluge.plugins.pluginbase import WebPluginBase

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from deluge.plugins.init import PluginInitBase from deluge.plugins.init import PluginInitBase

View File

@ -12,8 +12,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import os.path import os.path
from pkg_resources import resource_filename from pkg_resources import resource_filename

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from twisted.internet import defer from twisted.internet import defer

View File

@ -11,8 +11,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
from gi.repository import Gtk from gi.repository import Gtk

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
from twisted.trial import unittest from twisted.trial import unittest
import deluge.component as component import deluge.component as component

View File

@ -10,8 +10,6 @@
""" """
This base class is used in plugin's __init__ for the plugin entry points. This base class is used in plugin's __init__ for the plugin entry points.
""" """
from __future__ import unicode_literals
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -7,8 +7,6 @@
# See LICENSE for more details. # See LICENSE for more details.
# #
from __future__ import unicode_literals
import logging import logging
import deluge.component as component import deluge.component as component

View File

@ -7,8 +7,6 @@ python create_plugin.py --name MyPlugin2 --basepath . --author-name "Your Name"
""" """
from __future__ import print_function, unicode_literals
import os import os
import sys import sys
from argparse import ArgumentParser from argparse import ArgumentParser

View File

@ -12,8 +12,6 @@
# #
# Authour: Garett Harnish # Authour: Garett Harnish
from __future__ import unicode_literals
import logging import logging
import sys import sys
from optparse import OptionParser from optparse import OptionParser

View File

@ -1,7 +1,5 @@
# Increase open file descriptor limit to allow tests to run # Increase open file descriptor limit to allow tests to run
# without getting error: what(): epoll: Too many open files # without getting error: what(): epoll: Too many open files
from __future__ import print_function, unicode_literals
from deluge.i18n import setup_translation from deluge.i18n import setup_translation
try: try:

Some files were not shown because too many files have changed in this diff Show More