B
    .Kc                 @   st   d dl 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	 e
 pJe ZedddZe ZG dd deZdS )    N)IOAnyCallableListOptional)returnc              C   s   t d} t |  | S )zGet current umask valuer   )osumask)r	    r
   2lib/python3.7/site-packages/sphinx/testing/path.pygetumask
   s    

r   c                   s  e Zd ZdZed dddZedddZd dddZe	dd	d
Z
e	dddZe	dddZe	dddZe	dddZdDe	ee ddddZdEee	ddddZeddddZeZddddZedd d!Zedd"d#d$ZdFeeed&d'd(ZdGeeedd*d+d,ZdHeeed-d.d/Zejdd0d1ZdIee	dd2d3d4Z e	dd5d6Z!e	dd7d8Z"dJe#e	dd:d;d<Z$ed d=d>d?Z%e&e dd@dAZ'e% Z(Z)ed fdBdCZ*  Z+S )K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.parentc             C   s   t j| S )N)r   r   basename)r   r
   r
   r   r   !   s    zpath.basenamec             C   s   |  tj| S )z,
        Returns the absolute path.
        )r   r   r   abspath)r   r
   r
   r   r   $   s    zpath.abspathc             C   s   t j| S )z;
        Returns ``True`` if the path is absolute.
        )r   r   isabs)r   r
   r
   r   r   *   s    z
path.isabsc             C   s   t j| S )z>
        Returns ``True`` if the path is a directory.
        )r   r   isdir)r   r
   r
   r   r   0   s    z
path.isdirc             C   s   t j| S )z9
        Returns ``True`` if the path is a file.
        )r   r   isfile)r   r
   r
   r   r   6   s    zpath.isfilec             C   s   t j| S )zB
        Returns ``True`` if the path is a symbolic link.
        )r   r   islink)r   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   ismount)r   r
   r
   r   r   B   s    zpath.ismountFN)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   H   s    zpath.rmtree)destinationsymlinksr   c             C   sv   t j| ||d tjdrrxTt|D ]F\}}}t|dt @  x(|D ] }ttj	||dt @  qJW q(W 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   rootZ_dirsfilesnamer
   r
   r   r   Z   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   movetreep   s    zpath.movetreec             C   s   t |  dS )z!
        Removes a file.
        N)r   unlink)r   r
   r
   r   r+   |   s    zpath.unlinkc             C   s
   t | S )z-
        Returns a stat of the file.
        )r   stat)r   r
   r
   r   r,      s    z	path.stat)argr   c             C   s   t | | d S )N)r   utime)r   r-   r
   r
   r   r.      s    z
path.utimer)modekwargsr   c             K   s   t | |f|S )N)open)r   r0   r1   r
   r
   r   r2      s    z	path.openutf-8)textencodingr1   r   c          	   K   s0   t | dfd|i|}|| W dQ R X dS )z6
        Writes the given `text` to the file.
        wr5   N)r2   write)r   r4   r5   r1   fr
   r
   r   
write_text   s    zpath.write_text)r5   r1   r   c          	   K   s(   t | fd|i|
}| S Q R X dS )z/
        Returns the text in the file.
        r5   N)r2   read)r   r5   r1   r8   r
   r
   r   	read_text   s    zpath.read_textc          	   C   s    t | dd
}| S Q R X dS )z0
        Returns the bytes in the file.
        rb)r0   N)r2   r:   )r   r8   r
   r
   r   
read_bytes   s    zpath.read_bytes)bytesappendr   c          	   C   s4   |r
d}nd}t | |d}|| W d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.
        Zabwb)r0   N)r2   r7   )r   r>   r?   r0   r8   r
   r
   r   write_bytes   s
    zpath.write_bytesc             C   s   t j| S )z5
        Returns ``True`` if the path exist.
        )r   r   exists)r   r
   r
   r   rB      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   lexists)r   r
   r
   r   rC      s    zpath.lexists  )r0   exist_okr   c             C   s   t j| ||d dS )z1
        Recursively create directories.
        )rE   N)r   makedirs)r   r0   rE   r
   r
   r   rF      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   rG   r
   r
   r   joinpath   s    zpath.joinpathc             C   s
   t | S )N)r   listdir)r   r
   r
   r   rJ      s    zpath.listdirc                s   d| j jt  f S )Nz%s(%s))r   __name__super__repr__)r   )r   r
   r   rM      s    zpath.__repr__)FN)F)r/   )r3   )r3   )F)rD   F),rK   
__module____qualname____doc__propertyr   strr   r   boolr   r   r   r   r   r   r   r   r   r*   r)   r+   r   r,   r.   r   r2   r9   r;   builtinsr>   r=   rA   rB   rC   intrF   rI   r   rJ   Z__div____truediv__rM   __classcell__r
   r
   )r   r   r      s:   
r   )rT   r   r   systypingr   r   r   r   r   getfilesystemencodinggetdefaultencodingZFILESYSTEMENCODINGrU   r   r$   rR   r   r
   r
   r
   r   <module>   s   