Skip to content

Commit

Permalink
Merge branch 'deluge-torrent:develop' into console-move
Browse files Browse the repository at this point in the history
  • Loading branch information
mhertz authored Sep 10, 2024
2 parents c49c3d2 + d064ad0 commit bee0872
Show file tree
Hide file tree
Showing 61 changed files with 291 additions and 267 deletions.
28 changes: 9 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,25 @@ exclude: >
deluge/tests/data/.*svg|
)$
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.4
hooks:
- id: black
name: Fmt Black
- id: ruff
name: Chk Ruff
args: [--fix]
- id: ruff-format
name: Fmt Ruff
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
name: Fmt Prettier
# Workaround to list modified files only.
args: [--list-different]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: Fmt isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
name: Chk Flake8
additional_dependencies:
- pep8-naming==0.12.1
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: double-quote-string-fixer
name: Fix Double-quotes
- id: end-of-file-fixer
name: Fix End-of-files
exclude_types: [javascript, css]
Expand All @@ -47,5 +37,5 @@ repos:
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
stages: [manual]
6 changes: 6 additions & 0 deletions __builtins__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from twisted.web.http import Request

__request__: Request

def _(string: str) -> str: ...
def _n(string: str) -> str: ...
1 change: 1 addition & 0 deletions deluge/_libtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
>>> from deluge._libtorrent import lt
"""

from deluge.common import VersionSplit, get_version
from deluge.error import LibtorrentImportError

Expand Down
11 changes: 11 additions & 0 deletions deluge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""Common functions for various parts of Deluge to use."""

import base64
import binascii
import functools
Expand Down Expand Up @@ -720,6 +721,16 @@ def parse_human_size(size):
raise InvalidSize(msg % (size, tokens))


def anchorify_urls(text: str) -> str:
"""
Wrap all occurrences of text URLs with HTML
"""
url_pattern = r'((htt)|(ft)|(ud))ps?://\S+'
html_href_pattern = r'<a href="\g<0>">\g<0></a>'

return re.sub(url_pattern, html_href_pattern, text)


def is_url(url):
"""
A simple test to check if the URL is valid
Expand Down
1 change: 1 addition & 0 deletions deluge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
version as this will be done internally.
"""

import json
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions deluge/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def reset(timeout=0.5, *args, **kwargs):
mock.deferred = deferred

mock = Mock()
mock.__qualname__ = 'mock'
original_reset_mock = mock.reset_mock
mock.reset_mock = reset
mock.reset_mock()
Expand Down
1 change: 1 addition & 0 deletions deluge/core/alertmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
`:mod:EventManager` for similar functionality.
"""

import contextlib
import logging
import threading
Expand Down
1 change: 1 addition & 0 deletions deluge/core/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""The Deluge daemon"""

import logging
import os
import socket
Expand Down
1 change: 1 addition & 0 deletions deluge/core/pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


"""PluginManager for Core"""

import logging

from twisted.internet import defer
Expand Down
13 changes: 6 additions & 7 deletions deluge/core/rpcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""RPCServer Module"""

import logging
import os
import sys
Expand Down Expand Up @@ -46,13 +47,11 @@


@overload
def export(func: TCallable) -> TCallable:
...
def export(func: TCallable) -> TCallable: ...


@overload
def export(auth_level: int) -> Callable[[TCallable], TCallable]:
...
def export(auth_level: int) -> Callable[[TCallable], TCallable]: ...


def export(auth_level=AUTH_LEVEL_DEFAULT):
Expand Down Expand Up @@ -274,9 +273,9 @@ def send_error():
raise IncompatibleClient(deluge.common.get_version())
ret = component.get('AuthManager').authorize(*args, **kwargs)
if ret:
self.factory.authorized_sessions[
self.transport.sessionno
] = self.AuthLevel(ret, args[0])
self.factory.authorized_sessions[self.transport.sessionno] = (
self.AuthLevel(ret, args[0])
)
self.factory.session_protocols[self.transport.sessionno] = self
except Exception as ex:
send_error()
Expand Down
23 changes: 10 additions & 13 deletions deluge/core/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,8 @@ def _create_status_funcs(self):
'download_location': lambda: self.options['download_location'],
'seeds_peers_ratio': lambda: -1.0
if self.status.num_incomplete == 0
else ( # Use -1.0 to signify infinity
self.status.num_complete / self.status.num_incomplete
),
# Use -1.0 to signify infinity
else (self.status.num_complete / self.status.num_incomplete),
'seed_rank': lambda: self.status.seed_rank,
'state': lambda: self.state,
'stop_at_ratio': lambda: self.options['stop_at_ratio'],
Expand Down Expand Up @@ -1544,20 +1543,18 @@ def _get_pieces_info(self):
self.status.pieces, self.handle.piece_availability()
):
if piece:
pieces.append(3) # Completed.
# Completed.
pieces.append(3)
elif avail_piece:
pieces.append(
1
) # Available, just not downloaded nor being downloaded.
# Available, just not downloaded nor being downloaded.
pieces.append(1)
else:
pieces.append(
0
) # Missing, no known peer with piece, or not asked for yet.
# Missing, no known peer with piece, or not asked for yet.
pieces.append(0)

for peer_info in self.handle.get_peer_info():
if peer_info.downloading_piece_index >= 0:
pieces[
peer_info.downloading_piece_index
] = 2 # Being downloaded from peer.
# Being downloaded from peer.
pieces[peer_info.downloading_piece_index] = 2

return pieces
1 change: 1 addition & 0 deletions deluge/core/torrentmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

"""TorrentManager handles Torrent objects"""

import datetime
import logging
import operator
Expand Down
2 changes: 1 addition & 1 deletion deluge/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def addCallbacks(self, *args, **kwargs): # noqa: N802


def maybe_coroutine(
f: Callable[..., Coroutine[Any, Any, _RetT]]
f: Callable[..., Coroutine[Any, Any, _RetT]],
) -> 'Callable[..., defer.Deferred[_RetT]]':
"""Wraps a coroutine function to make it usable as a normal function that returns a Deferred."""

Expand Down
1 change: 1 addition & 0 deletions deluge/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
and subsequently emitted to the clients.
"""

known_events = {}


Expand Down
14 changes: 9 additions & 5 deletions deluge/httpdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See LICENSE for more details.
#

import cgi
import email.message
import logging
import os.path
import zlib
Expand Down Expand Up @@ -133,9 +133,10 @@ def request_callback(self, response):
content_disp = headers.getRawHeaders(b'content-disposition')[0].decode(
'utf-8'
)
content_disp_params = cgi.parse_header(content_disp)[1]
if 'filename' in content_disp_params:
new_file_name = content_disp_params['filename']
message = email.message.EmailMessage()
message['content-disposition'] = content_disp
new_file_name = message.get_filename()
if new_file_name:
new_file_name = sanitise_filename(new_file_name)
new_file_name = os.path.join(
os.path.split(self.filename)[0], new_file_name
Expand All @@ -152,7 +153,10 @@ def request_callback(self, response):
self.filename = new_file_name

cont_type_header = headers.getRawHeaders(b'content-type')[0].decode()
cont_type, params = cgi.parse_header(cont_type_header)
message = email.message.EmailMessage()
message['content-type'] = cont_type_header
cont_type = message.get_content_type()
params = message['content-type'].params
# Only re-ecode text content types.
encoding = None
if cont_type.startswith('text/'):
Expand Down
1 change: 1 addition & 0 deletions deluge/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

"""Logging functions"""

import inspect
import logging
import logging.handlers
Expand Down
1 change: 1 addition & 0 deletions deluge/pluginmanagerbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


"""PluginManagerBase"""

import email
import logging
import os.path
Expand Down
2 changes: 1 addition & 1 deletion deluge/plugins/AutoAdd/deluge_autoadd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def on_torrent_added(torrent_id, filename, filepath):
if 'Label' in component.get('CorePluginManager').get_enabled_plugins():
if watchdir.get('label_toggle', True) and watchdir.get('label'):
label = component.get('CorePlugin.Label')
if not watchdir['label'] in label.get_labels():
if watchdir['label'] not in label.get_labels():
label.add(watchdir['label'])
try:
label.set_torrent(torrent_id, watchdir['label'])
Expand Down
6 changes: 3 additions & 3 deletions deluge/plugins/Blocklist/deluge_blocklist/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def parse(cls, ip):
try:
q1, q2, q3, q4 = (int(q) for q in ip.split('.'))
except ValueError:
raise BadIP(_('The IP address "%s" is badly formed' % ip))
raise BadIP(_('The IP address "%s" is badly formed') % ip)
if q1 < 0 or q2 < 0 or q3 < 0 or q4 < 0:
raise BadIP(_('The IP address "%s" is badly formed' % ip))
raise BadIP(_('The IP address "%s" is badly formed') % ip)
elif q1 > 255 or q2 > 255 or q3 > 255 or q4 > 255:
raise BadIP(_('The IP address "%s" is badly formed' % ip))
raise BadIP(_('The IP address "%s" is badly formed') % ip)
return cls(q1, q2, q3, q4)

def quadrants(self):
Expand Down
3 changes: 2 additions & 1 deletion deluge/plugins/Label/deluge_label/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
torrent-label core plugin.
adds a status field for tracker.
"""

import logging
import re

Expand Down Expand Up @@ -182,7 +183,7 @@ def add(self, label_id):
RE_VALID.match(label_id), _('Invalid label, valid characters:[a-z0-9_-]')
)
check_input(label_id, _('Empty Label'))
check_input(not (label_id in self.labels), _('Label already exists'))
check_input(label_id not in self.labels, _('Label already exists'))

self.labels[label_id] = dict(OPTIONS_DEFAULTS)
self.config.save()
Expand Down
24 changes: 12 additions & 12 deletions deluge/plugins/Scheduler/deluge_scheduler/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def on_state_deferred(state):
def disable(self):
component.get('Preferences').remove_page(_('Scheduler'))
# Reset statusbar dict.
self.statusbar.config_value_changed_dict[
'max_download_speed'
] = self.statusbar._on_max_download_speed
self.statusbar.config_value_changed_dict[
'max_upload_speed'
] = self.statusbar._on_max_upload_speed
self.statusbar.config_value_changed_dict['max_download_speed'] = (
self.statusbar._on_max_download_speed
)
self.statusbar.config_value_changed_dict['max_upload_speed'] = (
self.statusbar._on_max_upload_speed
)
# Remove statusbar item.
self.statusbar.remove_item(self.status_item)
del self.status_item
Expand Down Expand Up @@ -246,12 +246,12 @@ def on_scheduler_event(self, state):
# Skip error due to Plugin being enabled before statusbar items created on startup.
pass
else:
self.statusbar.config_value_changed_dict[
'max_download_speed'
] = self.statusbar._on_max_download_speed
self.statusbar.config_value_changed_dict[
'max_upload_speed'
] = self.statusbar._on_max_upload_speed
self.statusbar.config_value_changed_dict['max_download_speed'] = (
self.statusbar._on_max_download_speed
)
self.statusbar.config_value_changed_dict['max_upload_speed'] = (
self.statusbar._on_max_upload_speed
)

def update_config_values(config):
try:
Expand Down
4 changes: 3 additions & 1 deletion deluge/plugins/Stats/deluge_stats/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def set_colors(self, colors):
self.colors = colors
# Fake switch page to update the graph colors (HACKY)
self._on_notebook_switch_page(
self.notebook, None, self.notebook.get_current_page() # This is unused
self.notebook,
None,
self.notebook.get_current_page(), # This is unused
)

def _on_intervals_changed(self, intervals):
Expand Down
1 change: 1 addition & 0 deletions deluge/plugins/Stats/deluge_stats/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_write(self, tmp_path):
Not strictly a unit test, but tests if calls do not fail...
"""
# ruff: noqa: I001
from deluge_stats import graph, gtkui

from deluge.configmanager import ConfigManager
Expand Down
1 change: 1 addition & 0 deletions deluge/plugins/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
This base class is used in plugin's __init__ for the plugin entry points.
"""

import logging

log = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit bee0872

Please sign in to comment.