diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 90b5e41a..6a6f387e 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -37,6 +37,7 @@ import jinja2.runtime import ansible.constants as C import ansible.errors import ansible.plugins.connection +import ansible.utils.shlex import mitogen.unix import mitogen.utils @@ -243,7 +244,7 @@ def config_from_play_context(transport, inventory_name, connection): getattr(connection._play_context, 'ssh_common_args', ''), getattr(connection._play_context, 'ssh_extra_args', '') ) - for term in shlex.split(s or '') + for term in ansible.utils.shlex.shlex_split(s or '') ], 'become_exe': connection._play_context.become_exe, 'sudo_args': [ @@ -252,7 +253,7 @@ def config_from_play_context(transport, inventory_name, connection): connection._play_context.sudo_flags, connection._play_context.become_flags ) - for term in shlex.split(s or '') + for term in ansible.utils.shlex.shlex_split(s or '') ], 'mitogen_via': connection.mitogen_via, 'mitogen_kind': connection.mitogen_kind, diff --git a/ansible_mitogen/logging.py b/ansible_mitogen/logging.py index 071ecd10..33d49831 100644 --- a/ansible_mitogen/logging.py +++ b/ansible_mitogen/logging.py @@ -40,7 +40,7 @@ class Handler(logging.Handler): Use Mitogen's log format, but send the result to a Display method. """ def __init__(self, display, normal_method): - super(Handler, self).__init__() + logging.Handler.__init__(self) self.formatter = mitogen.utils.log_get_formatter(usec=True) self.display = display self.normal_method = normal_method diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index 7155aee1..1ae6a907 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -217,10 +217,10 @@ class ModuleUtilsImporter(object): """ def __init__(self, context, module_utils): self._context = context - self._by_fullname = { - fullname: (path, is_pkg) + self._by_fullname = dict( + (fullname, (path, is_pkg)) for fullname, path, is_pkg in module_utils - } + ) self._loaded = set() sys.meta_path.insert(0, self) diff --git a/mitogen/debug.py b/mitogen/debug.py index 312c8d9a..a9a06763 100644 --- a/mitogen/debug.py +++ b/mitogen/debug.py @@ -77,26 +77,25 @@ def get_subclasses(klass): def get_routers(): - kl - return { - _hex(id(router)): router + return dict( + (_hex(id(router)), router) for klass in get_subclasses(mitogen.core.Router) for router in gc.get_referrers(klass) if isinstance(router, mitogen.core.Router) - } + ) def get_router_info(): return { - 'routers': { - id_: { + 'routers': dict( + (id_, { 'id': id_, 'streams': len(set(router._stream_by_id.values())), 'contexts': len(set(router._context_by_id.values())), 'handles': len(router._handle_map), - } + }) for id_, router in get_routers().items() - } + ) } @@ -121,10 +120,10 @@ def get_stream_info(router_id): def format_stacks(): - name_by_id = { - t.ident: t.name + name_by_id = dict( + (t.ident, t.name) for t in threading.enumerate() - } + ) l = ['', ''] for threadId, stack in sys._current_frames().items(): diff --git a/mitogen/parent.py b/mitogen/parent.py index 7e095dea..0ebad519 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -247,7 +247,6 @@ def hybrid_tty_create_child(args): mitogen.core.set_block(childfp) disable_echo(master_fd) disable_echo(slave_fd) - proc = subprocess.Popen( args=args, stdin=childfp, diff --git a/mitogen/utils.py b/mitogen/utils.py index df876ea0..d02c3f9c 100644 --- a/mitogen/utils.py +++ b/mitogen/utils.py @@ -37,6 +37,7 @@ import mitogen.master LOG = logging.getLogger('mitogen') +iteritems = getattr(dict, 'iteritems', dict.items) def disable_site_packages(): @@ -112,7 +113,7 @@ PASSTHROUGH = ( def cast(obj): if isinstance(obj, dict): - return {cast(k): cast(v) for k, v in obj.iteritems()} + return dict((cast(k), cast(v)) for k, v in iteritems(obj)) if isinstance(obj, (list, tuple)): return [cast(v) for v in obj] if isinstance(obj, PASSTHROUGH):