diff options
author | Louis Vézina <[email protected]> | 2019-09-16 22:04:27 -0400 |
---|---|---|
committer | Louis Vézina <[email protected]> | 2019-09-16 22:04:27 -0400 |
commit | 3ca2c98cd42f24299ac08daa26ed8a21a44c60de (patch) | |
tree | 225f3a4bdf7a8276299f71b49e3c37ba1e420a8d /libs/subzero | |
parent | c5fa0f56e41ee03fd7b02f6474cbb4fd1bdf08e6 (diff) | |
download | bazarr-3ca2c98cd42f24299ac08daa26ed8a21a44c60de.tar.gz bazarr-3ca2c98cd42f24299ac08daa26ed8a21a44c60de.zip |
WIP
Diffstat (limited to 'libs/subzero')
36 files changed, 104 insertions, 62 deletions
diff --git a/libs/subzero/analytics.py b/libs/subzero/analytics.py index 297bcf2c5..bda9d6252 100644 --- a/libs/subzero/analytics.py +++ b/libs/subzero/analytics.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import struct import binascii diff --git a/libs/subzero/cache_backends/file.py b/libs/subzero/cache_backends/file.py index 1ad404deb..d72d7b84a 100644 --- a/libs/subzero/cache_backends/file.py +++ b/libs/subzero/cache_backends/file.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import from dogpile.cache.api import CacheBackend, NO_VALUE from fcache.cache import FileCache diff --git a/libs/subzero/history_storage.py b/libs/subzero/history_storage.py index 38d859d55..e4e382d4f 100644 --- a/libs/subzero/history_storage.py +++ b/libs/subzero/history_storage.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import datetime import logging import traceback @@ -7,7 +8,8 @@ import types from subzero.language import Language -from constants import mode_map +from .constants import mode_map +import six logger = logging.getLogger(__name__) @@ -54,10 +56,10 @@ class SubtitleHistoryItem(object): return mode_map.get(self.mode, "Unknown") def __repr__(self): - return unicode(self) + return six.text_type(self) def __unicode__(self): - return u"%s (Score: %s)" % (unicode(self.item_title), self.score) + return u"%s (Score: %s)" % (six.text_type(self.item_title), self.score) def __str__(self): return str(self.rating_key) @@ -108,7 +110,7 @@ class SubtitleHistory(object): items = [] logger.error("Failed to load history storage: %s" % traceback.format_exc()) - if not isinstance(items, types.ListType): + if not isinstance(items, list): items = [] else: items = items[:] diff --git a/libs/subzero/intent.py b/libs/subzero/intent.py index 174e68fee..338e57134 100644 --- a/libs/subzero/intent.py +++ b/libs/subzero/intent.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import datetime import threading diff --git a/libs/subzero/language.py b/libs/subzero/language.py index 0a3a5e775..3923e2a93 100644 --- a/libs/subzero/language.py +++ b/libs/subzero/language.py @@ -1,8 +1,10 @@ # coding=utf-8 +from __future__ import absolute_import import types from babelfish.exceptions import LanguageError from babelfish import Language as Language_, basestr +from six.moves import zip repl_map = { "dk": "da", @@ -54,7 +56,7 @@ def wrap_forced(f): args = args[1:] s = args.pop(0) forced = None - if isinstance(s, types.StringTypes): + if isinstance(s, (str,)): base, forced = s.split(":") if ":" in s else (s, False) else: base = s @@ -108,7 +110,7 @@ class Language(Language_): state = instance.__getstate__() attrs = ("country", "script", "forced") language = state[0] - kwa = dict(zip(attrs, state[1:])) + kwa = dict(list(zip(attrs, state[1:]))) kwa.update(replkw) return cls(language, **kwa) diff --git a/libs/subzero/lib/__init__.py b/libs/subzero/lib/__init__.py index 9ffc2cdb3..41167dbec 100644 --- a/libs/subzero/lib/__init__.py +++ b/libs/subzero/lib/__init__.py @@ -1,8 +1,3 @@ -from .dict import * -from .geezip import * -from .httpfake import * -from .io import * -from .json import * -from .rar import * -from .which import *
\ No newline at end of file +from __future__ import absolute_import +from . import dict, geezip, httpfake, io, json, rar, which
\ No newline at end of file diff --git a/libs/subzero/lib/dict.py b/libs/subzero/lib/dict.py index 3f327dcf4..05516d4b8 100644 --- a/libs/subzero/lib/dict.py +++ b/libs/subzero/lib/dict.py @@ -1,3 +1,4 @@ +import six # coding=utf-8 @@ -19,11 +20,10 @@ class DictProxy(object): return getattr(super(DictProxy, self), name) def __setattr__(self, name, value): - if not self.__dict__.has_key( - '_DictProxy__initialized'): # this test allows attributes to be set in the __init__ method + if '_DictProxy__initialized' not in self.__dict__: # this test allows attributes to be set in the __init__ method return object.__setattr__(self, name, value) - elif self.__dict__.has_key(name): # any normal attributes are handled normally + elif name in self.__dict__: # any normal attributes are handled normally object.__setattr__(self, name, value) else: @@ -56,7 +56,7 @@ class DictProxy(object): return str(self.Dict[self.store]) def __len__(self): - return len(self.Dict[self.store].keys()) + return len(list(self.Dict[self.store].keys())) def __delitem__(self, key): del self.Dict[self.store][key] @@ -81,16 +81,16 @@ class DictProxy(object): return self.Dict[self.store].update(*args, **kwargs) def keys(self): - return self.Dict[self.store].keys() + return list(self.Dict[self.store].keys()) def values(self): - return self.Dict[self.store].values() + return list(self.Dict[self.store].values()) def items(self): - return self.Dict[self.store].items() + return list(self.Dict[self.store].items()) def __unicode__(self): - return unicode(repr(self.Dict[self.store])) + return six.text_type(repr(self.Dict[self.store])) def setup_defaults(self): raise NotImplementedError @@ -104,14 +104,14 @@ class Dicked(object): def __init__(self, **entries): self._entries = entries or None - for key, value in entries.iteritems(): + for key, value in six.iteritems(entries): self.__dict__[key] = (Dicked(**value) if isinstance(value, dict) else value) def __repr__(self): return str(self) def __unicode__(self): - return unicode(self.__digged__) + return six.text_type(self.__digged__) def __str__(self): return str(self.__digged__) @@ -143,7 +143,7 @@ class Dicked(object): @property def __digged__(self): - return {key: value for key, value in self.__dict__.iteritems() if key != "_entries"} + return {key: value for key, value in six.iteritems(self.__dict__) if key != "_entries"} def __len__(self): return len(self.__digged__) diff --git a/libs/subzero/lib/geezip.py b/libs/subzero/lib/geezip.py index 7609ef6be..5ffd09a4c 100644 --- a/libs/subzero/lib/geezip.py +++ b/libs/subzero/lib/geezip.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import gzip from zlib import Z_FINISH diff --git a/libs/subzero/lib/httpfake.py b/libs/subzero/lib/httpfake.py index 93b591a55..f7a8eb4db 100644 --- a/libs/subzero/lib/httpfake.py +++ b/libs/subzero/lib/httpfake.py @@ -1,3 +1,4 @@ +import six # coding=utf-8 @@ -37,7 +38,7 @@ class PlexPyNativeResponseProxy(object): return str(self.data) def __unicode__(self): - return unicode(self.data) + return six.text_type(self.data) def __repr__(self): return repr(self.data) diff --git a/libs/subzero/lib/io.py b/libs/subzero/lib/io.py index 07c442972..bc28a2ffe 100644 --- a/libs/subzero/lib/io.py +++ b/libs/subzero/lib/io.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import os import sys diff --git a/libs/subzero/lib/json.py b/libs/subzero/lib/json.py index d3f3184a2..4fe6829f5 100644 --- a/libs/subzero/lib/json.py +++ b/libs/subzero/lib/json.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import from gzip import GzipFile from json_tricks import TricksEncoder diff --git a/libs/subzero/lib/rar.py b/libs/subzero/lib/rar.py index 8e9cdafc8..e9a08bb3b 100644 --- a/libs/subzero/lib/rar.py +++ b/libs/subzero/lib/rar.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import logging import rarfile diff --git a/libs/subzero/lib/which.py b/libs/subzero/lib/which.py index e65a7d900..14eb0c2e3 100644 --- a/libs/subzero/lib/which.py +++ b/libs/subzero/lib/which.py @@ -4,6 +4,7 @@ # Public domain code by anatoly techtonik <[email protected]> # AKA Linux `which` and Windows `where` +from __future__ import absolute_import import os import sys diff --git a/libs/subzero/modification/__init__.py b/libs/subzero/modification/__init__.py index b4d3dd5dc..6bc059a5c 100644 --- a/libs/subzero/modification/__init__.py +++ b/libs/subzero/modification/__init__.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import from .registry import registry from .mods import hearing_impaired, ocr_fixes, fps, offset, common, color from .main import SubtitleModifications, SubMod diff --git a/libs/subzero/modification/dictionaries/__init__.py b/libs/subzero/modification/dictionaries/__init__.py index 903b99f0d..0fce979ff 100644 --- a/libs/subzero/modification/dictionaries/__init__.py +++ b/libs/subzero/modification/dictionaries/__init__.py @@ -1,3 +1,4 @@ # coding=utf-8 +from __future__ import absolute_import from .data import data
\ No newline at end of file diff --git a/libs/subzero/modification/dictionaries/data.py b/libs/subzero/modification/dictionaries/data.py index a7ae3ee44..61b35fef4 100644 --- a/libs/subzero/modification/dictionaries/data.py +++ b/libs/subzero/modification/dictionaries/data.py @@ -1,5 +1,7 @@ +from __future__ import absolute_import import re from collections import OrderedDict +import six data = {'bos': {'BeginLines': {'data': OrderedDict(), 'pattern': None}, 'EndLines': {'data': OrderedDict(), @@ -192,7 +194,7 @@ data = {'bos': {'BeginLines': {'data': OrderedDict(), 'pattern': None}, 'WholeWords': {'data': OrderedDict([(u'l\xe2rt', u'l\xe4rt'), (u'hederv\xe5rda', u'hederv\xe4rda'), (u'storm\xe2stare', u'storm\xe4stare'), (u'Avf\xe2rd', u'Avf\xe4rd'), (u't\xe2lten', u't\xe4lten'), (u'\xe2rjag', u'\xe4r jag'), (u'\xe4rjag', u'\xe4r jag'), (u'j\xe2mlikar', u'j\xe4mlikar'), (u'Riskako\ufb02', u'Riskakor'), (u'Karamellen/', u'Karamellen'), (u'Lngen\xfcng', u'Ingenting'), (u'\xe4rju', u'\xe4r ju'), (u'S\xe1', u'S\xe5'), (u'n\xe4rjag', u'n\xe4r jag'), (u'alltjag', u'allt jag'), (u'g\xf6rjag', u'g\xf6r jag'), (u'trorjag', u'tror jag'), (u'varju', u'var ju'), (u'g\xf6rju', u'g\xf6r ju'), (u'kanju', u'kan ju'), (u'blirjag', u'blir jag'), (u's\xe4gerjag', u's\xe4ger jag'), (u'beh\xe5llerjag', u'beh\xe5ller jag'), (u'pr\xf8blem', u'problem'), (u'r\xe4ddadeju', u'r\xe4ddade ju'), (u'hon\xf8m', u'honom'), (u'Ln', u'In'), (u'sv\xe5r\ufb02\xf6rtad', u'sv\xe5rfl\xf6rtad'), (u'\xf8ch', u'och'), (u'\ufb02\xf6rtar', u'fl\xf6rtar'), (u'k\xe4nnerjag', u'k\xe4nner jag'), (u'\ufb02ickan', u'flickan'), (u'sn\xf8', u'sn\xf6'), (u'gerju', u'ger ju'), (u'k\xf8ntakter', u'kontakter'), (u'\xf8lycka', u'olycka'), (u'n\xf8lla', u'nolla'), (u'sinnenajublar', u'sinnena jublar'), (u'ijobbet', u'i jobbet'), (u'F\xe5rjag', u'F\xe5r jag'), (u'Ar', u'\xc4r'), (u'liggerju', u'ligger ju'), (u'um', u'om'), (u'lbland', u'Ibland'), (u'skjuterjag', u'skjuter jag'), (u'Vadd\xe5', u'Vad d\xe5'), (u'pratarj\xe4mt', u'pratar j\xe4mt'), (u'harju', u'har ju'), (u'sitterjag', u'sitter jag'), (u'h\xe4\ufb02a', u'h\xe4rja'), (u's\ufb01\xe4l', u'stj\xe4l'), (u'F\xd6U', u'F\xf6lj'), (u'varf\xf6rjag', u'varf\xf6r jag'), (u's\ufb01\xe4rna', u'stj\xe4rna'), (u'b\xf6\ufb02ar', u'b\xf6rjar'), (u'b\xf6\ufb02an', u'b\xf6rjan'), (u'st\xe4ri', u'st\xe5r'), (u'p\xe4', u'p\xe5'), (u'harjag', u'har jag'), (u'attjag', u'att jag'), (u'Verkarjag', u'Verkar jag'), (u'K\xe4nnerjag', u'K\xe4nner jag'), (u'd\xe4rjag', u'd\xe4r jag'), (u'tu\ufb01', u'tuff'), (u'lurarjag', u'lurar jag'), (u'varj\xe4ttebra', u'var j\xe4ttebra'), (u'allvan', u'allvar'), (u'deth\xe4r', u'det h\xe4r'), (u'va\ufb02e', u'varje'), (u'F\xf6Uer', u'F\xf6ljer'), (u'personalm\xf6tetl', u'personalm\xf6tet!'), (u'harjust', u'har just'), (u'\xe4rj\xe4tteduktig', u'\xe4r j\xe4tteduktig'), (u'd\xe4rja', u'd\xe4r ja'), (u'lngen\xfcng', u'lngenting'), (u'iluften', u'i luften'), (u'\xf6sen', u'\xf6ser'), (u'tv\xe2', u'tv\xe5'), (u'Uejerna', u'Tjejerna'), (u'h\xe5n*', u'h\xe5rt'), (u'\xc4rjag', u'\xc4r jag'), (u'keL', u'Okej'), (u'F\xf6rjag', u'F\xf6r jag'), (u'varj\xe4ttekul', u'var j\xe4ttekul'), (u'k\xe4mpan', u'k\xe4mpar'), (u'mycketjobb', u'mycket jobb'), (u'Uus', u'ljus'), (u'serjag', u'ser jag'), (u'vetjag', u'vet jag'), (u'f\xe5rjag', u'f\xe5r jag'), (u'hurjag', u'hur jag'), (u'f\xf6rs\xf6kerjag', u'f\xf6rs\xf6ker jag'), (u't\xe1nagel', u't\xe5nagel'), (u'va\xfce', u'varje'), (u'Uudet', u'ljudet'), (u'amhopa', u'allihopa'), (u'V\xe4\xfc', u'V\xe4lj'), (u'g\xe4ri', u'g\xe5r'), (u'r\xf6d\xfcus', u'r\xf6dljus'), (u'Uuset', u'ljuset'), (u'Rid\xe0n', u'Rid\xe5n'), (u'vi\xfca', u'vilja'), (u'g\xe5ri', u'g\xe5r i'), (u'Hurd\xe5', u'Hur d\xe5'), (u'inter\\/juar', u'intervjuar'), (u'menarjag', u'menar jag'), (u'spyrjag', u'spyr jag'), (u'bri\xfcera', u'briljera'), (u'N\xe4rjag', u'N\xe4r jag'), (u'ner\\/\xf6s', u'nerv\xf6s'), (u'ilivets', u'i livets'), (u'n\xe4got', u'n\xe5got'), (u'p\xe0', u'p\xe5'), (u'Lnnan', u'Innan'), (u'Uf', u'Ut'), (u'lnnan', u'Innan'), (u'D\xe0ren', u'D\xe5ren'), (u'F\xe0rjag', u'F\xe5r jag'), (u'Vad\xe4rdetd\xe4L', u'Vad \xe4r det d\xe4r'), (u'sm\xe0tjuv', u'sm\xe5tjuv'), (u't\xe0gr\xe5nare', u't\xe5gr\xe5nare'), (u'dit\xe0t', u'dit\xe5t'), (u's\xe4', u's\xe5'), (u'v\xe0rdsl\xf6sa', u'v\xe5rdsl\xf6sa'), (u'n\xe0n', u'n\xe5n'), (u'kommerjag', u'kommer jag'), (u'\xe4rj\xe4ttebra', u'\xe4r j\xe4ttebra'), (u'\xe4rj\xe4vligt', u'\xe4r j\xe4vligt'), (u'\xe0kerjag', u'\xe5ker jag'), (u'ellerjapaner', u'eller japaner'), (u'attjaga', u'att jaga'), (u'eften', u'efter'), (u'h\xe4stan', u'h\xe4star'), (u'Lntensivare', u'Intensivare'), (u'fr\xe0garjag', u'fr\xe5gar jag'), (u'pen/ers', u'pervers'), (u'r\xe0barkade', u'r\xe5barkade'), (u'styrkon', u'styrkor'), (u'Dif\xe5f', u'Dit\xe5t'), (u'h\xe4nden', u'h\xe4nder'), (u'f\xf6\ufb01a', u'f\xf6lja'), (u'Idioten/', u'Idioter!'), (u'Varf\xf6rjagade', u'Varf\xf6r jagade'), (u'd\xe4rf\xf6rjag', u'd\xe4rf\xf6r jag'), (u'forjag', u'for jag'), (u'Iivsgladje', u'livsgl\xe4dje'), (u'narjag', u'n\xe4r jag'), (u'sajag', u'sa jag'), (u'genastja', u'genast ja'), (u'rockument\xe0ren', u'rockument\xe4ren'), (u'turne', u'turn\xe9'), (u'fickjag', u'fick jag'), (u'sager', u's\xe4ger'), (u'Ijush\xe5rig', u'ljush\xe5rig'), (u'tradg\xe5rdsolycka', u'tr\xe4dg\xe5rdsolycka'), (u'kvavdes', u'kv\xe4vdes'), (u'd\xe0rja', u'd\xe4r ja'), (u'hedersgaster', u'hedersg\xe4ster'), (u'Nar', u'N\xe4r'), (u'smaki\xf6sa', u'smakl\xf6sa'), (u'lan', u'Ian'), (u'Lan', u'Ian'), (u'eri', u'er i'), (u'universitetsamne', u'universitets\xe4mne'), (u'garna', u'g\xe4rna'), (u'ar', u'\xe4r'), (u'baltdjur', u'b\xe4ltdjur'), (u'varjag', u'var jag'), (u'\xe0r', u'\xe4r'), (u'f\xf6rf\xf6rst\xe0rkare', u'f\xf6rf\xf6rst\xe4rkare'), (u'arjattespeciell', u'\xe4r j\xe4ttespeciell'), (u'h\xe0rg\xe5r', u'h\xe4r g\xe5r'), (u'Ia', u'la'), (u'Iimousinen', u'limousinen'), (u'krickettra', u'krickettr\xe4'), (u'h\xe5rdrockv\xe0rlden', u'h\xe5rdrockv\xe4rlden'), (u'tr\xe0bit', u'tr\xe4bit'), (u'Mellanvastern', u'Mellanv\xe4stern'), (u'arju', u'\xe4r ju'), (u'turnen', u'turn\xe9n'), (u'kanns', u'k\xe4nns'), (u'battre', u'b\xe4ttre'), (u'v\xe0rldsturne', u'v\xe4rldsturne'), (u'dar', u'd\xe4r'), (u'sj\xe0lvant\xe0nder', u'sj\xe4lvant\xe4nder'), (u'jattelange', u'j\xe4ttel\xe4nge'), (u'berattade', u'ber\xe4ttade'), (u'S\xe4', u'S\xe5'), (u'vandpunkten', u'v\xe4ndpunkten'), (u'N\xe0rjag', u'N\xe4r jag'), (u'lasa', u'l\xe4sa'), (u'skitl\xe0skigt', u'skitl\xe4skigt'), (u'sambandsv\xe0g', u'sambandsv\xe4g'), (u'valdigt', u'v\xe4ldigt'), (u'Stamga\ufb01el', u'St\xe4mgaffel'), (u'\xe0rjag', u'\xe4r jag'), (u'tajming', u'tajmning'), (u'utg\xe4ng', u'utg\xe5ng'), (u'H\xe0r\xe5t', u'H\xe4r\xe5t'), (u'h\xe0r\xe5t', u'h\xe4r\xe5t'), (u'anvander', u'anv\xe4nder'), (u'harjobbat', u'har jobbat'), (u'imageide', u'imageid\xe9'), (u'kla\ufb01en', u'klaffen'), (u'sjalv', u'sj\xe4lv'), (u'dvarg', u'dv\xe4rg'), (u'detjag', u'det jag'), (u'dvargarna', u'dv\xe4rgarna'), (u'fantasiv\xe0rld', u'fantasiv\xe4rld'), (u'\ufb01olliga', u'Fjolliga'), (u'mandoiinstr\xe0ngar', u'mandollnstr\xe4ngar'), (u'mittjobb', u'mitt jobb'), (u'Skajag', u'Ska jag'), (u'landari', u'landar i'), (u'gang', u'g\xe4ng'), (u'Detjag', u'Det jag'), (u'Narmre', u'N\xe4rmre'), (u'I\xe5tjavelni', u'l\xe5tj\xe4veln'), (u'H\xe5llerjag', u'H\xe5ller jag'), (u'visionarer', u'vision\xe4rer'), (u'T\xfclvad', u'Till vad'), (u'milit\xe0rbas', u'milit\xe4rbas'), (u'jattegiada', u'j\xe4tteglada'), (u'Fastjag', u'Fast jag'), (u's\xe5jag', u's\xe5 jag'), (u'rockvarlden', u'rockv\xe4rlden'), (u'saknarjag', u'saknar jag'), (u'allafall', u'alla fall'), (u'\ufb01anta', u'fjanta'), (u'Kr\xe0ma', u'Kr\xe4ma'), (u'stammer', u'st\xe4mmer'), (u'budb\xe0rare', u'budb\xe4rare'), (u'Iivsfiiosofi', u'livsfiiosofi'), (u'f\xf6rj\xe4mnan', u'f\xf6r j\xe4mnan'), (u'gillarjag', u'gillar jag'), (u'Iarvat', u'larvat'), (u'klararjag', u'klarar jag'), (u"hatta\ufb01'\xe0r", u'hattaff\xe4r'), (u'D\xe0', u'D\xe5'), (u'upp\ufb01nna', u'uppfinna'), (u'R\xe0ttf\xe5glar', u'R\xe5ttf\xe5glar'), (u'Sv\xe4\xfcboda', u'Sv\xe4ljboda'), (u'P\xe5b\xf6\ufb02ar', u'P\xe5b\xf6rjar'), (u'slutarju', u'slutar ju'), (u'ni\ufb01skebu\xfcken', u'i fiskebutiken'), (u'h\xe4rj\xe4keln', u'h\xe4r j\xe4keln'), (u'H\xdfppa', u'Hoppa'), (u'f\xf6rst\xf6rds', u'f\xf6rst\xf6rdes'), (u'varj\xe4ttegoda', u'var j\xe4ttegoda'), (u'Kor\\/', u'Korv'), (u'br\xfcl\xe9el', u'br\xfcl\xe9e!'), (u'Hei', u'Hej'), (u'\xe4lskarjordgubbsglass', u'\xe4lskar jordgubbsglass'), (u'Sn\xf6bom', u'Sn\xf6boll'), (u'Sn\xf6boH', u'Sn\xf6boll'), (u'Sn\xf6bol', u'Sn\xf6boll'), (u'sn\xf6boH', u'sn\xf6boll'), (u'L\xe4ggerp\xe5', u'L\xe4gger p\xe5'), (u'lnge\ufb02', u'lnget!'), (u'S\xe4gerj\xe4ttesmarta', u'S\xe4ger j\xe4ttesmarta'), (u'dopplen/\xe4derradar', u'dopplerv\xe4derradar'), (u's\xe4kertj\xe4ttefin', u's\xe4kert j\xe4ttefin'), (u'\xe4rj\xe4ttefin', u'\xe4r j\xe4ttefin'), (u'verkarju', u'verkar ju'), (u'blirju', u'blir ju'), (u'kor\\/', u'korv'), (u'naturkatastro\ufb01', u'naturkatastrof!'), (u'stickerjag', u'stickerj ag'), (u'j\xe4ttebu\ufb01\xe9', u'j\xe4ttebuff\xe9'), (u'be\ufb01nner', u'befinner'), (u'Sp\ufb02ng', u'Spring'), (u'trec\ufb01e', u'tredje'), (u'ryckerjag', u'rycker jag'), (u'skullejag', u'skulle jag'), (u'vetju', u'vet ju'), (u'a\ufb02jag', u'att jag'), (u'\ufb02nns', u'finns'), (u'\xe4rl\xe5ng', u'\xe4r l\xe5ng'), (u'k\xe5ra', u'k\xe4ra'), (u'\xe4r\ufb01na', u'\xe4r \ufb01na'), (u'\xe4ri', u'\xe4r i'), (u'h\xf6rden', u'h\xf6r den'), (u'\xe4ttj\xe4g', u'att j\xe4g'), (u'g\xe4r', u'g\xe5r'), (u'f\xf6ri', u'f\xf6r i'), (u'Hurvisste', u'Hur visste'), (u'\ufb01ck', u'fick'), (u'\ufb01nns', u'finns'), (u'\ufb01n', u'fin'), (u'Fa', u'Bra.'), (u'bori', u'bor i'), (u'fiendeplanl', u'fiendeplan!'), (u'if\xf6rnamn', u'i f\xf6rnamn'), (u'detju', u'det ju'), (u'N\xfcd', u'Niki'), (u'hatarjag', u'hatar jag'), (u'Klararjag', u'Klarar jag'), (u'deta\ufb01er', u'detaljer'), (u'v\xe4/', u'v\xe4l'), (u'smakarju', u'smakar ju'), (u'Teache\ufb02', u'Teacher!'), (u'imorse', u'i morse'), (u'drickerjag', u'dricker jag'), (u'st\xe5ri', u'st\xe5r i'), (u'Harjag', u'Har jag'), (u'Talarjag', u'Talar jag'), (u'undrarjag', u'undrar jag'), (u'\xe5lderjag', u'\xe5lder jag'), (u'va\ufb01e', u'varje'), (u'f\xf6rfalskningl', u'f\xf6rfalskning!'), (u'Vi\ufb01iiiam', u'William'), (u'V\\\ufb01lliams', u'Williams'), (u'attjobba', u'att jobba'), (u'intei', u'inte i'), (u'n\xe4rV\\\ufb01lliam', u'n\xe4r William'), (u'V\\\ufb01lliam', u'William'), (u'E\ufb01ersom', u'Eftersom'), (u'Vl\ufb01lliam', u'William'), (u'I\xe4ngejag', u'l\xe4nge jag'), (u"'\ufb01digare", u'Tidigare'), (u'b\xf6rjadei', u'b\xf6rjade i'), (u'merjust', u'mer just'), (u'e\ufb01er\xe5t', u'efter\xe5t'), (u'gjordejag', u'gjorde jag'), (u'hadeju', u'hade ju'), (u'g\xe5rvi', u'g\xe5r vi'), (u'k\xf6perjag', u'k\xf6per jag'), (u'M\xe5stejag', u'M\xe5ste jag'), (u'k\xe4nnerju', u'k\xe4nner ju'), (u'\ufb02n', u'fin'), (u'treviig', u'trevlig'), (u'Grattisl', u'Grattis!'), (u'kande', u'k\xe4nde'), (u"'llden", u'Tiden'), (u'sakjag', u'sak jag'), (u'klartjag', u'klart jag'), (u'h\xe4\ufb01igt', u'h\xe4ftigt'), (u'I\xe4mnarjag', u'l\xe4mnar jag'), (u'gickju', u'gick ju'), (u'skajag', u'ska jag'), (u'G\xf6rjag', u'G\xf6r jag'), (u'm\xe5stejag', u'm\xe5ste jag'), (u'gra\\/iditet', u'graviditet'), (u'hittadqdin', u'hittade din'), (u'\xe4rjobbigt', u'\xe4r jobbigt'), (u'Overdrivet', u'\xd6verdrivet'), (u'hOgtidlig', u'h\xf6gtidlig'), (u'Overtyga', u'\xd6vertyga'), (u'SKILSMASSA', u'SKILSM\xc4SSA'), (u'brukarju', u'brukar ju'), (u'lsabel', u'Isabel'), (u'kundejag', u'kunde jag'), (u'\xe4rl\xe4get', u'\xe4r l\xe4get'), (u'blirinte', u'blir inte'), (u'ijakt', u'i jakt'), (u'avjordens', u'av jordens'), (u'90000O', u'900000'), (u'9O0', u'900'), (u'\xe4rp\xe5', u'\xe4r p\xe5'), (u'\xe4rproteserna', u'\xe4r proteserna'), (u'\xe4rytterst', u'\xe4r ytterst'), (u'beborjorden', u'bebor jorden'), (u'filmjag', u'film jag'), (u'fokuserarp\xe5', u'fokuserar p\xe5'), (u'folkjag', u'folk jag'), (u'f\xf6rest\xe4lldejag', u'f\xf6rest\xe4llde jag'), (u'f\xf6rpubliken', u'f\xf6r publiken'), (u'gilladejag', u'gillade jag'), (u'h\xe5llerp\xe5', u'h\xe5ller p\xe5'), (u'harp\xe5', u'har p\xe5'), (u'harplaner', u'har planer'), (u'harprylar', u'har prylar'), (u'kommerpubliken', u'kommer publiken'), (u'kostymerp\xe5', u'kostymer p\xe5'), (u'litarp\xe5', u'litar p\xe5'), (u'lngen', u'Ingen'), (u'lnom', u'Inom'), (u'lnte', u'Inte'), (u'ochjag', u'och jag'), (u'Ochjag', u'Och jag'), (u'ochjorden', u'och jorden'), (u'omjag', u'om jag'), (u'Omjag', u'Om jag'), (u'passarperfekt', u'passar perfekt'), (u's\xe4ttetjag', u's\xe4ttet jag'), (u'silverp\xe5', u'silver p\xe5'), (u'skruvarjag', u'skruvar jag'), (u'somjag', u'som jag'), (u'Somjag', u'Som jag'), (u'talarp\xe5', u'talar p\xe5'), (u't\xe4nktejag', u't\xe4nkte jag'), (u'tapparjag', u'tappar jag'), (u'tittarp\xe5', u'tittar p\xe5'), (u'visstejag', u'visste jag'), (u'medjetpacks', u'med jetpacks'), (u's\xe4tterp\xe5', u's\xe4tter p\xe5'), (u'st\xe5rp\xe5', u'st\xe5r p\xe5'), (u'tillh\xf6rp\xe5', u'tillh\xf6r p\xe5')]), 'pattern': u"(?um)(\\b|^)(?:l\\\xe2rt|hederv\\\xe5rda|storm\\\xe2stare|Avf\\\xe2rd|t\\\xe2lten|\\\xe2rjag|\\\xe4rjag|j\\\xe2mlikar|Riskako\\\ufb02|Karamellen\\/|Lngen\\\xfcng|\\\xe4rju|S\\\xe1|n\\\xe4rjag|alltjag|g\\\xf6rjag|trorjag|varju|g\\\xf6rju|kanju|blirjag|s\\\xe4gerjag|beh\\\xe5llerjag|pr\\\xf8blem|r\\\xe4ddadeju|hon\\\xf8m|Ln|sv\\\xe5r\\\ufb02\\\xf6rtad|\\\xf8ch|\\\ufb02\\\xf6rtar|k\\\xe4nnerjag|\\\ufb02ickan|sn\\\xf8|gerju|k\\\xf8ntakter|\\\xf8lycka|n\\\xf8lla|sinnenajublar|ijobbet|F\\\xe5rjag|Ar|liggerju|um|lbland|skjuterjag|Vadd\\\xe5|pratarj\\\xe4mt|harju|sitterjag|h\\\xe4\\\ufb02a|s\\\ufb01\\\xe4l|F\\\xd6U|varf\\\xf6rjag|s\\\ufb01\\\xe4rna|b\\\xf6\\\ufb02ar|b\\\xf6\\\ufb02an|st\\\xe4ri|p\\\xe4|harjag|attjag|Verkarjag|K\\\xe4nnerjag|d\\\xe4rjag|tu\\\ufb01|lurarjag|varj\\\xe4ttebra|allvan|deth\\\xe4r|va\\\ufb02e|F\\\xf6Uer|personalm\\\xf6tetl|harjust|\\\xe4rj\\\xe4tteduktig|d\\\xe4rja|lngen\\\xfcng|iluften|\\\xf6sen|tv\\\xe2|Uejerna|h\\\xe5n\\*|\\\xc4rjag|keL|F\\\xf6rjag|varj\\\xe4ttekul|k\\\xe4mpan|mycketjobb|Uus|serjag|vetjag|f\\\xe5rjag|hurjag|f\\\xf6rs\\\xf6kerjag|t\\\xe1nagel|va\\\xfce|Uudet|amhopa|V\\\xe4\\\xfc|g\\\xe4ri|r\\\xf6d\\\xfcus|Uuset|Rid\\\xe0n|vi\\\xfca|g\\\xe5ri|Hurd\\\xe5|inter\\\\\\/juar|menarjag|spyrjag|bri\\\xfcera|N\\\xe4rjag|ner\\\\\\/\\\xf6s|ilivets|n\\\xe4got|p\\\xe0|Lnnan|Uf|lnnan|D\\\xe0ren|F\\\xe0rjag|Vad\\\xe4rdetd\\\xe4L|sm\\\xe0tjuv|t\\\xe0gr\\\xe5nare|dit\\\xe0t|s\\\xe4|v\\\xe0rdsl\\\xf6sa|n\\\xe0n|kommerjag|\\\xe4rj\\\xe4ttebra|\\\xe4rj\\\xe4vligt|\\\xe0kerjag|ellerjapaner|attjaga|eften|h\\\xe4stan|Lntensivare|fr\\\xe0garjag|pen\\/ers|r\\\xe0barkade|styrkon|Dif\\\xe5f|h\\\xe4nden|f\\\xf6\\\ufb01a|Idioten\\/|Varf\\\xf6rjagade|d\\\xe4rf\\\xf6rjag|forjag|Iivsgladje|narjag|sajag|genastja|rockument\\\xe0ren|turne|fickjag|sager|Ijush\\\xe5rig|tradg\\\xe5rdsolycka|kvavdes|d\\\xe0rja|hedersgaster|Nar|smaki\\\xf6sa|lan|Lan|eri|universitetsamne|garna|ar|baltdjur|varjag|\\\xe0r|f\\\xf6rf\\\xf6rst\\\xe0rkare|arjattespeciell|h\\\xe0rg\\\xe5r|Ia|Iimousinen|krickettra|h\\\xe5rdrockv\\\xe0rlden|tr\\\xe0bit|Mellanvastern|arju|turnen|kanns|battre|v\\\xe0rldsturne|dar|sj\\\xe0lvant\\\xe0nder|jattelange|berattade|S\\\xe4|vandpunkten|N\\\xe0rjag|lasa|skitl\\\xe0skigt|sambandsv\\\xe0g|valdigt|Stamga\\\ufb01el|\\\xe0rjag|tajming|utg\\\xe4ng|H\\\xe0r\\\xe5t|h\\\xe0r\\\xe5t|anvander|harjobbat|imageide|kla\\\ufb01en|sjalv|dvarg|detjag|dvargarna|fantasiv\\\xe0rld|\\\ufb01olliga|mandoiinstr\\\xe0ngar|mittjobb|Skajag|landari|gang|Detjag|Narmre|I\\\xe5tjavelni|H\\\xe5llerjag|visionarer|T\\\xfclvad|milit\\\xe0rbas|jattegiada|Fastjag|s\\\xe5jag|rockvarlden|saknarjag|allafall|\\\ufb01anta|Kr\\\xe0ma|stammer|budb\\\xe0rare|Iivsfiiosofi|f\\\xf6rj\\\xe4mnan|gillarjag|Iarvat|klararjag|hatta\\\ufb01\\'\\\xe0r|D\\\xe0|upp\\\ufb01nna|R\\\xe0ttf\\\xe5glar|Sv\\\xe4\\\xfcboda|P\\\xe5b\\\xf6\\\ufb02ar|slutarju|ni\\\ufb01skebu\\\xfcken|h\\\xe4rj\\\xe4keln|H\\\xdfppa|f\\\xf6rst\\\xf6rds|varj\\\xe4ttegoda|Kor\\\\\\/|br\\\xfcl\\\xe9el|Hei|\\\xe4lskarjordgubbsglass|Sn\\\xf6bom|Sn\\\xf6boH|Sn\\\xf6bol|sn\\\xf6boH|L\\\xe4ggerp\\\xe5|lnge\\\ufb02|S\\\xe4gerj\\\xe4ttesmarta|dopplen\\/\\\xe4derradar|s\\\xe4kertj\\\xe4ttefin|\\\xe4rj\\\xe4ttefin|verkarju|blirju|kor\\\\\\/|naturkatastro\\\ufb01|stickerjag|j\\\xe4ttebu\\\ufb01\\\xe9|be\\\ufb01nner|Sp\\\ufb02ng|trec\\\ufb01e|ryckerjag|skullejag|vetju|a\\\ufb02jag|\\\ufb02nns|\\\xe4rl\\\xe5ng|k\\\xe5ra|\\\xe4r\\\ufb01na|\\\xe4ri|h\\\xf6rden|\\\xe4ttj\\\xe4g|g\\\xe4r|f\\\xf6ri|Hurvisste|\\\ufb01ck|\\\ufb01nns|\\\ufb01n|Fa|bori|fiendeplanl|if\\\xf6rnamn|detju|N\\\xfcd|hatarjag|Klararjag|deta\\\ufb01er|v\\\xe4\\/|smakarju|Teache\\\ufb02|imorse|drickerjag|st\\\xe5ri|Harjag|Talarjag|undrarjag|\\\xe5lderjag|va\\\ufb01e|f\\\xf6rfalskningl|Vi\\\ufb01iiiam|V\\\\\\\ufb01lliams|attjobba|intei|n\\\xe4rV\\\\\\\ufb01lliam|V\\\\\\\ufb01lliam|E\\\ufb01ersom|Vl\\\ufb01lliam|I\\\xe4ngejag|\\'\\\ufb01digare|b\\\xf6rjadei|merjust|e\\\ufb01er\\\xe5t|gjordejag|hadeju|g\\\xe5rvi|k\\\xf6perjag|M\\\xe5stejag|k\\\xe4nnerju|\\\ufb02n|treviig|Grattisl|kande|\\'llden|sakjag|klartjag|h\\\xe4\\\ufb01igt|I\\\xe4mnarjag|gickju|skajag|G\\\xf6rjag|m\\\xe5stejag|gra\\\\\\/iditet|hittadqdin|\\\xe4rjobbigt|Overdrivet|hOgtidlig|Overtyga|SKILSMASSA|brukarju|lsabel|kundejag|\\\xe4rl\\\xe4get|blirinte|ijakt|avjordens|90000O|9O0|\\\xe4rp\\\xe5|\\\xe4rproteserna|\\\xe4rytterst|beborjorden|filmjag|fokuserarp\\\xe5|folkjag|f\\\xf6rest\\\xe4lldejag|f\\\xf6rpubliken|gilladejag|h\\\xe5llerp\\\xe5|harp\\\xe5|harplaner|harprylar|kommerpubliken|kostymerp\\\xe5|litarp\\\xe5|lngen|lnom|lnte|ochjag|Ochjag|ochjorden|omjag|Omjag|passarperfekt|s\\\xe4ttetjag|silverp\\\xe5|skruvarjag|somjag|Somjag|talarp\\\xe5|t\\\xe4nktejag|tapparjag|tittarp\\\xe5|visstejag|medjetpacks|s\\\xe4tterp\\\xe5|st\\\xe5rp\\\xe5|tillh\\\xf6rp\\\xe5)(\\b|$)"}}} -for lang, grps in data.items(): - for grp in grps.keys(): +for lang, grps in six.iteritems(data): + for grp in six.iterkeys(grps): if data[lang][grp]["pattern"]: data[lang][grp]["pattern"] = re.compile(data[lang][grp]["pattern"]) diff --git a/libs/subzero/modification/dictionaries/make_data.py b/libs/subzero/modification/dictionaries/make_data.py index 7a0482dad..726208d3d 100644 --- a/libs/subzero/modification/dictionaries/make_data.py +++ b/libs/subzero/modification/dictionaries/make_data.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import re import os import pprint diff --git a/libs/subzero/modification/dictionaries/test_data.py b/libs/subzero/modification/dictionaries/test_data.py index 538c99fc0..55dcca643 100644 --- a/libs/subzero/modification/dictionaries/test_data.py +++ b/libs/subzero/modification/dictionaries/test_data.py @@ -1,10 +1,13 @@ # coding=utf-8 +from __future__ import absolute_import +from __future__ import print_function from subzero.language import Language -from data import data +from .data import data +import six #for lang, data in data.iteritems(): # print Language.fromietf(lang).alpha2 -for find, rep in data["dan"].iteritems(): - print find, rep
\ No newline at end of file +for find, rep in six.iteritems(data["dan"]): + print(find, rep)
\ No newline at end of file diff --git a/libs/subzero/modification/main.py b/libs/subzero/modification/main.py index f1fa3fbfd..e67042755 100644 --- a/libs/subzero/modification/main.py +++ b/libs/subzero/modification/main.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import traceback import re import pysubs2 @@ -9,6 +10,7 @@ import time from .mods import EMPTY_TAG_PROCESSOR, EmptyEntryError from .registry import registry from subzero.language import Language +import six logger = logging.getLogger(__name__) @@ -128,7 +130,7 @@ class SubtitleModifications(object): used_mods.append(orig_identifier) # finalize merged mods into final and used mods - for identifier, args in mods_merged.iteritems(): + for identifier, args in six.iteritems(mods_merged): pos_preserve_index = used_mods.index("%s_ORIG_POSITION" % identifier) # clear empty mods after merging @@ -143,7 +145,7 @@ class SubtitleModifications(object): continue # clear empty args - final_mod_args = dict(filter(lambda kv: bool(kv[1]), args.iteritems())) + final_mod_args = dict([k_v for k_v in six.iteritems(args) if bool(k_v[1])]) _data = SubtitleModifications.get_mod_signature(identifier, **final_mod_args) if _data == mods_merged_log[identifier]["final_identifier"]: @@ -159,11 +161,11 @@ class SubtitleModifications(object): final_mods[identifier] = args if self.debug: - for identifier, data in mods_merged_log.iteritems(): + for identifier, data in six.iteritems(mods_merged_log): logger.debug("Merged %s to %s", data["identifiers"], data["final_identifier"]) # separate all mods into line and non-line mods - for identifier, args in final_mods.iteritems(): + for identifier, args in six.iteritems(final_mods): mod_cls = registry.mods[identifier] if mod_cls.modifies_whole_file: non_line_mods.append((identifier, args)) diff --git a/libs/subzero/modification/mods/__init__.py b/libs/subzero/modification/mods/__init__.py index 5766dccc0..e38e899c9 100644 --- a/libs/subzero/modification/mods/__init__.py +++ b/libs/subzero/modification/mods/__init__.py @@ -1,8 +1,10 @@ # coding=utf-8 +from __future__ import absolute_import import re import logging from subzero.modification.processors.re_processor import ReProcessor, NReProcessor +import six logger = logging.getLogger(__name__) @@ -83,7 +85,7 @@ class SubtitleModification(object): @classmethod def get_signature(cls, **kwargs): - string_args = ",".join(["%s=%s" % (key, value) for key, value in kwargs.iteritems()]) + string_args = ",".join(["%s=%s" % (key, value) for key, value in six.iteritems(kwargs)]) return "%s(%s)" % (cls.identifier, string_args) @classmethod diff --git a/libs/subzero/modification/mods/color.py b/libs/subzero/modification/mods/color.py index 9e883b101..6e845298b 100644 --- a/libs/subzero/modification/mods/color.py +++ b/libs/subzero/modification/mods/color.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import logging from collections import OrderedDict diff --git a/libs/subzero/modification/mods/common.py b/libs/subzero/modification/mods/common.py index e57e53cd7..c0a4a3eb9 100644 --- a/libs/subzero/modification/mods/common.py +++ b/libs/subzero/modification/mods/common.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import re from subzero.language import Language diff --git a/libs/subzero/modification/mods/fps.py b/libs/subzero/modification/mods/fps.py index b209eddff..856af9e15 100644 --- a/libs/subzero/modification/mods/fps.py +++ b/libs/subzero/modification/mods/fps.py @@ -1,5 +1,6 @@ # coding=utf-8 +from __future__ import absolute_import import logging from subzero.modification.mods import SubtitleModification diff --git a/libs/subzero/modification/mods/hearing_impaired.py b/libs/subzero/modification/mods/hearing_impaired.py index c615b5679..dd42b5514 100644 --- a/libs/subzero/modification/mods/hearing_impaired.py +++ b/libs/subzero/modification/mods/hearing_impaired.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import import re from subzero.modification.mods import SubtitleTextModification, empty_line_post_processors, EmptyEntryError, TAG diff --git a/libs/subzero/modification/mods/ocr_fixes.py b/libs/subzero/modification/mods/ocr_fixes.py index ebf485bb7..31fc94cdc 100644 --- a/libs/subzero/modification/mods/ocr_fixes.py +++ b/libs/subzero/modification/mods/ocr_fixes.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import import logging import re diff --git a/libs/subzero/modification/mods/offset.py b/libs/subzero/modification/mods/offset.py index ca2ae30eb..6f645a1ac 100644 --- a/libs/subzero/modification/mods/offset.py +++ b/libs/subzero/modification/mods/offset.py @@ -1,9 +1,11 @@ # coding=utf-8 +from __future__ import absolute_import import logging from subzero.modification.mods import SubtitleModification from subzero.modification import registry +import six logger = logging.getLogger(__name__) @@ -20,9 +22,9 @@ class ShiftOffset(SubtitleModification): @classmethod def merge_args(cls, args1, args2): - new_args = dict((key, int(value)) for key, value in args1.iteritems()) + new_args = dict((key, int(value)) for key, value in six.iteritems(args1)) - for key, value in args2.iteritems(): + for key, value in six.iteritems(args2): if not int(value): continue @@ -31,7 +33,7 @@ class ShiftOffset(SubtitleModification): else: new_args[key] = int(value) - return dict(filter(lambda kv: bool(kv[1]), new_args.items())) + return dict([k_v for k_v in six.iteritems(new_args) if bool(k_v[1])]) def modify(self, content, debug=False, parent=None, **kwargs): parent.f.shift(h=int(kwargs.get("h", 0)), m=int(kwargs.get("m", 0)), s=int(kwargs.get("s", 0)), diff --git a/libs/subzero/modification/processors/__init__.py b/libs/subzero/modification/processors/__init__.py index 7cfb0aa33..4bbf29267 100644 --- a/libs/subzero/modification/processors/__init__.py +++ b/libs/subzero/modification/processors/__init__.py @@ -1,3 +1,4 @@ +import six # coding=utf-8 @@ -29,7 +30,7 @@ class Processor(object): return repr(self) def __unicode__(self): - return unicode(repr(self)) + return six.text_type(repr(self)) class FuncProcessor(Processor): diff --git a/libs/subzero/modification/processors/re_processor.py b/libs/subzero/modification/processors/re_processor.py index 5ff76331e..ad07240d2 100644 --- a/libs/subzero/modification/processors/re_processor.py +++ b/libs/subzero/modification/processors/re_processor.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import import re import logging diff --git a/libs/subzero/modification/processors/string_processor.py b/libs/subzero/modification/processors/string_processor.py index 270fd76f8..30a53de85 100644 --- a/libs/subzero/modification/processors/string_processor.py +++ b/libs/subzero/modification/processors/string_processor.py @@ -1,8 +1,10 @@ # coding=utf-8 +from __future__ import absolute_import import logging from subzero.modification.processors import Processor +import six logger = logging.getLogger(__name__) @@ -39,7 +41,7 @@ class MultipleLineProcessor(Processor): if not self.snr_dict["data"]: return content - for key, value in self.snr_dict["data"].iteritems(): + for key, value in six.iteritems(self.snr_dict["data"]): if debug and key in content: logger.debug(u"Replacing '%s' with '%s' in '%s'", key, value, content) @@ -54,7 +56,7 @@ class WholeLineProcessor(MultipleLineProcessor): return content content = content.strip() - for key, value in self.snr_dict["data"].iteritems(): + for key, value in six.iteritems(self.snr_dict["data"]): if content == key: if debug: logger.debug(u"Replacing '%s' with '%s'", key, value) diff --git a/libs/subzero/modification/registry.py b/libs/subzero/modification/registry.py index 7b240a69c..277abefa5 100644 --- a/libs/subzero/modification/registry.py +++ b/libs/subzero/modification/registry.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import from collections import OrderedDict diff --git a/libs/subzero/prefs.py b/libs/subzero/prefs.py index 252164fb9..5744d4eac 100644 --- a/libs/subzero/prefs.py +++ b/libs/subzero/prefs.py @@ -1,6 +1,7 @@ # coding=utf-8 +from __future__ import absolute_import import traceback -from constants import PLUGIN_IDENTIFIER +from .constants import PLUGIN_IDENTIFIER def get_user_prefs(Prefs, Logger): diff --git a/libs/subzero/sandbox.py b/libs/subzero/sandbox.py index f409b1824..888b17a9b 100644 --- a/libs/subzero/sandbox.py +++ b/libs/subzero/sandbox.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import import sys diff --git a/libs/subzero/score_range.py b/libs/subzero/score_range.py index ec80d665f..52d0680ad 100644 --- a/libs/subzero/score_range.py +++ b/libs/subzero/score_range.py @@ -1,5 +1,7 @@ # coding=utf-8 +from __future__ import absolute_import +from __future__ import print_function import sys from itertools import chain, combinations, permutations @@ -15,8 +17,8 @@ if __name__ == "__main__": leftover_keys = list(set(scores.keys()) - set(base_score_keys)) base_score = sum([val for key, val in scores.items() if key in base_score_keys]) leftover_scores = set([score for key, score in scores.items() if key in leftover_keys]) - print "base score:", base_score - print "leftover:", sorted(set(leftover_scores)) + print("base score:", base_score) + print("leftover:", sorted(set(leftover_scores))) # print sum_possible_scores(base_score, leftover_scores) # print list(permutations(leftover_scores)) - print ",\n".join(map(lambda x: '"%s"' % x, ["66"] + sorted(set(permute(leftover_scores))))) + print(",\n".join(['"%s"' % x for x in ["66"] + sorted(set(permute(leftover_scores)))])) diff --git a/libs/subzero/subtitle_storage.py b/libs/subzero/subtitle_storage.py index 186a03a38..53a31b8f2 100644 --- a/libs/subzero/subtitle_storage.py +++ b/libs/subzero/subtitle_storage.py @@ -1,4 +1,5 @@ # coding=utf-8 +from __future__ import absolute_import import datetime import gzip import hashlib @@ -13,7 +14,8 @@ import sys from json_tricks.nonp import loads from subzero.lib.json import dumps from scandir import scandir, scandir_generic as _scandir_generic -from constants import mode_map +from .constants import mode_map +import six logger = logging.getLogger(__name__) @@ -67,7 +69,7 @@ class JSONStoredSubtitle(object): def deserialize(self, data): if data["content"]: # legacy: storage was unicode; content is always present in encoded form - if isinstance(data["content"], types.UnicodeType): + if isinstance(data["content"], str): data["content"] = data["content"].encode(data["encoding"]) self.initialize(**data) @@ -103,18 +105,18 @@ class JSONStoredVideoSubtitles(object): self.__dict__.update(data) if parts: - for part_id, part in parts.iteritems(): + for part_id, part in six.iteritems(parts): self.parts[part_id] = {} - for language, sub_data in part.iteritems(): + for language, sub_data in six.iteritems(part): self.parts[part_id][language] = {} - for sub_key, subtitle_data in sub_data.iteritems(): + for sub_key, subtitle_data in six.iteritems(sub_data): if sub_key == "current": if not isinstance(subtitle_data, tuple): subtitle_data = tuple(subtitle_data.split("__")) self.parts[part_id][language]["current"] = subtitle_data elif sub_key == "blacklist": - bl = dict((tuple([str(a) for a in k.split("__")]), v) for k, v in subtitle_data.iteritems()) + bl = dict((tuple([str(a) for a in k.split("__")]), v) for k, v in six.iteritems(subtitle_data)) self.parts[part_id][language]["blacklist"] = bl else: sub = JSONStoredSubtitle() @@ -127,21 +129,21 @@ class JSONStoredVideoSubtitles(object): def serialize(self): data = {"parts": {}} - for key, value in self.__dict__.iteritems(): + for key, value in six.iteritems(self.__dict__): if key != "parts": data[key] = value - for part_id, part in self.parts.iteritems(): + for part_id, part in six.iteritems(self.parts): data["parts"][part_id] = {} - for language, sub_data in part.iteritems(): + for language, sub_data in six.iteritems(part): data["parts"][part_id][language] = {} - for sub_key, stored_subtitle in sub_data.iteritems(): + for sub_key, stored_subtitle in six.iteritems(sub_data): if sub_key == "current": data["parts"][part_id][language]["current"] = "__".join(stored_subtitle) elif sub_key == "blacklist": data["parts"][part_id][language]["blacklist"] = dict(("__".join(k), v) for k, v in - stored_subtitle.iteritems()) + six.iteritems(stored_subtitle)) else: if stored_subtitle.content and not stored_subtitle.encoding: continue @@ -223,7 +225,7 @@ class JSONStoredVideoSubtitles(object): if not all_subs: return out - for key, subtitle in all_subs.iteritems(): + for key, subtitle in six.iteritems(all_subs): if key in ("current", "blacklist"): continue @@ -238,7 +240,7 @@ class JSONStoredVideoSubtitles(object): return 0 subs = part.get(str(lang)) - return len(filter(lambda key: key not in ("current", "blacklist"), subs.keys())) + return len([key for key in list(subs.keys()) if key not in ("current", "blacklist")]) def get_sub_key(self, provider_name, id): return provider_name, str(id) @@ -275,7 +277,7 @@ class JSONStoredVideoSubtitles(object): subs["blacklist"] = current_bl def __repr__(self): - return unicode(self) + return six.text_type(self) def __unicode__(self): return u"%s (%s)" % (self.title, self.video_id) @@ -399,7 +401,7 @@ class StoredSubtitlesManager(object): pass # remove known info about non-existing languages - for part_id, part in stored_subs.parts.iteritems(): + for part_id, part in six.iteritems(stored_subs.parts): missing_languages = set(part).difference(wanted_languages) if missing_languages: logger.debug("Languages removed: %s:%s:%s, removing data", video_id, part_id, missing_languages) diff --git a/libs/subzero/util.py b/libs/subzero/util.py index 25ab0cd60..61f6e9299 100644 --- a/libs/subzero/util.py +++ b/libs/subzero/util.py @@ -1,7 +1,9 @@ # coding=utf-8 +from __future__ import absolute_import import os from subzero.lib.io import get_viable_encoding +import six def get_root_path(): - return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(unicode(__file__, get_viable_encoding()))), "..")) + return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(six.text_type(__file__, get_viable_encoding()))), "..")) diff --git a/libs/subzero/video.py b/libs/subzero/video.py index 13db33ddf..6e263bca9 100644 --- a/libs/subzero/video.py +++ b/libs/subzero/video.py @@ -1,11 +1,13 @@ # coding=utf-8 +from __future__ import absolute_import import logging import os from babelfish.exceptions import LanguageError from subzero.language import Language, language_from_stream from subliminal_patch import scan_video, refine, search_external_subtitles +import six logger = logging.getLogger(__name__) @@ -98,7 +100,7 @@ def refine_video(video, no_refining=False, refiner_settings=None): # our own metadata refiner :) if "stream" in video_info: - for key, value in video_info["stream"].iteritems(): + for key, value in six.iteritems(video_info["stream"]): if hasattr(video, key) and not getattr(video, key): logger.info(u"Adding stream %s info: %s", key, value) setattr(video, key, value) |