Your IP : 216.73.217.152


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_scandir.cpython-37.pyc

B

��\�)�@sfdZddlZddlmZGdd�de�ZGdd�d�Zdd	d
�Zdd�Zddd�Z	Gdd�de�Z
dS)z�A fake implementation for the `scandir` function working with
FakeFilesystem.
Works with both the function integrated into the `os` module since Python 3.5
and the standalone function available in the standalone `scandir` python
package.
�N)�use_scandir_packagec@sFeZdZdZdd�Zdd�Zddd�Zdd	d
�Zdd�Zdd
d�Z	dS)�DirEntryzNEmulates os.DirEntry. Note that we did not enforce keyword only
    arguments.cCs4||_d|_d|_d|_d|_d|_d|_d|_dS)z�Initialize the dir entry with unset values.

        Args:
            filesystem: the fake filesystem used for implementation.
        �NF)�_filesystem�name�path�_inode�_islink�_isdir�_statresult�_statresult_symlink)�self�
filesystem�r�F/opt/alt/python37/lib/python3.7/site-packages/pyfakefs/fake_scandir.py�__init__szDirEntry.__init__cCs|jdkr|jdd�|jS)z%Return the inode number of the entry.NF)�follow_symlinks)r�stat)r
rrr�inode+s
zDirEntry.inodeTcCs|jo|p|jS)a�Return True if this entry is a directory entry.

        Args:
            follow_symlinks: If True, also return True if this entry is a
                symlink pointing to a directory.

        Returns:
            True if this entry is an existing directory entry, or if
                follow_symlinks is set, and this entry points to an existing
                directory entry.
        )r
r	)r
rrrr�is_dir1szDirEntry.is_dircCs|jo|p|jS)a�Return True if this entry is a regular file entry.

        Args:
            follow_symlinks: If True, also return True if this entry is a
                symlink pointing to a regular file.

        Returns:
            True if this entry is an existing file entry, or if
                follow_symlinks is set, and this entry points to an existing
                file entry.
        )r
r	)r
rrrr�is_file?szDirEntry.is_filecCs|jS)z>Return True if this entry is a symbolic link (even if broken).)r	)r
rrr�
is_symlinkMszDirEntry.is_symlinkcCs||r<|jdkr6|j�|j�}|jjr*d|_|j��|_|jS|jdkrv|j�	|j�}|j
|_|jjrjd|_|j��|_|jS)z�Return a stat_result object for this entry.

        Args:
            follow_symlinks: If False and the entry is a symlink, return the
                result for the symlink, otherwise for the object it points to.
        Nr)rr�resolver�
is_windows_fs�st_nlink�stat_result�copyr�lresolve�st_inor)r
r�file_objectrrrrQs

z
DirEntry.statN)T)T)T)
�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrrs

rc@sNeZdZdZdd�Zdd�Zdd�ZeZej	dkrJd	d
�Z
dd�Zd
d�ZdS)�ScanDirIterzEIterator for DirEntry objects returned from `scandir()`
    function.cCs�||_t|t�r@ts.tjdks&|jjr.td��|j�|��	�j
}|j�|�|_
i}y|j�|�j
}Wntk
rxYnXt|�|_dS)N)��z6scandir does not support file descriptor path argument)r�
isinstance�intr�sys�version_infor�NotImplementedError�
get_open_file�
get_objectr�absnormpath�
confirmdir�contents�OSError�iter�
contents_iter)r
rrr0rrrrms

zScanDirIter.__init__cCs|S)Nr)r
rrr�__iter__�szScanDirIter.__iter__cCsvy|j��}Wntk
r,|j��}YnXt|j�}||_|j�|j|j�|_|j�	|j�|_
|j�|j�|_|S)N)
r3�next�AttributeError�__next__rrr�	joinpathsr�isdirr
�islinkr	)r
�entry�	dir_entryrrrr7�s


zScanDirIter.__next__)r%�cCs|S)Nr)r
rrr�	__enter__�szScanDirIter.__enter__cCs|��dS)N)�close)r
�exc_type�exc_val�exc_tbrrr�__exit__�szScanDirIter.__exit__cCsdS)Nr)r
rrrr?�szScanDirIter.closeN)
r r!r"r#rr4r7r5r)r*r>rCr?rrrrr$is
r$rcCs
t||�S)a�Return an iterator of DirEntry objects corresponding to the entries
    in the directory given by path.

    Args:
        filesystem: The fake filesystem used for implementation
        path: Path to the target directory within the fake filesystem.

    Returns:
        an iterator to an unsorted list of os.DirEntry objects for
        each entry in path.

    Raises:
        OSError: if the target is not a directory.
    )r$)rrrrr�scandir�srDcCsNg}g}x:|�|�D],}|�|�||��r6|�|�q|�|�qW|||fS)aTClassify contents of a directory as files/directories.

    Args:
        filesystem: The fake filesystem used for implementation
        root: (str) Directory to examine.

    Returns:
        (tuple) A tuple consisting of three values: the directory examined,
        a list containing all of the directory entries, and a list
        containing all of the non-directory entries.
        (This is the same format as returned by the `os.walk` generator.)

    Raises:
        Nothing on its own, but be ready to catch exceptions generated by
        underlying mechanisms like `os.listdir`.
    )�listdirr9r8�append)r�root�dirs�filesr;rrr�_classify_directory_contents�srJTFcs"d�����fdd�	��|dd�S)a�Perform an os.walk operation over the fake filesystem.

    Args:
        filesystem: The fake filesystem used for implementation
        top: The root directory from which to begin walk.
        topdown: Determines whether to return the tuples with the root as
            the first entry (`True`) or as the last, after all the child
            directory tuples (`False`).
      onerror: If not `None`, function which will be called to handle the
            `os.error` instance provided when `os.listdir()` fails.
      followlinks: If `True`, symbolic links are followed.

    Yields:
        (path, directories, nondirectories) for top and each of its
        subdirectories.  See the documentation for the builtin os module
        for further details.
    Fc
3s���|�}|s �s ��|�r dSyt�|�}Wn6tk
rd}zd}�dk	rT�|�Wdd}~XYnX|dk	rĈrx|Vx@|dD]4}�s���|�r�q�x���||��D]
}|Vq�Wq�W�s�|VdS)N�)�normpathr:rJr1r8)�top_dir�top_most�top_contents�exc�	directoryr0)�do_walkr�followlinks�onerror�topdownrrrR�s(

zwalk.<locals>.do_walkT)rN)Fr)r�toprUrTrSr)rRrrSrTrUr�walk�srWc@s8eZdZdZedd��Zdd�Zddd�Zddd
�Zd
S)�FakeScanDirModulea�Uses FakeFilesystem to provide a fake `scandir` module replacement.

    .. Note:: The ``scandir`` function is a part of the standard ``os`` module
      since Python 3.5. This class handles the separate ``scandir`` module
      that is available on pypi.

    You need a fake_filesystem to use this:
    `filesystem = fake_filesystem.FakeFilesystem()`
    `fake_scandir_module = fake_filesystem.FakeScanDirModule(filesystem)`
    cCsdS)zqReturn the list of patched function names. Used for patching
        functions imported from the module.
        )rDrWrrrrr�dirszFakeScanDirModule.dircCs
||_dS)N)r)r
rrrrr
szFakeScanDirModule.__init__�.cCst|j|�S)a�Return an iterator of DirEntry objects corresponding to the entries
        in the directory given by path.

        Args:
            path: Path to the target directory within the fake filesystem.

        Returns:
            an iterator to an unsorted list of os.DirEntry objects for
            each entry in path.

        Raises:
            OSError: if the target is not a directory.
        )rDr)r
rrrrrDszFakeScanDirModule.scandirTNFcCst|j||||�S)a�Perform a walk operation over the fake filesystem.

        Args:
            top: The root directory from which to begin walk.
            topdown: Determines whether to return the tuples with the root as
                the first entry (`True`) or as the last, after all the child
                directory tuples (`False`).
          onerror: If not `None`, function which will be called to handle the
                `os.error` instance provided when `os.listdir()` fails.
          followlinks: If `True`, symbolic links are followed.

        Yields:
            (path, directories, nondirectories) for top and each of its
            subdirectories.  See the documentation for the builtin os module
            for further details.
        )rWr)r
rVrUrTrSrrrrW szFakeScanDirModule.walk)rZ)TNF)	r r!r"r#�staticmethodrYrrDrWrrrrrX�s


rX)r)TNF)r#r)�pyfakefs.extra_packagesr�objectrr$rDrJrWrXrrrr�<module>sQ5

/