Skip to content

Commit

Permalink
Merge pull request #880 from oddstr13/pr-six-cleanup-1
Browse files Browse the repository at this point in the history
Remove dependency on six
  • Loading branch information
oddstr13 authored Jun 12, 2024
2 parents 6a072cc + 876e940 commit 9cdc027
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 127 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion jellyfin_kodi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

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
Expand Down
3 changes: 2 additions & 1 deletion jellyfin_kodi/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

##################################################################################################

from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon

from . import client
from .database import get_credentials, save_credentials
Expand Down
8 changes: 4 additions & 4 deletions jellyfin_kodi/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions jellyfin_kodi/dialogs/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

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
Expand Down Expand Up @@ -69,7 +69,7 @@ def onAction(self, action):
):

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()
Expand Down
5 changes: 2 additions & 3 deletions jellyfin_kodi/dialogs/loginmanual.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

##################################################################################################

from six import iteritems
from kodi_six import xbmcgui
import xbmcgui

from ..helper import translate, LazyLogger, kodi_version

Expand Down Expand Up @@ -34,7 +33,7 @@ def __init__(self, *args, **kwargs):

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):
Expand Down
3 changes: 2 additions & 1 deletion jellyfin_kodi/dialogs/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

##################################################################################################

from kodi_six import xbmc, xbmcgui
import xbmc
import xbmcgui

from ..helper import LazyLogger

Expand Down
6 changes: 3 additions & 3 deletions jellyfin_kodi/dialogs/serverconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

##################################################################################################

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
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(self, *args, **kwargs):

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):
Expand Down
5 changes: 2 additions & 3 deletions jellyfin_kodi/dialogs/servermanual.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import re

from six import iteritems
from kodi_six import xbmcgui
import xbmcgui

from ..helper import translate
from ..jellyfin.connection_manager import CONNECTION_STATE
Expand Down Expand Up @@ -41,7 +40,7 @@ def __init__(self, *args, **kwargs):

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):
Expand Down
5 changes: 2 additions & 3 deletions jellyfin_kodi/dialogs/usersconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

##################################################################################################

from six import iteritems
from kodi_six import xbmcgui
import xbmcgui

from ..helper import LazyLogger
from ..helper.utils import kodi_version
Expand Down Expand Up @@ -36,7 +35,7 @@ def __init__(self, *args, **kwargs):

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):
Expand Down
4 changes: 2 additions & 2 deletions jellyfin_kodi/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import concurrent.futures
from datetime import date

from six.moves import range, queue as Queue
import queue

import requests

Expand Down Expand Up @@ -308,7 +308,7 @@ def run(self):
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))
Expand Down
3 changes: 2 additions & 1 deletion jellyfin_kodi/entrypoint/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import json
import sys

from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon

from .. import database
from ..dialogs import context
Expand Down
11 changes: 7 additions & 4 deletions jellyfin_kodi/entrypoint/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions jellyfin_kodi/entrypoint/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
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
Expand Down
2 changes: 1 addition & 1 deletion jellyfin_kodi/full_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand Down
11 changes: 3 additions & 8 deletions jellyfin_kodi/helper/loghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
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

##################################################################################################
Expand Down Expand Up @@ -92,9 +92,6 @@ def __init__(
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
Expand All @@ -107,8 +104,6 @@ def formatException(self, exc_info):
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]
Expand Down
3 changes: 2 additions & 1 deletion jellyfin_kodi/helper/playutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from uuid import uuid4

import requests
from kodi_six import xbmc, xbmcvfs
import xbmc
import xbmcvfs

from .. import client
from .utils import translate_path
Expand Down
3 changes: 2 additions & 1 deletion jellyfin_kodi/helper/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

##################################################################################################

from kodi_six import xbmc, xbmcaddon
import xbmc
import xbmcaddon

from . import LazyLogger

Expand Down
21 changes: 11 additions & 10 deletions jellyfin_kodi/helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
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
Expand Down Expand Up @@ -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]
Expand All @@ -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('"', '\\"')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jellyfin_kodi/helper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#################################################################################################

from kodi_six import xbmcgui
import xbmcgui

from . import LazyLogger

Expand Down
3 changes: 2 additions & 1 deletion jellyfin_kodi/helper/xmls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
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
Expand Down
Loading

0 comments on commit 9cdc027

Please sign in to comment.