From 8cd4b56891f7c79a13518e38a18e0eb6a01fb04c Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sat, 15 Dec 2018 18:31:36 -0500 Subject: [PATCH] Fix imports for Python 3 --- core/versionCheck.py | 5 +++-- libs/synchronousdeluge/client.py | 12 +++++++----- libs/utorrent/client.py | 13 ++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/core/versionCheck.py b/core/versionCheck.py index b77ddab8..7fb94889 100644 --- a/core/versionCheck.py +++ b/core/versionCheck.py @@ -10,7 +10,8 @@ import stat import subprocess import tarfile import traceback -import urllib + +from six.moves.urllib.request import urlretrieve import core from core import gh_api as github, logger @@ -451,7 +452,7 @@ class SourceUpdateManager(UpdateManager): # retrieve file logger.log(u"Downloading update from {url!r}".format(url=tar_download_url)) tar_download_path = os.path.join(sb_update_dir, u'nzbtomedia-update.tar') - urllib.urlretrieve(tar_download_url, tar_download_path) + urlretrieve(tar_download_url, tar_download_path) if not os.path.isfile(tar_download_path): logger.log(u"Unable to retrieve new version from {url}, can't update".format diff --git a/libs/synchronousdeluge/client.py b/libs/synchronousdeluge/client.py index 7d0bbba0..bc82f8d6 100644 --- a/libs/synchronousdeluge/client.py +++ b/libs/synchronousdeluge/client.py @@ -28,12 +28,14 @@ class DelugeClient(object): if platform.system() in ('Windows', 'Microsoft'): appDataPath = os.environ.get("APPDATA") if not appDataPath: - import _winreg - hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") - appDataReg = _winreg.QueryValueEx(hkey, "AppData") + from six.moves import winreg + hkey = winreg.OpenKey( + winreg.HKEY_CURRENT_USER, + "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", + ) + appDataReg = winreg.QueryValueEx(hkey, "AppData") appDataPath = appDataReg[0] - _winreg.CloseKey(hkey) + winreg.CloseKey(hkey) auth_file = os.path.join(appDataPath, "deluge", "auth") else: diff --git a/libs/utorrent/client.py b/libs/utorrent/client.py index 12ff919c..44dd1679 100644 --- a/libs/utorrent/client.py +++ b/libs/utorrent/client.py @@ -1,8 +1,7 @@ # coding=utf8 import re -import urllib -from six import StringIO +from six import StringIO, iteritems from six.moves.http_cookiejar import CookieJar from six.moves.urllib.request import ( HTTPBasicAuthHandler, @@ -11,7 +10,7 @@ from six.moves.urllib.request import ( build_opener, install_opener, ) -from six.moves.urllib_parse import urljoin +from six.moves.urllib_parse import urlencode, urljoin from .upload import MultiPartForm @@ -94,7 +93,7 @@ class UTorrentClient(object): def setprops(self, hash, **kvpairs): params = [('action', 'setprops'), ('hash', hash)] - for k, v in kvpairs.iteritems(): + for k, v in iteritems(kvpairs): params.append( ("s", k) ) params.append( ("v", v) ) @@ -114,7 +113,7 @@ class UTorrentClient(object): if filepath is not None: file_handler = open(filepath,'rb') else: - file_handler = StringIO.StringIO(bytes) + file_handler = StringIO(bytes) form.add_file('torrent_file', filename.encode('utf-8'), file_handler) @@ -138,11 +137,11 @@ class UTorrentClient(object): def _action(self, params, body=None, content_type=None): #about token, see https://github.com/bittorrent/webui/wiki/TokenSystem - url = self.base_url + '?token=' + self.token + '&' + urllib.urlencode(params) + url = self.base_url + '?token=' + self.token + '&' + urlencode(params) request = Request(url) if body: - request.add_data(body) + request.data = body request.add_header('Content-length', len(body)) if content_type: request.add_header('Content-type', content_type)