diff --git a/couchpotato/__init__.py b/couchpotato/__init__.py index b61cd843..966da0cf 100644 --- a/couchpotato/__init__.py +++ b/couchpotato/__init__.py @@ -60,10 +60,7 @@ addView('', index) # API docs def apiDocs(): - routes = [] - - for route in api.iterkeys(): - routes.append(route) + routes = list(api.keys()) if api_docs.get(''): del api_docs[''] diff --git a/couchpotato/core/_base/updater/main.py b/couchpotato/core/_base/updater/main.py index 22668d92..ef595ad7 100644 --- a/couchpotato/core/_base/updater/main.py +++ b/couchpotato/core/_base/updater/main.py @@ -15,6 +15,7 @@ import time import traceback import version import zipfile +from six.moves import filter log = CPLog(__name__) @@ -350,8 +351,8 @@ class SourceUpdater(BaseUpdater): try: if os.path.isdir(path): shutil.rmtree(path) - except OSError, inst: - os.chmod(inst.filename, 0777) + except OSError as inst: + os.chmod(inst.filename, 0o777) self.removeDir(path) def getVersion(self): diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index f8108492..e0d6a921 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -261,7 +261,7 @@ class uTorrentAPI(object): def set_torrent(self, hash, params): action = 'action=setprops&hash=%s' % hash - for k, v in params.iteritems(): + for k, v in params.items(): action += '&s=%s&v=%s' % (k, v) return self._request(action) diff --git a/couchpotato/core/event.py b/couchpotato/core/event.py index 88df65cf..a36c430d 100644 --- a/couchpotato/core/event.py +++ b/couchpotato/core/event.py @@ -29,7 +29,7 @@ def addEvent(name, handler, priority = 100): has_parent = hasattr(handler, 'im_self') parent = None if has_parent: - parent = handler.im_self + parent = handler.__self__ bc = hasattr(parent, 'beforeCall') if bc: parent.beforeCall(handler) diff --git a/couchpotato/core/helpers/encoding.py b/couchpotato/core/helpers/encoding.py index 1c418418..0b85f64b 100644 --- a/couchpotato/core/helpers/encoding.py +++ b/couchpotato/core/helpers/encoding.py @@ -5,6 +5,7 @@ import os import re import traceback import unicodedata +import six log = CPLog(__name__) @@ -29,7 +30,7 @@ def toUnicode(original, *args): return original else: try: - return unicode(original, *args) + return six.text_type(original, *args) except: try: return ek(original, *args) @@ -102,10 +103,10 @@ def stripAccents(s): def tryUrlencode(s): - new = u'' + new = six.u('') if isinstance(s, dict): - for key, value in s.iteritems(): - new += u'&%s=%s' % (key, tryUrlencode(value)) + for key, value in s.items(): + new += six.u('&%s=%s') % (key, tryUrlencode(value)) return new[1:] else: diff --git a/couchpotato/core/helpers/request.py b/couchpotato/core/helpers/request.py index fb91f453..8a10f078 100644 --- a/couchpotato/core/helpers/request.py +++ b/couchpotato/core/helpers/request.py @@ -9,7 +9,7 @@ def getParams(params): reg = re.compile('^[a-z0-9_\.]+$') temp = {} - for param, value in sorted(params.iteritems()): + for param, value in sorted(params.items()): nest = re.split("([\[\]]+)", param) if len(nest) > 1: @@ -42,9 +42,9 @@ def dictToList(params): if type(params) is dict: new = {} - for x, value in params.iteritems(): + for x, value in params.items(): try: - new_value = [dictToList(value[k]) for k in sorted(value.iterkeys(), cmp = natcmp)] + new_value = [dictToList(value[k]) for k in sorted(value.keys(), cmp = natcmp)] except: new_value = value diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index b191d0a0..0a47f1de 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -8,6 +8,8 @@ import random import re import string import sys +import six +from six.moves import map, zip log = CPLog(__name__) @@ -19,7 +21,7 @@ def fnEscape(pattern): def link(src, dst): if os.name == 'nt': import ctypes - if ctypes.windll.kernel32.CreateHardLinkW(unicode(dst), unicode(src), 0) == 0: raise ctypes.WinError() + if ctypes.windll.kernel32.CreateHardLinkW(six.text_type(dst), six.text_type(src), 0) == 0: raise ctypes.WinError() else: os.link(src, dst) @@ -27,7 +29,7 @@ def link(src, dst): def symlink(src, dst): if os.name == 'nt': import ctypes - if ctypes.windll.kernel32.CreateSymbolicLinkW(unicode(dst), unicode(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError() + if ctypes.windll.kernel32.CreateSymbolicLinkW(six.text_type(dst), six.text_type(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError() else: os.symlink(src, dst) @@ -253,7 +255,7 @@ def randomString(size = 8, chars = string.ascii_uppercase + string.digits): def splitString(str, split_on = ',', clean = True): l = [x.strip() for x in str.split(split_on)] if str else [] - return filter(None, l) if clean else l + return [x for x in l if x] if clean else l def dictIsSubset(a, b): diff --git a/couchpotato/core/loader.py b/couchpotato/core/loader.py index c14b55bd..ee94949f 100644 --- a/couchpotato/core/loader.py +++ b/couchpotato/core/loader.py @@ -4,6 +4,7 @@ from importlib import import_module import os import sys import traceback +import six log = CPLog(__name__) @@ -37,7 +38,7 @@ class Loader(object): self.paths['custom_plugins'] = (30, '', custom_plugin_dir) # Loop over all paths and add to module list - for plugin_type, plugin_tuple in self.paths.iteritems(): + for plugin_type, plugin_tuple in self.paths.items(): priority, module, dir_name = plugin_tuple self.addFromDir(plugin_type, priority, module, dir_name) @@ -45,7 +46,7 @@ class Loader(object): did_save = 0 for priority in sorted(self.modules): - for module_name, plugin in sorted(self.modules[priority].iteritems()): + for module_name, plugin in sorted(self.modules[priority].items()): # Load module try: @@ -81,7 +82,7 @@ class Loader(object): for filename in os.listdir(root_path): path = os.path.join(root_path, filename) if os.path.isdir(path) and filename[:2] != '__': - if u'__init__.py' in os.listdir(path): + if six.u('__init__.py') in os.listdir(path): new_base_path = ''.join(s + '.' for s in base_path) + filename self.paths[new_base_path.replace('.', '_')] = (priority, new_base_path, path) diff --git a/couchpotato/core/logger.py b/couchpotato/core/logger.py index c2a7a836..fc198cdd 100644 --- a/couchpotato/core/logger.py +++ b/couchpotato/core/logger.py @@ -51,7 +51,7 @@ class CPLog(object): else: msg = msg % ss(replace_tuple) except Exception as e: - self.logger.error(u'Failed encoding stuff to log "%s": %s' % (msg, e)) + self.logger.error('Failed encoding stuff to log "%s": %s' % (msg, e)) if not Env.get('dev'): diff --git a/couchpotato/core/media/_base/searcher/main.py b/couchpotato/core/media/_base/searcher/main.py index 6ff09728..17dc9b57 100644 --- a/couchpotato/core/media/_base/searcher/main.py +++ b/couchpotato/core/media/_base/searcher/main.py @@ -6,6 +6,7 @@ from couchpotato.core.logger import CPLog from couchpotato.core.media._base.searcher.base import SearcherBase import datetime import re +from six.moves import filter log = CPLog(__name__) diff --git a/couchpotato/core/media/movie/library/movie/main.py b/couchpotato/core/media/movie/library/movie/main.py index 61d93ae9..3f07305c 100644 --- a/couchpotato/core/media/movie/library/movie/main.py +++ b/couchpotato/core/media/movie/library/movie/main.py @@ -7,6 +7,7 @@ from couchpotato.core.settings.model import Library, LibraryTitle, File from string import ascii_letters import time import traceback +import six log = CPLog(__name__) @@ -109,7 +110,7 @@ class MovieLibraryPlugin(LibraryBase): t = LibraryTitle( title = title, simple_title = self.simplifyTitle(title), - default = (len(default_title) == 0 and counter == 0) or len(titles) == 1 or title.lower() == toUnicode(default_title.lower()) or (toUnicode(default_title) == u'' and toUnicode(titles[0]) == title) + default = (len(default_title) == 0 and counter == 0) or len(titles) == 1 or title.lower() == toUnicode(default_title.lower()) or (toUnicode(default_title) == six.u('') and toUnicode(titles[0]) == title) ) library.titles.append(t) counter += 1 diff --git a/couchpotato/core/notifications/notifymyandroid/main.py b/couchpotato/core/notifications/notifymyandroid/main.py index 92e59562..16465101 100644 --- a/couchpotato/core/notifications/notifymyandroid/main.py +++ b/couchpotato/core/notifications/notifymyandroid/main.py @@ -2,6 +2,7 @@ from couchpotato.core.helpers.variable import splitString from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification import pynma +import six log = CPLog(__name__) @@ -26,7 +27,7 @@ class NotifyMyAndroid(Notification): successful = 0 for key in keys: - if not response[str(key)]['code'] == u'200': + if not response[str(key)]['code'] == six.u('200'): log.error('Could not send notification to NotifyMyAndroid (%s). %s', (key, response[key]['message'])) else: successful += 1 diff --git a/couchpotato/core/notifications/notifymywp/main.py b/couchpotato/core/notifications/notifymywp/main.py index 1cdd980a..74010441 100644 --- a/couchpotato/core/notifications/notifymywp/main.py +++ b/couchpotato/core/notifications/notifymywp/main.py @@ -2,6 +2,7 @@ from couchpotato.core.helpers.variable import splitString from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification from pynmwp import PyNMWP +import six log = CPLog(__name__) @@ -17,7 +18,7 @@ class NotifyMyWP(Notification): response = p.push(application = self.default_title, event = message, description = message, priority = self.conf('priority'), batch_mode = len(keys) > 1) for key in keys: - if not response[key]['Code'] == u'200': + if not response[key]['Code'] == six.u('200'): log.error('Could not send notification to NotifyMyWindowsPhone (%s). %s', (key, response[key]['message'])) return False diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 73e41c75..f9280098 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -169,7 +169,7 @@ class Plugin(object): } method = 'post' if len(data) > 0 or files else 'get' - log.info('Opening url: %s %s, data: %s', (method, url, [x for x in data.iterkeys()] if isinstance(data, dict) else 'with data')) + log.info('Opening url: %s %s, data: %s', (method, url, [x for x in data.keys()] if isinstance(data, dict) else 'with data')) response = r.request(method, url, verify = False, **kwargs) data = response.content diff --git a/couchpotato/core/plugins/browser/main.py b/couchpotato/core/plugins/browser/main.py index c8f7536b..956a7680 100644 --- a/couchpotato/core/plugins/browser/main.py +++ b/couchpotato/core/plugins/browser/main.py @@ -4,6 +4,7 @@ from couchpotato.core.plugins.base import Plugin import ctypes import os import string +import six if os.name == 'nt': import imp @@ -96,7 +97,7 @@ class FileBrowser(Plugin): def has_hidden_attribute(self, filepath): try: - attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath)) #@UndefinedVariable + attrs = ctypes.windll.kernel32.GetFileAttributesW(six.text_type(filepath)) #@UndefinedVariable assert attrs != -1 result = bool(attrs & 2) except (AttributeError, AssertionError): diff --git a/couchpotato/core/plugins/manage/main.py b/couchpotato/core/plugins/manage/main.py index 3b684f9a..9c7e80c7 100644 --- a/couchpotato/core/plugins/manage/main.py +++ b/couchpotato/core/plugins/manage/main.py @@ -223,7 +223,7 @@ class Manage(Plugin): groups = fireEvent('scanner.scan', folder = folder, files = files, single = True) if groups: - for group in groups.itervalues(): + for group in groups.values(): if group['library'] and group['library'].get('identifier'): fireEvent('release.add', group = group) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 97e59bde..f9f44d85 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -17,6 +17,8 @@ import re import shutil import time import traceback +import six +from six.moves import filter log = CPLog(__name__) @@ -787,19 +789,19 @@ Remove it if you want it to be renamed (again, or at least let it try again) replacements['cd_nr'] = '' replaced = toUnicode(string) - for x, r in replacements.iteritems(): + for x, r in replacements.items(): if x in ['thename', 'namethe']: continue if r is not None: - replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r)) + replaced = replaced.replace(six.u('<%s>') % toUnicode(x), toUnicode(r)) else: #If information is not available, we don't want the tag in the filename replaced = replaced.replace('<' + x + '>', '') replaced = self.replaceDoubles(replaced.lstrip('. ')) - for x, r in replacements.iteritems(): + for x, r in replacements.items(): if x in ['thename', 'namethe']: - replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r)) + replaced = replaced.replace(six.u('<%s>') % toUnicode(x), toUnicode(r)) replaced = re.sub(r"[\x00:\*\?\"<>\|]", '', replaced) sep = self.conf('foldersep') if folder else self.conf('separator') diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index 4f8f2aba..803c63c1 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -15,6 +15,7 @@ import re import threading import time import traceback +from six.moves import filter, map, zip log = CPLog(__name__) @@ -187,7 +188,7 @@ class Scanner(Plugin): # Group files minus extension ignored_identifiers = [] - for identifier, group in movie_files.iteritems(): + for identifier, group in movie_files.items(): if identifier not in group['identifiers'] and len(identifier) > 0: group['identifiers'].append(identifier) log.debug('Grouping files: %s', identifier) @@ -228,7 +229,7 @@ class Scanner(Plugin): # Group the files based on the identifier delete_identifiers = [] - for identifier, found_files in path_identifiers.iteritems(): + for identifier, found_files in path_identifiers.items(): log.debug('Grouping files on identifier: %s', identifier) group = movie_files.get(identifier) @@ -251,7 +252,7 @@ class Scanner(Plugin): # Group based on folder delete_identifiers = [] - for identifier, found_files in path_identifiers.iteritems(): + for identifier, found_files in path_identifiers.items(): log.debug('Grouping files on foldername: %s', identifier) for ff in found_files: diff --git a/couchpotato/core/plugins/status/main.py b/couchpotato/core/plugins/status/main.py index ad25d3c8..3ec2b45a 100644 --- a/couchpotato/core/plugins/status/main.py +++ b/couchpotato/core/plugins/status/main.py @@ -108,7 +108,7 @@ class StatusPlugin(Plugin): db = get_session() - for identifier, label in self.statuses.iteritems(): + for identifier, label in self.statuses.items(): s = db.query(Status).filter_by(identifier = identifier).first() if not s: log.info('Creating status: %s', label) diff --git a/couchpotato/core/plugins/subtitle/main.py b/couchpotato/core/plugins/subtitle/main.py index 7504d6a9..56056c0a 100644 --- a/couchpotato/core/plugins/subtitle/main.py +++ b/couchpotato/core/plugins/subtitle/main.py @@ -45,7 +45,7 @@ class Subtitle(Plugin): if self.isDisabled(): return try: - available_languages = sum(group['subtitle_language'].itervalues(), []) + available_languages = sum(group['subtitle_language'].values(), []) downloaded = [] files = [toUnicode(x) for x in group['files']['movie']] log.debug('Searching for subtitles for: %s', files) diff --git a/couchpotato/core/providers/automation/letterboxd/main.py b/couchpotato/core/providers/automation/letterboxd/main.py index ca457a21..efd04991 100644 --- a/couchpotato/core/providers/automation/letterboxd/main.py +++ b/couchpotato/core/providers/automation/letterboxd/main.py @@ -3,6 +3,7 @@ from couchpotato.core.helpers.variable import tryInt, splitString from couchpotato.core.logger import CPLog from couchpotato.core.providers.automation.base import Automation import re +from six.moves import filter log = CPLog(__name__) diff --git a/couchpotato/core/providers/info/couchpotatoapi/main.py b/couchpotato/core/providers/info/couchpotatoapi/main.py index e5efbcf6..848cbf05 100644 --- a/couchpotato/core/providers/info/couchpotatoapi/main.py +++ b/couchpotato/core/providers/info/couchpotatoapi/main.py @@ -81,7 +81,7 @@ class CouchPotatoApi(MovieProvider): result = self.getJsonData(self.urls['info'] % identifier, headers = self.getRequestHeaders()) if result: - return dict((k, v) for k, v in result.iteritems() if v) + return dict((k, v) for k, v in result.items() if v) return {} diff --git a/couchpotato/core/providers/info/omdbapi/main.py b/couchpotato/core/providers/info/omdbapi/main.py index 7c8be386..8f04d3b6 100755 --- a/couchpotato/core/providers/info/omdbapi/main.py +++ b/couchpotato/core/providers/info/omdbapi/main.py @@ -107,7 +107,7 @@ class OMDBAPI(MovieProvider): 'writers': splitString(movie.get('Writer', '')), 'actors': splitString(movie.get('Actors', '')), } - movie_data = dict((k, v) for k, v in movie_data.iteritems() if v) + movie_data = dict((k, v) for k, v in movie_data.items() if v) except: log.error('Failed parsing IMDB API json: %s', traceback.format_exc()) diff --git a/couchpotato/core/providers/info/themoviedb/main.py b/couchpotato/core/providers/info/themoviedb/main.py index d2f48934..5207eb11 100644 --- a/couchpotato/core/providers/info/themoviedb/main.py +++ b/couchpotato/core/providers/info/themoviedb/main.py @@ -145,7 +145,7 @@ class TheMovieDb(MovieProvider): 'actor_roles': actors } - movie_data = dict((k, v) for k, v in movie_data.iteritems() if v) + movie_data = dict((k, v) for k, v in movie_data.items() if v) # Add alternative names if extended: diff --git a/couchpotato/core/providers/torrent/passthepopcorn/main.py b/couchpotato/core/providers/torrent/passthepopcorn/main.py index 48a7e2a1..66cad33c 100644 --- a/couchpotato/core/providers/torrent/passthepopcorn/main.py +++ b/couchpotato/core/providers/torrent/passthepopcorn/main.py @@ -8,6 +8,7 @@ import json import re import time import traceback +import six log = CPLog(__name__) @@ -178,7 +179,7 @@ class PassThePopcorn(TorrentProvider): except KeyError: pass return text # leave as is - return re.sub("&#?\w+;", fixup, u'%s' % text) + return re.sub("&#?\w+;", fixup, six.u('%s') % text) def unicodeToASCII(self, text): import unicodedata diff --git a/couchpotato/core/providers/torrent/thepiratebay/main.py b/couchpotato/core/providers/torrent/thepiratebay/main.py index 46508506..f8b77787 100644 --- a/couchpotato/core/providers/torrent/thepiratebay/main.py +++ b/couchpotato/core/providers/torrent/thepiratebay/main.py @@ -5,6 +5,7 @@ from couchpotato.core.logger import CPLog from couchpotato.core.providers.torrent.base import TorrentMagnetProvider import re import traceback +import six log = CPLog(__name__) @@ -73,7 +74,7 @@ class ThePirateBay(TorrentMagnetProvider): download = result.find(href = re.compile('magnet:')) try: - size = re.search('Size (?P.+),', unicode(result.select('font.detDesc')[0])).group('size') + size = re.search('Size (?P.+),', six.text_type(result.select('font.detDesc')[0])).group('size') except: continue diff --git a/couchpotato/core/providers/torrent/torrentshack/main.py b/couchpotato/core/providers/torrent/torrentshack/main.py index 669c28fd..f0cd5997 100644 --- a/couchpotato/core/providers/torrent/torrentshack/main.py +++ b/couchpotato/core/providers/torrent/torrentshack/main.py @@ -4,6 +4,7 @@ from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.torrent.base import TorrentProvider import traceback +import six log = CPLog(__name__) @@ -53,7 +54,7 @@ class TorrentShack(TorrentProvider): results.append({ 'id': link['href'].replace('torrents.php?torrentid=', ''), - 'name': unicode(link.span.string).translate({ord(u'\xad'): None}), + 'name': six.text_type(link.span.string).translate({ord(six.u('\xad')): None}), 'url': self.urls['download'] % url['href'], 'detail_url': self.urls['download'] % link['href'], 'size': self.parseSize(result.find_all('td')[4].string), diff --git a/couchpotato/core/settings/__init__.py b/couchpotato/core/settings/__init__.py index 85dc7a8f..5e4952ae 100644 --- a/couchpotato/core/settings/__init__.py +++ b/couchpotato/core/settings/__init__.py @@ -77,7 +77,7 @@ class Settings(object): self.addSection(section_name) - for option_name, option in options.iteritems(): + for option_name, option in options.items(): self.setDefault(section_name, option_name, option.get('default', '')) # Migrate old settings from old location to the new location