ó
öÀ„\c           @   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	 r{ d d l
 m Z m Z m Z m Z n  e j ƒ  p e j ƒ  Z d e f d „  ƒ  YZ d S(   s£   
    sphinx.testing.path
    ~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   open(   t   PY2t	   text_type(   t   Anyt   Callablet   IOt   Listt   pathc           B   s5  e  Z d  Z e r$ e d d „ Z n  e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z e d d „ Z e d „ Z d „  Z e Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d d „ Z d „  Z e d „ Z d „  Z d „  Z d d „ Z d „  Z  d „  Z! e  Z" Z# d „  Z$ RS(    s8   
    Represents a path which behaves like a string.
    t   strictc         C   sA   t  | t ƒ r1 | j | | ƒ } t j |  | ƒ St j |  | ƒ S(   N(   t
   isinstancet   strt   decodeR   t   __new__(   t   clst   st   encodingt   errors(    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR      s    c         C   s   |  j  t j j |  ƒ ƒ S(   sH   
        The name of the directory the file or directory is in.
        (   t	   __class__t   osR   t   dirname(   t   self(    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyt   parent$   s    c         C   s   t  j j |  ƒ S(   N(   R   R   t   basename(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   ,   s    c         C   s   |  j  t j j |  ƒ ƒ S(   s,   
        Returns the absolute path.
        (   R   R   R   t   abspath(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   0   s    c         C   s   t  j j |  ƒ S(   s;   
        Returns ``True`` if the path is absolute.
        (   R   R   t   isabs(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   7   s    c         C   s   t  j j |  ƒ S(   s>   
        Returns ``True`` if the path is a directory.
        (   R   R   t   isdir(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   >   s    c         C   s   t  j j |  ƒ S(   s9   
        Returns ``True`` if the path is a file.
        (   R   R   t   isfile(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   E   s    c         C   s   t  j j |  ƒ S(   sB   
        Returns ``True`` if the path is a symbolic link.
        (   R   R   t   islink(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   L   s    c         C   s   t  j j |  ƒ S(   s@   
        Returns ``True`` if the path is a mount point.
        (   R   R   t   ismount(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR   S   s    c         C   s   t  j |  d | d | ƒd S(   sl  
        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`.
        t   ignore_errorst   onerrorN(   t   shutilt   rmtree(   R   R   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR    Z   s    c         C   s   t  j |  | d | ƒd S(   s~  
        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.
        t   symlinksN(   R   t   copytree(   R   t   destinationR!   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR"   m   s    c         C   s   t  j |  | ƒ d S(   sò   
        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   t   move(   R   R#   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyt   movetreez   s    	c         C   s   t  j |  ƒ d S(   s!   
        Removes a file.
        N(   R   t   unlink(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR&   ‡   s    c         C   s   t  j |  ƒ S(   s-   
        Returns a stat of the file.
        (   R   t   stat(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR'   Ž   s    c         C   s   t  j |  | ƒ d  S(   N(   R   t   utime(   R   t   arg(    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR(   •   s    t   rc         K   s   t  |  | |  S(   N(   R    (   R   t   modet   kwargs(    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR    ™   s    s   utf-8c         K   sS   t  | t ƒ r! | j | ƒ } n  t |  d d | |  } | j | ƒ Wd QXd S(   s6   
        Writes the given `text` to the file.
        t   wR   N(   R	   t   bytesR   R    t   write(   R   t   textR   R,   t   f(    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyt
   write_text   s    c         K   sD   t  r d n d } t |  d | d | |  } | j ƒ  SWd QXd S(   s/   
        Returns the text in the file.
        t   rUR*   R+   R   N(   R   R    t   read(   R   R   R,   R+   R1   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR0   §   s    c         C   s)   t  |  d d ƒ } | j ƒ  SWd QXd S(   s0   
        Returns the bytes in the file.
        R+   t   rbN(   R    R4   (   R   R1   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR.   °   s    c         C   sA   | r d } n d } t  |  d | ƒ } | j | ƒ Wd QXd S(   s—   
        Writes the given `bytes` to the file.

        :param append:
            If ``True`` given `bytes` are added at the end of the file.
        t   abt   wbR+   N(   R    R/   (   R   R.   t   appendR+   R1   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyt   write_bytes¸   s
    	c         C   s   t  j j |  ƒ S(   s5   
        Returns ``True`` if the path exist.
        (   R   R   t   exists(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR:   Ç   s    c         C   s   t  j j |  ƒ S(   sb   
        Returns ``True`` if the path exists unless it is a broken symbolic
        link.
        (   R   R   t   lexists(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR;   Î   s    iÿ  c         C   s   t  j |  | ƒ d S(   s1   
        Recursively create directories.
        N(   R   t   makedirs(   R   R+   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR<   Ö   s    c         G   s(   |  j  t j j |  t |  j  | ƒ Œ ƒ S(   sP   
        Joins the path with the argument given and returns the result.
        (   R   R   R   t   joint   map(   R   t   args(    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyt   joinpathÝ   s    c         C   s   t  j |  ƒ S(   N(   R   t   listdir(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyRA   ä   s    c         C   s   d |  j  j t j |  ƒ f S(   Ns   %s(%s)(   R   t   __name__R   t   __repr__(   R   (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyRC   ê   s    N(%   RB   t
   __module__t   __doc__R   t   FILESYSTEMENCODINGR   t   propertyR   R   R   R   R   R   R   R   t   Falset   NoneR    R"   R%   R$   R&   R'   R(   R    R2   R0   R.   R9   R:   R;   R<   R@   RA   t   __div__t   __truediv__RC   (    (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyR      s<   											
						
(   RE   R   R   t   syst   ioR    t   sixR   R   RH   t   typingR   R   R   R   t   getfilesystemencodingt   getdefaultencodingRF   R   (    (    (    s2   lib/python2.7/site-packages/sphinx/testing/path.pyt   <module>   s   %