From 2f3ce1e83f8873976eecdcf2821cd0f6ac6c1e81 Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:16:50 +1100 Subject: [PATCH] Move kodion.utils.methods.entity_escape to kodion.comptibility.entity_escape - For Python2 compatibility - Also use correct escape sequence for single quotes - Follow up to e73d7044bca63533566ea97b28e5b399f3c0410b --- .../kodion/compatibility/__init__.py | 28 +++++++++++++++++++ .../youtube_plugin/kodion/utils/__init__.py | 2 -- .../youtube_plugin/kodion/utils/methods.py | 12 -------- .../youtube/helper/stream_info.py | 3 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/resources/lib/youtube_plugin/kodion/compatibility/__init__.py b/resources/lib/youtube_plugin/kodion/compatibility/__init__.py index 8e702ce5e..58c08a8ba 100644 --- a/resources/lib/youtube_plugin/kodion/compatibility/__init__.py +++ b/resources/lib/youtube_plugin/kodion/compatibility/__init__.py @@ -13,6 +13,7 @@ 'byte_string_type', 'cpu_count', 'datetime_infolabel', + 'entity_escape', 'parse_qs', 'parse_qsl', 'quote', @@ -54,12 +55,25 @@ import xbmcplugin import xbmcvfs + xbmc.LOGNOTICE = xbmc.LOGINFO xbmc.LOGSEVERE = xbmc.LOGFATAL string_type = str byte_string_type = bytes to_str = str + + + def entity_escape(text, + entities=str.maketrans({ + '&': '&', + '"': '"', + '<': '<', + '>': '>', + '\'': ''', + })): + return text.translate(entities) + # Compatibility shims for Kodi v18 and Python v2.7 except ImportError: from BaseHTTPServer import BaseHTTPRequestHandler @@ -130,11 +144,25 @@ def _file_closer(*args, **kwargs): string_type = basestring byte_string_type = (bytes, str) + def to_str(value): if isinstance(value, unicode): return value.encode('utf-8') return str(value) + + def entity_escape(text, + entities={ + '&': '&', + '"': '"', + '<': '<', + '>': '>', + '\'': ''', + }): + for key, value in entities.viewitems(): + text = text.replace(key, value) + return text + # Kodi v20+ if hasattr(xbmcgui.ListItem, 'setDateTime'): def datetime_infolabel(datetime_obj, *_args, **_kwargs): diff --git a/resources/lib/youtube_plugin/kodion/utils/__init__.py b/resources/lib/youtube_plugin/kodion/utils/__init__.py index 8820cfd01..659ffb1de 100644 --- a/resources/lib/youtube_plugin/kodion/utils/__init__.py +++ b/resources/lib/youtube_plugin/kodion/utils/__init__.py @@ -13,7 +13,6 @@ from . import datetime_parser from .methods import ( duration_to_seconds, - entity_escape, find_video_id, friendly_number, get_kodi_setting_bool, @@ -38,7 +37,6 @@ 'current_system_version', 'datetime_parser', 'duration_to_seconds', - 'entity_escape', 'find_video_id', 'friendly_number', 'get_kodi_setting_bool', diff --git a/resources/lib/youtube_plugin/kodion/utils/methods.py b/resources/lib/youtube_plugin/kodion/utils/methods.py index 029180cbb..0730c5374 100644 --- a/resources/lib/youtube_plugin/kodion/utils/methods.py +++ b/resources/lib/youtube_plugin/kodion/utils/methods.py @@ -23,7 +23,6 @@ __all__ = ( 'duration_to_seconds', - 'entity_escape', 'find_video_id', 'friendly_number', 'get_kodi_setting_bool', @@ -317,14 +316,3 @@ def wait(timeout=None): def redact_ip(url): return re.sub(r'([?&/])ip([=/])[^?&/]+', r'\g<1>ip\g<2>', url) - - -def entity_escape(input, - entities=str.maketrans({ - '&': '&', - '"': '"', - '<': '<', - '>': '>', - '\'': ''', - })): - return input.translate(entities) diff --git a/resources/lib/youtube_plugin/youtube/helper/stream_info.py b/resources/lib/youtube_plugin/youtube/helper/stream_info.py index 9f6a1f857..408a6353e 100644 --- a/resources/lib/youtube_plugin/youtube/helper/stream_info.py +++ b/resources/lib/youtube_plugin/youtube/helper/stream_info.py @@ -23,6 +23,7 @@ from ..client.request_client import YouTubeRequestClient from ..youtube_exceptions import InvalidJSON, YouTubeException from ...kodion.compatibility import ( + entity_escape, parse_qs, quote, unescape, @@ -35,7 +36,7 @@ ) from ...kodion.constants import PATHS, TEMP_PATH from ...kodion.network import get_connect_address -from ...kodion.utils import entity_escape, make_dirs, redact_ip +from ...kodion.utils import make_dirs, redact_ip class StreamInfo(YouTubeRequestClient):