From f999b9adbf22fce6c8a0446298748a18d4924dcb Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Tue, 6 Mar 2018 02:51:38 +0000 Subject: [PATCH] Crank zlib.compress() upto 9 SSH command size: 482 bytes (no change) Preamble size: 8946 bytes (down 33) --- mitogen/core.py | 2 +- mitogen/master.py | 3 +-- mitogen/parent.py | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mitogen/core.py b/mitogen/core.py index e78bb0ac..39530454 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -445,7 +445,7 @@ class Importer(object): 'mitogen.core', None, 'mitogen/core.py', - zlib.compress(core_src), + zlib.compress(core_src, 9), [], ) diff --git a/mitogen/master.py b/mitogen/master.py index 7b007385..5201d16d 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -522,13 +522,12 @@ class ModuleResponder(object): if fullname == '__main__': source = self.neutralize_main(source) - compressed = zlib.compress(source) + compressed = zlib.compress(source, 9) related = [ name for name in self._finder.find_related(fullname) if not mitogen.core.is_blacklisted_import(self, name) ] - # 0:fullname 1:pkg_present 2:path 3:compressed 4:related tup = fullname, pkg_present, path, compressed, related self._cache[fullname] = tup diff --git a/mitogen/parent.py b/mitogen/parent.py index 829a0ca7..10ff7dee 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -345,7 +345,7 @@ class Stream(mitogen.core.Stream): source = textwrap.dedent('\n'.join(source.strip().split('\n')[2:])) source = source.replace(' ', '\t') source = source.replace('CONTEXT_NAME', self.remote_name) - encoded = source.encode('zlib').encode('base64').replace('\n', '') + encoded = zlib.compress(source, 9).encode('base64').replace('\n', '') # We can't use bytes.decode() in 3.x since it was restricted to always # return unicode, so codecs.decode() is used instead. In 3.x # codecs.decode() requires a bytes object. Since we must be compatible @@ -372,7 +372,7 @@ class Stream(mitogen.core.Stream): 'blacklist': self._router.get_module_blacklist(), },) - compressed = zlib.compress(minimize_source(source)) + compressed = zlib.compress(minimize_source(source), 9) return str(len(compressed)) + '\n' + compressed create_child = staticmethod(create_child)