Merge remote-tracking branch 'origin/dmw'

* origin/dmw:
  issue #555: ansible: workaround ancient reload(sys) hack.
This commit is contained in:
David Wilson 2019-03-06 14:28:54 +00:00
commit fda1647ad0
5 changed files with 49 additions and 1 deletions

View File

@ -40,6 +40,7 @@ import atexit
import codecs
import imp
import os
import re
import shlex
import shutil
import sys
@ -806,11 +807,20 @@ class NewStyleRunner(ScriptRunner):
def _setup_args(self):
pass
# issue #555: in old times it was considered good form to reload sys and
# change the default encoding. This hack was removed from Ansible long ago,
# but not before permeating into many third party modules.
PREHISTORIC_HACK_RE = re.compile(
b(r'reload\s*\(\s*sys\s*\)\s*'
r'sys\s*\.\s*setdefaultencoding\([^)]+\)')
)
def _setup_program(self):
self.source = ansible_mitogen.target.get_small_file(
source = ansible_mitogen.target.get_small_file(
context=self.service_context,
path=self.path,
)
self.source = self.PREHISTORIC_HACK_RE.sub(b(''), source)
def _get_code(self):
try:

View File

@ -45,6 +45,9 @@ Fixes
action plug-ins that invoked :func:`_make_tmp_path` repeatedly could trigger
an assertion failure.
* `#555 <https://github.com/dw/mitogen/issues/555>`_: work around an old idiom
that reloaded :mod:`sys` in order to change the interpreter's default encoding.
* `ffae0355 <https://github.com/dw/mitogen/commit/ffae0355>`_: needless
information was removed from the documentation and installation procedure.
@ -78,6 +81,7 @@ Thanks!
Mitogen would not be possible without the support of users. A huge thanks for
bug reports, testing, features and fixes in this release contributed by
`Fabian Arrotin <https://github.com/arrfab>`_,
`Giles Westwood <https://github.com/gilesw>`_,
`Matt Layman <https://github.com/mblayman>`_,
`Percy Grunwald <https://github.com/percygrunwald>`_,
`Petr Enkov <https://github.com/enkov>`_,

View File

@ -12,6 +12,7 @@
- include: custom_python_json_args_module.yml
- include: custom_python_new_style_missing_interpreter.yml
- include: custom_python_new_style_module.yml
- include: custom_python_prehistoric_module.yml
- include: custom_python_want_json_module.yml
- include: custom_script_interpreter.yml
- include: environment_isolation.yml

View File

@ -0,0 +1,10 @@
# issue #555
- name: integration/runner/custom_python_prehistoric_module.yml
hosts: test-targets
any_errors_fatal: true
tasks:
- custom_python_prehistoric_module:
register: out
- assert: that=out.ok

View File

@ -0,0 +1,23 @@
#!/usr/bin/python
# issue #555: I'm a module that cutpastes an old hack.
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import get_module_path
from ansible.module_utils import six
import os
import pwd
import socket
import sys
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def main():
module = AnsibleModule(argument_spec={})
module.exit_json(ok=True)
if __name__ == '__main__':
main()