U
    \Sh                     @  s   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	 erHd dl
Z
e pVe ZddddZe ZG dd	 d	eZdS )
    )annotationsN)IOTYPE_CHECKINGAnyCallableintreturnc                  C  s   t d} t |  | S )zGet current umask valuer   )osumask)r    r   F/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/testing/path.pygetumask   s    

r   c                      s  e Zd ZdZed dddZddddZd ddd	Zd
dddZd
dddZ	d
dddZ
d
dddZd
dddZdMd
dddddZdNdd
ddddZdddd d!ZeZddd"d#Zd$dd%d&Zd$dd'd(d)ZdOdd$d+d,d-d.ZdPddd$dd0d1d2ZdQdd$dd3d4d5Zd6dd7d8ZdRdd
dd9d:d;Zd
dd<d=Zd
dd>d?ZdSdAd
ddBdCdDZd$d dEdFdGZdHddIdJZe ZZdd fdKdLZ   Z!S )Tpathz8
    Represents a path which behaves like a string.
    r   c                 C  s   |  tj| S )zH
        The name of the directory the file or directory is in.
        )	__class__r
   r   dirnameselfr   r   r   parent   s    zpath.parentstrc                 C  s   t j| S N)r
   r   basenamer   r   r   r   r   %   s    zpath.basenamec                 C  s   |  tj| S )z,
        Returns the absolute path.
        )r   r
   r   abspathr   r   r   r   r   (   s    zpath.abspathboolc                 C  s   t j| S )z;
        Returns ``True`` if the path is absolute.
        )r
   r   isabsr   r   r   r   r   .   s    z
path.isabsc                 C  s   t j| S )z>
        Returns ``True`` if the path is a directory.
        )r
   r   isdirr   r   r   r   r   4   s    z
path.isdirc                 C  s   t j| S )z9
        Returns ``True`` if the path is a file.
        )r
   r   isfiler   r   r   r   r   :   s    zpath.isfilec                 C  s   t j| S )zB
        Returns ``True`` if the path is a symbolic link.
        )r
   r   islinkr   r   r   r   r   @   s    zpath.islinkc                 C  s   t j| S )z@
        Returns ``True`` if the path is a mount point.
        )r
   r   ismountr   r   r   r   r   F   s    zpath.ismountFNzCallable | NoneNone)ignore_errorsonerrorr	   c                 C  s   t j| ||d dS )al  
        Removes the file or directory and any files or directories it may
        contain.

        :param ignore_errors:
            If ``True`` errors are silently ignored, otherwise an exception
            is raised in case an error occurs.

        :param onerror:
            A callback which gets called with the arguments `func`, `path` and
            `exc_info`. `func` is one of :func:`os.listdir`, :func:`os.remove`
            or :func:`os.rmdir`. `path` is the argument to the function which
            caused it to fail and `exc_info` is a tuple as returned by
            :func:`sys.exc_info`.
        )r    r!   N)shutilrmtree)r   r    r!   r   r   r   r#   L   s    zpath.rmtree)destinationsymlinksr	   c                 C  sn   t j| ||d tjdrjt|D ]B\}}}t|dt @  |D ] }ttj	||dt @  qFq&dS )a~  
        Recursively copy a directory to the given `destination`. If the given
        `destination` does not exist it will be created.

        :param symlinks:
            If ``True`` symbolic links in the source tree result in symbolic
            links in the destination tree otherwise the contents of the files
            pointed to by the symbolic links are copied.
        )r%   ZSPHINX_READONLY_TESTDIRi  i  N)
r"   copytreer
   environgetwalkchmodUMASKr   join)r   r$   r%   root_dirsfilesnamer   r   r   r&   ^   s    
zpath.copytree)r$   r	   c                 C  s   t | | dS )z
        Recursively move the file or directory to the given `destination`
        similar to the  Unix "mv" command.

        If the `destination` is a file it may be overwritten depending on the
        :func:`os.rename` semantics.
        N)r"   move)r   r$   r   r   r   movetreet   s    zpath.movetreec                 C  s   t |  dS )z!
        Removes a file.
        N)r
   unlinkr   r   r   r   r3      s    zpath.unlinkr   c                 C  s
   t | S )z-
        Returns a stat of the file.
        )r
   statr   r   r   r   r4      s    z	path.stat)argr	   c                 C  s   t | | d S r   )r
   utime)r   r5   r   r   r   r6      s    z
path.utimerr   )modekwargsr	   c                 K  s   t | |f|S r   )open)r   r8   r9   r   r   r   r:      s    z	path.openutf-8)textencodingr9   r	   c              	   K  s0   t | dfd|i|}|| W 5 Q R X dS )z6
        Writes the given `text` to the file.
        wr=   Nr:   write)r   r<   r=   r9   fr   r   r   
write_text   s    zpath.write_text)r=   r9   r	   c              
   K  s4   t | fd|i|}| W  5 Q R  S Q R X dS )z/
        Returns the text in the file.
        r=   Nr:   read)r   r=   r9   rA   r   r   r   	read_text   s    zpath.read_textzbuiltins.bytesc              
   C  s,   t | dd}| W  5 Q R  S Q R X dS )z0
        Returns the bytes in the file.
        rbr8   NrC   )r   rA   r   r   r   
read_bytes   s    zpath.read_bytes)bytesappendr	   c              	   C  s4   |r
d}nd}t | |d}|| W 5 Q R X dS )z
        Writes the given `bytes` to the file.

        :param append:
            If ``True`` given `bytes` are added at the end of the file.
        abwbrG   Nr?   )r   rI   rJ   r8   rA   r   r   r   write_bytes   s
    zpath.write_bytesc                 C  s   t j| S )z5
        Returns ``True`` if the path exist.
        )r
   r   existsr   r   r   r   rN      s    zpath.existsc                 C  s   t j| S )zb
        Returns ``True`` if the path exists unless it is a broken symbolic
        link.
        )r
   r   lexistsr   r   r   r   rO      s    zpath.lexists  r   )r8   exist_okr	   c                 C  s   t j| ||d dS )z1
        Recursively create directories.
        )rQ   N)r
   makedirs)r   r8   rQ   r   r   r   rR      s    zpath.makedirs)argsr	   c                 G  s    |  tjj| ft| j | S )zP
        Joins the path with the argument given and returns the result.
        )r   r
   r   r,   map)r   rS   r   r   r   joinpath   s    zpath.joinpathz	list[str]c                 C  s
   t | S r   )r
   listdirr   r   r   r   rV      s    zpath.listdirc                   s   | j j dt   dS )N())r   __name__super__repr__r   r   r   r   r[      s    zpath.__repr__)FN)F)r7   )r;   )r;   )F)rP   F)"rY   
__module____qualname____doc__propertyr   r   r   r   r   r   r   r   r#   r&   r2   r1   r3   r4   r6   r:   rB   rE   rH   rM   rN   rO   rR   rU   rV   Z__div____truediv__r[   __classcell__r   r   r\   r   r      s:   
r   )
__future__r   r
   r"   systypingr   r   r   r   builtinsgetfilesystemencodinggetdefaultencodingZFILESYSTEMENCODINGr   r+   r   r   r   r   r   r   <module>   s   