Skip to content
Draft
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
89 changes: 89 additions & 0 deletions ansible_mitogen/compat/six.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# SPDX-FileCopyrightText: 2010-2024 Benjamin Peterson
# SPDX-FileCopyrightText: 2026 Mitogen authors <https://github.com/mitogen-hq>
# SPDX-License-Identifier: MIT
# Source: https://github.com/benjaminp/six/blob/1.17.0/six.py
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from __future__ import absolute_import

import sys
import types

if sys.version_info >= (3, 0):
exec_ = getattr(__import__('builtins'), 'exec')

string_types = (str,)

def reraise(tp, value, tb=None):
try:
if value is None:
value = tp()
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
finally:
value = None
tb = None

else:
string_types = (basestring,)

def exec_(_code_, _globs_=None, _locs_=None):
"""Execute code in a namespace."""
if _globs_ is None:
frame = sys._getframe(1)
_globs_ = frame.f_globals
if _locs_ is None:
_locs_ = frame.f_locals
del frame
elif _locs_ is None:
_locs_ = _globs_
exec("""exec _code_ in _globs_, _locs_""")

exec_("""def reraise(tp, value, tb=None):
try:
raise tp, value, tb
finally:
tb = None
""")


def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
# This requires a bit of explanation: the basic idea is to make a dummy
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
class metaclass(type):

def __new__(cls, name, this_bases, d):
if sys.version_info[:2] >= (3, 7):
# This version introduced PEP 560 that requires a bit
# of extra care (we mimic what is done by __build_class__).
resolved_bases = types.resolve_bases(bases)
if resolved_bases is not bases:
d['__orig_bases__'] = bases
else:
resolved_bases = bases
return meta(name, resolved_bases, d)

@classmethod
def __prepare__(cls, name, this_bases):
return meta.__prepare__(name, bases)
return type.__new__(metaclass, 'temporary_class', (), {})
7 changes: 6 additions & 1 deletion ansible_mitogen/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@
import os
import pwd
import random
import sys
import traceback

if sys.version_info >= (3, 3):
from shlex import quote as shlex_quote
else:
from pipes import quote as shlex_quote

import ansible
import ansible.plugins.action
import ansible.utils.unsafe_proxy
import ansible.vars.clean

from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible.module_utils.six.moves import shlex_quote

import mitogen.core
import mitogen.select
Expand Down
4 changes: 3 additions & 1 deletion ansible_mitogen/plugins/action/mitogen_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

import os
import base64

from ansible.errors import AnsibleError, AnsibleActionFail, AnsibleActionSkip
from ansible.module_utils.common.text.converters import to_bytes, to_text
from ansible.module_utils.six import string_types
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.plugins.action import ActionBase
from ansible.utils.display import Display
from ansible.utils.hashing import checksum, checksum_s, md5, secure_hash
from ansible.utils.path import makedirs_safe, is_subpath

from ansible_mitogen.compat.six import string_types

display = Display()


Expand Down
6 changes: 5 additions & 1 deletion ansible_mitogen/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import ctypes
import json
import logging
import io
import os
import re
import shlex
Expand All @@ -57,7 +58,10 @@
else:
import imp

from ansible.module_utils.six.moves import shlex_quote
if sys.version_info >= (3, 3):
from shlex import quote as shlex_quote
else:
from pipes import quote as shlex_quote

import mitogen.core
import ansible_mitogen.target # TODO: circular import
Expand Down
3 changes: 1 addition & 2 deletions ansible_mitogen/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@

import ansible.constants

from ansible.module_utils.six import reraise

import mitogen.core
import mitogen.service
import ansible_mitogen.loaders
import ansible_mitogen.module_finder
import ansible_mitogen.target
import ansible_mitogen.utils
import ansible_mitogen.utils.unsafe
from ansible_mitogen.compat.six import reraise


LOG = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
import ansible.constants as C
import ansible.executor.interpreter_discovery
import ansible.utils.unsafe_proxy

from ansible.module_utils.six import with_metaclass
from ansible.module_utils.parsing.convert_bool import boolean

import ansible_mitogen.utils
from ansible_mitogen.compat.six import with_metaclass

import mitogen.core


Expand Down
5 changes: 3 additions & 2 deletions mitogen/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

import logging
import re
import sys

try:
if sys.version_info >= (3, 3):
from shlex import quote as shlex_quote
except ImportError:
else:
from pipes import quote as shlex_quote

import mitogen.core
Expand Down