From ac8dbe03b2dc92acbea4e76c4d672378fc62faca Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 6 Oct 2014 23:02:30 +0200 Subject: [PATCH] Py3 fixes --- couchpotato/api.py | 4 ++-- couchpotato/core/event.py | 2 +- couchpotato/core/plugins/base.py | 6 +++++- libs/axl/axel.py | 4 ++-- libs/minify/cssmin.py | 3 +-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/couchpotato/api.py b/couchpotato/api.py index cd01197a..8b51e9c6 100644 --- a/couchpotato/api.py +++ b/couchpotato/api.py @@ -3,7 +3,7 @@ from threading import Thread import json import threading import traceback -import urllib +from six.moves import urllib from couchpotato.core.helpers.request import getParams from couchpotato.core.logger import CPLog @@ -102,7 +102,7 @@ class ApiHandler(RequestHandler): kwargs = {} for x in self.request.arguments: - kwargs[x] = urllib.unquote(self.get_argument(x)) + kwargs[x] = urllib.parse.unquote(self.get_argument(x)) # Split array arguments kwargs = getParams(kwargs) diff --git a/couchpotato/core/event.py b/couchpotato/core/event.py index 35818e7e..7f995e1f 100644 --- a/couchpotato/core/event.py +++ b/couchpotato/core/event.py @@ -102,7 +102,7 @@ def fireEvent(name, *args, **kwargs): # Fire result = e(*args, **kwargs) - result_keys = result.keys() + result_keys = list(result.keys()) result_keys.sort(key = natsortKey) if options['single'] and not options['merge']: diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 4b169fbf..06e5092e 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -231,7 +231,11 @@ class Plugin(object): status_code = response.status_code if response.status_code == requests.codes.ok: - data = response if stream else response.content + if stream: + data = response + else: + data = response.content + data = data.decode(response.encoding) else: response.raise_for_status() diff --git a/libs/axl/axel.py b/libs/axl/axel.py index 8eee556c..c8768f11 100644 --- a/libs/axl/axel.py +++ b/libs/axl/axel.py @@ -110,7 +110,7 @@ class Event(object): self.memoize = {} def hash(self, handler): - return hashlib.md5(str(handler)).hexdigest() + return hashlib.md5(repr(handler).encode('utf-8')).hexdigest() def handle(self, handler, priority = 0): """ Registers a handler. The handler can be transmitted together @@ -162,7 +162,7 @@ class Event(object): t.daemon = True t.start() - handler_keys = self.handlers.keys() + handler_keys = list(self.handlers.keys()) handler_keys.sort(key = natsortKey) for handler in handler_keys: diff --git a/libs/minify/cssmin.py b/libs/minify/cssmin.py index 09beb197..e6608488 100644 --- a/libs/minify/cssmin.py +++ b/libs/minify/cssmin.py @@ -4,7 +4,6 @@ # `cssmin.py` - A Python port of the YUI CSS compressor. -from StringIO import StringIO # The pure-Python StringIO supports unicode. import re @@ -52,7 +51,7 @@ def remove_unnecessary_whitespace(css): """ Prevents 'p :link' from becoming 'p:link'. - + Translates 'p :link' into 'p ___PSEUDOCLASSCOLON___link'; this is translated back again later. """