
    Vh{2                        d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZ 	  ej                  d       dZ ed      Zdd	Zdd
ZereZneZd Zd ZddZddZy# e$ r dZY /w xY w)    )annotationsN)Set)PY3binary_type	iteritems	text_typesurrogateescapeTF)Nsurrogate_or_replacesurrogate_or_strictsurrogate_then_replacec                R   t        | t              r| S |}|t        v rt        rd}n
|dk(  rd}nd}t        | t              r	 | j                  ||      S |dk(  r	 t        |       }n5|d	k(  r| S |d
k(  rt        d      S |dk(  rt        d      t        d|z        t        |||      S # t        $ r> |dv r8| j                  dd      }|j                  dd      }|j                  |d      cY S  w xY w# t        $ r, 	 t        |       }n# t        $ r t        d      cY cY S w xY wY w xY w)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   utf-8
simplerepr 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	nonstringoriginal_errorsreturn_stringvalues          [/home/dcms/DCMS/lib/python3.12/site-packages/ansible/module_utils/common/text/converters.pyr   r       s_   @ #{#
 O))&F,,FF#y!	::h// L 	$HE 
j	 
	g	|	h	344MPYYZZE8V,,A " 		"BB
 !$

74E F - 4 4Wi H$++Hi@@		   	$$S	 $|#$ 	$sI   B' C1 'AC.,C.1	D&;DD&D D&D  D&%D&c                   t        | t              r| S |t        v rt        rd}n
|dk(  rd}nd}t        | t              r| j                  ||      S |dk(  r	 t        |       }n+|dk(  r| S |dk(  ry|dk(  rt        d	      t        d
|z        t        |||      S # t        $ r  	 t        |       }n# t        $ r Y Y yw xY wY 5w xY w)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.common.text.converters.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.common.text.converters.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'   s        r(   r*   r*      s    f #y!
))&F,,FF#{# zz(F++ L 	HE 
j	 
	g		h	344MPYYZZ5(F++  	S	  	s6   B 	C$B0/C0	B=9C<B==CCc                    t        | t              rt        |       S t        | t        j                        r| j	                         S t        dt        |       z        )NzCannot json serialize %s)r   r   listdatetime	isoformatr    	to_native)r!   s    r(   _json_encode_fallbackr0     sG    #sCy	C**	+}}
.3?
@@    c                    	 t        | d      }t        j                  |fdt
        i|S # t        $ r t        d      w xY w)Nr   )r"   z$Invalid unicode encoding encountereddefault)container_to_textUnicodeDecodeErrorr   jsondumpsr0   )datakwargsnew_datas      r(   jsonifyr;     sO    C$TG< ::hH(=HHH  CABBCs	   + A c                L   t        | t              rt        |       S t        | t              rt        fdt	        |       D              S t        | t
              r| D cg c]  }t        |       c}S t        | t              rt        fd| D              S | S c c}w )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  8   K   | ]  }t        |        y wNcontainer_to_bytes.0or"   r#   s     r(   	<genexpr>z%container_to_bytes.<locals>.<genexpr>  s     R&q(F;R   c              3  8   K   | ]  }t        |        y wr?   r@   rB   s     r(   rE   z%container_to_bytes.<locals>.<genexpr>#  s     H'8V<HrF   )r   r   r   dictr   r,   rA   tupledr"   r#   rD   s    `` r(   rA   rA     s     !YHV<<	At	RYq\RRR	At	ABCA"1h7CC	Au	HaHHH	 D   #B!c                L   t        | t              rt        |       S t        | t              rt        fdt	        |       D              S t        | t
              r| D cg c]  }t        |       c}S t        | t              rt        fd| D              S | S c c}w )zRecursively 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)
    r=   c              3  8   K   | ]  }t        |        y wr?   r4   rB   s     r(   rE   z$container_to_text.<locals>.<genexpr>3  s     Qq%a6:QrF   c              3  8   K   | ]  }t        |        y wr?   rO   rB   s     r(   rE   z$container_to_text.<locals>.<genexpr>7  s     G&q(F;GrF   )r   r   r*   rH   r   r,   r4   rI   rJ   s    `` r(   r4   r4   (  s     ![!q8F;;	At	QIaLQQQ	At	@AB1!!Xv6BB	Au	GQGGG	 CrL   )r   Nr   )r   r   )
__future__r   codecsr-   r6   .ansible.module_utils.six.moves.collections_abcr   ansible.module_utils.sixr   r   r   r   lookup_errorr   LookupError	frozensetr   r   r*   r/   r0   r;   rA   r4    r1   r(   <module>rY      s    #    >  F)*
 % &@ A 
r-jX,T IIAI&c    s   A   A*)A*