Skip to content

Commit

Permalink
remove deprecated ansible.module_utils._text from documentation (ansi…
Browse files Browse the repository at this point in the history
…ble#73211)

According to comment in ansible.module_utils._text it is deprecated and
should not be used. This is now reflected in the documentation.
  • Loading branch information
schurzi committed Apr 20, 2021
1 parent 99a2b5f commit 5e5bfa8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/docsite/rst/dev_guide/developing_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ In the Python example the ``module_util`` in question is called ``qradar`` such
.. code-block:: python
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_text
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six.moves.urllib.parse import urlencode, quote_plus
from ansible.module_utils.six.moves.urllib.error import HTTPError
Expand Down
4 changes: 2 additions & 2 deletions docs/docsite/rst/dev_guide/developing_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ You should return errors encountered during plugin execution by raising ``Ansibl

.. code-block:: python
from ansible.module_utils._text import to_native
from ansible.module_utils.common.text.converters import to_native
try:
cause_an_exception()
Expand All @@ -45,7 +45,7 @@ You must convert any strings returned by your plugin into Python's unicode type.

.. code-block:: python
from ansible.module_utils._text import to_text
from ansible.module_utils.common.text.converters import to_text
result_string = to_text(result_string)
Plugin configuration & documentation standards
Expand Down
10 changes: 5 additions & 5 deletions docs/docsite/rst/dev_guide/developing_python_3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ to yield text but instead do the conversion explicitly ourselves. For example:

.. code-block:: python
from ansible.module_utils._text import to_text
from ansible.module_utils.common.text.converters import to_text
with open('filename-with-utf8-data.txt', 'rb') as my_file:
b_data = my_file.read()
Expand All @@ -136,7 +136,7 @@ Writing to files is the opposite process:

.. code-block:: python
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common.text.converters import to_bytes
with open('filename.txt', 'wb') as my_file:
my_file.write(to_bytes(some_text_string))
Expand All @@ -160,7 +160,7 @@ works on both versions:
import os.path
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common.text.converters import to_bytes
filename = u'/var/tmp/くらとみ.txt'
f = open(to_bytes(filename), 'wb')
Expand Down Expand Up @@ -246,9 +246,9 @@ In ``module_utils`` code:
* Functions that return strings **must** document whether they return strings of the same type as they were given or native strings.

Module-utils functions are therefore often very defensive in nature.
They convert their string parameters into text (using ``ansible.module_utils._text.to_text``)
They convert their string parameters into text (using ``ansible.module_utils.common.text.converters.to_text``)
at the beginning of the function, do their work, and then convert
the return values into the native string type (using ``ansible.module_utils._text.to_native``)
the return values into the native string type (using ``ansible.module_utils.common.text.converters.to_native``)
or back to the string type that their parameters received.

Tips, tricks, and idioms for Python 2/Python 3 compatibility
Expand Down
2 changes: 1 addition & 1 deletion docs/docsite/rst/dev_guide/migrating_roles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ In the Python example the ``module_utils`` is ``helper`` and the :abbr:`FQCN (Fu
.. code-block:: text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_text
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible_collections.ansible_example.community.plugins.module_utils.helper import HelperRequest
Expand Down
4 changes: 2 additions & 2 deletions docs/docsite/rst/dev_guide/testing/sanity/no-basestring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ from ``ansible.module_utils.six`` and then use ``isinstance(s, string_types)``
or ``isinstance(s, (binary_type, text_type))`` instead.

If this is part of code to convert a string to a particular type,
``ansible.module_utils._text`` contains several functions that may be even
better for you: ``to_text``, ``to_bytes``, and ``to_native``.
``ansible.module_utils.common.text.converters`` contains several functions
that may be even better for you: ``to_text``, ``to_bytes``, and ``to_native``.
4 changes: 2 additions & 2 deletions docs/docsite/rst/dev_guide/testing_units_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ variable is set it will be treated as if the input came on ``STDIN`` to the modu

import json
from units.modules.utils import set_module_args
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common.text.converters import to_bytes

def test_already_registered(self):
set_module_args({
Expand Down Expand Up @@ -388,7 +388,7 @@ mock for :meth:`Ansible.get_bin_path`::
from units.compat import unittest
from units.compat.mock import patch
from ansible.module_utils import basic
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common.text.converters import to_bytes
from ansible.modules.namespace import my_module


Expand Down

0 comments on commit 5e5bfa8

Please sign in to comment.