B
    лd                 @   s@  d Z ddlZddlZddlZddlZddlm	Z	 yddl
mZ W n ek
r\   ddlZY nX 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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.
  z)Expected binary or unicode string, got %rN)
codecslookupname
isinstance	bytearraybytes_six	text_typeencode	TypeError)bytes_or_textencoding r   O/var/www/html/venv/lib/python3.7/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.
  z)Expected binary or unicode string, got %rN)	r   r   r   r   r
   r   r	   decoder   )r   r   r   r   r   as_textY   s    

r   c             C   s
   t | |S )N)r   )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| |dS t| S d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   N)r   r	   r   str)valuer   r   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 )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   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   )r   )#__doc__numbersZ_numbersnumpy_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>,   s8   


'

