Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sshuttle/assembler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import zlib
import imp
import types

verbosity = verbosity # noqa: F821 must be a previously defined global
z = zlib.decompressobj()
Expand All @@ -15,7 +15,7 @@
% (name, nbytes))
content = z.decompress(sys.stdin.read(nbytes))

module = imp.new_module(name)
module = types.ModuleType(name)
parents = name.rsplit(".", 1)
if len(parents) == 2:
parent, parent_name = parents
Expand Down
42 changes: 7 additions & 35 deletions sshuttle/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import socket
import zlib
import imp
import importlib
import subprocess as ssubprocess
import shlex
from shlex import quote
Expand All @@ -14,43 +14,15 @@
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")
def get_module_source(name):
spec = importlib.util.find_spec(name)
with open(spec.origin, "rt") as f:
return f.read().encode("utf-8")


def empackage(z, name, data=None):
if not data:
data = readfile(name)
data = get_module_source(name)
content = z.compress(data)
content += z.flush(zlib.Z_SYNC_FLUSH)

Expand Down Expand Up @@ -117,7 +89,7 @@ def connect(ssh_cmd, rhostport, python, stderr, options):
rhost = host

z = zlib.compressobj(1)
content = readfile('sshuttle.assembler')
content = get_module_source('sshuttle.assembler')
optdata = ''.join("%s=%r\n" % (k, v) for (k, v) in list(options.items()))
optdata = optdata.encode("UTF8")
content2 = (empackage(z, 'sshuttle') +
Expand Down