Your IP : 216.73.217.152
B
��\�) � @ sf d Z ddlZddlmZ G dd� de�ZG dd� d�Zdd d
�Zdd� Zddd�Z G dd� 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 @ sF e Zd ZdZdd� Zdd� Zddd�Zdd d
�Zdd� Zdd
d�Z dS )�DirEntryzNEmulates os.DirEntry. Note that we did not enforce keyword only
arguments.c C s4 || _ 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__ s zDirEntry.__init__c C s | j dkr| jdd� | j S )z%Return the inode number of the entry.NF)�follow_symlinks)r �stat)r
r r r �inode+ s
zDirEntry.inodeTc C s | j o|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
r r r r �is_dir1 s zDirEntry.is_dirc C s | 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
r r r r �is_file? s zDirEntry.is_filec C s | j S )z>Return True if this entry is a symbolic link (even if broken).)r )r
r r r �
is_symlinkM s zDirEntry.is_symlinkc C s| |r<| j dkr6| j�| j�}| jjr*d|_|j�� | _ | j S | 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_objectr r r r Q s
z
DirEntry.statN)T)T)T)
�__name__�
__module__�__qualname__�__doc__r r r r r r r r r r r s
r c @ sN e Zd ZdZdd� Zdd� Zdd� ZeZej dkrJd d
� Z
dd� Zd
d� ZdS )�ScanDirIterzEIterator for DirEntry objects returned from `scandir()`
function.c C s� || _ t|t�r@ts.tjdk s&| j jr.td��| j �|�� � j
}| j �|�| _
i }y| j �|�j
}W n tk
rx Y nX t|�| _d S )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
r r r0 r r r r m s
zScanDirIter.__init__c C s | S )Nr )r
r r r �__iter__� s zScanDirIter.__iter__c C sv y| j �� }W n tk
r, | j �� }Y nX t| j�}||_| j�| j|j�|_| j� |j�|_
| j�|j�|_|S )N)
r3 �next�AttributeError�__next__r r r � joinpathsr �isdirr
�islinkr )r
�entry� dir_entryr r r r7 � s
zScanDirIter.__next__)r% � c C s | S )Nr )r
r r r � __enter__� s zScanDirIter.__enter__c C s | � � d S )N)�close)r
�exc_type�exc_val�exc_tbr r r �__exit__� s zScanDirIter.__exit__c C s d S )Nr )r
r r r r? � s zScanDirIter.closeN)
r r! r"