8rm"g(dZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z mZmZmZmZmZmZmZmZmZddlmZddlmZmZmZmZmZmZm Z ddl!m"Z"m#Z#dd l$m%Z%dd l&m'Z'm(Z(m)Z)dd l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8erdd l9m:Z:d Z;GddZej?eeB6edZFdS)zV Uses :py:class:`FakeOsModule` to provide a fake :py:mod:`os` module replacement. N)contextmanager)S_IFREGS_IFSOCK) ListOptionalCallableUnionAnyTuplecastAnyStr TYPE_CHECKINGSet) use_scandir) FakeDirectoryFakeDirWrapperStandardStreamWrapperFakeFileWrapperFakePipeWrapperFakeFileAnyFileWrapper) FakeFileOpen _OpenModes)FakePathModule)scandirwalk ScanDirIter)FakeStatResult is_int_typeis_byte_stringmake_string_pathIS_PYPY to_stringmatching_string AnyStringto_bytesPERM_EXEPERM_DEFis_rootget_uidget_gid)FakeFilesystemceZdZdZdZedeefdZdsdZ e defdZ e defd Z e de efd Ze defd Ze defd Zd edededefdZdefdZ dtdddedede ede edef dZd eddfdZd ededefdZd ededefdZdeeeffdZd edefdZd edefd!Z deddfd"Z!defd#Z"defd$Z#dedeefd%Z$d&Z%d'Z&d(d)ded*e'd+e(de efd,Z) dtd(d)de ed+e(deefd-Z*d(d)ded*e'd+e(ddfd.Z+ dud(d)ded*e'd0eded+e(ddf d1Z,dvdede-fd3Z. dwd4ed5e(d6e e(d7e(fd8Z/dtdede edefd9Z0dd(d:dede ed+e(defd;Z1dddede edefd<Z2dtdede eddfd=Z3dddede eddfd>Z4ddd?d@edAedBe edCe eddf dDZ5dEedFefdGZ6ddd?d@edAedBe edCe eddf dHZ7dddede eddfdIZ8dJeddfdKZ9e:fdddedede eddfdLZ;e:dfdJededMe e(ddfdNZdedQeddfdRZ?d edQeddfdSZ@ddd(dTdedede edUe(d+e(de(f dVZAdd(d:dedede ed+e(ddf dWZBdededdfdXZC dxdedYe eeDeeEfeDeeEffdZe eeefde ed+e(ddf d[ZFdd(d:ded\ed]ede ed+e(ddf d^ZG dydddede ed_ede eddf d`ZH dzddd@edAedae(de eddf dbZIddd?d@edAedBe edCe eddf dcZJd eddfddZKd eddfdeZLdfedgedhediedef djZMdefdkZNdefdlZOdePfdmZQe dePe=fdnZRe dePe=fdoZSe dePe=fdpZTe dePe=fdqZUdJedefdrZVdS){ FakeOsModuleaUses FakeFilesystem to provide a fake os module replacement. Do not create os.path separately from os, as there is a necessary circular dependency between os and os.path to replicate the behavior of the standard Python modules. What you want to do is to just let FakeOsModule take care of `os.path` setup itself. # You always want to do this. filesystem = fake_filesystem.FakeFilesystem() my_os_module = fake_os.FakeOsModule(filesystem) Freturncgd}tjdr|gdz }tjdkr|ddgz }tr|dgz }|S)zqReturn the list of patched function names. Used for patching functions imported from the module. )accesschdirchmodchownclosefstatfsyncgetcwdlchmodlinklistdirlstatmakedirsmkdirmknodopenreadreadlinkremove removedirsrenamermdirstatsymlinkumaskunlinkutimerwritegetcwdbreplacelinux) fdatasyncgetxattr listxattr removexattrsetxattrwin32getgidgetuidr)sysplatform startswithr)_dirs /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_os.pydirzFakeOsModule.dir]s    B < " "7 + +   D <7 " "  D  YK D filesystemr,c||_t|_t|j||_d|_d|_d|_d|_dS)zAlso exposes self.path (to fake os.path). Args: filesystem: FakeFilesystem used to provide file system information N) r`os os_modulerpath_supports_follow_symlinks_supports_dir_fd_supports_effective_ids _supports_fd)selfr`s r]__init__zFakeOsModule.__init__sK % "4?D99 8<&/36:$+/r_c|jjSN)rddevnullris r]rmzFakeOsModule.devnull y  r_c|jjSrl)rdseprns r]rqzFakeOsModule.seps y}r_c|jjSrl)rdaltseprns r]rszFakeOsModule.altseps yr_c|jjSrl)rdlineseprns r]ruzFakeOsModule.linesepror_c|jjSrl)rdpathseprns r]rwzFakeOsModule.pathsepror_fdargskwargsczt|stdt|j|g|Ri|S)a[Redirector to open() builtin function. Args: fd: The file descriptor of the file to open. *args: Pass through args. **kwargs: Pass through kwargs. Returns: File object corresponding to file_des. Raises: TypeError: if file descriptor is not an integer. an integer is required)r TypeErrorrr`)rirxryrzs r]fdopenzFakeOsModule.fdopensK2 6455 5,|DO,,RA$AAA&AAAr_c|jjrdStjdkrdSt jd}t j||S)zReturn the current umask.rrV)r` is_windows_fsrYrZrbrJ)rimasks r]_umaskzFakeOsModule._umasksG ? ( 1 <7 " "5 8A;;D HTNNNKr_N)dir_fdrdflagsmoderc |||j|}|'|jjrd}nd|z}t t do|t jzt jk}t|t j z o| |t j z |t j t j zzdk|t j zdk|t j zdk|t jzdk}|jr|jrt#d|rG|j|t'|t)t+j}|jjs|j|r|j|}t3|t4rx|js |jjr|jr%|jt<j|tA|||j}|j!|} | |_"| Sd} |} t t d r|t j#zt j#k} tI|j| d || | } t3| tJrJ| j&|jj'kr|(||| )S) aReturn the file descriptor for a FakeFile. Args: path: the path to the file flags: low-level bits to indicate io operation mode: bits to define default permissions Note: only basic modes are supported, OS-specific modes are ignored dir_fd: If not `None`, the file descriptor of a directory, with `file_path` being relative to this directory. Returns: A file descriptor. Raises: OSError: if the path cannot be found ValueError: if invalid mode is given NotImplementedError: if `os.O_EXCL` is used without `os.O_CREAT` Nii O_TMPFILEr) must_existcan_read can_writetruncateappendmust_not_existz,O_EXCL without O_CREAT mode is not supportedb O_TEMPORARYT)delete_on_closeraw_io) open_modes)*_path_with_dir_fdrAr`rrhasattrrbrrO_CREATO_WRONLYO_RDWRO_TRUNCO_APPENDO_EXCLrrNotImplementedError joinpathsr$struuiduuid4existsresolve isinstanceris_macosrraise_os_errorerrnoEISDIRr_add_open_filefiledesrrr file_objectdev_nullr4fileno) rirdrrrhas_tmpfile_flagrobj dir_wrapperfile_des str_flagsr fake_files r]rAzFakeOsModule.opens6%%dDIv>> <, . ~- B $ $ M)=)M   2:--F6F2F,,ry2;671<RZ'1,2;&!+ 29,1      $ V)> V%&TUU U  ?,,odC ,=,=>>D, 1G1G1M1M /))$//C#}-- "-G6:o6NG)GO225<FFF,S$HH ?99+FF&. # * 2} % % G#bn4FO L O_T    j222 i)>?????  DO$< < < JJtT " " "!!!r_cb|j|}|dS)zClose a file descriptor. Args: fd: An integer file descriptor for the file object requested. Raises: OSError: bad file descriptor. TypeError: if file descriptor is not an integer. N)r` get_open_filer6)rirx file_handles r]r6zFakeOsModule.close*s1o33B77 r_nc|j|}t|trd|_t|t r*|jtj|j | |S)aRead number of bytes from a file descriptor, returns bytes read. Args: fd: An integer file descriptor for the file object requested. n: Number of bytes to read from file. Returns: Bytes read from file. Raises: OSError: bad file descriptor. TypeError: if file descriptor is not an integer. T) r`rrrrrrrEBADF file_pathrB)rirxrrs r]rBzFakeOsModule.read7swo33B77 k? 3 3 &!%K  k> 2 2 O O * *5; 8M N N N"""r_contentsctt|j|}t |t r*|jtj|j t |tr| |Sd|_ | || ||t!|S)aWrite string to file descriptor, returns number of bytes written. Args: fd: An integer file descriptor for the file object requested. contents: String of bytes to write to file. Returns: Number of bytes written. Raises: OSError: bad file descriptor. TypeError: if file descriptor is not an integer. T)r rr`rrrrrrrrrMr_sync_ioupdate_flush_posflushlen)rirxrrs r]rMzFakeOsModule.writeLs?DO,I,I",M,MNN k> 2 2 O O * *5; 8M N N N k? 3 3 /$$X.. .! $$&&&(###8}}r_c&tj\}}t|j|d}|j|}||_t|j|d}|j|}||_|j|jfS)NFT)rbpiperr`rr)riread_fdwrite_fd read_wrapperr write_wrappers r]rzFakeOsModule.pipehsGII&tGG ?11,??' '4HH ?11-@@ ( #]%:::r_c|j|}t|tsJ|jS)aCReturn the os.stat-like tuple for the FakeFile object of file_des. Args: fd: The file descriptor of filesystem object to retrieve. Returns: The FakeStatResult object corresponding to entry_path. Raises: OSError: if the filesystem object doesn't exist. )r`r get_objectrr stat_resultcopyrirxrs r]r7zFakeOsModule.fstatrsPo33B77BBDD +x00000&++---r_rcrt|std|jj}||j_|S)zChange the current umask. Args: mask: (int) The new umask value. Returns: The old umask. Raises: TypeError: if new_mask is of an invalid type. r|)rr}r`rJ)rir old_umasks r]rJzFakeOsModule.umasks=4   6455 5O) $r_c  |j|d}n^#t$rQ}|jjr?|jtjkr*ttjdt|zd}~wwxYw|j||j |}ts9|j tzs*|j tj|j||j_dS)aChange current working directory to target directory. Args: path: The path to new current working directory. Raises: OSError: if user lacks permission to enter the argument directory or if the target is not a directory. Tallow_fdzNot a directory: N)r` resolve_pathOSErrorrrrENOTDIRr confirmdirrr)st_moder'rEACCESnamecwd)rirdexc directorys r]r3zFakeOsModule.chdirs ?//t/DDDD   ' NCI,D,Dem-@3t99-LMMM   ""4(((O++D11 yy I!2X!= I O * *5< H H H"s A:A A55A:c4t|jjS)z!Return current working directory.)r#r`rrns r]r9zFakeOsModule.getcwds,---r_c4t|jjS)z*Return current working directory as bytes.)r&r`rrns r]rNzFakeOsModule.getcwdbs+,,,r_c6|j|S)a]Return a list of file names in target_directory. Args: path: Path to the target directory within the fake filesystem. Returns: A list of file names within the target directory in arbitrary order. Raises: OSError: if the target is not a directory. )r`r<rirds r]r<zFakeOsModule.listdirs&&t,,,r_rTfollow_symlinks attributerc|jjstdt|tr&|t j}|j||d}|j |S)a;Return the value of the given extended filesystem attribute for `path`. Args: path: File path, file descriptor or path-like object (for Python >= 3.6). attribute: (str or bytes) The attribute name. follow_symlinks: (bool) If True (the default), symlinks in the path are traversed. Returns: The contents of the extended attribute as bytes or None if the attribute does not exist. Raises: OSError: if the path does not exist. z'module 'os' has no attribute 'getxattr'Tr) r`is_linuxAttributeErrorrbytesdecoderYgetfilesystemencodingrxattrgetrirdrrfile_objs r]rRzFakeOsModule.getxattrs(' L !JKK K i ' ' F!(()B)D)DEEI?**44*PP~!!),,,r_c|jjstd| |jjn|}|jt t ||d}t|j S)aReturn a list of the extended filesystem attributes on `path`. Args: path: File path, file descriptor or path-like object (for Python >= 3.6). If None, the current directory is used. follow_symlinks: (bool) If True (the default), symlinks in the path are traversed. Returns: A list of all attribute names for the given path as str. Raises: OSError: if the path does not exist. z(module 'os' has no attribute 'listxattr'NTr) r`rrrrr r listrkeys)rirdrpath_strrs r]rSzFakeOsModule.listxattrs"' M !KLL L*.,4?&&D?**  " " +   HN''))***r_c|jjstdt|tr&|t j}|j||d}||j vr |j |=dSdS)aRemoves the extended filesystem attribute attribute from `path`. Args: path: File path, file descriptor or path-like object (for Python >= 3.6). attribute: (str or bytes) The attribute name. follow_symlinks: (bool) If True (the default), symlinks in the path are traversed. Raises: OSError: if the path does not exist. z*module 'os' has no attribute 'removexattr'TrN) r`rrrrrrYrrrrs r]rTzFakeOsModule.removexattrs' O !MNN N i ' ' F!(()B)D)DEEI?**44*PP  & &y))) ' &r_rvaluec*|jjstdt|tr&|t j}t|std|j ||d}||j v}|r5||j kr*|j tj|j|s5||jkr*|j tj|j||j |<dS)a'Sets the value of the given extended filesystem attribute for `path`. Args: path: File path, file descriptor or path-like object (for Python >= 3.6). attribute: The attribute name (str or bytes). value: (byte-like) The value to be set. follow_symlinks: (bool) If True (the default), symlinks in the path are traversed. Raises: OSError: if the path does not exist. TypeError: if `value` is not a byte-like object. z'module 'os' has no attribute 'setxattr'za bytes-like object is requiredTrN)r`rrrrrrYrr r}rr XATTR_CREATErrENODATArd XATTR_REPLACEEEXIST)rirdrrrrrrs r]rUzFakeOsModule.setxattrs 0' L !JKK K i ' ' F!(()B)D)DEEIe$$ ?=>> >?**44*PPhn,  Iet000 O * *5=(- H H H H%4#555 O * *5< G G G$)y!!!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. )rr`rs r]rzFakeOsModule.scandir?st---r_toptopdownonerror followlinksc2t|j||||S)aPerform an os.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. )rr`)rirrrrs r]rzFakeOsModule.walkOs.DOS'7KHHHr_cn|||j|}|j|S)a!Read the target of a symlink. Args: path: Symlink to read the target of. dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. Returns: the string representing the path to which the symbolic link points. Raises: TypeError: if `path` is None OSError: (with errno=ENOENT) if path is not a valid path, or (with errno=EINVAL) if path is valid, but is not a symlink )rrCr`rirdrs r]rCzFakeOsModule.readlinkhs3 %%dDM6BB''---r_)rrcp|||j|}|j||S)axReturn the os.stat-like tuple for the FakeFile object of entry_path. Args: path: path to filesystem object to retrieve. dir_fd: (int) If not `None`, the file descriptor of a directory, with `entry_path` being relative to this directory. follow_symlinks: (bool) If `False` and `entry_path` points to a symlink, the link itself is changed instead of the linked object. Returns: The FakeStatResult object corresponding to entry_path. Raises: OSError: if the filesystem object doesn't exist. )rrHr`)rirdrrs r]rHzFakeOsModule.stat{s5.%%dDIv>>##D/:::r_cr|||j|}|j|dS)aReturn the os.stat-like tuple for entry_path, not following symlinks. Args: path: path to filesystem object to retrieve. dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. Returns: the FakeStatResult object corresponding to `path`. Raises: OSError: if the filesystem object doesn't exist. Fr)rr=r`rHrs r]r=zFakeOsModule.lstats8 %%dDJ??##D%#@@@r_cr|||j|}|j|dSaRemove the FakeFile object at the specified file path. Args: path: Path to file to be removed. dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. Raises: OSError: if path points to a directory. OSError: if path does not exist. OSError: if removal failed. N)rrDr`rs r]rDzFakeOsModule.remove9%%dDK@@ t$$$$$r_cr|||j|}|j|dSr)rrKr`rDrs r]rKzFakeOsModule.unlinkrr_) src_dir_fd dst_dir_fdsrcdstrrc|||j|}|||j|}|j||dS)aSRename a FakeFile object at old_file_path to new_file_path, preserving all properties. Also replaces existing new_file_path object, if one existed (Unix only). Args: src: Path to filesystem object to rename. dst: Path to where the filesystem object will live after this call. src_dir_fd: If not `None`, the file descriptor of a directory, with `src` being relative to this directory. dst_dir_fd: If not `None`, the file descriptor of a directory, with `dst` being relative to this directory. Raises: OSError: if old_file_path does not exist. OSError: if new_file_path is an existing directory. OSError: if new_file_path is an existing file (Windows only) OSError: if new_file_path is an existing file and could not be removed (Unix) OSError: if `dirname(new_file)` does not exist OSError: if the file would be moved to another filesystem (e.g. mount point) NrrFr`rirr rrs r]rFzFakeOsModule.renamesU@$$S$+zBB$$S$+zBB sC(((((r_oldnewcj|j|\}}|r1|r/|j|s||||||j|\}}|r+|r+ ||dS#t $rYdSwxYwdSdS)aFakes `os.renames`, documentation taken from there. Super-rename; create directories as necessary and delete any left empty. Works like rename, except creation of any intermediate directories needed to make the new pathname good is attempted first. After the rename, directories corresponding to rightmost path segments of the old name will be pruned until either the whole path is consumed or a nonempty directory is found. Note: this function can fail with the new directory structure made if you lack permissions needed to unlink the leaf directory or file. N)r` splitpathrr>rFrEr)rir rheadtails r]renameszFakeOsModule.renamess_..s33 d  D !7!7!=!= MM$    C_..s33 d  D  %%%%%        s B B.-B.c|||j|}|||j|}|j||ddS)aRenames a FakeFile object at old_file_path to new_file_path, preserving all properties. Also replaces existing new_file_path object, if one existed. Arg src: Path to filesystem object to rename. dst: Path to where the filesystem object will live after this call. src_dir_fd: If not `None`, the file descriptor of a directory, with `src` being relative to this directory. dst_dir_fd: If not `None`, the file descriptor of a directory, with `dst` being relative to this directory. Raises: OSError: if old_file_path does not exist. OSError: if new_file_path is an existing directory. OSError: if new_file_path is an existing file and could not be removed OSError: if `dirname(new_file)` does not exist OSError: if the file would be moved to another filesystem (e.g. mount point) T) force_replaceNr r s r]rOzFakeOsModule.replacesY<$$S$+zBB$$S$+zBB sCt<<<<|jt j|j|n| ||j |\}}|s|j |\}}|rd|rd|j|}|jrdS|j |d|j |\}}|r|`dSdSdSdS)aRemove a leaf fake directory and all empty intermediate ones. Args: name: the directory to be removed. Raises: OSError: if target_directory does not exist or is not a directory. OSError: if target_directory is not empty. T) allow_symlinkN) r` absnormpathrentriesrr ENOTEMPTYrdbasenamerGsplit)rirrrrhead_dirs r]rEzFakeOsModule.removedirs7sM**400O..t44    O * *5?DI)rirrr"s r]r>zFakeOsModule.makedirsks/"  H   tX66666r_fctc t|}n#t$r|}YnwxYw|||jvrtdt |t rt d|jz|j |s_|j |}|j tt|j|S|S)z@Return the path considering dir_fd. Raise on invalid parameters.Nz#dir_fd unavailable on this platformz2%s: Can't specify dir_fd without matching path_str)r!r}supports_dir_fdrrint ValueError__name__rdisabsr`rjoinr rr)rirdr$r open_files r]rzFakeOsModule._path_with_dir_fds #D))DD   DDD   $...)*OPPP$$$  (*-,79??4((  O99&AA y~~9#7#7#9#9::? s  !!lengthcL|j|d}||_dS)aTruncate the file corresponding to path, so that it is length bytes in size. If length is larger than the current size, the file is filled up with zero bytes. Args: path: (str or int) Path to the file, or an integer file descriptor for the file object. length: (int) Length of the file after truncating it. Raises: OSError: if the file does not exist or the file descriptor is invalid. TrN)r`rsize)rirdr-rs r]rzFakeOsModule.truncates,o--dT-BB ! r_c|j|}t|tr ||_dSt tjd)aTruncate the file corresponding to fd, so that it is length bytes in size. If length is larger than the current size, the file is filled up with zero bytes. Args: fd: (int) File descriptor for the file object. length: (int) Maximum length of the file after truncating it. Raises: OSError: if the file descriptor is invalid zInvalid file descriptorN) r`rrrrr/rrr)rirxr-rs r] ftruncatezFakeOsModule.ftruncatesYo33B77BBDD k? 3 3 B%K   %+'@AA Ar_)r effective_idsrr2cf|r|jjrtd|||j|} |||}n.#t $r!}|jtjkrYd}~dSd}~wwxYwtr|tj z}||j dz dzz|kS)aCheck if a file exists and has the specified permissions. Args: path: (str) Path to the file. mode: (int) Permissions represented as a bitwise-OR combination of os.F_OK, os.R_OK, os.W_OK, and os.X_OK. dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. effective_ids: (bool) Unused. Only here to match the signature. follow_symlinks: (bool) If `False` and `path` points to a symlink, the link itself is queried instead of the linked object. Returns: bool, `True` if file is accessible, `False` otherwise. z2access: effective_ids unavailable on this platformrNF) r`rrrr2rHrrENOENTr)rbW_OKr)rirdrrr2rros_errors r]r2zFakeOsModule.accesss0  T_: %D %%dDK@@ ))D/)JJKK   ~--uuuuu   99  RWH D,1Q67D@@sA A>A98A99A>c|s$|j|jvstrtd|||j|}|j|||dS)aChange the permissions of a file as encoded in integer mode. Args: path: (str) Path to the file. mode: (int) Permissions. dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. follow_symlinks: (bool) If `False` and `path` points to a symlink, the link itself is queried instead of the linked object. z=`follow_symlinks` for chmod() is not available on this systemN)r4supports_follow_symlinksr"rrr`)rirdrrrs r]r4zFakeOsModule.chmodsq$  Jd; ; ;w ;%R %%dDJ?? dD/:::::r_cv|jjrtd|j||ddS)zChange the permissions of a file as encoded in integer mode. If the file is a link, the permissions of the link are changed. Args: path: (str) Path to the file. mode: (int) Permissions. zname 'lchmod' is not definedFrN)r`r NameErrorr4)rirdrs r]r:zFakeOsModule.lchmodsC ? ( <:;; ; dD%@@@@@r_timesnscz|||j|}|j||||dS)acChange the access and modified times of a file. Args: path: (str) Path to the file. times: 2-tuple of int or float numbers, of the form (atime, mtime) which is used to set the access and modified times in seconds. If None, both times are set to the current time. ns: 2-tuple of int numbers, of the form (atime, mtime) which is used to set the access and modified times in nanoseconds. If None, both times are set to the current time. dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. follow_symlinks: (bool) If `False` and `path` points to a symlink, the link itself is queried instead of the linked object. Raises: TypeError: If anything other than the expected types is specified in the passed `times` or `ns` tuple, or if the tuple length is not equal to 2. ValueError: If both times and ns are specified. )r=r>rN)rrLr`)rirdr=r>rrs r]rLzFakeOsModule.utime sB:%%dDJ?? d%BXXXXXr_uidgidc"|||j|}|j||d}t |t rt |t st d|dkr||_|dkr ||_dSdS)aSet ownership of a faked file. Args: path: (str) Path to the file or directory. uid: (int) Numeric uid to set the file or directory to. gid: (int) Numeric gid to set the file or directory to. dir_fd: (int) If not `None`, the file descriptor of a directory, with `path` being relative to this directory. follow_symlinks: (bool) If `False` and path points to a symlink, the link itself is changed instead of the linked object. Raises: OSError: if path does not exist. `None` is also allowed for `uid` and `gid`. This permits `os.rename` to use `os.chown` even when the source file `uid` and `gid` are `None` (unset). TrzAn integer is requiredN) rr5r`rrr'r}st_uidst_gid)rirdr@rArrrs r]r5zFakeOsModule.chown*s6%%dDJ??o--dOd-SS #s## 6:c3+?+? 6455 5 "99!$K  "99!$K    9r_devicec|jjrtd| tdz}|s|tzs2t s$|jt j|||j |}|j |\}}|sf|j |dr%|jt j ||jt j||t|dt|dfvr%|jt j||j |dr%|jt j ||j|t#|||jjz|jdS) aCreate a filesystem node named 'filename'. Does not support device special files or named pipes as the real os module does. Args: path: (str) Name of the file to create mode: (int) Permissions to use and type of file to be created. Default permissions are 0o666. Only the stat.S_IFREG file type is supported by the fake implementation. The umask is applied to this mode. device: not supported in fake implementation dir_fd: If not `None`, the file descriptor of a directory, with `path` being relative to this directory. Raises: OSError: if called with unsupported options or the file can not be created. z%module 'os' has no attribute 'mknode'NiT) check_linkrz..)r`)r`rrrr)rrEPERMrr@rdrrrr6r$ add_objectrrJ)rirdrrFrrrs r]r@zFakeOsModule.mknodNs6 ? ( J !HII I <U?D  8 8  8 O * *5; 7 7 7%%dDJ??Y__T** d ?%%dt%<< C..u|TBBB O * *5< > > > OD#..d0K0KL L L O * *5< > > > ? ! !$4 ! 8 8 ? O * *5< > > > ""  T44?#8"88T_ U U U     r_target_is_directorycx|||j|}|j||ddS)aCreates the specified symlink, pointed at the specified link target. Args: src: The target of the symlink. dst: Path to the symlink to create. target_is_directory: Currently ignored. dir_fd: If not `None`, the file descriptor of a directory, with `src` being relative to this directory. Raises: OSError: if the file already exists. F)create_missing_dirsN)rrIr`create_symlink)rirr rKrs r]rIzFakeOsModule.symlinks@($$S$,?? &&sCU&KKKKKr_c|||j|}|||j|}|j||dS)a_Create a hard link at new_path, pointing at old_path. Args: src: An existing path to the target file. dst: The destination path to create a new link at. src_dir_fd: If not `None`, the file descriptor of a directory, with `src` being relative to this directory. dst_dir_fd: If not `None`, the file descriptor of a directory, with `dst` being relative to this directory. Raises: OSError: if something already exists at new_path. OSError: if the parent directory doesn't exist. N)rr;r`r s r]r;zFakeOsModule.linksT,$$S$)Z@@$$S$)Z@@ S#&&&&&r_ctd|cxkr tkr'nn$|jtjt t |j|}|jjrCt|dr|j s.|jtj |j dSdSdS)a Perform fsync for a fake file (in other words, do nothing). Args: fd: The file descriptor of the open file. Raises: OSError: file_des is an invalid file descriptor. TypeError: file_des is not an integer. r allow_updateN) NR_STD_STREAMSr`rrEINVALr rrrrrQrrrs r]r8zFakeOsModule.fsyncs  # # # #^ # # # # # O * *5< 8 8 8?DO,I,I",M,MNN ? ( S;77 S{?W S..u{K??? >' > <==={{5))HH{{}}H KK   zzdo6z!;;==!;;u-- KK ! ! !  jj**G JJLLLNqr_cT|jjrtdtS)zReturns the user id set in the fake filesystem. If not changed using ``set_uid``, this is the uid of the real system. zname 'getuid' is not defined)r`rr<r*rns r]rXzFakeOsModule.getuid* ? ( <:;; ;yyr_cT|jjrtdtS)zReturns the group id set in the fake filesystem. If not changed using ``set_gid``, this is the gid of the real system. zname 'getgid' is not defined)r`rr<r+rns r]rWzFakeOsModule.getgid rbr_ct}|D]U}t||jr)|t ||j@||V|Srl)setrr)addgetattr)rioriginal_functions functionsfns r]fake_functionszFakeOsModule.fake_functionssjEE $ " "BtR[)) " gdBK889999 b!!!!r_cf|j$||jj|_|jSrl)rerkrcr:rns r]r:z%FakeOsModule.supports_follow_symlinkss6  ) 1-1-@-@7..D *--r_cf|j$||jj|_|jSrl)rfrkrcr&rns r]r&zFakeOsModule.supports_dir_fd%s/  ($($7$78V$W$WD !$$r_cf|j$||jj|_|jSrl)rhrkrc supports_fdrns r]rozFakeOsModule.supports_fd+s/   $ $ 3 3DN4N O OD   r_cf|j$||jj|_|jSrl)rgrkrcsupports_effective_idsrns r]rqz#FakeOsModule.supports_effective_ids1s6  ' /+/+>+>5,,D (++r_c,t|j|S)z5Forwards any unfaked calls to the standard os module.)rgrc)rirs r] __getattr__zFakeOsModule.__getattr__9st~t,,,r_)r`r,rl)r)r)TNF)NNNT)Nr)F)Wr) __module__ __qualname____doc__ use_original staticmethodrrr^rjpropertyrmrqrrsrurwr'r rr~rr rAr6rrBrMr rrr7rJr3r9rNr<rrr%boolrRrSrTrUrrrrCrHr=rDrKrFrrOrGrEr(r?r>rrrr1r2r4r:r floatrLr5r@rIr;r8rQr`rXrWrrkr:r&rorqrsr_r]r/r/Ns   L4c444\4l 0 0 0 0!!!!X!SX     X !!!!X!!!!!X!BBSBCBNBBBB$(# P" !% P"P"P"P"P"sm P"  P" P"P"P"P"d      #s#s#u####*u8;eCHo;;;;......"##$#&#T####0.....------F-tF|---- LMNR----'0-FJ- %----:(,+HL+++V$+AE+ c++++:NR****'0*FJ* ****: %*!%%*%*%*%*%* %*  %*%* %*%*%*%*N..C.+....&"&! II II$ I  IIII2..V.Xc].c.....!% $ ;;;; ;  ;  ;;;;4>BAAA&AXc]AnAAAA&%%6%8C=%D%%%% ?C%%%6%hsm%t%%%%*%)$( ")")") ")") SM ") SM ") ")")")")H6>%)$( = = =  = = SM = SM =  = = = =D>B $ $ $& $Xc] $d $ $ $ $/v/$////8)1MQ"%=Ec] 4)1T777"%7.wrappedEso( @$JtAw ==$8D.wr1:..????1d%f%% %r_) functoolswraps)r~rs` r]handle_original_callr@s:    & & & &   &r__c#fK dt_dVdt_dS#dt_wxYw)zTemporarily use original os functions instead of faked ones. Used to ensure that skipped modules do not use faked calls. TNF)r/rwr|r_r]use_original_osrUs> *$( ! $) !!!E !))))s"0)GrvrrinspectrbrYr contextlibrrHrrtypingrrrr r r r r rrpyfakefs.extra_packagesrpyfakefs.fake_filerrrrrrrpyfakefs.fake_openrrpyfakefs.fake_pathrpyfakefs.fake_scandirrrrpyfakefs.helpersrrr r!r"r#r$r%r&r'r(r)r*r+pyfakefs.fake_filesystemr,rRr/ version_infor getmembers isfunctionrrjr)r[setattrrr|r_r]rs`  %%%%%%                        0/////87777777------<<<<<<<<<<"8777777m-m-m-m-m-m-m-m-`'gX 'G&|W5GHHBBb{%%c** B GL$(<(