
    1Vh3                        d Z ddlZddlZddlZddlZddlZddlZddlZ	 ddl	Z
ddlZdZ	 ddlZdZej                   dk  reZddlmZmZ dZi Zd Zd	 Z ej4                  d
       G d d             Z G d d      Z G d d      Z G d d      Z e       Zd Z  ed e              er ed e               G d d      Z!d Z"d Zd Z#d Z$d Z%d!dZ&d Z'd Z(d"d Z)y# e$ r dZY w xY w# e$ r dZY w xY w)#a&  A limited reimplementation of the TensorFlow FileIO API.

The TensorFlow version wraps the C++ FileSystem API.  Here we provide a
pure Python implementation, limited to the features required for
TensorBoard.  This allows running TensorBoard without depending on
TensorFlow for file operations.
    NTF)   r   )compaterrorsi   c                 4    d| v rt        d      |t        | <   y )N:z$Filesystem prefix cannot contain a :)
ValueError_REGISTERED_FILESYSTEMS)prefix
filesystems     [/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/compat/tensorflow_stub/io/gfile.pyregister_filesystemr   B   s     
f}?@@&0F#    c                     t        j                  |       } d}| j                  d      }|dk\  r| d| }t        j	                  |d      }|t        |       }|t        d|z        |S )z4Return the registered filesystem for the given file. ://r   Nz&No recognized filesystem for prefix %s)r   
as_str_anyfindr	   get_get_fsspec_filesystemr   )filenamer
   indexfss       r   get_filesystemr   H   st      *HFMM% Ez&5!	 	$	$VT	2B	z#H-	zAFJKKIr   )frozenc                       e Zd ZU dZeed<   y)StatDatazaData returned from the Stat call.

    Attributes:
      length: Length of the data content.
    lengthN)__name__
__module____qualname____doc__int__annotations__ r   r   r   r   W   s     Kr   r   c                   X    e Zd ZdZd Zd ZddZddZddZd Z	d	 Z
d
 Zd Zd Zd Zy)LocalFileSystemz Provides local fileystem access.c                 f    t         j                  j                  t        j                  |            S (Determines whether a path exists or not.)ospathexistsr   as_bytes)selfr   s     r   r,   zLocalFileSystem.existse   s    ww~~fooh788r   c                 B    t        j                  j                  |g| S )zJoin paths with path delimiter.)r*   r+   joinr.   r+   pathss      r   r0   zLocalFileSystem.joini   s    ww||D)5))r   Nc                    |rdnd}|rdnd}t        |      s-t        j                  dddt        j                  |      z         d}||j                  dd      }t        j                  |||      5 }||j                  |       |j                  |      }	d|j                         i}
|	|
fcddd       S # 1 sw Y   yxY w)  Reads contents of a file to a string.

        Args:
            filename: string, a path
            binary_mode: bool, read as binary if True, otherwise text
            size: int, number of bytes or characters to read, otherwise
                read all the contents of the file (from the continuation
                marker, if present).
            continue_from: An opaque value returned from a prior invocation of
                `read(...)` marking the last read position, so that reading
                may continue from there.  Otherwise read from the beginning.

        Returns:
            A tuple of `(data, continuation_token)` where `data' provides either
            bytes read from the file (if `binary_mode == true`) or the decoded
            string representation thereof (otherwise), and `continuation_token`
            is an opaque value that can be passed to the next invocation of
            `read(...) ' in order to continue from the last read position.
        rbrNutf8Not Found: opaque_offsetencoding)r,   r   NotFoundErrorr   as_textr   ioopenseekreadtell)r.   r   binary_modesizecontinue_frommoder;   offsetfdatacontinuation_tokens              r   rA   zLocalFileSystem.readm   s    ( #t&4Fh&&dMFNN8,DD  $"&&=FWWXth7 	.1!v66$<D #21668!<,-	. 	. 	.s   3:B77C c                 <    | j                  |||rd       yd       y)a  Writes string file contents to a file, overwriting any existing
        contents.

        Args:
            filename: string, a path
            file_content: string, the contents
            binary_mode: bool, write as binary if True, otherwise text
        wbwN_writer.   r   file_contentrC   s       r   writezLocalFileSystem.write        	HlKDISIr   c                 <    | j                  |||rd       yd       yzAppend string file contents to a file.

        Args:
            filename: string, a path
            file_content: string, the contents to append
            binary_mode: bool, write as binary if True, otherwise text
        abaNrN   rP   s       r   appendzLocalFileSystem.append   s     	HlKDISIr   c                     d|v rd nd}t        j                  |||      5 }d|v rt        j                  nt        j                  }|j                   ||             d d d        y # 1 sw Y   y xY wNbr7   r:   )r>   r?   r   r-   r=   rR   )r.   r   rQ   rF   r;   rH   	compatifys          r   rO   zLocalFileSystem._write   s\    $;4FWWXth7 	-1+.$;FNNIGGIl+,	- 	- 	-s   <A&&A/c           	      n   t        |t              rIt        j                  t	        j
                  |            D cg c]  }t	        j                  |       c}S |D cg c]D  }t        j                  t	        j
                  |            D ]  }t	        j                  |       F c}}S c c}w c c}}w )8Returns a list of files that match the given pattern(s).)
isinstancestrpy_globglobr   r-   r   )r.   r   matching_filenamesingle_filenames       r   rb   zLocalFileSystem.glob   s    h$ *1fooh6O)P & !!"34  (0 $)0OOO4*	 & !!"344 s   B,A	B1c                 f    t         j                  j                  t        j                  |            S /Returns whether the path is a directory or not.)r*   r+   isdirr   r-   )r.   dirnames     r   rh   zLocalFileSystem.isdir   s    ww}}V__W566r   c                     | j                  |      st        j                  ddd      t        j                  t        j                  |            }|D cg c]  }t        j                  |       }}|S c c}w )7Returns a list of entries contained within a directory.NzCould not find directory)rh   r   r<   r*   listdirr   r   )r.   ri   entriesitems       r   rl   zLocalFileSystem.listdir   sf    zz'"&&tT3MNN**V..w787>?t6$$T*?? @s   A5c                 2    t        j                  |d       y)<Creates a directory and all parent/intermediate directories.Texist_okN)r*   makedirs)r.   r+   s     r   rs   zLocalFileSystem.makedirs   s    
D4(r   c                     	 t        j                  t        j                  |            j                  }t        |      S # t
        $ r t        j                  ddd      w xY w))Returns file statistics for a given path.NCould not find file)	r*   statr   r-   st_sizeOSErrorr   r<   r   )r.   r   file_lengths      r   rw   zLocalFileSystem.stat   s[    	J''&//(";<DDK $$  	J&&tT3HII	Js	   2? !A FNNF)r   r   r    r!   r,   r0   rA   rR   rX   rO   rb   rh   rl   rs   rw   r$   r   r   r&   r&   b   s?    *9*%.N	JJ-$7)%r   r&   c                   V    e Zd ZdZd Zd Zd Zd ZddZddZ	d	 Z
d
 Zd Zd Zd Zy)S3FileSystemz!Provides filesystem access to S3.c                 p    t         st        d      t        j                  j	                  dd       | _        y )Nz'boto3 must be installed for S3 support.S3_ENDPOINT)boto3ImportErrorr*   environr   _s3_endpointr.   s    r   __init__zS3FileSystem.__init__   s(    GHHJJNN=$?r   c                     t        j                  |      }|j                  d      r|t        d      d }|j	                  d      }|d| }||dz   d }||fS )z.Split an S3-prefixed URL into bucket and path.zs3://N/   )r   r   
startswithlenr   )r.   urlidxbucketr+   s        r   bucket_and_pathzS3FileSystem.bucket_and_path   s`    $>>'"c'ln%CiinTcC!G;t|r   c                     t        j                  d| j                        }| j                  |      \  }}|j	                  ||d      }|j                  d      s|j                  d      ryy)	r)   s3endpoint_urlr   BucketPrefix	DelimiterContentsCommonPrefixesTF)r   clientr   r   list_objectsr   )r.   r   r   r   r+   r6   s         r   r,   zS3FileSystem.exists   sa    d1B1BC++H5vdcJ55&6 7r   c                 ,    dj                  |f|z         S )Join paths with a slash.r   )r0   r1   s      r   r0   zS3FileSystem.join   s    xx%((r   Nc                 n   t        j                  d| j                        }| j                  |      \  }}i }d}	||j	                  dd      }	d}
||	|z   }
|	dk7  s|
dk7  rdj                  |	|
      |d<   	  |j                  ||      j                  di |d	   j                         }d|	t        |      z   i}|rt!        |      |fS |j#                  d      |fS # t        j                  j                  $ r}|j                  d
   d   dv r|Ht        j                  d| j                        }|j                  ||      }|d   }t        ||	|z         }
|	|
k(  rd}nJdj                  |	|
      |d<    |j                  ||      j                  di |d	   j                         }n Y d}~d}~ww xY w)r4   r   r   r   Nbyte_offsetr   zbytes={}-{}RangeBodyErrorCode)416InvalidRanger   KeyContentLengthr   utf-8r$   )r   resourcer   r   r   formatObjectrA   botocore
exceptionsClientErrorresponser   head_objectminr   bytesdecode)r.   r   rC   rD   rE   r   r   r+   argsrG   endpointstreamexcr   objcontent_lengthrJ   s                    r   rA   zS3FileSystem.read   s   ( ^^Dt/@/@A++H5 $"&&}a8F }HQ;(b.)00BDM	0RYYvt,00848@EEGF* ,fs6{.BD&M#566MM'*,>??1 "".. 	||G$V,0GG# #\\$T=N=NOF ,,F,EC%(%9N">6D=AHX% F$1$8$8$JDM8RYYvt488@4@HMMOF!	s   73C F49B0F//F4c                     t        j                  d| j                        }| j                  |      \  }}|rt	        |t
              s t        d      t        j                  |      }|j                  |||       y)Writes string file contents to a file.

        Args:
            filename: string, a path
            file_content: string, the contents
            binary_mode: bool, write as binary if True, otherwise text
        r   r   zFile content type must be bytesr   r   r   N)
r   r   r   r   r_   r   	TypeErrorr   r-   
put_object)r.   r   rQ   rC   r   r   r+   s          r   rR   zS3FileSystem.writeA  sj     d1B1BC++H5lE2 ABB!??<8L|FEr   c                    |j                  d      }|j                  d      }|dk\  rt        dj                  |            |t        |      dz
  k7  rg S |dd }t	        j
                  d| j                  	      }| j                  |      \  }}|j                  d
      }g }|j                  ||      D ]A  }	|	j                  dg       D ]*  }
|
d   t        |      d }|s|j                  ||z          , C |S )r^   *?r   z{} not supported by compat globr   Nr   r   r   )r   r   r   r   )r   NotImplementedErrorr   r   r   r   r   r   get_paginatorpaginater   rX   )r.   r   star_iquest_ir   r   r+   pkeysr6   okeys               r   rb   zS3FileSystem.globS  s
    s#--$a<%188B  S]Q&& ICR=d1B1BC++H5  06$7 	0AUU:r* 0hs4y{+KK3/0	0
 r   c                    t        j                  d| j                        }| j                  |      \  }}|j	                  d      s|dz  }|j                  ||d      }|j                  d      s|j                  d      ryy)	rg   r   r   r   r   r   r   TF)r   r   r   r   endswithr   r   )r.   ri   r   r   r+   r6   s         r   rh   zS3FileSystem.isdiro  sv    d1B1BC++G4}}S!CKDvdcJ55&6 7r   c                   	 t        j                  d| j                        }| j                  |      \  }	|j	                  d      }	j                  d      s	dz  	g }|j                  |	d      D ]h  }|j                  	fd|j                  dg       D               |j                  dg       D ]'  }|d	   t        	      d
 }|s|j                  |       ) j |S )rk   r   r   r   r   r   c              3   @   K   | ]  }|d    t              d   yw)r   r   N)r   ).0r   r+   s     r   	<genexpr>z'S3FileSystem.listdir.<locals>.<genexpr>  s%      01(CI+s   r   r   r   N)r   r   r   r   r   r   r   extendr   r   rX   )
r.   ri   r   r   r   r   r6   r   r   r+   s
            @r   rl   zS3FileSystem.listdirz  s    d1B1BC++G4  0}}S!CKD6$#F 	%AKK 56UU;KR5P  UU:r* %hs4y{+KK$%		% r   c                     | j                  |      s`t        j                  d| j                        }| j	                  |      \  }}|j                  d      s|dz  }|j                  d||       yy)rp   r   r   r   r   r   N)r,   r   r   r   r   r   r   )r.   ri   r   r   r+   s        r   rs   zS3FileSystem.makedirs  sg    {{7#\\$T5F5FGF//8LFD==%2f$? $r   c                 T   t        j                  d| j                        }| j                  |      \  }}	 |j	                  ||      }t        |d         S # t        j                  j                  $ r2}|j                  d   d   dk(  rt        j                  ddd	       d}~ww xY w)
ru   r   r   r   r   r   r   404Nrv   )r   r   r   r   r   r   r   r   r   r   r   r<   )r.   r   r   r   r+   r   r   s          r   rw   zS3FileSystem.stat  s     d1B1BC++H5	$$F$=CC011"".. 	||G$V,5**47LMM		s    A B'5-B""B'r{   r|   )r   r   r    r!   r   r   r,   r0   rA   rR   rb   rh   rl   rs   rw   r$   r   r   r~   r~      sB    +@
)C@JF$8	$@r   r~   c                       e Zd ZdZdZdZd Zd Zd Zed        Z	d Z
ed	        Zedd       Zedd       Zedd       Zd Zd Zed        Zed        Zed        Zed        Zed        Zy
)FSSpecFileSystema  Provides filesystem access via fsspec.

    The current gfile interface doesn't map perfectly to the fsspec interface
    leading to some notable inefficiencies.

    * Reads and writes to files cause the file to be reopened each time which
      can cause a performance hit when accessing local file systems.
    * walk doesn't use the native fsspec walk function so performance may be
      slower.

    See https://github.com/tensorflow/tensorboard/issues/5286 for more info on
    limitations.
    r   z::c                     |j                  | j                        }|d d D ]6  }| j                  |v st        j                  d d dj                  |             y )Nr   zFfsspec URL must only have paths in the last chained filesystem, got {})splitCHAIN_SEPARATOR	SEPARATORr   InvalidArgumentErrorr   )r.   r+   partsparts       r   _validate_pathzFSSpecFileSystem._validate_path  sa    

4//0#2J 	D~~%11\cc 	r   c                       fd}|S )Nc                     	  | g|i |S # t         $ r%}t        j                  d d t        |            d }~ww xY wN)FileNotFoundErrorr   r<   r`   )r.   r   kwargsefuncs       r   func_wrapperz8FSSpecFileSystem._translate_errors.<locals>.func_wrapper  sF    ?D242622$ ?**4s1v>>?s    	= 8=r$   )r   r   s   ` r   _translate_errorsz"FSSpecFileSystem._translate_errors  s    	? r   c                     t        |t              r|j                  d      }| j                  |       t        j
                  j                  |      \  }}||fS )Nr   )r_   r   r   r   fsspeccore	url_to_fsr.   r   r   r+   s       r   _fs_pathzFSSpecFileSystem._fs_path  sI    h&w/HH%;;((2D4xr   c                 L    | j                  |      \  }}|j                  |      S r(   )r   r,   r   s       r   r,   zFSSpecFileSystem.exists  s$     ==*Dyyr   c                     g }|D ]R  }|j                  |      rg }|r*|d   r%|d   j                  |      s|j                  |       |j                  |       T dj                  |      S )zA
        _join joins the paths with the given separator.
        r   r   )r   r   rX   r0   )r.   sepr2   resultr   s        r   _joinzFSSpecFileSystem._join  sk      	 Ds#&*VBZ-@-@-Ec"MM$	  wwvr   c                 H   | j                  |       |j                  | j                        \  }}}||z   }t        j                  j                  |      \  }}t        j                  |      }|r||| j                  z   z  }|| j                  |j                  |f|z         z   S )r   )
r   
rpartitionr   r   r   split_protocolget_filesystem_classr   r   r   )	r.   r+   r2   beforer   	last_pathchain_prefixprotocolr   s	            r   r0   zFSSpecFileSystem.join  s     	D!!%1E1E!FY|33I>$((2Ht~~55Ldjj4'E/CCCr   Nc                 2   | j                  |      \  }}|rdnd}|rdnd}t        |      s-t        j                  dddt	        j
                  |      z         |j                  |||      5 }	|[|	j                         s&t        j                  dddj                  |            |j                  dd      }
|
|	j                  |
       |	j                  |      }|	j                         rd|	j                         ini }||fcddd       S # 1 sw Y   yxY w)	r4   r5   r6   Nr7   r8   r:   z{} is not seekabler9   )r   r,   r   r<   r   r=   r?   seekabler   r   r   r@   rA   rB   )r.   r   rC   rD   rE   r   r+   rF   r;   rH   rG   rI   rJ   s                r   rA   zFSSpecFileSystem.read  s   * ==*D"t&4Fh&&dMFNN8,DD  WWT4(W3 	.q(zz| 55,33H= 
 '**?DA%FF6N66$<D
 01zz|!&&(+  ,-'	. 	. 	.s   -BDDc                 <    | j                  |||rd       yd       y)r   rL   rM   NrN   rP   s       r   rR   zFSSpecFileSystem.write&  rS   r   c                 <    | j                  |||rd       yd       yrU   rN   rP   s       r   rX   zFSSpecFileSystem.append1  rS   r   c                    | j                  |      \  }}d|v rd nd}|j                  |||      5 }d|v rt        j                  nt        j                  }|j                   ||             d d d        y # 1 sw Y   y xY wrZ   )r   r?   r   r-   r=   rR   )	r.   r   rQ   rF   r   r+   r;   rH   r\   s	            r   rO   zFSSpecFileSystem._write<  sp    ==*D$;4FWWT4(W3 	-q+.$;FNNIGGIl+,	- 	- 	-s   <A66A?c                     |j                  | j                        \  }}}|j                  | j                        \  }}}||z   |z   |z   S r   )r   r   r   )r.   r   r   	chain_sepr   r   r   _s           r   _get_chain_protocol_prefixz+FSSpecFileSystem._get_chain_protocol_prefixC  sT    -5-@-@  .
*i %//?#qi'(2S88r   c                 X   t        |t              r|j                  d      }| j                  |      \  }}|j	                  |      }| j
                  |vr| j                  |vr|S | j                  |      }|D cg c]%  }| j
                  |v s| j                  |v r|n||z   ' c}S c c}w )r^   r   )r_   r   r   r   rb   r   r   r  )r.   r   r   r+   filesr
   files          r   rb   zFSSpecFileSystem.globJ  s     h&w/H==*D NN(*$$H4L00: 
  NNd*d.B.Bd.J d]#
 	
 
s   :*B'c                 L    | j                  |      \  }}|j                  |      S rf   )r   rh   r.   ri   r   r+   s       r   rh   zFSSpecFileSystem.isdire  s$     ==)Dxx~r   c                     | j                  |      \  }}|j                  |d      }|D cg c]!  }t        j                  j	                  |      # }}|S c c}w )rk   F)detail)r   rl   r*   r+   basename)r.   ri   r   r+   r  fnames         r   rl   zFSSpecFileSystem.listdirk  sT     ==)D

4
.6;<U!!%(<< =s   &Ac                 P    | j                  |      \  }}|j                  |d      S )rp   Trq   )r   rs   r
  s       r   rs   zFSSpecFileSystem.makedirss  s)     ==)D{{4${//r   c                 ^    | j                  |      \  }}t        |j                  |            S )ru   )r   r   rD   r   s       r   rw   zFSSpecFileSystem.staty  s)     ==*D&&r   r{   r|   )r   r   r    r!   r   r   r   r   r   r,   r   r0   rA   rR   rX   rO   r  rb   rh   rl   rs   rw   r$   r   r   r   r     s     IO
  
 
D 
D /. /.b J J J J-9 
 
4  
   0 0
 ' 'r   r   c                     t         sy| j                  t        j                        d   }|j                  t        j                        d   }t        j                  |      rt        S y)z
    _get_fsspec_filesystem checks if the provided protocol is known to fsspec
    and if so returns the filesystem wrapper for it.
    Nr   )FSSPEC_ENABLED	partitionr   r   r   r   r   _FSSPEC_FILESYSTEM)r   segmentr   s      r   r   r     sY    
   !1!A!AB1EG  !1!;!;<Q?H""8,!!r   r   r   c                   P    e Zd Zd Zd Zd Zd Zd ZddZd Z	d	 Z
d
 Zd Zd Zy)GFilec                 l   |dvrt        dj                  |            t        j                  |      | _        t        | j                        | _        t        | j                  d      | _        d | _	        t        | _        d| _        d | _        d | _        d| _        d|v | _        d|v | _        d| _        y )N)r6   r5   brrM   rL   bwz%mode {} not supported by compat GFilerX   r   Fr[   rM   )r   r   r   r-   r   r   r   hasattrfs_supports_appendbuff_DEFAULT_BLOCK_SIZEbuff_chunk_sizebuff_offsetrJ   
write_tempwrite_startedrC   
write_modeclosed)r.   r   rF   s      r   r   zGFile.__init__  s    99%7>>tD  1 /")$''8"<	  3"&"$;+r   c                     | S r   r$   r   s    r   	__enter__zGFile.__enter__      r   c                 N    | j                          d | _        d| _        d | _        y )Nr   )closer  r   rJ   )r.   r   s     r   __exit__zGFile.__exit__  s"    

	"&r   c                     | S r   r$   r   s    r   __iter__zGFile.__iter__  r'  r   c                     | j                   }t        t        | j                        |      |z
  }| xj                   |z  c_         | j                  |||z    S r   )r   r   r   r  )r.   new_buff_offsetold_buff_offset	read_sizes       r   _read_buffer_to_offsetzGFile._read_buffer_to_offset  sM    **DII8?J	I%yy?Y+FGGr   Nc                    | j                   rt        j                  ddd      d}| j                  rt	        | j                        | j
                  kD  re|?| j                  | j
                  |z         }t	        |      |k(  r|S |}|t	        |      z  }n$| j                  t	        | j                              }|t        | j                  |      nd}| j                  j                  | j                  | j                  || j                        \  | _        | _        d| _        || j                  |      }n$| j                  t	        | j                              }|r||z   }|S |}|S )a	  Reads contents of file to a string.

        Args:
            n: int, number of bytes or characters to read, otherwise
                read all the contents of the file

        Returns:
            Subset of the contents of the file as a string or bytes.
        NzFile not opened in read moder   )r#  r   PermissionDeniedErrorr  r   r   r1  maxr  r   rA   r   rC   rJ   )r.   nr   chunkr0  s        r   rA   z
GFile.read  sK    ??..d:  99TYY$*:*::}33D4D4Dq4HIu:? LSZ 44S^D 56MC,,a0t	/3ww||MM4++Y8O8O0
,D+  =//2E //DII?E#)% 05r   c                    | j                   st        j                  ddd      | j                  rt        j                  ddd      | j
                  rw| j                  s9| j                  j                  | j                  || j                         d| _        y| j                  j                  | j                  || j                         y| j                  *| j                  rdnd}t        j                  |      | _        | j                  rt        j                   nt        j"                  }| j                  j                   ||             y)zWrites string file contents to file, clearing contents of the file
        on first write and then appending on subsequent calls.

        Args:
            file_content: string, the contents
        NzFile not opened in write modeFile already closedTzw+bzw+)r#  r   r3  r$  FailedPreconditionErrorr  r"  r   rR   r   rC   rX   r!  tempfileTemporaryFiler   r-   r=   )r.   rQ   rF   r\   s       r   rR   zGFile.write  s     ..d;  ;;00d1  ""%%dmm\4;K;KL%)" t}}lD<L<LM & $ 0 0ud"*"8"8">+/+;+;IOO!!)L"9:r   c                 *   d }	 | j                   s?| j                  d      }|r|d   dk(  s| j                   s|S | j                   st               | j                   j                  d| j                        }|dk7  r.| j                  |dz   | j                  z
        }|r||z   }|S |}|S | j                  t        | j                         dz   | j                  z
        }|r||z   n|}|r|d   dk(  s| j                   s|S | j                   s
t               )Nr   r   
)r  rA   StopIterationr   r   r   )r.   liner   r6  s       r   __next__zGFile.__next__  s   99yy|T"X-TYYKyy'/)		tT-=-=>B; IIeai$2B2B&BCE+/4%<DK 6;DK 		#dii.1"4t7G7G"GH'+te|T"X-TYYKyy'/)- r   c                 "    | j                         S r   )r@  r   s    r   nextz
GFile.next+  s    }}r   c                    | j                   rt        j                  d d d      | j                  s| j                  | j                  j                          | j                  j                  d       | j                  j                         }|V| j                  j                  | j                  || j                         | j                  j                  t        |             y y y y )Nr8  r   )r$  r   r9  r  r!  flushr@   rA   r   rR   r   rC   r   )r.   r6  s     r   rD  zGFile.flush.  s    ;;00d1  &&*%%'$$Q',,.$GGMM$--8H8HIOO((U4 % + 'r   c                     | j                          | j                  (| j                  j                          d | _        d| _        d| _        y )NFT)rD  r!  r)  r"  r$  r   s    r   r)  zGFile.close?  s;    

??&OO!!#"DO!&Dr   r   )r   r   r    r   r&  r*  r,  r1  rA   rR   r@  rB  rD  r)  r$   r   r   r  r    s<    *'H+Z ;D*45"r   r  c                 6    t        |       j                  |       S )aK  Determines whether a path exists or not.

    Args:
      filename: string, a path

    Returns:
      True if the path exists, whether its 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.
    )r   r,   r   s    r   r,   r,   H  s     (#**844r   c                 6    t        |       j                  |       S )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.
    )r   rb   rG  s    r   rb   rb   X       (#((22r   c                 6    t        |       j                  |       S )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
    )r   rh   ri   s    r   rh   rh   g  s     '"((11r   c                 6    t        |       j                  |       S )aY  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
    )r   rl   rK  s    r   rl   rl   s  s     '"**733r   c                 6    t        |       j                  |       S )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
    )r   rs   )r+   s    r   rs   rs     s     $((..r   c              #   *  K   t        j                  |       } t        |       }	 t        |       }g }g }D ]U  }|j                  | t        j                  |            }	t        |	      r|j                  |       E|j                  |       W | ||f}
|r|
 |D ]>  }|j                  | t        j                  |            }t        |||      D ]  }|  @ |s|
 yy# t        j
                  $ r}|r	 ||       nY d}~yY d}~d}~ww xY ww)aq  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.
      (dirname, [subdirname, subdirname, ...], [filename, filename, ...])
      as strings
    N)onerror)
r   r   r   rl   r   r<   r0   rh   rX   walk)toptopdownrO  r   listingerrr  subdirsrn   	full_pathheresubdirjoined_subdirsubitems                 r   rP  rP    s    " 

C
 C		B#, EG GGC!2!24!89	NN4 LL % D
 V%6%6v%>?M7GD 	GM	
 
 3  CL s.   !DC# B4D#D6D
DDDc                 6    t        |       j                  |       S )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.
    )r   rw   rG  s    r   rw   rw     rI  r   c                     t        | d      5 }|j                  t        j                  |             ddd       y# 1 sw Y   yxY w)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.
    rM   rF   N)r  rR   r   r=   )r   rQ   rH   s      r   _write_string_to_filer^    s:     
xc	" .a	|,-. . .s	   %<Ac                 z    |rt        | d      }|j                         S t        | d      }|j                         S )a  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.
    r5   r]  r6   )r  rA   )r   rC   rH   s      r   _read_file_to_stringr`    s9     (& 668O (%668Or   )TNr|   )*r!   dataclassesrb   ra   r>   r*   os.pathsysr:  botocore.exceptionsr   r   
S3_ENABLEDr   r   r  version_infory   FileExistsError"tensorboard.compat.tensorflow_stubr   r   r  r	   r   r   	dataclassr   r&   r~   r   r  r   r  r,   rh   rl   rs   rP  rw   r^  r`  r$   r   r   <module>rj     sT     	 	  
 JN f O =
 '   1 d#  $x% x%vE EPX' X'v &'   B) *ln-m m`5 3	24$//d3 .{  J  Ns"   
C" C/ "C,+C,/C98C9