diff options
author | Calum Lind <calumlind@gmail.com> | 2018-05-16 11:27:49 +0100 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2018-06-27 16:41:21 +0100 |
commit | c3a2c67b98501932438762a47c7ef45e4cebb66b (patch) | |
tree | 55f541ef596d9e9eedd95b05ee3540f9db991199 /deluge/common.py | |
parent | 200e8f552b5aee8e7d597750acf132a37f2a00c8 (diff) | |
download | deluge-c3a2c67b98501932438762a47c7ef45e4cebb66b.tar.gz deluge-c3a2c67b98501932438762a47c7ef45e4cebb66b.tar.bz2 deluge-c3a2c67b98501932438762a47c7ef45e4cebb66b.zip |
[Py3] A large set of fixes for tests to pass under Python 3
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.
Diffstat (limited to 'deluge/common.py')
-rw-r--r-- | deluge/common.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/deluge/common.py b/deluge/common.py index 225d3e797..f90d58799 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -11,6 +11,7 @@ from __future__ import division, print_function, unicode_literals import base64 +import binascii import datetime import functools import glob @@ -702,10 +703,11 @@ def get_magnet_info(uri): xt_hash = param[len(XT_BTIH_PARAM):] if len(xt_hash) == 32: try: - info_hash = base64.b32decode(xt_hash.upper()).encode('hex') + infohash_str = base64.b32decode(xt_hash.upper()) except TypeError as ex: log.debug('Invalid base32 magnet hash: %s, %s', xt_hash, ex) break + info_hash = binascii.hexlify(infohash_str) elif is_infohash(xt_hash): info_hash = xt_hash.lower() else: @@ -744,11 +746,15 @@ def create_magnet_uri(infohash, name=None, trackers=None): """ try: - infohash = infohash.decode('hex') - except AttributeError: - pass - - uri = [MAGNET_SCHEME, XT_BTIH_PARAM, base64.b32encode(infohash)] + infohash = binascii.unhexlify(infohash) + except TypeError: + infohash.encode('utf-8') + + uri = [ + MAGNET_SCHEME, + XT_BTIH_PARAM, + base64.b32encode(infohash).decode('utf-8'), + ] if name: uri.extend(['&', DN_PARAM, name]) if trackers: |