summaryrefslogtreecommitdiffstats
path: root/deluge/core/core.py
Commit message (Collapse)AuthorAge
* [Core] Refactor prefetch_metadata for more clarityChase Sterling2022-05-17
| | | | | | | | | | | | | | | | | | | | | | | | Just trying to clean up some of the more complicated callback logic. Notable changes: * The test was awaiting a DeferredList. By default that will eat exceptions and just add them to the result list (including test assertion exceptions.) Added fireOnOneErrback=True to make sure that wasn't happening. * Moved the logic for multiple calls to await the same response into torrentmanager from core, so no matter where the prefetch is called from it will wait for the original call. * Implemented the multiple calls with an explicit queue of waiting callbacks, rather than a callback callback chain. * Moved to one inline async function rather than split into a main and callback after alert function. * Added some more type hints to the stuff I changed. Adjusted test since we are using prefetch as an async function now we have to schedule the alert to come after we start awaiting the prefetch call. Closes: https://github.com/deluge-torrent/deluge/pull/368
* [Core] Cleanup temp files in add_torrent_urlCalum Lind2022-05-01
| | | | | | | | | | | | | Temporary torrent files are not deleted by add_torrent_url. Not as big a problem as with tracker icons pages but should be removed after use. Fixed by updating the method to use async and a try..finally cleanup block. Perhaps could be refactored to not require temporary files and instead store the downloaded torrent as object for passing to add_torrent_file. Trac: https://dev.deluge-torrent.org/ticket/3167
* [Core] Document all exported core methods with type hintsChase Sterling2022-02-11
| | | | | | | | | | | | | | | Standardize docstrings in core.py to google standard. Remove type hints in docstrings in favor of the ones in method signatures. Use function signature type hints in autodoc generated docs. Change Deferred type hints to strings. Older versions of twisted (<21.7) don't support generic Deferred type hinting, this prevents crashes on those versions. Closes: https://github.com/deluge-torrent/deluge/pull/359
* [Core] Convert inlineCallbacks to maybe_coroutineChase Sterling2022-02-06
| | | | | | | | | | Make logging functions synchronous. They were not calling any async functions, and wrapping them in maybe_coroutine caused reactor to be imported before gtkui could install the gtk reactor. Closes: https://github.com/deluge-torrent/deluge/pull/353
* Revert "[Core] Document all exported core methods with type hints"Calum Lind2022-02-05
| | | | | | | | | | | | | | | Typing is broken with older versions of Twisted e.g. with v21.2 deluge/deluge/core/core.py", line 404, in Core ) -> defer.Deferred[str]: TypeError: 'type' object is not subscriptable Also it might not be compatible with Python 3.6 or 3.7 with use of certain types such as dict rather than Dict This reverts commit 4096cdfdfe4fc7e42746cedd868bd7d8fea99f23. Ref: https://twistedmatrix.com/trac/ticket/9816
* [Core] Document all exported core methods with type hintsChase Sterling2022-02-05
| | | | | | | | | Standardize docstrings in core.py to google standard. Remove type hints in docstrings in favor of the ones in method signatures. Use function signature type hints in autodoc generated docs. Closes: https://github.com/deluge-torrent/deluge/pull/359
* [Common] Add is_interface to validate network interfacestbkizle2022-01-30
| | | | | | | | | | | | | | | | | | | | | | Libtorrent now supports interface names instead of just IP address so add new common functions to validate user input. * Added is_interface that will verify if a libtorrent interface of name or IP address. * Added is_interface_name to verify that the name supplied is a valid network interface name in the operating system. On Windows sock.if_nameindex() is only supported on 3.8+ and does not return a uuid (required by libtorrent) so use ifaddr package. Using git commit version for ifaddr due to adapter name decode bug in v0.1.7. On other OSes attempt to use stdlib and fallback to ifaddr if installed otherwiser return True. * Added tests for is_interface & is_interface_name * Updated UIs with change from address to interface * Updated is_ipv6 and is_ipv4 to used inet_pton; now supported on Windows. Ref: https://github.com/pydron/ifaddr/pull/32 Closes: https://github.com/deluge-torrent/deluge/pull/338
* [Core] Return plugin keys with get_torrents_statusChase Sterling2022-01-26
| | | | | | | | When requesting all keys, get_torrents_status was missing plugin added keys This commit brings the behavior in line with get_torrent_status, and deluge 1.3 Closes: https://dev.deluge-torrent.org/ticket/3357 Closes: https://github.com/deluge-torrent/deluge/pull/347
* [GTK] Fix unable to prefetch magnet in thinclientCalum Lind2022-01-08
| | | | | | | | | | | | | | | | A UnicodeDecodeError is raised in transfer module when attempting to prefetch a magnet. This is result of passing a Python dict containing text bytes and raw bytes that cannot be decoded as utf-8 in rencode when recieving the message. This could be handled in rencode by returning raw bytes if decoding fails (perhaps with a strict mode?) however better to follow convention of encoding raw bytes in base64 in API calls. Fixed by retaining bencoding and encoding with base64 when sending result. Resolves: https://github.com/deluge-torrent/deluge/pull/334
* Upgrade codebase with pyupgrade (>=py3.6)DjLegolas2021-12-29
| | | | | | | | Added pyupgrade utility with manual stage to pre-commit and run on all files. Ref: https://github.com/asottile/pyupgrade Closes: deluge-torrent/deluge#326
* Remove all Python 2 supportdeluge-2.1.0.dev0DjLegolas2021-12-28
| | | | | | | | | * 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
* [Core] Stop using removed disk.num_blocks_cache_hits staticzero2021-10-03
| | | | | Removed in libtorrent v2.0.0: https://github.com/arvidn/libtorrent/commit/569d47c3914d1f4a8672b92166ee461b4ae33aef
* [Lint] Fix spelling mistakesCalum Lind2021-09-21
| | | | | | | A quick fix of some of the mistakes caught by codespell. Updated readme with new IRC server Useful to add it as part of linting checks.
* [Core] Export torrent get_magnet_uri methodCalum Lind2021-09-21
| | | | Returns a generated magnet uri from torrent info
* [#3310|Core] Change logging invalid session status key to debugCalum Lind2021-08-29
| | | | | | | | Users were complaining about logs being flooded with `Session status key not valid` which was a result of the Stats plugin using the wrong status keys. Fixed by changing to debug log level since not useful in warning level if spamming.
* [Lint] Update pre-commit hook and isort versionsCalum Lind2021-01-24
| | | | | | | | | | | | | * Fixed black hook requiring Py3.6 to installed locally. Will now assume Py3.6+ in installed. * Added isort traceback in pre-commit flake8 hook fails * Updated versions of Black, Prettier and isort * Keep Flake8 at 3.7.9 due to E402 issue: https://gitlab.com/pycqa/flake8/-/issues/638 * New pyproject config for isort v5 with fixes for Python 2 imports. * Fixed travis config to run Python 3.6 for lint run. Replaced the virtualenv with_system_site_packages config with Travis specific Python config value so lint run doesn't attempt to append with_system_site_packages to Python 3.6 command.
* [Docs] Add spellchecking with pyenchantCalum Lind2019-06-15
| | | | | | | | | - Use sphinxcontrib.spelling with custom wordlist. - Skip the checking of the modules documents as they raise false-positives. - Add a setup.py spellcheck_docs command. - Fix spelling and other issues. - Add a doc favicon.
* [Core] Fix prefetch magnets missing trackersCalum Lind2019-05-20
| | | | | | | | | | | | | | | | | | | | | | When adding magnets that have been prefetched the tracker details were lost. A result of returning only the lt.torrent_info.metadata which does not contain full torrent details, such as trackers. - Modified torrentmanager prefetch_metadata to return dict instead of base64 encoded bencoded metadata dict... - Used a namedtuple to ease identifying tuple contents. - Updated tests to reflect changes with mock trackers added to test_torrent.file.torrent. - Refactor TorrentInfo to accept dict instead of bytes and add a class method to accept metadata dict with lists of trackers. - Rename class arg from metainfo to torrent_file, matching lt.torrent_info. - Rename metadata property to correct name; metainfo. - Simplify class variable naming with _filedata and _metainfo for torrent file contents encoded and decoded respectively. - Update GTK Add torrent dialog to pass trackers to TorrentInfo.
* [Docs] Fix formatting of exported docstringsCalum Lind2018-11-16
|
* [Lint] Fix flake8 warningsCalum Lind2018-10-25
| | | | | | - Use six to silence flake8 undefined Python 2 names on Python 3. - Fix W605 invalid escape sequence. - Cleanup unused exception variables.
* Cleanup outgoing_interface code and help textCalum Lind2018-10-04
| | | | | | - Remove is_ip check as libtorrent does accept IP address for this setting. See: https://github.com/arvidn/libtorrent/issues/3087 - Use consistent wording for help text.
* [Lint] Use Black to auto-format codeCalum Lind2018-10-03
| | | | | | | | | | | | | | | | | The move to using auto-formatter makes it easier to read, submit and speeds up development time. https://github.com/ambv/black/ Although I would prefer 79 chars, the default line length of 88 chars used by black suffices. The flake8 line length remains at 120 chars since black does not touch comments or docstrings and this will require another round of fixes. The only black setting that is not standard is the use of double-quotes for strings so disabled any formatting of these. Note however that flake8 will still flag usage of double-quotes. I may change my mind on double vs single quotes but for now leave them. A new pyproject.toml file has been created for black configuration.
* [Core] Fix saving listen_interface as NoneCalum Lind2018-09-30
| | | | | A mistake in refactoring meant that listen_interface was reset to None on shutdown.
* [Core] Refactor session status codeCalum Lind2018-09-28
| | | | | | | | | Simplify the methods by initialising the session_status dict using libtorrent session_stats_metrics and rate keys. Instead of first looking for deprecated keys use exception then lookup. Added a few more tests.
* [Core] Handle already prefetching magnet metadataCalum Lind2018-09-26
|
* [Core] Tweaks to prefetch metadata methodCalum Lind2018-09-26
| | | | | | | - Disable the magnet from being auto_managed so it starts immediately. - Reduce the default timeout to 30secs. - Use the generic tempfile dir. - Move callback method to be class method
* [Py2to3] Fix log.warn deprecation warningCalum Lind2018-09-14
|
* [Core] Fix torrent pause/resume logicDeepak2018-08-10
| | | | If the torrent_id argument received in the pause or resume methods is not a string, the methods execute with the un-parsed input and then with parsed input on a second call. A key error exception is thrown from the first call, and the second call succeeds.
* [Win32] Fix missing certs for HTTPS requestsCalum Lind2018-06-29
| | | | | | | | | | | | | The following error occured on Windows when switching to using HTTPS url with Twisted Agent: ``` <class 'twisted.web._newclient.ResponseNeverReceived'>: [<twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]> ``` The fix is to install certifi and provide the path to the trust store as env var for OpenSSL to pick up. Also includes a simplication of the core test_listen_port code.
* Fix flake8 trailing commaCalum Lind2018-06-27
|
* [Py3] Decode new_release version to unicode stringCalum Lind2018-06-27
|
* [Py3] A large set of fixes for tests to pass under Python 3Calum Lind2018-06-27
| | | | | | | | | The usual minor fixes for unicode/bytes for library calls. The minimum Twisted version is now 16 for Python 3 support so remove old code and start replacing deprecated methods. Raised the minimum TLS version to 1.2 for the web server.
* [Core] Add prefetch metadata methods for magnetsCalum Lind2018-06-26
|
* [Py2to3] Replace deprecated base64.(de|en)codestringCalum Lind2018-06-26
| | | | | | * In Py3 base64.encodestring is deprecated so rather than use the Py3 only encodebytes instead use b64encode. The other advantage is that with issue a consistent TypeError is raised that we can catch.
* [Core] Add is_session_paused methodCalum Lind2018-06-18
|
* [Core] Add methods pause_torrents & resume_torrentsCalum Lind2018-06-18
|
* Fix and cleanup outgoing interface codeCalum Lind2018-06-02
| | | | | | | | | | | | There was a misunderstand about outgoing interface setting in libtorrent and instead of being able to take both IP and adapater names, it only accepts adapter names and errors with an IP address, which was the default of '0.0.0.0' in code. This fixes the code to not accept IP address and use empty string if it is given one. Also includes a bit of code cleanup.
* Fix files to pass new Flake8 checkersCalum Lind2018-06-01
| | | | | | | | | | | Some new flake8 checkers were added so fix these new warnings and any issues uncovered. Use add-trailing-comma to fix missing trailing commas. It does not format it as well as I would like however it was fast to change and helps with git changes in future. Removed pylint from tox due to large number of warnings.
* [#3171] Add Option To Specify Outgoing Connection InterfaceDoadin2018-05-21
|
* [#3121] Fix the peer-id to be uniqueCalum Lind2017-12-17
| | | | | The associated ticket made us aware that the id '-DE2000-' might be blocked.
* Use a constant for versionsCalum Lind2017-12-17
|
* [#3126|Core] Restore synchonous add torrent methods for backward compatibiltyCalum Lind2017-11-18
| | | | | | | | | | | | | The synchonous add torrent method was replaced with async but this break backward compatibility with 3rd party plugins and clients. Added a new add_torrent_file_async method for adding single torrent. Torrent manager has a new add_async method and split up code to prevent duplication. Update any use of add_torrent_file to add_torrent_file_async. Future refactoring could use add_torrent_files instead.
* [#3084] Fix error changing ownership on torrentsCalum Lind2017-06-29
|
* [#3044|Core] Stop libtorrent checking file timestamps in resume dataCalum Lind2017-06-08
| | | | | | * The verfication of timestamps of files on disc against those in resume data can be buggy and sends torrents to error state for no apparent reason. It has also been removed in latest version of libtorrent so disabling this check.
* [Core] Update new release urlCalum Lind2017-05-03
|
* [Py2to3] Large set of changes for Python 3 compatCalum Lind2017-03-16
| | | | | | | | | | | | - Preparation work for using six or future module for Py2/3 compat. The code will be written in Python 3 with Python 2 fallbacks. - Added some Py3 imports with Py2 fallbacks to make it easier to remove Py2 code in future. - Replace xrange with range (sort out import as top of files in future). - Workaround Py2to3 basestring issue with inline if in instances. This means every usage of basestring is more considered. - Replace iteritems and itervalues for items and values. There might be a performance penalty on Py2 so might need to revisit this change.
* [Py2to3] Refactor out usage of unicode and basestringCalum Lind2017-02-23
| | | | | | | | | | - Python 3 renames `unicode` type to `str` and introduces `bytes` type. - Python 2.7 has `bytes` but is only an alias for `str` so restricted to comparisons but helps keep compatibility. - To test for unicode string on Py2 and Py3 uses the "''.__class__" type. - Remove usage of utf8encode and just encode, problems with bytes being passed in code will be picked up faster. - Where possible refactor out isinstance for try..except duck-typing.
* [Core] Markup byte-strings to fix httpdownloader and core testsCalum Lind2017-02-22
| | | | | | | * Twisted methods require byte-string arguments. * The headers str conversion in httpdownloader _download_file was incorrent and left the dict key still as unicode so replaced with a dict comprehension (py2.7 requirement).
* [Py2to3] Force unicode_literals and fix related issuesCalum Lind2017-02-22
| | | | | | | | | | | | | | | | | | * Added `from __future__ import unicode_literals` to every file so now all strings in code are forced to be unicode strings unless marked as byte string `b'str'` or encoded to byte string `'str'.encode('utf-8')`. This is a large change but we have been working towards the goal of unicode strings passed in the code so decoding external input and encoding output as byte strings (where applicable). Note that in Python 2 the `str` type still refers to byte strings. * Replaced the use of `str` for `basestring` in isinstance comparison as this was the original intention but breaks code when encoutering unicode strings. * Marked byte strings in gtkui as the conversion to utf8 is not always handled, mostly related to gobject signal names.
* [#2826] Fix create_torrent filedump not encodedCalum Lind2017-02-21
|