issue #555: ansible: workaround ancient reload(sys) hack.

This is the most minimal change for what might be relatively minimal
edge case. Alternative is replacing reload(), but let's not do that yet.

Closes #555
pull/564/head
David Wilson 6 years ago
parent 30b8172573
commit 2bd0bbd4df

@ -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:

@ -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>`_,

@ -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

@ -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

@ -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()
Loading…
Cancel
Save