a
    ij                     @  s   d Z ddlmZ ddlZddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ edZddd	d
dZG dd dejZdS )zAbstract path.    )annotationsN)AnyAnyStrIteratorOptionalTypeTypeVar)register)
stat_utils)PathLike_T)fnreturnc                 C  s   | S )N )r   r   r   W/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/etils/epath/abstract_path.pyabstractmethod#   s    r   c                      s
  e Zd ZdZdddd fddZddd	d
dZdddddddZeddddZeddddZ	ddddZ
edddddZeddddddZdddddd Zdddd!d"ZedWdddd$d%d&ZedXdd)d)dd*d+d,d-Zd.dd/d0ZdYd)dd1d2d3Zed4dd5d6ZedZd8ddd9d:d;d<Zed9dd=d>Zed[dd9d?d@dAZed\dd9d?dBdCZd.d8dDdEdFZd]dd)d)d8dGdHdIZd^d8dd9dLdMdNZeddddOdPdQZeddddOdRdSZed_dddddTdUdVZ  ZS )`PathzAbstract base class for pathlib.Path-like API.

  See [pathlib.Path](https://docs.python.org/3/library/pathlib.html)
  documentation.

  zType[_T]r   r   )clsargsr   c                   sF   | t kr.|stdS |^}}t|j| S t j| g|R  S dS )zCreate a new path.

    ```python
    path = abcpath.Path()
    ```

    Args:
      *args: Paths to create

    Returns:
      path: The registered path
    .N)r   r	   Z	make_pathjoinpathsuper__new__)r   r   rootparts	__class__r   r   r   /   s    
zPath.__new__bool)otherr   c                 G  s*   z| j |  W dS  ty$   Y dS 0 dS )z=Return True if the path is relative to another path or False.TFN)relative_to
ValueError)selfr   r   r   r   is_relative_toH   s
    
zPath.is_relative_tor   )r!   r   kwargsr   c                 O  s   t | t| j|i |S )z!Apply `str.format()` to the path.)typeosfspathformat)r!   r   r#   r   r   r   r'   P   s    zPath.format)r   c                 C  s   t dS )zReturns True if self exists.NNotImplementedErrorr!   r   r   r   existsV   s    zPath.existsc                 C  s   t dS )zReturns True if self is a dir.Nr(   r*   r   r   r   is_dir[   s    zPath.is_dirc                 C  s
   |    S )zReturns True if self is a file.)r,   r*   r   r   r   is_file`   s    zPath.is_filezIterator[_T])r!   r   c                 C  s   t dS )zIterates over the directory.Nr(   r*   r   r   r   iterdird   s    zPath.iterdirstr)r!   patternr   c                 C  s   t dS )z(Yields all matching files (of any kind).Nr(   r!   r0   r   r   r   globi   s    z	Path.globc                 C  s   |  d| S )z4Yields all matching files recursively (of any kind).z**/)r2   r1   r   r   r   rglobo   s    z
Path.rglobc                 C  s   d| j vr| S tdS )z<Returns a new path with expanded `~` and `~user` constructs.~N)r   r)   r*   r   r   r   
expandusers   s    
zPath.expanduserF)r!   strictr   c                 C  s   t dS )zReturns the absolute path.Nr(   )r!   r6   r   r   r   resolvey   s    zPath.resolverNzOptional[str]ztyping.IO[AnyStr])modeencodingerrorsr#   r   c                 K  s   t dS )zOpens the file.Nr(   )r!   r9   r:   r;   r#   r   r   r   open~   s    	z	Path.openbytesc                 C  s6   |  d}| W  d   S 1 s(0    Y  dS )z Reads contents of self as bytes.rbNr<   read)r!   fr   r   r   
read_bytes   s    zPath.read_bytes)r:   r   c                 C  s:   | j d|d}| W  d   S 1 s,0    Y  dS )z#Reads contents of self as a string.r8   )r:   Nr?   )r!   r:   rA   r   r   r   	read_text   s    zPath.read_textzstat_utils.StatResultc                 C  s   t dS )z(Returns metadata for the file/directory.Nr(   r*   r   r   r   stat   s    z	Path.stat  intNone)r9   parentsexist_okr   c                 C  s   t dS )z*Create a new directory at this given path.Nr(   )r!   r9   rH   rI   r   r   r   mkdir   s    z
Path.mkdirc                 C  s   t dS )z.Remove the empty directory at this given path.Nr(   r*   r   r   r   rmdir   s    z
Path.rmdir)
missing_okr   c                 C  s   t dS )z.Remove the directory, including all sub-files.Nr(   r!   rL   r   r   r   rmtree   s    zPath.rmtreec                 C  s   t dS )z"Remove this file or symbolic link.Nr(   rM   r   r   r   unlink   s    zPath.unlink)datar   c                 C  s8   |  d}||W  d   S 1 s*0    Y  dS )zWrites content as bytes.wbN)r<   write)r!   rP   rA   r   r   r   write_bytes   s    zPath.write_bytes)rP   r:   r;   r   c                 C  sh   |r|  dvrtd|  |r0td|  | d}||W  d   S 1 sZ0    Y  dS )zWrites content as str.>   zutf-8utf8z%Non UTF-8 encoding not supported for z Error not supported for writing wN)lowerr)   r<   rR   )r!   rP   r:   r;   rA   r   r   r   
write_text   s    zPath.write_text  T)r9   rI   r   c                 C  sB   |dkrt d|  |  r4|r&dS t|  d| d dS )z!Create a file at this given path.rX   zOnly mode=0o666 supported for Nz already exists. )r)   r+   FileExistsErrorrW   )r!   r9   rI   r   r   r   touch   s    z
Path.touch)r!   targetr   c                 C  s   dS )zRenames the path.Nr   r!   r\   r   r   r   rename   s    zPath.renamec                 C  s   dS )z Overwrites the destination path.Nr   r]   r   r   r   replace   s    zPath.replace)r!   dst	overwriter   c                 C  s   dS )z/Copy the current file to the given destination.Nr   )r!   r`   ra   r   r   r   copy   s    z	Path.copy)F)r8   NN)N)rE   FF)F)F)NN)rX   T)F)__name__
__module____qualname____doc__r   r"   r'   r   r+   r,   r-   r.   r2   r3   r5   r7   r<   rB   rC   rD   rJ   rK   rN   rO   rS   rW   r[   r^   r_   rb   __classcell__r   r   r   r   r   '   s`      
   	  r   )rf   
__future__r   r%   pathlibtypingr   r   r   r   r   r   Zetils.epathr	   r
   Zetils.epath.typingr   r   r   PurePosixPathr   r   r   r   r   <module>   s    