Fix imports for Python 3

This commit is contained in:
Labrys of Knossos 2018-12-15 18:31:36 -05:00
parent f5f6562fe9
commit 8cd4b56891
3 changed files with 16 additions and 14 deletions

View file

@ -10,7 +10,8 @@ import stat
import subprocess import subprocess
import tarfile import tarfile
import traceback import traceback
import urllib
from six.moves.urllib.request import urlretrieve
import core import core
from core import gh_api as github, logger from core import gh_api as github, logger
@ -451,7 +452,7 @@ class SourceUpdateManager(UpdateManager):
# retrieve file # retrieve file
logger.log(u"Downloading update from {url!r}".format(url=tar_download_url)) 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') 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): if not os.path.isfile(tar_download_path):
logger.log(u"Unable to retrieve new version from {url}, can't update".format logger.log(u"Unable to retrieve new version from {url}, can't update".format

View file

@ -28,12 +28,14 @@ class DelugeClient(object):
if platform.system() in ('Windows', 'Microsoft'): if platform.system() in ('Windows', 'Microsoft'):
appDataPath = os.environ.get("APPDATA") appDataPath = os.environ.get("APPDATA")
if not appDataPath: if not appDataPath:
import _winreg from six.moves import winreg
hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, hkey = winreg.OpenKey(
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") winreg.HKEY_CURRENT_USER,
appDataReg = _winreg.QueryValueEx(hkey, "AppData") "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
)
appDataReg = winreg.QueryValueEx(hkey, "AppData")
appDataPath = appDataReg[0] appDataPath = appDataReg[0]
_winreg.CloseKey(hkey) winreg.CloseKey(hkey)
auth_file = os.path.join(appDataPath, "deluge", "auth") auth_file = os.path.join(appDataPath, "deluge", "auth")
else: else:

View file

@ -1,8 +1,7 @@
# coding=utf8 # coding=utf8
import re import re
import urllib
from six import StringIO from six import StringIO, iteritems
from six.moves.http_cookiejar import CookieJar from six.moves.http_cookiejar import CookieJar
from six.moves.urllib.request import ( from six.moves.urllib.request import (
HTTPBasicAuthHandler, HTTPBasicAuthHandler,
@ -11,7 +10,7 @@ from six.moves.urllib.request import (
build_opener, build_opener,
install_opener, install_opener,
) )
from six.moves.urllib_parse import urljoin from six.moves.urllib_parse import urlencode, urljoin
from .upload import MultiPartForm from .upload import MultiPartForm
@ -94,7 +93,7 @@ class UTorrentClient(object):
def setprops(self, hash, **kvpairs): def setprops(self, hash, **kvpairs):
params = [('action', 'setprops'), ('hash', hash)] params = [('action', 'setprops'), ('hash', hash)]
for k, v in kvpairs.iteritems(): for k, v in iteritems(kvpairs):
params.append( ("s", k) ) params.append( ("s", k) )
params.append( ("v", v) ) params.append( ("v", v) )
@ -114,7 +113,7 @@ class UTorrentClient(object):
if filepath is not None: if filepath is not None:
file_handler = open(filepath,'rb') file_handler = open(filepath,'rb')
else: else:
file_handler = StringIO.StringIO(bytes) file_handler = StringIO(bytes)
form.add_file('torrent_file', filename.encode('utf-8'), file_handler) 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): def _action(self, params, body=None, content_type=None):
#about token, see https://github.com/bittorrent/webui/wiki/TokenSystem #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) request = Request(url)
if body: if body:
request.add_data(body) request.data = body
request.add_header('Content-length', len(body)) request.add_header('Content-length', len(body))
if content_type: if content_type:
request.add_header('Content-type', content_type) request.add_header('Content-type', content_type)