diff --git a/plugin/controllers/base.py b/plugin/controllers/base.py
index 1e42b87dc..a3074be88 100644
--- a/plugin/controllers/base.py
+++ b/plugin/controllers/base.py
@@ -22,9 +22,12 @@
from __future__ import print_function
import os
-import imp
import json
import six
+if six.PY3:
+ from importlib.util import spec_from_file_location, module_from_spec
+else:
+ import imp
from twisted.web import server, http, resource
from twisted.web.resource import EncodingResourceWrapper
@@ -117,18 +120,25 @@ def error404(self, request):
request.write(b"
OpenWebifError 404: Not found
The requested page doesn't exist.")
request.finish()
+ def load_source(self, module, pathname):
+ spec = spec_from_file_location(module, pathname)
+ template = module_from_spec(spec)
+ spec.loader.exec_module(template)
+ return template
+
def loadTemplate(self, path, module, args):
- if fileExists(getViewsPath(path + ".py")) or fileExists(getViewsPath(path + ".pyo")) or fileExists(getViewsPath(path + ".pyc")):
- if fileExists(getViewsPath(path + ".pyo")):
- template = imp.load_compiled(module, getViewsPath(path + ".pyo"))
- elif fileExists(getViewsPath(path + ".pyc")):
- template = imp.load_compiled(module, getViewsPath(path + ".pyc"))
- else:
- template = imp.load_source(module, getViewsPath(path + ".py"))
+ template = None
+ if fileExists(getViewsPath(path + ".pyo")):
+ template = self.load_source(module, getViewsPath(path + ".pyo")) if six.PY3 else imp.load_compiled(module, getViewsPath(path + ".pyo"))
+ elif fileExists(getViewsPath(path + ".pyc")):
+ template = self.load_source(module, getViewsPath(path + ".pyc")) if six.PY3 else imp.load_compiled(module, getViewsPath(path + ".pyc"))
+ elif fileExists(getViewsPath(path + ".py")):
+ template = self.load_source(module, getViewsPath(path + ".py")) if six.PY3 else imp.load_source(module, getViewsPath(path + ".py"))
+ if template:
mod = getattr(template, module, None)
if callable(mod):
return str(mod(searchList=args))
- elif fileExists(getViewsPath(path + ".tmpl")):
+ if fileExists(getViewsPath(path + ".tmpl")):
vp = str(getViewsPath(path + ".tmpl"))
return str(Template(file=vp, searchList=[args]))
return None
diff --git a/plugin/httpserver.py b/plugin/httpserver.py
index 4fba811da..c6c503b82 100644
--- a/plugin/httpserver.py
+++ b/plugin/httpserver.py
@@ -38,7 +38,6 @@
from Components.Network import iNetwork
import os
-import imp
import ipaddress
import six
@@ -158,11 +157,6 @@ def buildRootTree(session):
continue
loaded.append(modulename)
- try:
- imp.load_source(modulename, origwebifpath + "/WebChilds/External/" + modulename + ".py")
- except Exception as e:
- # maybe there's only the compiled version
- imp.load_compiled(modulename, origwebifpath + "/WebChilds/External/" + external)
if len(loaded_plugins) > 0:
for plugin in loaded_plugins: