o $a@sdZddlZddlZddlZddlZddlZddlmZmZm Z m Z ddl m Z e p/eZdefddZeZGdd d eZdS) z sphinx.testing.path ~~~~~~~~~~~~~~~~~~~ :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)IOAnyCallableList)RemovedInSphinx50WarningreturncCstd}t||S)zGet current umask valuer)osumask)r r 5/usr/lib/python3/dist-packages/sphinx/testing/path.pygetumasks  r c seZdZdZedKddZdefddZdKddZde fd d Z de fd d Z de fd dZ de fddZ de fddZdLde deddfddZdMdede ddfddZdeddfddZeZdNdd Zdefd!d"Zd#eddfd$d%ZdOd'ed(edefd)d*ZdPd,ed-ed(eddfd.d/ZdPd-ed(edefd0d1ZdPd-ed(edefd2d3Zdejfd4d5Zdejfd6d7ZdMd8ed9e ddfd:d;Z de fdd?Z"dQd'e#dAe ddfdBdCZ$dDeddfdEdFZ%de&efdGdHZ'e%Z(Z)deffdIdJ Z*Z+S)Rpathz8 Represents a path which behaves like a string. rcC|tj|S)zH The name of the directory the file or directory is in. ) __class__rr dirnameselfr r r parent%sz path.parentcC tj|SN)rr basenamerr r r r,s z path.basenamecCr)z, Returns the absolute path. )rrr abspathrr r r r/sz path.abspathcCr)z; Returns ``True`` if the path is absolute. )rr isabsrr r r r5 z path.isabscCr)z> Returns ``True`` if the path is a directory. )rr isdirrr r r r;rz path.isdircCr)z9 Returns ``True`` if the path is a file. )rr isfilerr r r rArz path.isfilecCr)zB Returns ``True`` if the path is a symbolic link. )rr islinkrr r r rGrz path.islinkcCr)z@ Returns ``True`` if the path is a mount point. )rr ismountrr r r rMrz path.ismountFN ignore_errorsonerrorcCtj|||ddS)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`. )rrN)shutilrmtree)rrrr r r r"Ssz path.rmtree destinationsymlinkscCsrtj|||dtjdr5t|D]#\}}}t|dt@|D]}ttj ||dt@q#qdSdS)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$SPHINX_READONLY_TESTDIRiiN) r!copytreerenvirongetwalkchmodUMASKr join)rr#r$rootdirsfilesnamer r r r&es z path.copytreecCst||dS)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)rr#r r r movetree{sz path.movetreecCst|dS)z! Removes a file. N)runlinkrr r r r3sz path.unlinkcC t|S)z- Returns a stat of the file. )rstatrr r r r5s z path.statargcCst||dSr)rutime)rr6r r r r7sz path.utimermodekwargscKst||fi|Sr)open)rr9r:r r r r;sz path.openutf-8textencodingcKsFt|dfd|i|}||WddS1swYdS)z6 Writes the given `text` to the file. wr>Nr;write)rr=r>r:fr r r write_texts "zpath.write_textcKs"tjdtdd|j|fi|S)/ Returns the text in the file. z;Path.text() is deprecated. Please use read_text() instead. stacklevel)warningswarnr read_text)rr>r:r r r r=sz path.textcKs@t|fd|i| }|WdS1swYdS)rDr>Nr;read)rr>r:rBr r r rJs$zpath.read_textcCstjdtdd|S)0 Returns the bytes in the file. z=Path.bytes() is deprecated. Please use read_bytes() instead.rErF)rHrIr read_bytesrr r r bytessz path.bytescCs8t|dd }|WdS1swYdS)rMrbr9NrK)rrBr r r rNs$zpath.read_bytesrOappendcCsJ|rd}nd}t||d}||WddS1swYdS)z Writes the given `bytes` to the file. :param append: If ``True`` given `bytes` are added at the end of the file. abwbrQNr@)rrOrRr9rBr r r write_bytess  "zpath.write_bytescCr)z5 Returns ``True`` if the path exist. )rr existsrr r r rVrz path.existscCr)zb Returns ``True`` if the path exists unless it is a broken symbolic link. )rr lexistsrr r r rWs z path.lexistsexist_okcCr )z1 Recursively create directories. )rYN)rmakedirs)rr9rYr r r rZsz path.makedirsargscGs"|tjj|gt|j|RS)zP Joins the path with the argument given and returns the result. )rrr r,map)rr[r r r joinpaths"z path.joinpathcCr4r)rlistdirrr r r r^s z path.listdircsd|jjtfS)Nz%s(%s))r__name__super__repr__rrr r rasz path.__repr__)rr )FN)F)rN)r8)r<)rXF),r_ __module__ __qualname____doc__propertyrstrrrboolrrrrrrr"r&r2r1r3rr5r7rr;rCr=rJbuiltinsrOrNrUrVrWintrZr]rr^__div__ __truediv__ra __classcell__r r rbr r s@   r )rerirr!sysrHtypingrrrrsphinx.deprecationrgetfilesystemencodinggetdefaultencodingFILESYSTEMENCODINGrjr r+rgr r r r r s