B
    \                 @   s\   d Z ddlZddlZddlZddlmZ ddlmZmZ e	 pFe
 ZG dd deZdS )z
    sphinx.testing.path
    ~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)open)PY2	text_typec               @   s  e Zd ZdZeredfddZedd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zd<ddZd=ddZdd ZeZdd Zdd  Zd!d" Zd>d$d%Zd?d'd(Zd@d)d*Zd+d, ZdAd-d.Zd/d0 Zd1d2 ZdBd4d5Zd6d7 Zd8d9 Z e Z!Z"d:d; Z#dS )Cpathz8
    Represents a path which behaves like a string.
    strictc             C   s.   t |tr"|||}t| |S t| |S )N)
isinstancestrdecoder   __new__)clssencodingerrors r   2lib/python3.7/site-packages/sphinx/testing/path.pyr
      s    
zpath.__new__c             C   s   |  tj| S )zH
        The name of the directory the file or directory is in.
        )	__class__osr   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   0   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   7   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   >   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   E   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   L   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   S   s    zpath.ismountFNc             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`.
        )ignore_errorsonerrorN)shutilrmtree)r   r   r   r   r   r   r    Z   s    zpath.rmtreec             C   s   t j| ||d 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.
        )symlinksN)r   copytree)r   destinationr!   r   r   r   r"   m   s    zpath.copytreec             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   movetreez   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.statc             C   s   t | | d S )N)r   utime)r   argr   r   r   r(      s    z
path.utimerc             K   s   t | |f|S )N)r   )r   modekwargsr   r   r   r      s    z	path.openutf-8c          	   K   sD   t |tr||}t| dfd|i|}|| W dQ R X dS )z6
        Writes the given `text` to the file.
        wr   N)r   bytesr	   r   write)r   textr   r,   fr   r   r   
write_text   s    

zpath.write_textc          	   K   s6   t rdnd}t| f||d|
}| S Q R X dS )z/
        Returns the text in the file.
        ZrUr*   )r+   r   N)r   r   read)r   r   r,   r+   r2   r   r   r   r1      s    z	path.textc          	   C   s    t | dd
}| S Q R X dS )z0
        Returns the bytes in the file.
        rb)r+   N)r   r4   )r   r2   r   r   r   r/      s    z
path.bytesc          	   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)r+   N)r   r0   )r   r/   appendr+   r2   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   r9      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   r:      s    zpath.lexists  c             C   s   t | | dS )z1
        Recursively create directories.
        N)r   makedirs)r   r+   r   r   r   r<      s    zpath.makedirsc             G   s    |  tjj| ft| j | S )zP
        Joins the path with the argument given and returns the result.
        )r   r   r   joinmap)r   argsr   r   r   joinpath   s    zpath.joinpathc             C   s
   t | S )N)r   listdir)r   r   r   r   rA      s    zpath.listdirc             C   s   d| j jt| f S )Nz%s(%s))r   __name__r   __repr__)r   r   r   r   rC      s    zpath.__repr__)FN)F)r*   )r-   )r-   )F)r;   )$rB   
__module____qualname____doc__r   FILESYSTEMENCODINGr
   propertyr   r   r   r   r   r   r   r   r    r"   r%   r$   r&   r'   r(   r   r3   r1   r/   r8   r9   r:   r<   r@   rA   Z__div____truediv__rC   r   r   r   r   r      s<   





	

r   )rF   r   r   sysior   Zsixr   r   getfilesystemencodinggetdefaultencodingrG   r   r   r   r   r   <module>   s   