Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253"""The far end of a remote session. pyrepld sends this over ssh stdin, afterthe sh script in pyrepld.REMOTE_SCRIPT has found an interpreter, with`FILES = {...}` put in front: worker.py, tk.py and vendor/, as source.
Nothing is written on that host. vendor/ is served by an import hook frommemory, placed after the normal path so a session's own packages still win,and the sources go into linecache so tracebacks show their lines. Thenworker.py runs as the remote form (--stdio), exactly as it would from disk.
Must stay runnable on python3.6."""import importlib.abcimport importlib.utilimport linecacheimport sys
ROOT = "<pyrepl>"
def _cache(name, src): linecache.cache[name] = (len(src), None, src.splitlines(True), name)
class _Vendor(importlib.abc.MetaPathFinder, importlib.abc.Loader): def find_spec(self, name, path=None, target=None): rel = "vendor/" + name.replace(".", "/") for key, pkg in ((rel + "/__init__.py", True), (rel + ".py", False)): if key in FILES: spec = importlib.util.spec_from_loader(name, self, origin=ROOT + "/" + key, is_package=pkg) spec.has_location = True return spec return None
def create_module(self, spec): return None
def exec_module(self, module): name = module.__spec__.origin src = FILES[name[len(ROOT) + 1:]] _cache(name, src) exec(compile(src, name, "exec"), module.__dict__)
sys.meta_path.append(_Vendor())_name = ROOT + "/worker.py"_cache(_name, FILES["worker.py"])sys.argv = [_name, "--stdio"]exec(compile(FILES["worker.py"], _name, "exec"), {"__name__": "__main__", "__file__": _name, "__builtins__": __builtins__, "PYREPL_FILES": FILES})