Merge pull request #880 from oddstr13/pr-six-cleanup-1

Remove dependency on six
This commit is contained in:
Odd Stråbø 2024-06-12 03:00:04 +02:00 committed by GitHub
commit 9cdc027b39
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 118 additions and 127 deletions

View file

@ -37,7 +37,6 @@ repos:
# - pytest
# - types-requests >= 2.31
# - types-PyYAML >= 6.0
# - types-six >= 1.13
# - types-python-dateutil >= 2.8.1
# - types-setuptools >= 44.1.1
# - types-Pygments

View file

@ -5,7 +5,9 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import os
from kodi_six import xbmc, xbmcaddon, xbmcvfs
import xbmc
import xbmcaddon
import xbmcvfs
from .helper import translate, window, settings, addon_id, dialog, LazyLogger
from .helper.utils import create_id, translate_path

View file

@ -3,7 +3,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon
from . import client
from .database import get_credentials, save_credentials

View file

@ -10,8 +10,8 @@ import sqlite3
import sys
import re
from kodi_six import xbmc, xbmcvfs
from six import text_type
import xbmc
import xbmcvfs
from . import jellyfin_db
from ..helper import translate, settings, window, dialog
@ -362,7 +362,7 @@ def save_sync(sync):
with open(os.path.join(ADDON_DATA, "sync.json"), "wb") as outfile:
data = json.dumps(sync, sort_keys=True, indent=4, ensure_ascii=False)
if isinstance(data, text_type):
if isinstance(data, str):
data = data.encode("utf-8")
outfile.write(data)
@ -411,7 +411,7 @@ def save_credentials(credentials):
try:
with open(os.path.join(ADDON_DATA, "data.json"), "wb") as outfile:
data = json.dumps(credentials, sort_keys=True, indent=4, ensure_ascii=False)
if isinstance(data, text_type):
if isinstance(data, str):
data = data.encode("utf-8")
outfile.write(data)
except Exception:

View file

@ -5,8 +5,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import os
from kodi_six import xbmcgui, xbmcaddon
from six import ensure_text
import xbmcgui
import xbmcaddon
from ..helper import window, addon_id
from ..helper import LazyLogger
@ -69,7 +69,7 @@ class ContextMenu(xbmcgui.WindowXMLDialog):
):
option = self.list_.getSelectedItem()
self.selected_option = ensure_text(option.getLabel())
self.selected_option = option.getLabel()
LOG.info("option selected: %s", self.selected_option)
self.close()

View file

@ -3,8 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from six import iteritems
from kodi_six import xbmcgui
import xbmcgui
from ..helper import translate, LazyLogger, kodi_version
@ -34,7 +33,7 @@ class LoginManual(xbmcgui.WindowXMLDialog):
def set_args(self, **kwargs):
# connect_manager, user_image, servers
for key, value in iteritems(kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
def is_logged_in(self):

View file

@ -3,7 +3,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from kodi_six import xbmc, xbmcgui
import xbmc
import xbmcgui
from ..helper import LazyLogger

View file

@ -3,8 +3,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from six import iteritems
from kodi_six import xbmc, xbmcgui
import xbmc
import xbmcgui
from ..helper import translate
from ..jellyfin.connection_manager import CONNECTION_STATE
@ -44,7 +44,7 @@ class ServerConnect(xbmcgui.WindowXMLDialog):
def set_args(self, **kwargs):
# connect_manager, user_image, servers
for key, value in iteritems(kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
def is_server_selected(self):

View file

@ -5,8 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import re
from six import iteritems
from kodi_six import xbmcgui
import xbmcgui
from ..helper import translate
from ..jellyfin.connection_manager import CONNECTION_STATE
@ -41,7 +40,7 @@ class ServerManual(xbmcgui.WindowXMLDialog):
def set_args(self, **kwargs):
# connect_manager, user_image, servers, jellyfin_connect
for key, value in iteritems(kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
def is_connected(self):

View file

@ -3,8 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from six import iteritems
from kodi_six import xbmcgui
import xbmcgui
from ..helper import LazyLogger
from ..helper.utils import kodi_version
@ -36,7 +35,7 @@ class UsersConnect(xbmcgui.WindowXMLDialog):
def set_args(self, **kwargs):
# connect_manager, user_image, servers
for key, value in iteritems(kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
def is_user_selected(self):

View file

@ -7,7 +7,7 @@ import threading
import concurrent.futures
from datetime import date
from six.moves import range, queue as Queue
import queue
import requests
@ -308,7 +308,7 @@ class GetItemWorker(threading.Thread):
while True:
try:
item_ids = self.queue.get(timeout=1)
except Queue.Empty:
except queue.Empty:
self.is_done = True
LOG.info("--<[ q:download/%s ]", id(self))

View file

@ -6,7 +6,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json
import sys
from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon
from .. import database
from ..dialogs import context

View file

@ -6,10 +6,13 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json
import sys
import os
from urllib.parse import parse_qsl, urlencode
from six import iteritems
from six.moves.urllib.parse import parse_qsl, urlencode
from kodi_six import xbmc, xbmcvfs, xbmcgui, xbmcplugin, xbmcaddon
import xbmc
import xbmcvfs
import xbmcgui
import xbmcplugin
import xbmcaddon
from .. import client
from ..database import reset, get_sync, Database, jellyfin_db, get_credentials
@ -1073,7 +1076,7 @@ def create_listitem(item):
li.setProperty("dbid", str(item["episodeid"]))
li.setProperty("fanart_image", item["art"].get("tvshow.fanart", ""))
for key, value in iteritems(item["streamdetails"]):
for key, value in item["streamdetails"].items():
for stream in value:
li.addStreamInfo(key, stream)

View file

@ -6,11 +6,12 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json
import sys
from datetime import datetime
from importlib import reload
# Workaround for threads using datetime: _striptime is locked
import _strptime # noqa:F401
from kodi_six import xbmc, xbmcgui
from six.moves import reload_module as reload
import xbmc
import xbmcgui
from .. import objects
from .. import connect

View file

@ -6,7 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
from contextlib import contextmanager
import datetime
from kodi_six import xbmc
import xbmc
from . import downloader as server
from .objects import Movies, TVShows, MusicVideos, Music

View file

@ -7,11 +7,11 @@ import os
import logging
import traceback
from six import ensure_text
from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon
from .. import database
from . import get_filesystem_encoding, settings, kodi_version
from . import settings, kodi_version
from .utils import translate_path
##################################################################################################
@ -92,9 +92,6 @@ class MyFormatter(logging.Formatter):
logging.Formatter.__init__(self, fmt)
def format(self, record):
if record.pathname:
record.pathname = ensure_text(record.pathname, get_filesystem_encoding())
self._gen_rel_path(record)
# Call the original formatter class to do the grunt work
@ -107,8 +104,6 @@ class MyFormatter(logging.Formatter):
res = []
for o in traceback.format_exception(*exc_info):
o = ensure_text(o, get_filesystem_encoding())
if o.startswith(' File "'):
# If this split can't handle your file names, you should seriously consider renaming your files.
fn = o.split(' File "', 2)[1].split('", line ', 1)[0]

View file

@ -7,7 +7,8 @@ import os
from uuid import uuid4
import requests
from kodi_six import xbmc, xbmcvfs
import xbmc
import xbmcvfs
from .. import client
from .utils import translate_path

View file

@ -3,7 +3,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon
from . import LazyLogger

View file

@ -10,12 +10,14 @@ import sys
import re
import unicodedata
from uuid import uuid4
from urllib.parse import quote_plus
from dateutil import tz, parser
from six import text_type, string_types, iteritems, ensure_text, ensure_binary
from six.moves.urllib.parse import quote_plus
from kodi_six import xbmc, xbmcaddon, xbmcgui, xbmcvfs
import xbmc
import xbmcaddon
import xbmcgui
import xbmcvfs
from . import LazyLogger
from .translate import translate
@ -103,11 +105,12 @@ def create_id():
def find(dict, item):
# FIXME: dead code
"""Find value in dictionary."""
if item in dict:
return dict[item]
for key, value in sorted(iteritems(dict), key=lambda kv: (kv[1], kv[0])):
for key, value in sorted(dict.items(), key=lambda kv: (kv[1], kv[0])):
if re.match(key, item, re.I):
return dict[key]
@ -119,7 +122,7 @@ def event(method, data=None, sender=None, hexlify=False):
sender = sender or "plugin.video.jellyfin"
if hexlify:
data = ensure_text(binascii.hexlify(ensure_binary(json.dumps(data))))
data = str(binascii.hexlify(json.dumps(data).encode()))
data = '"[%s]"' % json.dumps(data).replace('"', '\\"')
@ -272,7 +275,7 @@ def values(item, keys):
return (
(
item[key.replace("{", "").replace("}", "")]
if isinstance(key, text_type) and key.startswith("{")
if isinstance(key, str) and key.startswith("{")
else key
)
for key in keys
@ -422,9 +425,7 @@ def normalize_string(text):
text = text.strip()
text = text.rstrip(".")
text = unicodedata.normalize("NFKD", text_type(text, "utf-8")).encode(
"ascii", "ignore"
)
text = unicodedata.normalize("NFKD", text).encode("ascii", "ignore")
return text
@ -437,7 +438,7 @@ def split_list(itemlist, size):
def convert_to_local(date, timezone=tz.tzlocal()):
"""Convert the local datetime to local."""
try:
date = parser.parse(date) if isinstance(date, string_types) else date
date = parser.parse(date) if isinstance(date, str) else date
date = date.replace(tzinfo=tz.tzutc())
date = date.astimezone(timezone)
# Bad metadata defaults to date 1-1-1. Catch it and don't throw errors

View file

@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
#################################################################################################
from kodi_six import xbmcgui
import xbmcgui
from . import LazyLogger

View file

@ -6,7 +6,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import os
import xml.etree.ElementTree as etree
from kodi_six import xbmc, xbmcvfs
import xbmc
import xbmcvfs
from .utils import translate_path
from . import translate, dialog, settings, LazyLogger

View file

@ -4,7 +4,6 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json
import requests
from six import ensure_str
from ..helper.exceptions import HTTPException
from ..helper.utils import settings
@ -416,7 +415,7 @@ class API(object):
"User-Agent": self.config.data["http.user_agent"]
or "%s/%s"
% (self.config.data["app.name"], self.config.data["app.version"]),
"x-emby-authorization": ensure_str(auth, "utf-8"),
"x-emby-authorization": auth,
}
def send_request(

View file

@ -6,7 +6,6 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import time
import requests
from six import string_types, ensure_str
from ..helper.utils import JsonDebugPrinter
from ..helper import LazyLogger
@ -218,7 +217,7 @@ class HTTP(object):
if isinstance(value, dict):
self._process_params(value)
if isinstance(value, string_types):
if isinstance(value, str):
params[key] = self._replace_user_info(value)
def _get_header(self, data):
@ -257,14 +256,14 @@ class HTTP(object):
)
auth += "Version=%s" % self.config.data.get("app.version", "0.0.0")
data["headers"].update({"x-emby-authorization": ensure_str(auth, "utf-8")})
data["headers"].update({"x-emby-authorization": auth})
if self.config.data.get("auth.token") and self.config.data.get("auth.user_id"):
auth += ", UserId=%s" % self.config.data.get("auth.user_id")
data["headers"].update(
{
"x-emby-authorization": ensure_str(auth, "utf-8"),
"x-emby-authorization": auth,
"X-MediaBrowser-Token": self.config.data.get("auth.token"),
}
)

View file

@ -1,14 +1,12 @@
from collections import namedtuple
from six import string_types
from six.moves import collections_abc
from collections.abc import Iterable, Mapping, MutableMapping
def clean_none_dict_values(obj):
"""
Recursively remove keys with a value of None
"""
if not isinstance(obj, collections_abc.Iterable) or isinstance(obj, string_types):
if not isinstance(obj, Iterable) or isinstance(obj, str):
return obj
queue = [obj]
@ -16,18 +14,18 @@ def clean_none_dict_values(obj):
while queue:
item = queue.pop()
if isinstance(item, collections_abc.Mapping):
mutable = isinstance(item, collections_abc.MutableMapping)
if isinstance(item, Mapping):
mutable = isinstance(item, MutableMapping)
remove = []
for key, value in item.items():
if value is None and mutable:
remove.append(key)
elif isinstance(value, string_types):
elif isinstance(value, str):
continue
elif isinstance(value, collections_abc.Iterable):
elif isinstance(value, Iterable):
queue.append(value)
if mutable:
@ -35,11 +33,11 @@ def clean_none_dict_values(obj):
for key in remove:
item.pop(key)
elif isinstance(item, collections_abc.Iterable):
elif isinstance(item, Iterable):
for value in item:
if value is None or isinstance(value, string_types):
if value is None or isinstance(value, str):
continue
elif isinstance(value, collections_abc.Iterable):
elif isinstance(value, Iterable):
queue.append(value)
return obj

View file

@ -7,7 +7,7 @@ import json
import threading
import time
from kodi_six import xbmc
import xbmc
from ..helper import LazyLogger, settings

View file

@ -6,9 +6,10 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import threading
from datetime import datetime, timedelta
from six.moves import queue as Queue
import queue
from kodi_six import xbmc, xbmcgui
import xbmc
import xbmcgui
from .objects import Movies, TVShows, MusicVideos, Music
from .objects.kodi import Movies as KodiDb
@ -48,13 +49,13 @@ class Library(threading.Thread):
self.monitor = monitor
self.player = monitor.monitor.player
self.server = Jellyfin().get_client()
self.updated_queue = Queue.Queue()
self.userdata_queue = Queue.Queue()
self.removed_queue = Queue.Queue()
self.updated_queue = queue.Queue()
self.userdata_queue = queue.Queue()
self.removed_queue = queue.Queue()
self.updated_output = self.__new_queues__()
self.userdata_output = self.__new_queues__()
self.removed_output = self.__new_queues__()
self.notify_output = Queue.Queue()
self.notify_output = queue.Queue()
self.jellyfin_threads = []
self.download_threads = []
@ -67,16 +68,16 @@ class Library(threading.Thread):
def __new_queues__(self):
return {
"Movie": Queue.Queue(),
"BoxSet": Queue.Queue(),
"MusicVideo": Queue.Queue(),
"Series": Queue.Queue(),
"Season": Queue.Queue(),
"Episode": Queue.Queue(),
"MusicAlbum": Queue.Queue(),
"MusicArtist": Queue.Queue(),
"AlbumArtist": Queue.Queue(),
"Audio": Queue.Queue(),
"Movie": queue.Queue(),
"BoxSet": queue.Queue(),
"MusicVideo": queue.Queue(),
"Series": queue.Queue(),
"Season": queue.Queue(),
"Episode": queue.Queue(),
"MusicAlbum": queue.Queue(),
"MusicArtist": queue.Queue(),
"AlbumArtist": queue.Queue(),
"Audio": queue.Queue(),
}
def run(self):
@ -271,13 +272,13 @@ class Library(threading.Thread):
def worker_downloads(self):
"""Get items from jellyfin and place them in the appropriate queues."""
for queue in (
for work_queue in (
(self.updated_queue, self.updated_output),
(self.userdata_queue, self.userdata_output),
):
if queue[0].qsize() and len(self.download_threads) < DTHREADS:
if work_queue[0].qsize() and len(self.download_threads) < DTHREADS:
new_thread = GetItemWorker(self.server, queue[0], queue[1])
new_thread = GetItemWorker(self.server, work_queue[0], work_queue[1])
new_thread.start()
LOG.info("-->[ q:download/%s ]", id(new_thread))
self.download_threads.append(new_thread)
@ -722,7 +723,7 @@ class UpdateWorker(threading.Thread):
try:
item = self.queue.get(timeout=1)
except Queue.Empty:
except queue.Empty:
break
try:
@ -801,7 +802,7 @@ class UserDataWorker(threading.Thread):
try:
item = self.queue.get(timeout=1)
except Queue.Empty:
except queue.Empty:
break
try:
@ -852,7 +853,7 @@ class SortWorker(threading.Thread):
try:
item_id = self.queue.get(timeout=1)
except Queue.Empty:
except queue.Empty:
break
try:
@ -918,7 +919,7 @@ class RemovedWorker(threading.Thread):
try:
item = self.queue.get(timeout=1)
except Queue.Empty:
except queue.Empty:
break
if item["Type"] == "Movie":
@ -970,7 +971,7 @@ class NotifyWorker(threading.Thread):
try:
item = self.queue.get(timeout=3)
except Queue.Empty:
except queue.Empty:
break
time = self.music_time if item[0] == "Audio" else self.video_time

View file

@ -7,7 +7,7 @@ import binascii
import json
import threading
from kodi_six import xbmc
import xbmc
from . import connect
from . import player

View file

@ -8,7 +8,10 @@ import sys
import json
from datetime import timedelta
from kodi_six import xbmc, xbmcgui, xbmcplugin, xbmcaddon
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
from ..helper import translate, playutils, api, window, settings, dialog
from ..dialogs import resume

View file

@ -3,8 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
##################################################################################################
from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode
from urllib.parse import urlencode
from .. import downloader as server
from ..database import jellyfin_db, queries as QUEM
@ -240,7 +239,7 @@ class Movies(KodiDb):
else:
obj["Path"] = "plugin://plugin.video.jellyfin/%s/" % obj["LibraryId"]
params = {
"filename": py2_encode(obj["Filename"], "utf-8"),
"filename": obj["Filename"],
"id": obj["Id"],
"dbid": obj["MovieId"],
"mode": "play",

View file

@ -5,9 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import datetime
import re
from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode
from urllib.parse import urlencode
from ..database import jellyfin_db, queries as QUEM
from ..helper import api, stop, validate, jellyfin_item, values, Local, LazyLogger
@ -210,7 +208,7 @@ class MusicVideos(KodiDb):
else:
obj["Path"] = "plugin://plugin.video.jellyfin/%s/" % obj["LibraryId"]
params = {
"filename": py2_encode(obj["Filename"], "utf-8"),
"filename": obj["Filename"],
"id": obj["Id"],
"dbid": obj["MvideoId"],
"mode": "play",

View file

@ -6,9 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import json
import os
from six import iteritems, ensure_text
from ..helper import LazyLogger, get_filesystem_encoding
from ..helper import LazyLogger
##################################################################################################
@ -29,7 +27,7 @@ class Objects(object):
def mapping(self):
"""Load objects mapping."""
file_dir = os.path.dirname(ensure_text(__file__, get_filesystem_encoding()))
file_dir = os.path.dirname(__file__)
with open(os.path.join(file_dir, "obj_map.json")) as infile:
self.objects = json.load(infile)
@ -54,7 +52,7 @@ class Objects(object):
mapping = self.objects[mapping_name]
for key, value in iteritems(mapping):
for key, value in mapping.items():
self.mapped_item[key] = None
params = value.split(",")
@ -151,7 +149,7 @@ class Objects(object):
result = False
for key, value in iteritems(filters):
for key, value in filters.items():
inverse = False

View file

@ -5,9 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import sqlite3
from ntpath import dirname
from six.moves.urllib.parse import urlencode
from kodi_six.utils import py2_encode
from urllib.parse import urlencode
from .. import downloader as server
from ..database import jellyfin_db, queries as QUEM
@ -535,7 +533,7 @@ class TVShows(KodiDb):
obj["SeriesId"],
)
params = {
"filename": py2_encode(obj["Filename"], "utf-8"),
"filename": obj["Filename"],
"id": obj["Id"],
"dbid": obj["EpisodeId"],
"mode": "play",

View file

@ -5,7 +5,8 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import os
from kodi_six import xbmc, xbmcvfs
import xbmc
import xbmcvfs
from .objects.obj import Objects
from .helper import translate, api, window, settings, dialog, event, JSONRPC

View file

@ -5,9 +5,9 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import os
import xml.etree.ElementTree as etree
from urllib.parse import urlencode
from six.moves.urllib.parse import urlencode
from kodi_six import xbmcvfs
import xbmcvfs
from .database import Database, jellyfin_db, get_sync, save_sync
from .helper import translate, api, window, event

View file

@ -11,10 +11,6 @@ dependencies:
version: '2.22.0+matrix.1'
- addon: 'script.module.dateutil'
version: '2.8.1+matrix.1'
- addon: 'script.module.six'
version: '1.14.0+matrix.2'
- addon: 'script.module.kodi-six'
version: '0.1.3+1'
- addon: 'script.module.addon.signals'
version: '0.0.5+matrix.1'
- addon: 'script.module.websocket'

View file

@ -1,5 +1,4 @@
setuptools >= 44.1.1 # Old setuptools causes script.module.addon.signals to fail installing
six >= 1.13
python-dateutil >= 2.8.1
requests >= 2.22
PyYAML >= 6.0
@ -9,7 +8,6 @@ tzdata; platform_system == "Windows"
Kodistubs ~=21.0
git+https://github.com/romanvm/kodi.six
git+https://github.com/ruuk/script.module.addon.signals
pre-commit >= 3.7.1
@ -21,7 +19,6 @@ websocket-client >= 1.6.4
types-requests >= 2.31
types-PyYAML >= 6.0
types-six >= 1.13
types-python-dateutil >= 2.8.1
types-setuptools >= 44.1.1

View file

@ -5,7 +5,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
import threading
from kodi_six import xbmc
import xbmc
from jellyfin_kodi.entrypoint.service import Service
from jellyfin_kodi.helper.utils import settings