HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/pathlib_mate/mate_mutate_methods.pyc
�
�ɴac@s`dZddlZddlZyddlmZWnek
rEnXdefd��YZdS(s.
Provide methods to mutate the Path instance.
i����Ni(tPatht
MutateMethodsc	Bs�eZdZdd�Zd�Zddddddd�Zed�Zddddddeed�Z	ddddddeed�Z
d�Zd	�Zd
�Z
RS(s6
    Provide methods to mutate the Path instance.
    icCs|j|j| �S(s�
        Drop parts from the ends.

        :param n: integer, number of parts you wants to drop from ends.
          n has to greater equal than 0.

        :rtype: Path
        :returns: a new Path object.

        Example::

            >>> self.__class__("/usr/bin/python").drop_parts(1)
            "/user/bin"

            >>> self.__class__("/usr/bin/python").drop_parts(2)
            "/user"
        (t	__class__tparts(tselftn((s#pathlib_mate/mate_mutate_methods.pyt
drop_partsscGs|j||�S(sq
        Append some parts to the end of this path.

        :rtype: Path
        :returns: a new Path object.

        Example::

            >>> self.__class__("/usr/bin/python").append_parts("lib")
            "/user/bin/python/lib"

            >>> self.__class__("/usr/bin/python").append_parts("lib", "core.py")
            "/user/bin/python/lib/core.py"
        (R(RR((s#pathlib_mate/mate_mutate_methods.pytappend_parts+scCsA|dk	r|j|�}|S|dkrU|dk	rUtjj|jj|�}nl|dk	rv|dkrv|}nK|dkr�|dkr�|j}n'|dk	r�|dk	r�td��n|dkr
|dkr�|j}n|dkr�|j	}n||}n'|dk	s"|dk	r1td��n|j||�S(sy
        Return a new :class:`pathlib_mate.pathlib2.Path` object with updated information.

        :rtype: Path
        s/Cannot having both new_dirpath and new_dirname!s4Cannot having both new_basename, new_fname, new_ext!N(
tNoneRtostpathtjointparenttdirpatht
ValueErrortfnametext(Rtnew_abspathtnew_dirpathtnew_dirnametnew_basenamet	new_fnametnew_exttp((s#pathlib_mate/mate_mutate_methods.pytchange<s(	
cCs%|j�s|tkrtStSdS(sd
        Test whether a file target is not exists or it exists but allow
        overwrite.
        N(texiststTruetFalse(Rt	overwrite((s#pathlib_mate/mate_mutate_methods.pytis_not_exist_or_allow_overwriteesc	
Cs�|j�|jd|d|d|d|d|d|�}	|	jd|�r�|j|	jkr�|r�|	j}
|
j�s�tj|
j�q�n|j|	�q�n|	S(s�
        An advanced :meth:`pathlib_mate.pathlib2.Path.rename` method provide ability to rename by
        each components of a path. A new ``Path`` instance will returns.

        :rtype: Path

        **中文文档**

        高级重命名函数, 允许用于根据路径的各个组成部分进行重命名。但和os.rename
        方法一样, 需要保证母文件夹存在。
        RRRRRRR(	t
assert_existsRRtabspathRRR	tmakedirstrename(RRRRRRRRR RR((s#pathlib_mate/mate_mutate_methods.pytmovetoos 
			c	
Cs�|j�|jd|d|d|d|d|d|�}	|	jd|�r�|j|	jkr�ytj|j|	j�Wq�tk
r�}
|r�tj|	j	j�tj|j|	j�q�|
�q�Xq�n|	S(sF
        Copy this file to other place.

        :rtype: Path
        RRRRRRR(
RRRRtshutiltcopytIOErrorR	R R(RRRRRRRRR Rte((s#pathlib_mate/mate_mutate_methods.pytcopyto�s$
		cOs|j||�dS(s
        Remove it.
        N(tunlink(Rtargstkwargs((s#pathlib_mate/mate_mutate_methods.pytremove�scOsB|j�r>|j�r+tj|j�q>|j||�ndS(s@
        Remove a file or entire directory recursively.
        N(Rtis_dirR#trmtreeRR+(RR)R*((s#pathlib_mate/mate_mutate_methods.pytremove_if_exists�scCs|jdtdt�dS(Ntparentstexist_ok(tmkdirR(R((s#pathlib_mate/mate_mutate_methods.pytmkdir_if_not_exists�sN(t__name__t
__module__t__doc__RRRRRRR"R'R+R.R2(((s#pathlib_mate/mate_mutate_methods.pyRs:	#"		
(R5R	R#tpathlib2RtImportErrortobjectR(((s#pathlib_mate/mate_mutate_methods.pyt<module>s