Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pyfakefs/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pyfakefs/__pycache__/fake_pathlib.cpython-37.pyc

B

��\a�@s2dZddlZyddlmZWn ek
r<ddlmZYnXddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZddlmZddlmZmZd	d
�Zdd�Zd
d�Zdd�ZGdd�dej�Ze�ZGdd�dej�ZGdd�de�ZGdd�de�Z Gdd�dej!�Z"Gdd�de#�Z$Gdd�de#�Z%dS)a�A fake implementation for pathlib working with FakeFilesystem.
New in pyfakefs 3.0.

Usage:

* With fake_filesystem_unittest:
  If using fake_filesystem_unittest.TestCase, pathlib gets replaced
  by fake_pathlib together with other file system related modules.

* Stand-alone with FakeFilesystem:
  `filesystem = fake_filesystem.FakeFilesystem()`
  `fake_pathlib_module = fake_filesystem.FakePathlibModule(filesystem)`
  `path = fake_pathlib_module.Path('/foo/bar')`

Note: as the implementation is based on FakeFilesystem, all faked classes
(including PurePosixPath, PosixPath, PureWindowsPath and WindowsPath)
get the properties of the underlying fake filesystem.
�N)�quote_from_bytes)�quote)�fake_scandir)�use_scandir�pathlib�pathlib2)�	text_type)�FakeFileOpen�FakeFilesystemcCs"|t_t|�tj_t|�tj_dS)z6Initializes the fake module with the fake file system.N)�FakePath�
filesystem�_FakeWindowsFlavour�FakePathlibModule�PureWindowsPath�_flavour�_FakePosixFlavour�
PurePosixPath)r�r�F/opt/alt/python37/lib/python3.7/site-packages/pyfakefs/fake_pathlib.py�init_module3s
rcst����fdd��}t|�S)Ncs�|jt|�f|��S)N)r�str)�pathobj�args)�strfuncrr�_wrapped=sz_wrap_strfunc.<locals>._wrapped)�	functools�wraps�staticmethod)rrr)rr�
_wrap_strfunc<srcst����fdd��}t|�S)Ncs�|jt|�t|�f|��S)N)rr)�pathobj1�pathobj2r)rrrrEsz&_wrap_binary_strfunc.<locals>._wrapped)rrr)rrr)rr�_wrap_binary_strfuncDsr!cst����fdd��}t|�S)Ncs�|jt|�t|�f|��S)N)rr)rr r)rrrrNsz._wrap_binary_strfunc_reverse.<locals>._wrapped)rrr)rrr)rr�_wrap_binary_strfunc_reverseMsr"c@s�eZdZdZeej�Zedd��Zeej�Zeej	�Z	e
rDeej�Ze
ed�r\edd��Zndd�Zeej�Zeej�Zeej�Zeej�Zedd��Zed	d��Zeej�Zd
S)�
_FakeAccessorzMAccessor which forwards some of the functions to FakeFilesystem methods.
    cCstj||dd�S)NF)�follow_symlinks)r
�stat)�fs�pathrrr�<lambda>]�z_FakeAccessor.<lambda>�lchmodcCstj|||dd�S)NF)r$)r
�chmod)r&r'�moderrrr(gscCstd��dS)z+Raises not implemented for Windows systems.z%lchmod() not available on this systemN)�NotImplementedError)�selfrr,rrrr*jsz_FakeAccessor.lchmodcCstj|||dd�S)NT)�
force_replace)r
�rename)r&�old_path�new_pathrrrr(wscCstj|||dd�S)NF)�create_missing_dirs)r
�create_symlink)r&�	file_path�link_target�target_is_directoryrrrr(|s
N)�__name__�
__module__�__qualname__�__doc__rr
r%�lstat�listdirr+rr�scandir�hasattr�osr*�makedir�mkdir�remove�unlink�rmdirr!r0�replacer"�symlink�utimerrrrr#Vs(











r#cs�eZdZdZdZdZdZdZdZe	dd�e
ed�ed	�d
�D��e	dd�e
ed�ed
�d
�D��BZ�fdd�Z
eefdd��Zdd�Zedd��Zd$dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Z�ZS)%�_FakeFlavourz9Fake Flavour implementation used by PurePath and _FlavourN�/Fz\\?\ccs|]}t|�VqdS)N)�chr)�.0�xrrr�	<genexpr>�sz_FakeFlavour.<genexpr>�a�z�ccs|]}t|�VqdS)N)rK)rLrMrrrrN�s�A�Zcs0||_|j|_|j|_|j|_tt|��	�dS)N)
r�path_separator�sep�alternative_path_separator�altsep�
is_windows_fs�has_drv�superrI�__init__)r.r)�	__class__rrr[�s
z_FakeFlavour.__init__cCsXd}|�|�rP|dd�}|dd�}|�d�rP||dd�7}d|dd�}||fS)N��zUNC\��\)�
startswith)r'�
ext_prefix�prefixrrr�_split_extended_path�s

z!_FakeFlavour._split_extended_pathcCs\|dd�}|dd�}||krP||krP|�|�\}}|dd�}|dd�}nd}|dd�}||kr�||kr�||kr�|�|d�}|dkr�|�||d�}||dkr�|dkr�t|�}|r�||d|�|||dd�fS|d|�|||dd�fSd}	}
|dk�r6||jk�r6|dd�}	|dd�}|}||k�rN|}
|�|�}||	|
|fS)NrrQ�r]r_����:)rd�find�len�
drive_letters�lstrip)r.r'rU�first�secondrc�third�index�index2�drv�rootrrr�_splitroot_with_drive�s6"

z"_FakeFlavour._splitroot_with_drivecCsT|rF|d|krF|�|�}t|�t|�dkr<d|d|fSd||fSdd|fSdS)Nrrer])rkri)r'rU�
stripped_partrrr�_splitroot_posix�s

z_FakeFlavour._splitroot_posixcCs0|dkr|jj}|jjr$|�||�S|�||�S)z%Split path into drive, root and rest.N)rrTrXrsru)r.r'rUrrr�	splitroot�s
z_FakeFlavour.splitrootcCs|jjr|��S|S)z<Return the lower-case version of s for a Windows filesystem.)rrX�lower)r.r'rrr�casefold�sz_FakeFlavour.casefoldcCs|jjrdd�|D�S|S)z@Return the lower-case version of parts for a Windows filesystem.cSsg|]}|���qSr)rw)rL�prrr�
<listcomp>�sz/_FakeFlavour.casefold_parts.<locals>.<listcomp>)rrX)r.�partsrrr�casefold_parts�sz_FakeFlavour.casefold_partscsD�j�i������fdd��|��r*dn�jj}�|t|��pB�S)Ncs�|���rd}x�|���D]�}|r|dkr,q|dkrF|���\}}}q|�|}|�krx�|}|dk	rlqtd|��y�j�|�}Wn8tk
r�}z|jtjkr��r��|}Wdd}~XYqXd�|<�||�}|�|<qW|S)Nr]�.z..zSymlink loop from %r)	ra�split�
rpartition�RuntimeErrorr�readlink�OSError�errno�EINVAL)r'�rest�name�_�newpath�target�e)�_resolve�seenr.rU�strictrrr��s0

z-_FakeFlavour._resolve_posix.<locals>._resolver])rU�is_absoluter�cwdr)r.r'r��baser)r�r�r.rUr�r�_resolve_posix�s
'z_FakeFlavour._resolve_posixcCs�t|�}|st��Sd}|rD|j�|�s8|j�tj|�|j�|�Sx`y|j�|�}Wn(t	k
r~|}|j�
|�d}YqFX|dkr�|S|j�|tj�
|��SqFWdS)Nr)rr@�getcwdr�exists�raise_os_errorr��ENOENT�resolve_path�IOError�	splitpath�	joinpathsr'�basename)r.r'r��
previous_srrr�_resolve_windowss$z_FakeFlavour._resolve_windowscCs |jjr|�||�S|�||�S)z/Make the path absolute, resolving any symlinks.)rrXr�r�)r.r'r�rrr�resolve/sz_FakeFlavour.resolvecCst|s:y
tjdStk
r6ddl}|�t���jSXn6ddl}y|�|�jStk
rntd|��YnXdS)z.Return the home directory of the current user.�HOMErNz%Can't determine home directory for %r)	r@�environ�KeyError�pwd�getpwuid�getuid�pw_dir�getpwnamr�)r.�usernamer�rrr�
gethomedir5s
z_FakeFlavour.gethomedir)N)r8r9r:r;rrUrWrY�ext_namespace_prefix�set�range�ordrjr[rrdrsrurvrxr|r�r�r�r��
__classcell__rr)r\rrI�s("&
&

.rIc@s\eZdZdZddddhdd�edd	�D�Bd
d�edd	�D�BZdd�Zd
d�Zdd�ZdS)r
z}Flavour used by PureWindowsPath with some Windows specific
    implementations independent of FakeFilesystem properties.
    �CON�PRN�AUX�NULcCsh|]}d|�qS)zCOM%dr)rL�irrr�	<setcomp>Lsz_FakeWindowsFlavour.<setcomp>rQ�
cCsh|]}d|�qS)zLPT%dr)rLr�rrrr�MscCs>|sdS|jjr"|d�d�r"dS|d�d�d��|jkS)z=Return True if the path is considered reserved under Windows.Frz\\rfr})rrXra�	partition�upper�reserved_names)r.r{rrr�is_reservedPs
z_FakeWindowsFlavour.is_reservedcCsd|j}t|�dkrJ|ddkrJ|��dd��d�}d|t|�d��fSdt|���d��SdS)	z$Return a file URI for the given pathrerQrgNrJz
file:///%s/%szutf-8zfile:)�driveri�as_posixrk�urlquote_from_bytes�encode)r.r'r�r�rrr�make_uri^sz_FakeWindowsFlavour.make_uricCs�dtjkrtjd}n`dtjkr,tjd}nJdtjkrnytjd}Wntk
r\d}YnX|tjd}ntd��|r�tjd|kr�|�|f�\}}}|dtjdkr�td	|��||d<|s�|r�|||�|d
d��}n
|�|�}|S)z.Return the home directory of the current user.r��USERPROFILE�HOMEPATH�	HOMEDRIVEr]zCan't determine home directory�USERNAMErfz%Can't determine home directory for %rrQN)r@r�r�r��parse_parts�join)r.r��userhomerqrrr{rrrr�ns,




z_FakeWindowsFlavour.gethomedirN)	r8r9r:r;r�r�r�r�r�rrrrr
Fsr
c@s(eZdZdZdd�Zdd�Zdd�ZdS)	rzxFlavour used by PurePosixPath with some Unix specific implementations
    independent of FakeFilesystem properties.
    cCsdS)NFr)r.r{rrrr��sz_FakePosixFlavour.is_reservedcCst|�}dt|�S)Nzfile://)�bytesr�)r.r'�bpathrrrr��sz_FakePosixFlavour.make_uricCst|s:y
tjdStk
r6ddl}|�t���jSXn6ddl}y|�|�jStk
rntd|��YnXdS)Nr�rz%Can't determine home directory for %r)	r@r�r�r�r�r�r�r�r�)r.r�r�rrrr��s
z_FakePosixFlavour.gethomedirN)r8r9r:r;r�r�r�rrrrr�src@s�eZdZdZdZdd�Zdd�Zd$dd�Zed	d
��Z	d%dd�Z
d&dd�Zej
dksXer�dd�Zd'dd�Zdd�Zd(dd�Zedd��Zdd�Zdd�Zd)d"d#�ZdS)*rz�Replacement for pathlib.Path. Reimplement some methods to use
    fake filesystem. The rest of the methods work as they are, as they will
    use the fake accessor.
    New in pyfakefs 3.0.
    NcOs2|tjkr tjdkrtjntj}|j|dd�}|S)z)Creates the correct subclass based on OS.�ntT)�init)r�Pathr@r��WindowsPath�	PosixPath�_from_parts)�clsr�kwargsr.rrr�__new__�s

zFakePath.__new__cCst|�S)zKReturns the underlying path string as used by the fake filesystem.
        )r)r.rrr�_path�szFakePath._pathcCst|_d|_dS)z#Initializer called from base class.FN)�_fake_accessor�	_accessor�_closed)r.�templaterrr�_init�szFakePath._initcCs||jj�S)zjReturn a new path pointing to the current working directory
        (as returned by os.getcwd()).
        )rr�)r�rrrr��szFakePath.cwdcCs~tjdkstr|dkr0d}n|dk	r,td��d}|jr>|��|jj||d�}|dkrj|��t	|�
��}|j�|�}t
|�S)a�Make the path absolute, resolving all symlinks on the way and also
        normalizing it (for example turning slashes into backslashes
        under Windows).

        Args:
            strict: If False (default) no exception is raised if the path
                does not exist.
                New in Python 3.6.

        Raises:
            IOError: if the path doesn't exist (strict=True or Python < 3.6)
        )r_�NFz5resolve() got an unexpected keyword argument 'strict'T)r�)�sys�version_infor�	TypeErrorr��
_raise_closedrr�r%r�absoluter�absnormpathr)r.r�r'rrrr��s
zFakePath.resolve�rrfcCs.|jr|��t|jdd�|��|||||�S)z�Open the file pointed by this path and return a fake file object.

        Raises:
            IOError: if the target object is a directory, the path is invalid
                or permission is denied.
        T)�use_io)r�r�r	rr�)r.r,�	buffering�encoding�errors�newlinerrr�open�sz
FakePath.open)r_�c	Cs*t|j�|��dd��
}|��SQRXdS)z�Open the fake file in bytes mode, read it, and close the file.

            Raises:
                IOError: if the target object is a directory, the path is
                    invalid or permission is denied.
            �rb)r,N)r	rr��read)r.�frrr�
read_bytes�szFakePath.read_bytesc	Cs2t|jdd�|��d||d��
}|��SQRXdS)zW
            Open the fake file in text mode, read it, and close the file.
            T)r�r�)r,r�r�N)r	rr�r�)r.r�r�r�rrr�	read_text	s

zFakePath.read_textc	Cs4t|�}t|j�|��dd��}|�|�SQRXdS)a"Open the fake file in bytes mode, write to it, and close the file.
            Args:
                data: the bytes to be written
            Raises:
                IOError: if the target object is a directory, the path is
                    invalid or permission is denied.
            �wb)r,N)�
memoryviewr	rr��write)r.�data�viewr�rrr�write_bytess	zFakePath.write_bytesc	CsNt|t�std|jj��t|jdd�|��d||d��}|�|�SQRXdS)a@Open the fake file in text mode, write to it, and close
            the file.

            Args:
                data: the string to be written
                encoding: the encoding used for the string; if not given, the
                    default locale encoding is used
                errors: ignored
            Raises:
                TypeError: if data is not of type 'str' (Python 3) or 'unicode'
                    (Python 2)
                IOError: if the target object is a directory, the path is
                    invalid or permission is denied.
            zdata must be str, not %sT)r��w)r,r�r�N)	�
isinstancerr�r\r8r	rr�r�)r.r�r�r�r�rrr�
write_text s

zFakePath.write_textcCs ||�j�d��tj|jj��S)zzReturn a new path pointing to the user's home directory (as
            returned by os.path.expanduser('~')).
            N)rr�rFr@rUrrT)r�rrr�home9sz
FakePath.homecCsN|��}y|��}Wn tk
r4|j�|�}YnX|j|jkoL|j|jkS)aKReturn whether other_path is the same or not as this file
            (as returned by os.path.samefile()).

            Args:
                other_path: A path object or string of the file object
                to be compared with

            Raises:
                OSError: if the filesystem object doesn't exist.
            )r%�AttributeErrorr�st_ino�st_dev)r.�
other_path�st�other_strrr�samefileAszFakePath.samefilecCs$ttj�|����tjj|jj��S)zt Return a new path with expanded ~ and ~user constructs
            (as returned by os.path.expanduser)
            )	rr@r'�
expanduserr�rFrUrrT)r.rrrr�TszFakePath.expanduser�TcCsd|jr|��|��rD|r.|j�|��d�q`|j�tj|���n|�	d�}|�
�|�|�dS)aCreate a fake file for the path with the given access mode,
        if it doesn't exist.

        Args:
            mode: the file mode for the file if it does not exist
            exist_ok: if the file already exists and this is True, nothing
                happens, otherwise FileExistError is raised

        Raises:
            OSError: (Python 2 only) if the file exists and exits_ok is False.
            FileExistsError: (Python 3 only) if the file exists and exits_ok is
                False.
        Nr�)r�r�r�rrHr�r�r��EEXISTr��closer+)r.r,�exist_ok�	fake_filerrr�touch\s
zFakePath.touch)N)N)r�rfNNN)NN)NN)r�T)r8r9r:r;rr�r�r��classmethodr�r�r�r�r�rr�r�r�r�r�r�r�rrrrrr�s$






rc@sxeZdZdZdd�ZGdd�dej�ZGdd�dej�Ze	j
dkrVGd	d
�d
ee�ZnGdd�dee�Z
eZd
d�ZdS)raaUses FakeFilesystem to provide a fake pathlib module replacement.
    Can be used to replace both the standard `pathlib` module and the
    `pathlib2` package available on PyPi.

    You need a fake_filesystem to use this:
    `filesystem = fake_filesystem.FakeFilesystem()`
    `fake_pathlib_module = fake_filesystem.FakePathlibModule(filesystem)`
    cCst|�t|_dS)z�
        Initializes the module with the given filesystem.

        Args:
            filesystem: FakeFilesystem used to provide file system information
        N)rr�_pathlib_module)r.rrrrr[�szFakePathlibModule.__init__c@seZdZdZdZdS)zFakePathlibModule.PurePosixPathzLA subclass of PurePath, that represents non-Windows filesystem
        pathsrN)r8r9r:r;�	__slots__rrrrr�src@seZdZdZdZdS)z!FakePathlibModule.PureWindowsPathz@A subclass of PurePath, that represents Windows filesystem pathsrN)r8r9r:r;rrrrrr�sr�win32c@seZdZdZdZdS)zFakePathlibModule.WindowsPathzrA subclass of Path and PureWindowsPath that represents
            concrete Windows filesystem paths.
            rN)r8r9r:r;rrrrrr��sr�c@seZdZdZdZdS)zFakePathlibModule.PosixPathztA subclass of Path and PurePosixPath that represents
            concrete non-Windows filesystem paths.
            rN)r8r9r:r;rrrrrr��sr�cCst|j|�S)z:Forwards any unfaked calls to the standard pathlib module.)�getattrr)r.r�rrr�__getattr__�szFakePathlibModule.__getattr__N)r8r9r:r;r[r�PurePathrrr��platformrr�r�r�rrrrrrws

rc@s,eZdZdZdZdd�Zdd�Zdd�ZdS)	�FakePathlibPathModulezAPatches `pathlib.Path` by passing all calls to FakePathlibModule.NcCs|jdkrt|�|j_dS)N)�fake_pathlibrr\)r.rrrrr[�s
zFakePathlibPathModule.__init__cOs|jj||�S)N)r
r�)r.rr�rrr�__call__�szFakePathlibPathModule.__call__cCst|jj|�S)N)rr
r�)r.r�rrrr�sz!FakePathlibPathModule.__getattr__)r8r9r:r;r
r[rrrrrrr	�s
r	)&r;r@�urllib.parserr��ImportError�urllibrr�rr��pyfakefsr�pyfakefs.extra_packagesrrr�pyfakefs.helpersr�pyfakefs.fake_filesystemr	r
rrr!r"�	_Accessorr#r��_FlavourrIr
rr�r�objectrr	rrrr�<module>s4			-AKH1