
    BVh;                     R   d Z ddlZddlmZ ddlZddlZddl	m
Z
 ddZddZddZ  e
d      e         e
d      e         e
d	      e        e
d
      dd       Z e
d      d        Zd Zej"                  ej$                  fZ e
d      j)                  ed       ej,                  ej$                  ej.                  fZ e
d      j)                  ed       ej2                  ej4                  fZ e
d      j)                  ed       eefZ e
d      j)                  ed       y)aN  Compatibility functions.

The `tf.compat` module contains two sets of compatibility functions.

## Tensorflow 1.x and 2.x APIs

The `compat.v1` and `compat.v2` submodules provide a complete copy of both the
`v1` and `v2` APIs for backwards and forwards compatibility across TensorFlow
versions 1.x and 2.x. See the
[migration guide](https://www.tensorflow.org/guide/migrate) for details.

## Utilities for writing compatible code

Aside from the `compat.v1` and `compat.v2` submodules, `tf.compat` also contains
a set of helper functions for writing code that works in both:

* TensorFlow 1.x and 2.x
* Python 2 and 3


## Type collections

The compatibility module also provides the following aliases for common
sets of python types:

* `bytes_or_text_types`
* `complex_types`
* `integral_types`
* `real_types`

API docstring: tensorflow.compat
    N)	tf_exportc                     t        j                  |      j                  }t        | t              rt        |       S t        | t              r| j                  |      S t        | t
              r| S t        d|       )a}  Converts `bytearray`, `bytes`, or unicode python input types to `bytes`.

  Uses utf-8 encoding for text by default.

  Args:
    bytes_or_text: A `bytearray`, `bytes`, `str`, or `unicode` object.
    encoding: A string indicating the charset for encoding unicode.

  Returns:
    A `bytes` object.

  Raises:
    TypeError: If `bytes_or_text` is not a binary or unicode string.
  z'Expected binary or unicode string, got )	codecslookupname
isinstance	bytearraybytesstrencode	TypeErrorbytes_or_textencodings     M/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/util/compat.pyas_bytesr   9   sm      ]]8$))(y)-%))-'
"% & &    c                     t        j                  |      j                  }t        | t              r| S t        | t
              r| j                  |      S t        d| z        )a  Converts any string-like python input types to unicode.

  Returns the input as a unicode string. Uses utf-8 encoding for text
  by default.

  Args:
    bytes_or_text: A `bytes`, `str`, or `unicode` object.
    encoding: A string indicating the charset for decoding unicode.

  Returns:
    A `unicode` (Python 2) or `str` (Python 3) object.

  Raises:
    TypeError: If `bytes_or_text` is not a binary or unicode string.
  z)Expected binary or unicode string, got %r)r   r   r   r   r   r
   decoder   r   s     r   as_textr   U   sT    " ]]8$))(s#-'))
?-O
PPr   c                     t        | |      S )a  Acts as an alias for the `as_text` function..

  Args:
    bytes_or_text: The input value to be converted. A bytes or unicode object.
    encoding: Optional string. The encoding to use if bytes_or_text is a bytes
      object. Defaults to 'utf-8'.

  Returns:
    A unicode string.

  Raises:
    TypeError: If bytes_or_text is not a bytes or unicode object.
    UnicodeDecodeError: If bytes_or_text is a bytes object and cannot be
                        decoded using the specified encoding.
  )r   r   s     r   as_strr   o   s      
	))r   zcompat.as_textzcompat.as_byteszcompat.as_strzcompat.as_str_anyc                 R    t        | t              rt        | |      S t        |       S )a  Converts input to `str` type.

     Uses `str(value)`, except for `bytes` typed inputs, which are converted
     using `as_str`.

  Args:
    value: A object that can be converted to `str`.
    encoding: Encoding for `bytes` typed inputs.

  Returns:
    A `str` object.
  )r   )r   r
   r   r   )valuer   s     r   
as_str_anyr      s%     u%(++u:r   zcompat.path_to_strc                 P    t        | d      rt        | j                               } | S )a  Converts input which is a `PathLike` object to `str` type.

  Converts from any python constant representation of a `PathLike` object to
  a string. If the input is not a `PathLike` object, simply returns the input.

  Args:
    path: An object that can be converted to path representation.

  Returns:
    A `str` object.

  Usage:
    In case a simplified `str` version of the path is needed from an
    `os.PathLike` object.

  Examples:
  ```python
  $ tf.compat.path_to_str('C:\XYZ\tensorflow\./.././tensorflow')
  'C:\XYZ\tensorflow\./.././tensorflow' # Windows OS
  $ tf.compat.path_to_str(Path('C:\XYZ\tensorflow\./.././tensorflow'))
  'C:\XYZ\tensorflow\..\tensorflow' # Windows OS
  $ tf.compat.path_to_str(Path('./corpus'))
  'corpus' # Linux OS
  $ tf.compat.path_to_str('./.././Corpus')
  './.././Corpus' # Linux OS
  $ tf.compat.path_to_str(Path('./.././Corpus'))
  '../Corpus' # Linux OS
  $ tf.compat.path_to_str(Path('./..////../'))
  '../..' # Linux OS

  ```
  
__fspath__)hasattrr   r   paths    r   path_to_strr!      s%    D T< doo'(D	+r   c                 P    t        | d      r| j                         } t        |       S )ar  Converts input which is a `PathLike` object to `bytes`.

  Converts from any python constant representation of a `PathLike` object
  or `str` to bytes.

  Args:
    path: An object that can be converted to path representation.

  Returns:
    A `bytes` object.

  Usage:
    In case a simplified `bytes` version of the path is needed from an
    `os.PathLike` object.
  r   )r   r   r   r   s    r   path_to_bytesr#      s$      T< ??D	$r   zcompat.integral_typesintegral_typeszcompat.real_types
real_typeszcompat.complex_typescomplex_typeszcompat.bytes_or_text_typesbytes_or_text_types)zutf-8)__doc__r   collections.abcabccollections_abcnumbers_numbersnumpy_np tensorflow.python.util.tf_exportr   r   r   r   r   r!   r#   Integralintegerr$   export_constant__name__Realfloatingr%   Complexnumberr&   r
   r   r'    r   r   <module>r:      sB  B  )   6&8Q4*$ 	
 G $ 	
 X & 	/ 6 "   &  # !#L. ##S[[1 	
! " 2 28=M NmmS[[#,,7
 	
  . .x F!!3::. 	
  ! 1 1(O L cl  	
& ' 7 78MOr   