a
    .Sic•  ã                   @   s<  d Z ddlZddlZddlZddlZddlm	Z	 zddl
mZ W n eyZ   ddlZY n0 ddd„Zddd„Zd d	d
„Ze	dƒeƒ e	dƒeƒ e	dƒeƒ e	dƒdd„ ƒZe	dƒdd„ ƒZdd„ ZejejfZe	dƒ ed¡ ejejejfZe	dƒ ed¡ ejejfZe	dƒ ed¡ e ej!fZ"e	dƒ ed¡ dS )!a,  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`
é    N)Ú	tf_exportúutf-8c                 C   sT   t  |¡j}t| tƒrt| ƒS t| tjƒr4|  |¡S t| tƒrB| S t	d| f ƒ‚dS )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.
  ú)Expected binary or unicode string, got %rN)
ÚcodecsÚlookupÚnameÚ
isinstanceÚ	bytearrayÚbytesÚ_sixÚ	text_typeÚencodeÚ	TypeError©Zbytes_or_textÚencoding© r   úY/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorflow/python/util/compat.pyÚas_bytes=   s    


ÿr   c                 C   s@   t  |¡j}t| tjƒr| S t| tƒr0|  |¡S td|  ƒ‚dS )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.
  r   N)	r   r   r   r   r   r   r
   Údecoder   r   r   r   r   Úas_textY   s    

r   c                 C   s
   t | |ƒS )N)r   r   r   r   r   Úas_strs   s    r   zcompat.as_textzcompat.as_byteszcompat.as_strzcompat.as_str_anyc                 C   s   t | tƒrt| ƒS t| ƒS dS )zà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`.

  Returns:
    A `str` object.
  N)r   r
   r   Ústr)Úvaluer   r   r   Ú
as_str_any{   s    
r   zcompat.path_to_strc                 C   s   t | dƒrt|  ¡ ƒ} | 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   ©Úpathr   r   r   Úpath_to_strŽ   s    "
r   c                 C   s   t | dƒr|  ¡ } t| ƒS )aq  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   r   r   r   Úpath_to_bytesµ   s    
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)r   )r   )r   )#Ú__doc__ÚnumbersZ_numbersÚnumpyZ_npÚsixr   r   Ú tensorflow.python.util.tf_exportr   Úcollections.abcÚabcÚcollections_abcÚImportErrorÚcollectionsr   r   r   r   r   r   ÚIntegralÚintegerr    Úexport_constantÚ__name__ÚRealÚfloatingr!   ÚComplexÚnumberr"   r
   r   r#   r   r   r   r   Ú<module>   s<   




&

ÿ