mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-02-19 20:01:01 +01:00
use source loader from importlib
This commit is contained in:
parent
04f2135a1c
commit
1f255704f7
@ -3,7 +3,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import zlib
|
import zlib
|
||||||
import imp
|
import importlib
|
||||||
import subprocess as ssubprocess
|
import subprocess as ssubprocess
|
||||||
import shlex
|
import shlex
|
||||||
from shlex import quote
|
from shlex import quote
|
||||||
@ -15,37 +15,9 @@ from sshuttle.helpers import debug2
|
|||||||
|
|
||||||
|
|
||||||
def readfile(name):
|
def readfile(name):
|
||||||
tokens = name.split(".")
|
spec = importlib.util.find_spec(name)
|
||||||
f = None
|
source = spec.loader.get_source(spec)
|
||||||
|
return source.encode("UTF8")
|
||||||
token = tokens[0]
|
|
||||||
token_name = [token]
|
|
||||||
token_str = ".".join(token_name)
|
|
||||||
|
|
||||||
try:
|
|
||||||
f, pathname, description = imp.find_module(token_str)
|
|
||||||
|
|
||||||
for token in tokens[1:]:
|
|
||||||
module = imp.load_module(token_str, f, pathname, description)
|
|
||||||
if f is not None:
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
token_name.append(token)
|
|
||||||
token_str = ".".join(token_name)
|
|
||||||
|
|
||||||
f, pathname, description = imp.find_module(
|
|
||||||
token, module.__path__)
|
|
||||||
|
|
||||||
if f is not None:
|
|
||||||
contents = f.read()
|
|
||||||
else:
|
|
||||||
contents = ""
|
|
||||||
|
|
||||||
finally:
|
|
||||||
if f is not None:
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
return contents.encode("UTF8")
|
|
||||||
|
|
||||||
|
|
||||||
def empackage(z, name, data=None):
|
def empackage(z, name, data=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user