-
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
Wrappers around Kodi Python API that normalize byte and Unicode string handling
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from .utils import PY2, py2_encode, py2_decode, encode_decode
|
||||
|
||||
__all__ = ['PY2', 'py2_encode', 'py2_decode', 'encode_decode']
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
116
Kodi/Lenovo/addons/script.module.kodi-six/libs/kodi_six/utils.py
Normal file
116
Kodi/Lenovo/addons/script.module.kodi-six/libs/kodi_six/utils.py
Normal file
@@ -0,0 +1,116 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
Utility functions for string conversion depending on Python version
|
||||
"""
|
||||
|
||||
import sys
|
||||
import inspect
|
||||
|
||||
__all__ = [
|
||||
'PY2',
|
||||
'py2_encode',
|
||||
'py2_decode',
|
||||
'encode_decode',
|
||||
'patch_object',
|
||||
'ModuleWrapper',
|
||||
]
|
||||
|
||||
PY2 = sys.version_info[0] == 2 #: ``True`` for Python 2
|
||||
|
||||
|
||||
def py2_encode(s, encoding='utf-8', errors='strict'):
|
||||
"""
|
||||
Encode Python 2 ``unicode`` to ``str``
|
||||
|
||||
In Python 3 the string is not changed.
|
||||
"""
|
||||
if PY2 and isinstance(s, unicode):
|
||||
s = s.encode(encoding, errors)
|
||||
return s
|
||||
|
||||
|
||||
def py2_decode(s, encoding='utf-8', errors='strict'):
|
||||
"""
|
||||
Decode Python 2 ``str`` to ``unicode``
|
||||
|
||||
In Python 3 the string is not changed.
|
||||
"""
|
||||
if PY2 and isinstance(s, str):
|
||||
s = s.decode(encoding, errors)
|
||||
return s
|
||||
|
||||
|
||||
def encode_decode(func):
|
||||
"""
|
||||
A decorator that encodes all unicode function arguments to UTF-8-encoded
|
||||
byte strings and decodes function str return value to unicode.
|
||||
|
||||
This decorator is no-op in Python 3.
|
||||
|
||||
:param func: wrapped function or a method
|
||||
:type func: types.FunctionType or types.MethodType
|
||||
:return: function wrapper
|
||||
:rtype: types.FunctionType
|
||||
"""
|
||||
if PY2:
|
||||
def wrapper(*args, **kwargs):
|
||||
mod_args = tuple(py2_encode(item) for item in args)
|
||||
mod_kwargs = {key: py2_encode(value) for key, value
|
||||
in kwargs.iteritems()}
|
||||
return py2_decode(func(*mod_args, **mod_kwargs),
|
||||
errors='replace')
|
||||
wrapper.__name__ = 'wrapped_func_{0}'.format(func.__name__)
|
||||
return wrapper
|
||||
return func
|
||||
|
||||
|
||||
def _wrap_class(cls):
|
||||
class ClassWrapper(cls):
|
||||
pass
|
||||
ClassWrapper.__name__ = 'wrapped_class_{0}'.format(cls.__name__)
|
||||
return ClassWrapper
|
||||
|
||||
|
||||
def patch_object(obj):
|
||||
"""
|
||||
Applies func:`encode_decode` decorator to an object
|
||||
|
||||
:param obj: object for patching
|
||||
:return: patched object
|
||||
"""
|
||||
if inspect.isbuiltin(obj):
|
||||
obj = encode_decode(obj)
|
||||
elif inspect.isclass(obj):
|
||||
# We cannot patch methods of Kodi classes directly.
|
||||
obj = _wrap_class(obj)
|
||||
for memb_name, member in inspect.getmembers(obj):
|
||||
# Do not patch special methods!
|
||||
if (inspect.ismethoddescriptor(member) and
|
||||
not memb_name.endswith('__')):
|
||||
setattr(obj, memb_name, encode_decode(member))
|
||||
return obj
|
||||
|
||||
|
||||
class ModuleWrapper(object):
|
||||
"""
|
||||
Implements lazy patching of Kodi Python API modules
|
||||
|
||||
This class applies func:`encode_decode` decorator to Kodi API functions
|
||||
and classes on demand when a function or a class is first used.
|
||||
"""
|
||||
def __init__(self, base_module):
|
||||
self._base_module = base_module
|
||||
|
||||
def __getattr__(self, item):
|
||||
if not hasattr(self._base_module, item):
|
||||
raise AttributeError(
|
||||
'Module {0} does not have attribute "{1}"!'.format(
|
||||
self._base_module, item
|
||||
)
|
||||
)
|
||||
obj = getattr(self._base_module, item)
|
||||
obj = patch_object(obj)
|
||||
setattr(self, item, obj)
|
||||
return obj
|
||||
@@ -0,0 +1,17 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
General classes and functions for interacting with Kodi
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys as _sys
|
||||
from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper
|
||||
|
||||
if _PY2:
|
||||
import xbmc as _xbmc
|
||||
_wrapped_xbmc = _ModuleWrapper(_xbmc)
|
||||
_sys.modules[__name__] = _wrapped_xbmc
|
||||
else:
|
||||
from xbmc import *
|
||||
@@ -0,0 +1,17 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
A class for accessing addon properties
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys as _sys
|
||||
from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper
|
||||
|
||||
if _PY2:
|
||||
import xbmcaddon as _xbmcaddon
|
||||
_wrapped_xbmcaddon = _ModuleWrapper(_xbmcaddon)
|
||||
_sys.modules[__name__] = _wrapped_xbmcaddon
|
||||
else:
|
||||
from xbmcaddon import *
|
||||
@@ -0,0 +1,17 @@
|
||||
# coding: utf-8
|
||||
# Created on: 20.01.2019
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
A class for working with DRM
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys as _sys
|
||||
from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper
|
||||
|
||||
if _PY2:
|
||||
import xbmcdrm as _xbmcdrm
|
||||
_wrapped_xbmcdrm = _ModuleWrapper(_xbmcdrm)
|
||||
_sys.modules[__name__] = _wrapped_xbmcdrm
|
||||
else:
|
||||
from xbmcdrm import *
|
||||
@@ -0,0 +1,17 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
Classes and functions for interacting with Kodi GUI
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys as _sys
|
||||
from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper
|
||||
|
||||
if _PY2:
|
||||
import xbmcgui as _xbmcgui
|
||||
_wrapped_xbmcgui = _ModuleWrapper(_xbmcgui)
|
||||
_sys.modules[__name__] = _wrapped_xbmcgui
|
||||
else:
|
||||
from xbmcgui import *
|
||||
@@ -0,0 +1,17 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
Functions to create media contents plugins
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys as _sys
|
||||
from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper
|
||||
|
||||
if _PY2:
|
||||
import xbmcplugin as _xbmcplugin
|
||||
_wrapped_xbmcplugin = _ModuleWrapper(_xbmcplugin)
|
||||
_sys.modules[__name__] = _wrapped_xbmcplugin
|
||||
else:
|
||||
from xbmcplugin import *
|
||||
@@ -0,0 +1,17 @@
|
||||
# coding: utf-8
|
||||
# Created on: 04.01.2018
|
||||
# Author: Roman Miroshnychenko aka Roman V.M. (roman1972@gmail.com)
|
||||
"""
|
||||
Functions and classes to work with files and folders
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys as _sys
|
||||
from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper
|
||||
|
||||
if _PY2:
|
||||
import xbmcvfs as _xbmcvfs
|
||||
_wrapped_xbmcvfs = _ModuleWrapper(_xbmcvfs)
|
||||
_sys.modules[__name__] = _wrapped_xbmcvfs
|
||||
else:
|
||||
from xbmcvfs import *
|
||||
Reference in New Issue
Block a user