mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-30 09:48:55 +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 socket
|
||||
import zlib
|
||||
import imp
|
||||
import importlib
|
||||
import subprocess as ssubprocess
|
||||
import shlex
|
||||
from shlex import quote
|
||||
@ -15,37 +15,9 @@ from sshuttle.helpers import debug2
|
||||
|
||||
|
||||
def readfile(name):
|
||||
tokens = name.split(".")
|
||||
f = None
|
||||
|
||||
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")
|
||||
spec = importlib.util.find_spec(name)
|
||||
source = spec.loader.get_source(spec)
|
||||
return source.encode("UTF8")
|
||||
|
||||
|
||||
def empackage(z, name, data=None):
|
||||
|
Loading…
Reference in New Issue
Block a user