관리-도구
편집 파일: converters.cpython-39.opt-1.pyc
a �����)g4����������������������@���s����d�dl�mZmZmZ�eZd�dlZd�dlZd�dlZd�dl m Z �d�dlmZm Z mZmZ�ze�d��dZW�n�ey|���dZY�n0�ed�Zddd�Zdd d�Zer�eZneZdd��Zdd��Zddd�Zddd�ZdS�)�����)�absolute_import�division�print_functionN)�Set)�PY3�binary_type� iteritems� text_type�surrogateescapeTF)NZsurrogate_or_replace�surrogate_or_strict�surrogate_then_replace�utf-8� simplereprc�����������������C���s6��t�|�t�r|�S�|}|tv�r6tr$d}n|dkr2d}nd}t�|�t�r�z|��||�W�S��ty����|dv�r�|��dd�}|�dd�}|�|d��Y�S���Y�n0�|dkr�zt|��}W�n>�t y����zt |��}W�n�t y����td��Y��Y�S�0�Y�n0�n@|d k��r�|�S�|d k�r td�S�|dk�rtd��ntd|���t|||�S�) a� ��Make sure that a string is a byte string :arg obj: An object to make sure is a byte string. In most cases this will be either a text string or a byte string. However, with ``nonstring='simplerepr'``, this can be used as a traceback-free version of ``str(obj)``. :kwarg encoding: The encoding to use to transform from a text string to a byte string. Defaults to using 'utf-8'. :kwarg errors: The error handler to use if the text string is not encodable using the specified encoding. Any valid `codecs error handler <https://docs.python.org/3/library/codecs.html#codec-base-classes>`_ may be specified. There are three additional error strategies specifically aimed at helping people to port code. The first two are: :surrogate_or_strict: Will use ``surrogateescape`` if it is a valid handler, otherwise it will use ``strict`` :surrogate_or_replace: Will use ``surrogateescape`` if it is a valid handler, otherwise it will use ``replace``. Because ``surrogateescape`` was added in Python3 this usually means that Python3 will use ``surrogateescape`` and Python2 will use the fallback error handler. Note that the code checks for ``surrogateescape`` when the module is imported. If you have a backport of ``surrogateescape`` for Python2, be sure to register the error handler prior to importing this module. The last error handler is: :surrogate_then_replace: Will use ``surrogateescape`` if it is a valid handler. If encoding with ``surrogateescape`` would traceback, surrogates are first replaced with a replacement characters and then the string is encoded using ``replace`` (which replaces the rest of the nonencodable bytes). If ``surrogateescape`` is not present it will simply use ``replace``. (Added in Ansible 2.3) This strategy is designed to never traceback when it attempts to encode a string. The default until Ansible-2.2 was ``surrogate_or_replace`` From Ansible-2.3 onwards, the default is ``surrogate_then_replace``. :kwarg nonstring: The strategy to use if a nonstring is specified in ``obj``. Default is 'simplerepr'. Valid values are: :simplerepr: The default. This takes the ``str`` of the object and then returns the bytes version of that string. :empty: Return an empty byte string :passthru: Return the object passed in :strict: Raise a :exc:`TypeError` :returns: Typically this returns a byte string. If a nonstring object is passed in this may be a different type depending on the strategy specified by nonstring. This will never return a text string. .. note:: If passed a byte string, this function does not check that the string is valid in the specified encoding. If it's important that the byte string is in the specified encoding do:: encoded_string = to_bytes(to_text(input_string, 'latin-1'), 'utf-8') .. version_changed:: 2.3 Added the ``surrogate_then_replace`` error handler and made it the default error handler. r ���r����strict�replace)Nr���r ���r������passthru�empty�obj must be a string typez2Invalid value %s for to_bytes' nonstring parameter) � isinstancer����_COMPOSED_ERROR_HANDLERS�HAS_SURROGATEESCAPEr ����encode�UnicodeEncodeError�decode�str�UnicodeError�repr�to_bytes� TypeError)�obj�encoding�errors� nonstringZoriginal_errorsZ return_string�value��r%����O/usr/lib/python3.9/site-packages/ansible/module_utils/common/text/converters.pyr���!���sD����@ r���c�����������������C���s����t�|�t�r|�S�|tv�r2tr d}n|dkr.d}nd}t�|�t�rH|��||�S�|dkr�zt|��}W�q��ty����zt|��}W�n�ty����Y�Y�dS�0�Y�q�0�n6|dkr�|�S�|dkr�dS�|dkr�t d ��nt d |���t |||�S�)a� ��Make sure that a string is a text string :arg obj: An object to make sure is a text string. In most cases this will be either a text string or a byte string. However, with ``nonstring='simplerepr'``, this can be used as a traceback-free version of ``str(obj)``. :kwarg encoding: The encoding to use to transform from a byte string to a text string. Defaults to using 'utf-8'. :kwarg errors: The error handler to use if the byte string is not decodable using the specified encoding. Any valid `codecs error handler <https://docs.python.org/3/library/codecs.html#codec-base-classes>`_ may be specified. We support three additional error strategies specifically aimed at helping people to port code: :surrogate_or_strict: Will use surrogateescape if it is a valid handler, otherwise it will use strict :surrogate_or_replace: Will use surrogateescape if it is a valid handler, otherwise it will use replace. :surrogate_then_replace: Does the same as surrogate_or_replace but `was added for symmetry with the error handlers in :func:`ansible.module_utils._text.to_bytes` (Added in Ansible 2.3) Because surrogateescape was added in Python3 this usually means that Python3 will use `surrogateescape` and Python2 will use the fallback error handler. Note that the code checks for surrogateescape when the module is imported. If you have a backport of `surrogateescape` for python2, be sure to register the error handler prior to importing this module. The default until Ansible-2.2 was `surrogate_or_replace` In Ansible-2.3 this defaults to `surrogate_then_replace` for symmetry with :func:`ansible.module_utils._text.to_bytes` . :kwarg nonstring: The strategy to use if a nonstring is specified in ``obj``. Default is 'simplerepr'. Valid values are: :simplerepr: The default. This takes the ``str`` of the object and then returns the text version of that string. :empty: Return an empty text string :passthru: Return the object passed in :strict: Raise a :exc:`TypeError` :returns: Typically this returns a text string. If a nonstring object is passed in this may be a different type depending on the strategy specified by nonstring. This will never return a byte string. From Ansible-2.3 onwards, the default is `surrogate_then_replace`. .. version_changed:: 2.3 Added the surrogate_then_replace error handler and made it the default error handler. r ���r���r���r���r���r���r���r���r���z2Invalid value %s for to_text's nonstring parameter)r���r ���r���r���r���r���r���r���r���r����to_text)r ���r!���r"���r#���r$���r%���r%���r&���r'�������s4����3 r'���c�����������������C���s:���t�|�t�rt|��S�t�|�tj�r&|����S�tdt|�����d�S�)NzCannot json serialize %s)r���r����list�datetimeZ isoformatr���� to_native)r ���r%���r%���r&����_json_encode_fallback��s ���� r+���c�����������������K���s����dD�]�}zt�j|�f|td�|��W���S��ty|���zt|�|d�}W�n�ty\���Y�Y�qY�n0�t�j|fdti|���Y���S��ty����Y�qY�q0�qtd��d�S�)N)r ���zlatin-1)r!����default)r!���r,���z$Invalid unicode encoding encountered)�json�dumpsr+���r����container_to_text�UnicodeDecodeErrorr���)�data�kwargsr!���Znew_datar%���r%���r&����jsonify��s����r3���r���c��������������������s����t�|�t�rt|����d�S�t�|�t�r>t���fdd�t|��D���S�t�|�t�r\���fdd�|�D��S�t�|�t�r~t���fdd�|�D���S�|�S�dS�)z� Recursively convert dict keys and values to byte str Specialized for json return because this only handles, lists, tuples, and dict container types (the containers that the json module returns) �r!���r"���c�����������������3���s���|�]}t�|����V��qd�S��N��container_to_bytes��.0�or4���r%���r&���� <genexpr>(�������z%container_to_bytes.<locals>.<genexpr>c��������������������s���g�|�]}t�|�����qS�r%���r6���r8���r4���r%���r&���� <listcomp>*��r<���z&container_to_bytes.<locals>.<listcomp>c�����������������3���s���|�]}t�|����V��qd�S�r5���r6���r8���r4���r%���r&���r;���,��r<���N)r���r ���r����dictr���r(����tuple��dr!���r"���r%���r4���r&���r7�����s���� r7���c��������������������s����t�|�t�rt|����d�S�t�|�t�r>t���fdd�t|��D���S�t�|�t�r\���fdd�|�D��S�t�|�t�r~t���fdd�|�D���S�|�S�dS�)z�Recursively convert dict keys and values to text str Specialized for json return because this only handles, lists, tuples, and dict container types (the containers that the json module returns) r4���c�����������������3���s���|�]}t�|����V��qd�S�r5����r/���r8���r4���r%���r&���r;���<��r<���z$container_to_text.<locals>.<genexpr>c��������������������s���g�|�]}t�|�����qS�r%���rB���r8���r4���r%���r&���r=���>��r<���z%container_to_text.<locals>.<listcomp>c�����������������3���s���|�]}t�|����V��qd�S�r5���rB���r8���r4���r%���r&���r;���@��r<���N)r���r���r'���r>���r���r(���r?���r@���r%���r4���r&���r/���1��s���� r/���)r ���Nr���)r ���Nr���)r ���r���)r ���r���)Z __future__r���r���r����typeZ __metaclass__�codecsr)���r-���Z/ansible.module_utils.common._collections_compatr���Zansible.module_utils.sixr���r���r���r ����lookup_errorr����LookupError� frozensetr���r���r'���r*���r+���r3���r7���r/���r%���r%���r%���r&����<module>���s*��� u j