diff --git a/assets/root/system.py b/assets/root/system.py index f06c4eb8..00248e64 100644 --- a/assets/root/system.py +++ b/assets/root/system.py @@ -1,8 +1,17 @@ import sys import app import dbg +import builtins +import _frozen_importlib as _bootstrap +import _frozen_importlib_external as _bootstrap_external +import marshal +import pack +import __main__ -sys.path.append("lib") +# Keep import paths deterministic for the embedded runtime. +sys.path = [p for p in sys.path if isinstance(p, str)] +if "lib" not in sys.path: + sys.path.append("lib") class TraceFile: def write(self, msg): @@ -38,10 +47,6 @@ sys.stderr = TraceErrorFile() # pack file support (must move to system.py, systemrelease.pyc) # -import marshal -import imp -import pack - class pack_file_iterator(object): def __init__(self, packfile): self.pack_file = packfile @@ -52,7 +57,7 @@ class pack_file_iterator(object): return tmp raise StopIteration -_chr = __builtins__.chr +_chr = builtins.chr class pack_file(object): @@ -67,12 +72,12 @@ class pack_file(object): def __iter__(self): return pack_file_iterator(self) - def read(self, len = None): + def read(self, length = None): if not self.data: return '' - if len: - tmp = self.data[:len] - self.data = self.data[len:] + if length: + tmp = self.data[:length] + self.data = self.data[length:] return tmp else: tmp = self.data @@ -85,57 +90,66 @@ class pack_file(object): def readlines(self): return [x for x in self] -__builtins__.pack_open = pack_open = pack_file +builtins.pack_open = pack_open = pack_file + +old_open = open +def open(filename, mode = 'rb'): + try: + if mode in ('r', 'rb') and pack.Exist(filename): + return pack_file(filename, mode) + except Exception: + pass + return old_open(filename, mode) + +builtins.open = open +builtins.old_open = old_open +builtins.new_open = open _ModuleType = type(sys) -old_import = __import__ -def _process_result(code, fqname): - # did get_code() return an actual module? (rather than a code object) - is_module = isinstance(code, _ModuleType) - - # use the returned module, or create a new one to exec code into - if is_module: - module = code - else: - module = imp.new_module(fqname) - - # insert additional values into the module (before executing the code) - #module.__dict__.update(values) - - # the module is almost ready... make it visible - sys.modules[fqname] = module - - # execute the code within the module's namespace - if not is_module: - exec(code, module.__dict__) - - # fetch from sys.modules instead of returning module directly. - # also make module's __name__ agree with fqname, in case - # the "exec code in module.__dict__" played games on us. - module = sys.modules[fqname] - module.__name__ = fqname - return module - module_do = lambda x:None +currentExecName = "" -def __pack_import(name,globals=None,locals=None,fromlist=None): - if name in sys.modules: - return sys.modules[name] +class custom_import_hook(object): + def _pack_filename(self, name): + filename = name + ".py" + if pack.Exist(filename): + return filename + return None - filename = name + '.py' + def find_spec(self, fullname, path=None, target=None): + filename = self._pack_filename(fullname) + if not filename: + return None + return _bootstrap.spec_from_loader(fullname, self, origin=filename) - if pack.Exist(filename): + def create_module(self, spec): + return None + + def exec_module(self, module): + global currentExecName + name = module.__name__ + filename = self._pack_filename(name) + if not filename: + raise ImportError(name) dbg.Trace('importing from pack %s\\n' % name) + currentExecName = name + execfile(filename, module.__dict__) + module_do(module) - newmodule = _process_result(compile(pack_file(filename,'r').read(),filename,'exec'),name) + def find_module(self, name, path=None): + if self._pack_filename(name): + return self + return None - module_do(newmodule) - return newmodule - #return imp.load_module(name, pack_file(filename,'r'),filename,('.py','r',imp.PY_SOURCE)) - else: - dbg.Trace('importing from lib %s\\n' % name) - return old_import(name,globals,locals,fromlist) + def load_module(self, name): + if name in sys.modules: + return sys.modules[name] + + module = _ModuleType(name) + sys.modules[name] = module + self.exec_module(module) + return sys.modules[name] def splitext(p): root, ext = '', '' @@ -180,12 +194,18 @@ class PythonExecutioner: def __LoadCompiledFile__(kPESelf, sFileName): kFile=pack_open(sFileName) - if kFile.read(4)!=imp.get_magic(): + magic = kFile.read(4) + if isinstance(magic, str): + magic = magic.encode("latin1") + + if magic != _bootstrap_external.MAGIC_NUMBER: raise kFile.read(4) kData=kFile.read() + if isinstance(kData, str): + kData = kData.encode("latin1") return marshal.loads(kData) def execfile(fileName, dict): @@ -196,10 +216,12 @@ def exec_add_module_do(mod): global execfile mod.__dict__['execfile'] = execfile -import builtins -builtins.__import__ = __pack_import module_do = exec_add_module_do +meta_hook = custom_import_hook() +if meta_hook not in sys.meta_path: + sys.meta_path.insert(0, meta_hook) + """ # # PSYCO installation (must move to system.py, systemrelease.pyc) @@ -287,7 +309,10 @@ def RunMainScript(name): dbg.LogBox(msg) app.Abort() -import debugInfo +try: + import debugInfo +except ImportError: + import debuginfo as debugInfo debugInfo.SetDebugMode(__DEBUG__) loginMark = "-cs" diff --git a/assets/root/ui.py b/assets/root/ui.py index 9b5d9fd0..db9bfbb7 100644 --- a/assets/root/ui.py +++ b/assets/root/ui.py @@ -2750,9 +2750,6 @@ class PythonScriptLoader(object): def LoadScriptFile(self, window, FileName): import exception - import exceptions - import os - import errno self.Clear() print(("===== Load Script File : %s" % (FileName))) diff --git a/lib/UserDict.pyc b/lib/UserDict.pyc deleted file mode 100644 index 62e6c410..00000000 Binary files a/lib/UserDict.pyc and /dev/null differ diff --git a/lib/__future__.pyc b/lib/__future__.pyc deleted file mode 100644 index 5da83aea..00000000 Binary files a/lib/__future__.pyc and /dev/null differ diff --git a/lib/_abcoll.pyc b/lib/_abcoll.pyc deleted file mode 100644 index 0ca4c431..00000000 Binary files a/lib/_abcoll.pyc and /dev/null differ diff --git a/lib/_locale.pyc b/lib/_locale.pyc deleted file mode 100644 index 57241431..00000000 Binary files a/lib/_locale.pyc and /dev/null differ diff --git a/lib/_weakrefset.pyc b/lib/_weakrefset.pyc deleted file mode 100644 index 79e2091e..00000000 Binary files a/lib/_weakrefset.pyc and /dev/null differ diff --git a/lib/abc.pyc b/lib/abc.pyc deleted file mode 100644 index 72e560e3..00000000 Binary files a/lib/abc.pyc and /dev/null differ diff --git a/lib/bisect.pyc b/lib/bisect.pyc deleted file mode 100644 index b48d6708..00000000 Binary files a/lib/bisect.pyc and /dev/null differ diff --git a/lib/codecs.pyc b/lib/codecs.pyc deleted file mode 100644 index 74ad79c6..00000000 Binary files a/lib/codecs.pyc and /dev/null differ diff --git a/lib/collections.pyc b/lib/collections.pyc deleted file mode 100644 index 9966d685..00000000 Binary files a/lib/collections.pyc and /dev/null differ diff --git a/lib/copy.pyc b/lib/copy.pyc deleted file mode 100644 index 582d9bed..00000000 Binary files a/lib/copy.pyc and /dev/null differ diff --git a/lib/copy_reg.pyc b/lib/copy_reg.pyc deleted file mode 100644 index 360e8904..00000000 Binary files a/lib/copy_reg.pyc and /dev/null differ diff --git a/lib/encodings/__init__.pyc b/lib/encodings/__init__.pyc deleted file mode 100644 index 064807af..00000000 Binary files a/lib/encodings/__init__.pyc and /dev/null differ diff --git a/lib/encodings/aliases.pyc b/lib/encodings/aliases.pyc deleted file mode 100644 index a751bc90..00000000 Binary files a/lib/encodings/aliases.pyc and /dev/null differ diff --git a/lib/encodings/cp949.pyc b/lib/encodings/cp949.pyc deleted file mode 100644 index 036621be..00000000 Binary files a/lib/encodings/cp949.pyc and /dev/null differ diff --git a/lib/fnmatch.pyc b/lib/fnmatch.pyc deleted file mode 100644 index 54ea6e4a..00000000 Binary files a/lib/fnmatch.pyc and /dev/null differ diff --git a/lib/functools.pyc b/lib/functools.pyc deleted file mode 100644 index a9c6c83a..00000000 Binary files a/lib/functools.pyc and /dev/null differ diff --git a/lib/genericpath.pyc b/lib/genericpath.pyc deleted file mode 100644 index c285197b..00000000 Binary files a/lib/genericpath.pyc and /dev/null differ diff --git a/lib/heapq.pyc b/lib/heapq.pyc deleted file mode 100644 index 5cef988f..00000000 Binary files a/lib/heapq.pyc and /dev/null differ diff --git a/lib/keyword.pyc b/lib/keyword.pyc deleted file mode 100644 index 60cd4cba..00000000 Binary files a/lib/keyword.pyc and /dev/null differ diff --git a/lib/linecache.pyc b/lib/linecache.pyc deleted file mode 100644 index d0535534..00000000 Binary files a/lib/linecache.pyc and /dev/null differ diff --git a/lib/locale.pyc b/lib/locale.pyc deleted file mode 100644 index 57241431..00000000 Binary files a/lib/locale.pyc and /dev/null differ diff --git a/lib/ntpath.pyc b/lib/ntpath.pyc deleted file mode 100644 index 94cac60b..00000000 Binary files a/lib/ntpath.pyc and /dev/null differ diff --git a/lib/os.pyc b/lib/os.pyc deleted file mode 100644 index dc0f923f..00000000 Binary files a/lib/os.pyc and /dev/null differ diff --git a/lib/pyexpat.pyd b/lib/pyexpat.pyd deleted file mode 100644 index 6c6b291a..00000000 Binary files a/lib/pyexpat.pyd and /dev/null differ diff --git a/lib/pyexpat_d.pdb b/lib/pyexpat_d.pdb deleted file mode 100644 index 5872d76b..00000000 Binary files a/lib/pyexpat_d.pdb and /dev/null differ diff --git a/lib/pyexpat_d.pyd b/lib/pyexpat_d.pyd deleted file mode 100644 index c47ea73f..00000000 Binary files a/lib/pyexpat_d.pyd and /dev/null differ diff --git a/lib/re.pyc b/lib/re.pyc deleted file mode 100644 index c83160f2..00000000 Binary files a/lib/re.pyc and /dev/null differ diff --git a/lib/shutil.pyc b/lib/shutil.pyc deleted file mode 100644 index 0d4fc2e7..00000000 Binary files a/lib/shutil.pyc and /dev/null differ diff --git a/lib/site.pyc b/lib/site.pyc deleted file mode 100644 index 7fa02b8c..00000000 Binary files a/lib/site.pyc and /dev/null differ diff --git a/lib/sre_compile.pyc b/lib/sre_compile.pyc deleted file mode 100644 index 536fc685..00000000 Binary files a/lib/sre_compile.pyc and /dev/null differ diff --git a/lib/sre_constants.pyc b/lib/sre_constants.pyc deleted file mode 100644 index d3e7a714..00000000 Binary files a/lib/sre_constants.pyc and /dev/null differ diff --git a/lib/sre_parse.pyc b/lib/sre_parse.pyc deleted file mode 100644 index f3ec144a..00000000 Binary files a/lib/sre_parse.pyc and /dev/null differ diff --git a/lib/stat.pyc b/lib/stat.pyc deleted file mode 100644 index cc59c8b4..00000000 Binary files a/lib/stat.pyc and /dev/null differ diff --git a/lib/string.pyc b/lib/string.pyc deleted file mode 100644 index 47f74516..00000000 Binary files a/lib/string.pyc and /dev/null differ diff --git a/lib/sysconfig.pyc b/lib/sysconfig.pyc deleted file mode 100644 index 81af9bda..00000000 Binary files a/lib/sysconfig.pyc and /dev/null differ diff --git a/lib/traceback.pyc b/lib/traceback.pyc deleted file mode 100644 index 67b83635..00000000 Binary files a/lib/traceback.pyc and /dev/null differ diff --git a/lib/types.pyc b/lib/types.pyc deleted file mode 100644 index 515bde25..00000000 Binary files a/lib/types.pyc and /dev/null differ diff --git a/lib/warnings.pyc b/lib/warnings.pyc deleted file mode 100644 index 302e06e9..00000000 Binary files a/lib/warnings.pyc and /dev/null differ diff --git a/lib/weakref.pyc b/lib/weakref.pyc deleted file mode 100644 index bbfc8a16..00000000 Binary files a/lib/weakref.pyc and /dev/null differ diff --git a/lib/xml/__init__.pyc b/lib/xml/__init__.pyc deleted file mode 100644 index 4b3c03ef..00000000 Binary files a/lib/xml/__init__.pyc and /dev/null differ diff --git a/lib/xml/dom/__init__.pyc b/lib/xml/dom/__init__.pyc deleted file mode 100644 index ce134387..00000000 Binary files a/lib/xml/dom/__init__.pyc and /dev/null differ diff --git a/lib/xml/dom/domreg.pyc b/lib/xml/dom/domreg.pyc deleted file mode 100644 index a46c5bb0..00000000 Binary files a/lib/xml/dom/domreg.pyc and /dev/null differ diff --git a/lib/xml/dom/expatbuilder.pyc b/lib/xml/dom/expatbuilder.pyc deleted file mode 100644 index 990fbad0..00000000 Binary files a/lib/xml/dom/expatbuilder.pyc and /dev/null differ diff --git a/lib/xml/dom/minicompat.pyc b/lib/xml/dom/minicompat.pyc deleted file mode 100644 index bf91fd37..00000000 Binary files a/lib/xml/dom/minicompat.pyc and /dev/null differ diff --git a/lib/xml/dom/minidom.pyc b/lib/xml/dom/minidom.pyc deleted file mode 100644 index 831515f0..00000000 Binary files a/lib/xml/dom/minidom.pyc and /dev/null differ diff --git a/lib/xml/dom/nodefilter.pyc b/lib/xml/dom/nodefilter.pyc deleted file mode 100644 index 470de0b1..00000000 Binary files a/lib/xml/dom/nodefilter.pyc and /dev/null differ diff --git a/lib/xml/dom/xmlbuilder.pyc b/lib/xml/dom/xmlbuilder.pyc deleted file mode 100644 index dff47ae0..00000000 Binary files a/lib/xml/dom/xmlbuilder.pyc and /dev/null differ diff --git a/lib/xml/parsers/__init__.pyc b/lib/xml/parsers/__init__.pyc deleted file mode 100644 index 889ce135..00000000 Binary files a/lib/xml/parsers/__init__.pyc and /dev/null differ diff --git a/lib/xml/parsers/expat.pyc b/lib/xml/parsers/expat.pyc deleted file mode 100644 index 65e2aa16..00000000 Binary files a/lib/xml/parsers/expat.pyc and /dev/null differ