o
    i er                     @   s  d Z ddl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l
mZ ddlmZ ddlmZ ddlmZ d	ZG d
d deZeddd Zedgddd Zej e_ edgddd Zeddd ZdiddZdd Zedgddd  Zed!d"d# Zed$gdd%d& Zed'd(d) Zed*gdd+d, Zed-d.d/ Zed0did1d2Z ed3gddid4d5Z!e j e!_ ed6gddid7d8Z"ed9did:d;Z#djd=d>Z$ed?gdd@dA Z%edBdCdD Z&edEgddFdG Z'edHdIdJ Z(dKdL Z)edMgddNdO Z*edPdQdR Z+edSdTdU ZedVgddjdWdXZ,edYdkdZd[Z-ed\gdd]d^ Z.ed_d`da Z/dbdc Z0efdddeZ1edfdgdh Z2dS )lz1File IO methods that wrap the C++ FileSystem API.    N)join)errors)_pywrap_file_io)compat)deprecation)	tf_exporti   c                   @   s   e Zd ZdZd2ddZedd Zedd Zd	d
 Zdd Z	dd Z
dd Zdd Zd3ddZedddd4ddZdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 ZdS )5FileIOa	  FileIO class that exposes methods to read / write to / from files.

  The constructor takes the following arguments:
  name: [path-like object](https://docs.python.org/3/glossary.html#term-path-like-object)
    giving the pathname of the file to be opened.
  mode: one of `r`, `w`, `a`, `r+`, `w+`, `a+`. Append `b` for bytes mode.

  Can be used as an iterator to iterate over lines in the file.

  The default buffer size used for the BufferedInputStream used for reading
  the file line by line is 1024 * 512 bytes.
  utf-8c                 C   sb   || _ || _|| _d | _d | _d|v | _|dd}|dvr%td d d|dv | _	|dv | _
d S )Nb )rwar+w+a+z5mode is not 'r' or 'w' or 'a' or 'r+' or 'w+' or 'a+')r   r   r   r   )r   r   r   r   r   )_FileIO__name_FileIO__mode_FileIO__encoding	_read_buf_writable_file_binary_modereplacer   InvalidArgumentError_read_check_passed_write_check_passed)selfnamemodeencoding r    O/var/www/myenv/lib/python3.10/site-packages/tensorflow/python/lib/io/file_io.py__init__0   s   

zFileIO.__init__c                 C      | j S )zReturns the file name.)r   r   r    r    r!   r   >      zFileIO.namec                 C   r#   )z.Returns the mode in which the file was opened.)r   r$   r    r    r!   r   C   r%   zFileIO.modec                 C   s8   | j s| jstd d dtt| jd| _ d S d S )NzFile isn't open for readingi   )	r   r   r   PermissionDeniedErrorr   BufferedInputStreamr   path_to_strr   r$   r    r    r!   _preread_checkH   s   
zFileIO._preread_checkc                 C   s@   | j s| jstd d dtt| jt	| j
| _ d S d S )NzFile isn't open for writing)r   r   r   r&   r   WritableFiler   path_to_bytesr   as_bytesr   r$   r    r    r!   _prewrite_checkP   s   
zFileIO._prewrite_checkc                 C   s&   | j rtj|| jdS tj|| jdS )Nr   )r   r   r,   r   
as_str_any)r   valr    r    r!   _prepare_valueX   s   zFileIO._prepare_valuec                 C   s   t | jjS )zReturns the size of the file.)statr   lengthr$   r    r    r!   size^      zFileIO.sizec                 C   s$   |    | jtj|| jd dS )z@Writes file_content to the file. Appends to the end of the file.r.   N)r-   r   appendr   r,   r   )r   file_contentr    r    r!   writeb   s   zFileIO.writec                 C   s8   |    |dkr|  |   }n|}| | j|S )a=  Returns the contents of a file as a string.

    Starts reading from current position in file.

    Args:
      n: Read `n` bytes if `n != -1`. If `n = -1`, reads to end of file.

    Returns:
      `n` bytes of the file (or whole file) in bytes mode or `n` bytes of the
      string if in string (regular) mode.
    r9   )r)   r4   tellr1   r   read)r   nr3   r    r    r!   r;   h   s
   zFileIO.readNz7position is deprecated in favor of the offset argument.positionr   c                 C   s   |    |du r|du rtd|dur|durtd|dur"|}|dkr'n |dkr2||  7 }n|dkr=||  7 }n
tddd|| j| dS )a>  Seeks to the offset in the file.

    Args:
      offset: The byte count relative to the whence argument.
      whence: Valid values for whence are:
        0: start of the file (default)
        1: relative to the current position of the file
        2: relative to the end of file. `offset` is usually negative.
    Nz seek(): offset argument requiredz:seek(): offset and position may not be set simultaneously.r         z9Invalid whence argument: {}. Valid values are 0, 1, or 2.)	r)   	TypeErrorr:   r4   r   r   formatr   seek)r   offsetwhencer=   r    r    r!   rB   {   s(   zFileIO.seekc                 C   s   |    | | j S )z4Reads the next line, keeping \n. At EOF, returns ''.)r)   r1   r   readliner$   r    r    r!   rE      s   zFileIO.readlinec                 C   s,   |    g }	 |  }|s	 |S || q)z*Returns all lines from the file in a list.)r)   rE   r6   )r   linessr    r    r!   	readlines   s   
zFileIO.readlinesc                 C   s*   | j r|   | j S |   | j S )z)Returns the current position in the file.)r   r)   r   r:   r-   r   r$   r    r    r!   r:      s
   

zFileIO.tellc                 C      | S )"Make usable with "with" statement.r    r$   r    r    r!   	__enter__      zFileIO.__enter__c                 C   s   |    dS )rJ   N)close)r   unused_typeunused_valueunused_tracebackr    r    r!   __exit__   r5   zFileIO.__exit__c                 C   rI   Nr    r$   r    r    r!   __iter__   s   zFileIO.__iter__c                 C   s   |   }|s	t |S rR   )rE   StopIteration)r   retvalr    r    r!   __next__   s   zFileIO.__next__c                 C   s   |   S rR   )rV   r$   r    r    r!   next   s   zFileIO.nextc                 C   s   | j r
| j   dS dS )a  Flushes the Writable file.

    This only ensures that the data has made its way out of the process without
    any guarantees on whether it's written to disk. This means that the
    data would survive an application crash but not necessarily an OS crash.
    N)r   flushr$   r    r    r!   rX      s   zFileIO.flushc                 C   s$   d| _ | jr| j  d| _dS dS )a  Closes the file.

    Should be called for the WritableFile to be flushed.

    In general, if you use the context manager pattern, you don't need to call
    this directly.

    >>> with tf.io.gfile.GFile("/tmp/x", "w") as f:
    ...   f.write("asdf\n")
    ...   f.write("qwer\n")
    >>> # implicit f.close() at the end of the block

    For cloud filesystems, forgetting to call `close()` might result in data
    loss as last write might not have been replicated.
    N)r   r   rM   r$   r    r    r!   rM      s
   

zFileIO.closec                 C   s   dS )zBReturns True as FileIO supports random access ops of seek()/tell()Tr    r$   r    r    r!   seekable   rL   zFileIO.seekable)r	   )r9   )Nr   N)__name__
__module____qualname____doc__r"   propertyr   r   r)   r-   r1   r4   r8   r;   r   deprecated_argsrB   rE   rH   r:   rK   rQ   rS   rV   rW   rX   rM   rY   r    r    r    r!   r   "   s:    



)

r   zio.gfile.existsc                 C   s.   zt t|  W dS  tjy   Y dS w )a  Determines whether a path exists or not.

  >>> with open("/tmp/x", "w") as f:
  ...   f.write("asdf")
  ...
  4
  >>> tf.io.gfile.exists("/tmp/x")
  True

  You can also specify the URI scheme for selecting a different filesystem:

  >>> # for a GCS filesystem path:
  >>> # tf.io.gfile.exists("gs://bucket/file")
  >>> # for a local filesystem:
  >>> with open("/tmp/x", "w") as f:
  ...   f.write("asdf")
  ...
  4
  >>> tf.io.gfile.exists("file:///tmp/x")
  True

  This currently returns `True` for existing directories but don't rely on this
  behavior, especially if you are using cloud filesystems (e.g., GCS, S3,
  Hadoop):

  >>> tf.io.gfile.exists("/tmp")
  True

  Args:
    path: string, a path

  Returns:
    True if the path exists, whether it's a file or a directory.
    False if the path does not exist and there are no filesystem errors.

  Raises:
    errors.OpError: Propagates any errors reported by the FileSystem API.
  FT)r   
FileExistsr   r+   r   NotFoundErrorpathr    r    r!   file_exists_v2   s   (rd   zgfile.Exists)v1c                 C      t | S rR   )rd   filenamer    r    r!   file_exists(  s   ri   zgfile.Removec                 C      t |  dS )zDeletes the file located at 'filename'.

  Args:
    filename: string, a filename

  Raises:
    errors.OpError: Propagates any errors reported by the FileSystem API.  E.g.,
    `NotFoundError` if the file does not exist.
  N)delete_file_v2rg   r    r    r!   delete_file0  s   rl   zio.gfile.removec                 C      t t|  dS )zDeletes the path located at 'path'.

  Args:
    path: string, a path

  Raises:
    errors.OpError: Propagates any errors reported by the FileSystem API.  E.g.,
    `NotFoundError` if the path does not exist.
  N)r   
DeleteFiler   r+   rb   r    r    r!   rk   >  s   rk   Fc                 C   s,   |rt | dd}| S t | dd}| S )ay  Reads the entire contents of a file to a string.

  Args:
    filename: string, path to a file
    binary_mode: whether to open the file in binary mode or not. This changes
      the type of the object returned.

  Returns:
    contents of the file as a string or bytes.

  Raises:
    errors.OpError: Raises variety of errors that are subtypes e.g.
    `NotFoundError` etc.
  rbr   r   )r   r;   )rh   binary_modefr    r    r!   read_file_to_stringL  s
   rs   c                 C   s<   t | dd}|| W d   dS 1 sw   Y  dS )zWrites a string to a given file.

  Args:
    filename: string, path to a file
    file_content: string, contents that need to be written to the file

  Raises:
    errors.OpError: If there are errors during the operation.
  r   rp   N)r   r8   )rh   r7   rr   r    r    r!   write_string_to_fileb  s   
"rt   z
gfile.Globc                 C   rf   )a  Returns a list of files that match the given pattern(s).

  Args:
    filename: string or iterable of strings. The glob pattern(s).

  Returns:
    A list of strings containing filenames that match the given pattern(s).

  Raises:
  *  errors.OpError: If there are filesystem / directory listing errors.
  *  errors.NotFoundError: If pattern to be matched is an invalid directory.
  )get_matching_files_v2rg   r    r    r!   get_matching_filesp  s   rv   zio.gfile.globc                 C   s4   t | tjrdd tt| D S dd | D S )a  Returns a list of files that match the given pattern(s).

  The patterns are defined as strings. Supported patterns are defined
  here. Note that the pattern can be a Python iteratable of string patterns.

  The format definition of the pattern is:

  **pattern**: `{ term }`

  **term**:
    * `'*'`: matches any sequence of non-'/' characters
    * `'?'`: matches a single non-'/' character
    * `'[' [ '^' ] { match-list } ']'`: matches any single
      character (not) on the list
    * `c`: matches character `c`  where `c != '*', '?', '\\', '['`
    * `'\\' c`: matches character `c`

  **character range**:
    * `c`: matches character `c` while `c != '\\', '-', ']'`
    * `'\\' c`: matches character `c`
    * `lo '-' hi`: matches character `c` for `lo <= c <= hi`

  Examples:

  >>> tf.io.gfile.glob("*.py")
  ... # For example, ['__init__.py']

  >>> tf.io.gfile.glob("__init__.??")
  ... # As above

  >>> files = {"*.py"}
  >>> the_iterator = iter(files)
  >>> tf.io.gfile.glob(the_iterator)
  ... # As above

  See the C++ function `GetMatchingPaths` in
  [`core/platform/file_system.h`]
  (../../../core/platform/file_system.h)
  for implementation details.

  Args:
    pattern: string or iterable of strings. The glob pattern(s).

  Returns:
    A list of strings containing filenames that match the given pattern(s).

  Raises:
    errors.OpError: If there are filesystem / directory listing errors.
    errors.NotFoundError: If pattern to be matched is an invalid directory.
  c                 S      g | ]}t |qS r    r   r/   ).0matching_filenamer    r    r!   
<listcomp>  s    z)get_matching_files_v2.<locals>.<listcomp>c                 S   s,   g | ]}t t|D ]}t|qqS r    )r   GetMatchingFilesr   r,   r/   )ry   single_filenamerz   r    r    r!   r{     s    )
isinstancesixstring_typesr   r|   r   r,   )patternr    r    r!   ru     s   4ru   zgfile.MkDirc                 C   rj   )a=  Creates a directory with the name `dirname`.

  Args:
    dirname: string, name of the directory to be created

  Notes: The parent directories need to exist. Use `tf.io.gfile.makedirs`
    instead if there is the possibility that the parent dirs don't exist.

  Raises:
    errors.OpError: If the operation fails.
  N)create_dir_v2dirnamer    r    r!   
create_dir  s   r   zio.gfile.mkdirc                 C   rm   )a@  Creates a directory with the name given by `path`.

  Args:
    path: string, name of the directory to be created

  Notes: The parent directories need to exist. Use `tf.io.gfile.makedirs`
    instead if there is the possibility that the parent dirs don't exist.

  Raises:
    errors.OpError: If the operation fails.
  N)r   	CreateDirr   r+   rb   r    r    r!   r     s   r   zgfile.MakeDirsc                 C   rj   )zCreates a directory and all parent/intermediate directories.

  It succeeds if dirname already exists and is writable.

  Args:
    dirname: string, name of the directory to be created

  Raises:
    errors.OpError: If the operation fails.
  N)recursive_create_dir_v2r   r    r    r!   recursive_create_dir  s   r   zio.gfile.makedirsc                 C   rm   )zCreates a directory and all parent/intermediate directories.

  It succeeds if path already exists and is writable.

  Args:
    path: string, name of the directory to be created

  Raises:
    errors.OpError: If the operation fails.
  N)r   RecursivelyCreateDirr   r+   rb   r    r    r!   r     s   r   zio.gfile.copyc                 C      t t| t|| dS )a  Copies data from `src` to `dst`.

  >>> with open("/tmp/x", "w") as f:
  ...   f.write("asdf")
  ...
  4
  >>> tf.io.gfile.exists("/tmp/x")
  True
  >>> tf.io.gfile.copy("/tmp/x", "/tmp/y")
  >>> tf.io.gfile.exists("/tmp/y")
  True
  >>> tf.io.gfile.remove("/tmp/y")

  You can also specify the URI scheme for selecting a different filesystem:

  >>> with open("/tmp/x", "w") as f:
  ...   f.write("asdf")
  ...
  4
  >>> tf.io.gfile.copy("/tmp/x", "file:///tmp/y")
  >>> tf.io.gfile.exists("/tmp/y")
  True
  >>> tf.io.gfile.remove("/tmp/y")

  Note that you need to always specify a file name, even if moving into a new
  directory. This is because some cloud filesystems don't have the concept of a
  directory.

  >>> with open("/tmp/x", "w") as f:
  ...   f.write("asdf")
  ...
  4
  >>> tf.io.gfile.mkdir("/tmp/new_dir")
  >>> tf.io.gfile.copy("/tmp/x", "/tmp/new_dir/y")
  >>> tf.io.gfile.exists("/tmp/new_dir/y")
  True
  >>> tf.io.gfile.rmtree("/tmp/new_dir")

  If you want to prevent errors if the path already exists, you can use
  `overwrite` argument:

  >>> with open("/tmp/x", "w") as f:
  ...   f.write("asdf")
  ...
  4
  >>> tf.io.gfile.copy("/tmp/x", "file:///tmp/y")
  >>> tf.io.gfile.copy("/tmp/x", "file:///tmp/y", overwrite=True)
  >>> tf.io.gfile.remove("/tmp/y")

  Note that the above will still result in an error if you try to overwrite a
  directory with a file.

  Note that you cannot copy a directory, only file arguments are supported.

  Args:
    src: string, name of the file whose contents need to be copied
    dst: string, name of the file to which to copy to
    overwrite: boolean, if false it's an error for `dst` to be occupied by an
      existing file.

  Raises:
    errors.OpError: If the operation fails.
  N)r   CopyFiler   r+   srcdst	overwriter    r    r!   copy_v2  s   Ar   z
gfile.Copyc                 C   s   t | || d S rR   )r   )oldpathnewpathr   r    r    r!   copyI  s   r   zgfile.Renamec                 C   s   t | || dS )a7  Rename or move a file / directory.

  Args:
    oldname: string, pathname for a file
    newname: string, pathname to which the file needs to be moved
    overwrite: boolean, if false it's an error for `newname` to be occupied by
      an existing file.

  Raises:
    errors.OpError: If the operation fails.
  N)	rename_v2)oldnamenewnamer   r    r    r!   renameQ     r   zio.gfile.renamec                 C   r   )a+  Rename or move a file / directory.

  Args:
    src: string, pathname for a file
    dst: string, pathname to which the file needs to be moved
    overwrite: boolean, if false it's an error for `dst` to be occupied by an
      existing file.

  Raises:
    errors.OpError: If the operation fails.
  N)r   
RenameFiler   r+   r   r    r    r!   r   a  s   r   Tc                 C   s`   t | st| | dS | d t j }t|| z	t|| | W dS  tjy/   t|  w )a!  Writes to `filename` atomically.

  This means that when `filename` appears in the filesystem, it will contain
  all of `contents`. With write_string_to_file, it is possible for the file
  to appear in the filesystem with `contents` only partially written.

  Accomplished by writing to a temp file and then renaming it.

  Args:
    filename: string, pathname for a file
    contents: string, contents that need to be written to the file
    overwrite: boolean, if false it's an error for `filename` to be occupied by
      an existing file.
  z.tmpN)	has_atomic_movert   uuiduuid4hexr   r   OpErrorrl   )rh   contentsr   temp_pathnamer    r    r!   atomic_write_string_to_filer  s   
r   zgfile.DeleteRecursivelyc                 C   rj   )zDeletes everything under dirname recursively.

  Args:
    dirname: string, a path to a directory

  Raises:
    errors.OpError: If the operation fails.
  N)delete_recursively_v2r   r    r    r!   delete_recursively  s   
r   zio.gfile.rmtreec                 C   rm   )zDeletes everything under path recursively.

  Args:
    path: string, a path

  Raises:
    errors.OpError: If the operation fails.
  N)r   DeleteRecursivelyr   r+   rb   r    r    r!   r     s   
r   zgfile.IsDirectoryc                 C   rf   )zReturns whether the path is a directory or not.

  Args:
    dirname: string, path to a potential directory

  Returns:
    True, if the path is a directory; False otherwise
  )is_directory_v2r   r    r    r!   is_directory  s   
r   zio.gfile.isdirc                 C   *   z	t t| W S  tjy   Y dS w )zReturns whether the path is a directory or not.

  Args:
    path: string, path to a potential directory

  Returns:
    True, if the path is a directory; False otherwise
  F)r   IsDirectoryr   r+   r   r   rb   r    r    r!   r     s
   
r   c                 C   r   )au  Checks whether the file system supports atomic moves.

  Returns whether or not the file system of the given path supports the atomic
  move operation for a file or folder.  If atomic move is supported, it is
  recommended to use a temp location for writing and then move to the final
  location.

  Args:
    path: string, path to a file

  Returns:
    True, if the path is on a file system that supports atomic move
    False, if the file system does not support atomic move. In such cases
           we need to be careful about using moves. In some cases it is safer
           not to use temporary locations in this case.
  T)r   HasAtomicMover   r+   r   r   rb   r    r    r!   r     s
   r   zgfile.ListDirectoryc                 C   rf   )aG  Returns a list of entries contained within a directory.

  The list is in arbitrary order. It does not contain the special entries "."
  and "..".

  Args:
    dirname: string, path to a directory

  Returns:
    [filename1, filename2, ... filenameN] as strings

  Raises:
    errors.NotFoundError if directory doesn't exist
  )list_directory_v2r   r    r    r!   list_directory  s   r   zio.gfile.listdirc                 C   s8   t | stjddd| ddd tt| D S )aD  Returns a list of entries contained within a directory.

  The list is in arbitrary order. It does not contain the special entries "."
  and "..".

  Args:
    path: string, path to a directory

  Returns:
    [filename1, filename2, ... filenameN] as strings

  Raises:
    errors.NotFoundError if directory doesn't exist
  NzCould not find directory {})node_defopmessagec                 S   rw   r    rx   )ry   rh   r    r    r!   r{     s    z%list_directory_v2.<locals>.<listcomp>)r   r   ra   rA   r   GetChildrenr   r+   rb   r    r    r!   r     s   r   zio.gfile.joinc                 G   sD   t t | }d|dd v rt| g|R  S tjj| g|R  S )a  Join one or more path components intelligently.

  TensorFlow specific filesystems will be joined
  like a url (using "/" as the path seperator) on all platforms:

  On Windows or Linux/Unix-like:
  >>> tf.io.gfile.join("gcs://folder", "file.py")
  'gcs://folder/file.py'

  >>> tf.io.gfile.join("ram://folder", "file.py")
  'ram://folder/file.py'

  But the native filesystem is handled just like os.path.join:

  >>> path = tf.io.gfile.join("folder", "file.py")
  >>> if os.name == "nt":
  ...   expected = "folder\\file.py"  # Windows
  ... else:
  ...   expected = "folder/file.py"  # Linux/Unix-like
  >>> path == expected
  True

  Args:
    path: string, path to a directory
    paths: string, additional paths to concatenate

  Returns:
    path: the joined path.
  z://r>   N)r   r/   r(   urljoinosrc   r   )rc   pathspath_r    r    r!   r     s    r   z
gfile.Walkc                 C   s
   t | |S )a  Recursive directory tree generator for directories.

  Args:
    top: string, a Directory name
    in_order: bool, Traverse in order if True, post order if False.  Errors that
      happen while listing directories are ignored.

  Yields:
    Each yield is a 3-tuple:  the pathname of a directory, followed by lists of
    all its subdirectories and leaf files. That is, each yield looks like:
    `(dirname, [subdirname, subdirname, ...], [filename, filename, ...])`.
    Each item is a string.
  )walk_v2)topin_orderr    r    r!   walk3  s   
r   zio.gfile.walkc              
   c   s    dd }t t | } zt| }W n! tjy4 } z|r#|| nW Y d}~dS W Y d}~nd}~ww g }g }|D ]}|| |}	t|	rL|| q;|| q;| ||f}
|r\|
V  |D ]}t|| |||dD ]}|V  qjq^|sx|
V  dS dS )a  Recursive directory tree generator for directories.

  Args:
    top: string, a Directory name
    topdown: bool, Traverse pre order if True, post order if False.
    onerror: optional handler for errors. Should be a function, it will be
      called with the error as argument. Rethrowing the error aborts the walk.
      Errors that happen while listing directories are ignored.

  Yields:
    Each yield is a 3-tuple:  the pathname of a directory, followed by lists of
    all its subdirectories and leaf files. That is, each yield looks like:
    `(dirname, [subdirname, subdirname, ...], [filename, filename, ...])`.
    Each item is a string.
  c                 S   s,   |d t jkrdt| d|gS t| |S )Nr   r   )r   sepr   )parentitemr    r    r!   _make_full_pathW  s   
z walk_v2.<locals>._make_full_pathN)onerror)	r   r/   r(   r   r   ra   r   r6   r   )r   topdownr   r   listingerrfilessubdirsr   	full_pathheresubdirsubitemr    r    r!   r   E  s>   




r   z
gfile.Statc                 C   rf   )zReturns file statistics for a given path.

  Args:
    filename: string, path to a file

  Returns:
    FileStatistics struct that contains information about the path

  Raises:
    errors.OpError: If the operation fails.
  )stat_v2rg   r    r    r!   r2     s   r2   zio.gfile.statc                 C   s   t t| S )zReturns file statistics for a given path.

  Args:
    path: string, path to a file

  Returns:
    FileStatistics struct that contains information about the path

  Raises:
    errors.OpError: If the operation fails.
  )r   Statr   r(   rb   r    r    r!   r     r   r   c                 C   s@   t | d }t |d }||krdS t| }t|}||kS )a  Compare two files, returning True if they are the same, False otherwise.

  We check size first and return False quickly if the files are different sizes.
  If they are the same size, we continue to generating a crc for the whole file.

  You might wonder: why not use Python's `filecmp.cmp()` instead? The answer is
  that the builtin library is not robust to the many different filesystems
  TensorFlow runs on, and so we here perform a similar comparison with
  the more robust FileIO.

  Args:
    filename_a: string path to the first file.
    filename_b: string path to the second file.

  Returns:
    True if the files are the same, False otherwise.
  ro   F)r   r4   
file_crc32)
filename_a
filename_bsize_asize_bcrc_acrc_br    r    r!   filecmp  s   r   c                 C   sh   d}t | dd}|j|d}|rt||}|j|d}|sW d   n1 s)w   Y  t|d@ S )a  Get the crc32 of the passed file.

  The crc32 of a file can be used for error checking; two files with the same
  crc32 are considered equivalent. Note that the entire file must be read
  to produce the crc32.

  Args:
    filename: string, path to a file
    block_size: Integer, process the files by reading blocks of `block_size`
      bytes. Use -1 to read the file as once.

  Returns:
    hexadecimal as string, the crc32 of the passed file.
  r   ro   rp   )r<   Nl    )r   r;   binasciicrc32r   )rh   
block_sizecrcrr   chunkr    r    r!   r     s   r   zio.gfile.get_registered_schemesc                   C   s   t  S )a  Returns the currently registered filesystem schemes.

  The `tf.io.gfile` APIs, in addition to accepting traditional filesystem paths,
  also accept file URIs that begin with a scheme. For example, the local
  filesystem path `/tmp/tf` can also be addressed as `file:///tmp/tf`. In this
  case, the scheme is `file`, followed by `://` and then the path, according to
  [URI syntax](https://datatracker.ietf.org/doc/html/rfc3986#section-3).

  This function returns the currently registered schemes that will be recognized
  by `tf.io.gfile` APIs. This includes both built-in schemes and those
  registered by other TensorFlow filesystem implementations, for example those
  provided by [TensorFlow I/O](https://github.com/tensorflow/io).

  The empty string is always included, and represents the "scheme" for regular
  local filesystem paths.

  Returns:
    List of string schemes, e.g. `['', 'file', 'ram']`, in arbitrary order.

  Raises:
    errors.OpError: If the operation fails.
  )r   GetRegisteredSchemesr    r    r    r!   get_registered_schemes  s   r   )F)T)TN)3r]   r   r   	posixpathr   r   r   r   tensorflow.python.frameworkr   tensorflow.python.lib.ior   tensorflow.python.utilr   r    tensorflow.python.util.tf_exportr   _DEFAULT_BLOCK_SIZEobjectr   rd   ri   rl   rk   rs   rt   rv   ru   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r   r   r   r   r    r    r    r!   <module>   s    X

.








D





D












%
9

