B
    ÿ‹d‚  ã               @   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
   ú`/work/yifan.wang/ringdown/master-ringdown-env/lib/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   ÚrootÚ_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   r1   r2   r
   r
   r   r3   ‹   s    z	path.openúutf-8)ÚtextÚencodingr2   r   c          	   K   s0   t | dfd|i|—Ž}| |¡ W dQ R X dS )z6
        Writes the given `text` to the file.
        Úwr6   N)r3   Úwrite)r   r5   r6   r2   Úfr
   r
   r   Ú
write_textŽ   s    zpath.write_text)r6   r2   r   c          	   K   s(   t | fd|i|—Ž
}| ¡ S Q R X dS )z/
        Returns the text in the file.
        r6   N)r3   Úread)r   r6   r2   r9   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)r1   N)r3   r;   )r   r9   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.
        ÚabÚwb)r1   N)r3   r8   )r   r?   r@   r1   r9   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   rD   ±   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   rE   ·   s    zpath.lexistséÿ  )r1   Úexist_okr   c             C   s   t j| ||d dS )z1
        Recursively create directories.
        )rG   N)r   Úmakedirs)r   r1   rG   r
   r
   r   rH   ¾   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   rI   r
   r
   r   ÚjoinpathÄ   s    zpath.joinpathc             C   s
   t  | ¡S )N)r   Úlistdir)r   r
   r
   r   rL   Ê   s    zpath.listdirc                s   d| j jtƒ  ¡ f S )Nz%s(%s))r   Ú__name__ÚsuperÚ__repr__)r   )r   r
   r   rO   Ï   s    zpath.__repr__)FN)F)r0   )r4   )r4   )F)rF   F),rM   Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   Ústrr   r   Úboolr   r   r   r   r   r   r   r   r   r+   r*   r,   r   r-   r/   r   r3   r:   r<   Úbuiltinsr?   r>   rC   rD   rE   ÚintrH   rK   r   rL   Z__div__Ú__truediv__rO   Ú__classcell__r
   r
   )r   r   r      s:   
r   )rV   r   r   ÚsysÚtypingr   r   r   r   r   ÚgetfilesystemencodingÚgetdefaultencodingZFILESYSTEMENCODINGrW   r   r$   rT   r   r
   r
   r
   r   Ú<module>   s   