v1hqWdZddlZddlZddlmZddlmZmZejdkrej Z ne Z Gdde Z Gdd Z dd Zd ZddZGddZdS)zA 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_package) to_stringmake_string_pathc~eZdZdZdZdZddZddZdZddZ e j d krd Z e j d krd e fd ZdSdS)DirEntryzNEmulates os.DirEntry. Note that we did not enforce keyword only arguments.c||_d|_d|_d|_d|_d|_d|_d|_d|_dS)zInitialize the dir entry with unset values. Args: filesystem: the fake filesystem used for implementation. NF) _filesystemnamepath_abspath_inode_islink_isdir _statresult_statresult_symlinkself filesystems /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/pyfakefs/fake_scandir.py__init__zDirEntry.__init__#sL &      #'   cJ|j|d|jS)z%Return the inode number of the entry.NF)follow_symlinks)rstatrs rinodezDirEntry.inode3s& ;  IIeI , , ,{rTc$|jo |p|j S)aReturn 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. rrrrs ris_dirzDirEntry.is_dir9s{D Ct|3CDrc&|j o |p|j S)aReturn 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#s ris_filezDirEntry.is_fileGs;HO$G4<7GHrc|jS)z>Return True if this entry is a symbolic link (even if broken).)rrs r is_symlinkzDirEntry.is_symlinkUs |rc|rc|jU|j|j}|j|_|jjr d|j_|jS|ja|j |j}|j |_ |j|_|jjr d|j_|jS)zReturn 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) rr resolver stat_resultcopy is_windows_fsst_nlinkrlresolvest_inor)rr file_objects rrz DirEntry.statYs  ,'/".66t}EE +6+B+G+G+I+I(#1:89D,5+ +   #*33DMBBK%,DK*6;;==D - .,- )rrc|jSN)rrs r __fspath__zDirEntry.__fspath__rs 9 r)r returncj|jjsdS|j|j}|jS)z`Return True if this entry is a junction. Junctions are not a part of posix semantic.F)r r-r*r is_junction)rr1s rr8zDirEntry.is_junctionws8#1 u*224=AAK* *rN)T)__name__ __module__ __qualname____doc__rr r$r&r(rsys version_infor4boolr8rrr r s(((  E E E E I I I I    . 6!!    7"" + + + + + + +#"rr cPeZdZdZdZdZdZejdkr dZ dZ dZ d Sd S) ScanDirIterzEIterator for DirEntry objects returned from `scandir()` function.cB||_t|trts+tjdks |jjrtd|j|j | j |_ d|_ nBt|}|j||_ t||_ |j|j j}t#||_dS)N)rz6scandir does not support file descriptor path argumentr )r isinstanceintrr=r>r-NotImplementedError absnormpath get_open_file get_objectrabspathrr confirmdirentriesiter entry_iter)rrrrMs rrzScanDirIter.__init__s$ dC  (&  6))T_-J))O ?66--d33>>@@EDLDII#D))D?66t<rZr`r\r@rrrBrBs(((( 6!!           "!rrBr c"t||S)aReturn 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. )rB)rrs rscandirrcs z4 ( ((rcg}g}||D]V}||||r||A||W|||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`. )listdirrUrTappend)rrootdirsfilesrWs r_classify_directory_contentsrjs" D E##D))     J00u== > > KK     LL     u rTFcTdfd t|dS)aPerform 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. Fc3lK|s s|rdS t|}n&#t$r}d}  |Yd}~nd}~wwxYw|Y r|V|dD]B}||} s|r0|D]}|VC s|VdSdSdS)N)rVrjOSErrorrT) top_dirtop_most top_contentsexc directoryrcontentsdo_walkr followlinksonerrortopdowns rruzwalk..do_walks9    0A0A'0J0J  F 7 GLLLL   L"    # #"""")!_ # # !++GY??"z'8'8'>'> ' ##H"NNNN# #"""""" $ # # #s1 AAAT)rp)F)r)rtoprxrwrvrus` ```@rwalkrzsV&##########. 79S>>D 1 1 11rc>eZdZdZedZdZd dZd d ZdS) FakeScanDirModuleaUses 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)` cdS)zqReturn the list of patched function names. Used for patching functions imported from the module. )rcrzr@r@rrdirzFakeScanDirModule.dirs ! rc||_dSr3)rrs rrzFakeScanDirModule.__init__s $r.c,t|j|S)aReturn 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. )rcr)rrs rrczFakeScanDirModule.scandir!st---rTNFc2t|j||||S)aPerform 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. )rzr)rryrxrwrvs rrzzFakeScanDirModule.walk1s"DOS'7KHHHr)rTNF) r9r:r;r< staticmethodr~rrcrzr@rrr|r| sv  !!\! %%%.... IIIIIIrr|)r r)r<osr=pyfakefs.extra_packagesrpyfakefs.helpersrrr>PathLike BaseClassobjectr rBrcrjrzr|r@rrrs9  77777788888888v III^+^+^+^+^+y^+^+^+B........b))))$6*2*2*2*2Z7I7I7I7I7I7I7I7I7I7Ir