From 1fad214fc04e1159eb45f46c98f2e80cd376d456 Mon Sep 17 00:00:00 2001 From: Roman Miroshnychenko Date: Tue, 9 Jan 2018 15:55:21 +0200 Subject: [PATCH 1/4] Convert code to Python 3-compatible --- addon.xml | 1 + main.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/addon.xml b/addon.xml index 9e0305d..1756f68 100644 --- a/addon.xml +++ b/addon.xml @@ -5,6 +5,7 @@ name="Example Kodi Video Plugin" provider-name="Roman_V_M"> + video diff --git a/main.py b/main.py index e62672f..55e5ca9 100644 --- a/main.py +++ b/main.py @@ -3,10 +3,23 @@ # Author: Roman V. M. # Created on: 28.11.2014 # License: GPL v.3 https://www.gnu.org/copyleft/gpl.html +""" +Example video plugin that is compatible with both Python 2 and 3 +Compatibility features are provided by ``script.module.future`` library addon. +""" + +# Enable unicode strings by default as in Python 3 +from __future__ import unicode_literals +# Monkey-patch standard libary names to enable Python 3-like behavior +from future import standard_library +standard_library.install_aliases() +# The above strings provide compatibility layer for Python 2 +# so the code can work in both versions. +# In Python 3 they do nothing and can be safely removed. +# Normal imports for your addon: import sys -from urllib import urlencode -from urlparse import parse_qsl +from urllib.parse import urlencode, parse_qsl import xbmcgui import xbmcplugin @@ -65,7 +78,6 @@ def get_url(**kwargs): Create a URL for calling the plugin recursively from the given set of keyword arguments. :param kwargs: "argument=value" pairs - :type kwargs: dict :return: plugin call URL :rtype: str """ @@ -86,7 +98,7 @@ def get_categories(): :return: The list of video categories :rtype: types.GeneratorType """ - return VIDEOS.iterkeys() + return VIDEOS.keys() def get_videos(category): From 0ef4b3a6c043328d42c493ecbd22f80bd870ad14 Mon Sep 17 00:00:00 2001 From: Roman Miroshnychenko Date: Tue, 9 Jan 2018 16:04:48 +0200 Subject: [PATCH 2/4] Use future.iterkeys to iterate over dict keys --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 55e5ca9..836cf11 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ from __future__ import unicode_literals # Monkey-patch standard libary names to enable Python 3-like behavior from future import standard_library standard_library.install_aliases() +from future.utils import iterkeys # The above strings provide compatibility layer for Python 2 # so the code can work in both versions. # In Python 3 they do nothing and can be safely removed. @@ -98,7 +99,7 @@ def get_categories(): :return: The list of video categories :rtype: types.GeneratorType """ - return VIDEOS.keys() + return iterkeys(VIDEOS) def get_videos(category): From b6b2c5e1ebf252814f858413cdad6e2b4fb726a8 Mon Sep 17 00:00:00 2001 From: Roman Miroshnychenko Date: Tue, 9 Jan 2018 16:05:26 +0200 Subject: [PATCH 3/4] Version bump 2.4.0 --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 1756f68..5031ef3 100644 --- a/addon.xml +++ b/addon.xml @@ -1,6 +1,6 @@ From 04da3801c2d038cf714f522e36495b11f495d017 Mon Sep 17 00:00:00 2001 From: Roman Miroshnychenko Date: Fri, 3 Apr 2020 12:55:27 +0300 Subject: [PATCH 4/4] Make the code Python 3 only --- .gitignore | 2 ++ addon.xml | 3 +-- main.py | 20 +++----------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 92c2af4..32927aa 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,9 @@ __pycache__/ # Distribution / packaging .Python +.env env/ +.venv/ venv/ venv2/ build/ diff --git a/addon.xml b/addon.xml index 5031ef3..921b040 100644 --- a/addon.xml +++ b/addon.xml @@ -4,8 +4,7 @@ version="2.4.0" name="Example Kodi Video Plugin" provider-name="Roman_V_M"> - - + video diff --git a/main.py b/main.py index 836cf11..ced3dda 100644 --- a/main.py +++ b/main.py @@ -1,24 +1,10 @@ -# -*- coding: utf-8 -*- -# Module: default +# Module: main # Author: Roman V. M. # Created on: 28.11.2014 # License: GPL v.3 https://www.gnu.org/copyleft/gpl.html """ -Example video plugin that is compatible with both Python 2 and 3 - -Compatibility features are provided by ``script.module.future`` library addon. +Example video plugin that is compatible with Kodi 19.x "Matrix" and above """ - -# Enable unicode strings by default as in Python 3 -from __future__ import unicode_literals -# Monkey-patch standard libary names to enable Python 3-like behavior -from future import standard_library -standard_library.install_aliases() -from future.utils import iterkeys -# The above strings provide compatibility layer for Python 2 -# so the code can work in both versions. -# In Python 3 they do nothing and can be safely removed. -# Normal imports for your addon: import sys from urllib.parse import urlencode, parse_qsl import xbmcgui @@ -99,7 +85,7 @@ def get_categories(): :return: The list of video categories :rtype: types.GeneratorType """ - return iterkeys(VIDEOS) + return VIDEOS.keys() def get_videos(category):