a~0dZddlZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z m Z mZmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%erddl&m'Z'ed Z(ed Z)Gd d e*Z+Gd dZ,Gdde,Z-Gdde,Z.Gdde,Z/Gdde/Z0GddZ1GddZ2GddZ3GddZ4dS)z1Fake implementations for different file objects. N)S_IFREGS_IFDIR) TracebackType) ListOptionalCallableUnionAnyDictcastAnyStrNoReturnIteratorTextIOType TYPE_CHECKING)helpers) FakeStatResultBinaryBufferIO TextBufferIO is_int_typeis_unicode_string to_stringmatching_string real_encodingAnyPath AnyString)FakeFilesystem)FakeFileWrapperFakeDirWrapperStandardStreamWrapperFakePipeWrapper)FakeFile FakeDirectoryc,eZdZdZdeddffd ZxZS)FakeLargeFileIoExceptionz|Exception thrown on unsupported operations for fake large files. Fake large files have a size with no real content. file_pathreturnNc^tt|d|zdS)Nz?Read and write operations not supported for fake large file: %s)superr&__init__)selfr' __class__s /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_file.pyr+z!FakeLargeFileIoException.__init__Js= &--66 "$- .     )__name__ __module__ __qualname____doc__strr+ __classcell__r-s@r.r&r&EsU # $          r/r&c&eZdZdZdZeejzdddddfdede de ede dd e e d e e d e e dgdffd Z ed e efdZed e e fdZed efdZejded dfdZed efdZejded dfdZed efdZejded dfdZde d dfdZde d dfdZd efdZdee edfd e efdZded efdZd*ded e e d efdZed e fdZejde d dfd Zed efd!Z e!j"d"kred efd#Z#d$e d e$ffd% Z%d&e d'e$d dffd( Z&d e fd)Z'xZ(S)+r#aProvides the appearance of a real file. Attributes currently faked out: * `st_mode`: user-specified, otherwise S_IFREG * `st_ctime`: the time.time() timestamp of the file change time (updated each time a file's attributes is modified). * `st_atime`: the time.time() timestamp when the file was last accessed. * `st_mtime`: the time.time() timestamp when the file was last modified. * `st_size`: the size of the file * `st_nlink`: the number of hard links to the file * `st_ino`: the inode number - a unique number identifying the file * `st_dev`: a unique number identifying the (fake) file system device the file belongs to * `st_uid`: always set to USER_ID, which can be changed globally using `set_uid` * `st_gid`: always set to GROUP_ID, which can be changed globally using `set_gid` .. note:: The resolution for `st_ctime`, `st_mtime` and `st_atime` in the real file system depends on the used file system (for example it is only 1s for HFS+ and older Linux file systems, but much higher for ext4 and NTFS). This is currently ignored by pyfakefs, which uses the resolution of `time.time()`. Under Windows, `st_atime` is not updated for performance reasons by default. pyfakefs never updates `st_atime` under Windows, assuming the default setting. ) st_modest_inost_devst_nlinkst_uidst_gidst_sizest_atimest_mtimest_ctime st_atime_ns st_mtime_ns st_ctime_nsNnamer8contents filesystemrencodingerrors side_effectc0|td||_||_||_t |jt jt jt j |_ |dz dkr |tz}||j _ d|_ t||_|pd|_|||_|jt'|jnd|j _ d|_d|_i|_d|_dS)a Args: name: Name of the file/directory, without parent path information st_mode: The stat.S_IF* constant representing the file type (i.e. stat.S_IFREG, stat.S_IFDIR), and the file permissions. If no file type is set (e.g. permission flags only), a regular file type is assumed. contents: The contents of the filesystem object; should be a string or byte object for regular files, and a dict of other FakeFile or FakeDirectory objects wih the file names as keys for FakeDirectory objects filesystem: The fake filesystem where the file is created. encoding: If contents is a unicode string, the encoding used for serialization. errors: The error mode used for encoding/decoding errors. side_effect: function handle that is executed when file is written, must accept the file object as an argument. Nzfilesystem shall not be None rstrict) ValueErrorrG _side_effectrEr is_windows_fsrget_uidget_gidnow stat_resultrr8r>rrHrI_encode_contents_byte_contentslenepoch parent_dirxattr opened_as)r,rEr8rFrGrHrIrJs r.r+zFakeFile.__init__s :  ;<< <,60;  )  $ O   O   KMM    b=A   w G#*  '4X'>'> !-X /3/D/DX/N/N(,(;(GC# $ $ $Q   37 $&r/r(c|jS)z&Return the contents as raw byte array.rWr,s r. byte_contentszFakeFile.byte_contentss ""r/ct|jtr:|j|jpt jd|jSdS)z9Return the contents as string with the original encoding.F)rIN) isinstancer`bytesdecoderHlocalegetpreferredencodingrIr_s r.rFzFakeFile.contentssZ d(% 0 0 %,, C!c|||jrd|_|jr&|j||j|j||_d|_dS)aSets the self.st_size attribute and replaces self.content with None. Provided specifically to simulate very large files without regards to their content (which wouldn't fit in memory). Note that read/write operations with such a file raise :py:class:`FakeLargeFileIoException`. Args: st_size: (int) The desired file size Raises: OSError: if the st_size is not a non-negative integer, or if st_size exceeds the available file system space rN)_check_positive_intr>sizerGchange_disk_usagerEr:rWr,r>s r.set_large_file_sizezFakeFile.set_large_file_sizesg   ))) < DI ? O O - -gty$+ N N N "r/rvct|r|dkr,|jtj|jdSdSNr)rrGraise_os_errorerrnoENOSPCrE)r,rvs r.ruzFakeFile._check_positive_intsD4   DD1HH O * *5< C C C C C%-Hr/c|jduS)zVReturn `True` if this file was initialized with size but no contents. Nr^r_s r. is_large_filezFakeFile.is_large_files"d**r/ct|rBttt||jpt jd|j}tt|SNF)rrcr r4rHrerfrIr,rFs r.rVzFakeFile._encode_contentssZ X & & S(## C!rGrwrEr:rY)r,rFr`changedr> current_sizes r.set_initial_contentszFakeFile.set_initial_contentss--h77 %6(5<#m$$$1|(q  )) l "DIt{   ,  a r/ct||_||}|j|||S)ahSets the file contents and size and increases the modification time. Also executes the side_effects if available. Args: contents: (str, bytes) new content of file. encoding: (str) the encoding to be used for writing the contents if they are a unicode string. If not given, the locale preferred encoding is used. Returns: True if the contents have been changed. Raises: OSError: if `st_size` is not a non-negative integer, or if it exceeds the available file system space. )rrHrrP)r,rFrHrs r. set_contentszFakeFile.set_contents*sH"&h// ++H55   (   d # # #r/c|jS)z.Return the size in bytes of the file contents.)r>r_s r.rvz FakeFile.sizeAs |r/c2|||jpd}|j||z |j|j|jr1||kr|jd||_n|xjd||z zz c_||_|xjdz c_dS)a:Resizes file content, padding with nulls if new size exceeds the old size. Args: st_size: The desired size for the file. Raises: OSError: if the st_size arg is not a non-negative integer or if st_size exceeds the available file system space rNr)rur>rGrwrEr:rWrY)r,r>rs r.rvz FakeFile.sizeFs   )))|(q  )) l "DIt{      H%%&*&9(7(&C####u,0F'GG##  a r/cg}|}|r7|dt|j|j|j}|7|j|d}|d|krR|d||}|j|d}|s||z}n||}|j |S)z+Return the full path of the current object.r) insertrrErZrGget_path_separatorpopjoin splitdrive absnormpath)r,namesobjsepdir_pathdrives r.pathz FakeFile.path`s!"& ! LLODIsx@@ A A A.C !o00q:: 8s?? IIaLLLxxHO..x88;E *>xxH**8444r/)rLc@|j|jSN)rG isjunctionrr_s r. is_junctionzFakeFile.is_junctionws?--di88 8r/itemc||jvrt|j|St|Sz'Forward some properties to stat_result.) stat_typesgetattrrUr*__getattribute__)r,rr-s r. __getattr__zFakeFile.__getattr__{s; 4? " "4+T22 2ww''---r/keyvaluec||jvrt|j||St||Sr)rsetattrrUr* __setattr__)r,rrr-s r.rzFakeFile.__setattr__s? $/ ! !4+S%88 8ww""3...r/c$d|j|jfzS)Nz%r(%o))rEr8r_s r.__str__zFakeFile.__str__s49dl333r/r))r0r1r2r3rrr PERM_DEF_FILEr intrr4rr+propertyrcr`rFfloatrAsetterr?r@ryruboolrr rVrrrvrsys version_inforr rrrr5r6s@r.r#r#QsB:J&!66%)15"& $>B6'6'6'6'6" 6' -. 6' 3- 6' 6'h |T'9:;6'6'6'6'p#x###X#(3-X)%)))X)_(E(d(((_()%)))X)_(E(d(((_()%)))X)_(E(d(((_(#3#4####.DDDDDD +t++++ %sE4/?)@%Xe_%%%%V6Vx}PT.cX [CD[25f555X5( 7""  9 9 9 9  9........ /s/3/4////// 444444444r/r#cLeZdZd fd ZedefdZdedefdZ xZ S) FakeNullFilerGrr(Nct|jrdnd}tt|||ddS)Nnulz /dev/nullrN)rGrF)rQr*rr+)r,rGdevnullr-s r.r+zFakeNullFile.__init__s@%3D%% lD!!**7zTV*WWWWWr/cdS)Nr/r_s r.r`zFakeNullFile.byte_contentsssr/rFcdSrrrs r.rz!FakeNullFile.set_initial_contentssur/)rGrr(N) r0r1r2r+rrcr`r rrr5r6s@r.rrsXXXXXXuXVr/rc ~eZdZdZ d dedddeeddffd Zedee fd Z d fd Z d Z xZ S) FakeFileFromRealFileztRepresents a fake file copied from the real file system. The contents of the file are read on demand only. Nr'rGrrJr(cttj|||d|_dS)a3 Args: file_path: Path to the existing file. filesystem: The fake filesystem where the file is created. Raises: OSError: if the file does not exist in the real file system. OSError: if the file already exists in the fake file system. )rErGrJFN)r*r+osrbasename contents_read)r,r'rGrJr-s r.r+zFakeFileFromRealFile.__init__sO !!),,!#    #r/c|jsRd|_tj|jd5}||_dddn #1swxYwYt j|jj|_|jS)NTrb) rioopenr'readrWrstatr?)r,fs r.r`z"FakeFileFromRealFile.byte_contentss! /!%D .. /!&'ffhh# / / / / / / / / / / / / / / ///8 ""sAAAchd|_tt|||dSNT)rr*rr)r,rFrHr-s r.rz!FakeFileFromRealFile.set_contentss2! "D))66xJJJJJr/cdS)zThe contents are never faked.Frr_s r.rz"FakeFileFromRealFile.is_large_fileur/r)r0r1r2r3r4rrr+rrcr`rrr5r6s@r.rrs+/ ###%#h' #  ######,#x###X#KKKKKKr/rcjeZdZdZejdfdedededfdZ dde d eed e fd Z e d eeeffd Ze d eefd Zded dfdZded efdZded efdZddede d dfdZe d efdZejded dfdZddd e fdZd effd ZxZS)r$z,Provides the appearance of a real directory.NrE perm_bitsrGrct||t|zd||xjdz c_i|_dS)a Args: name: name of the file/directory, without parent path information perm_bits: permission bits. defaults to 0o777. filesystem: if set, the fake filesystem where the directory is created rN)rGrN)r#r+rr;_entries)r,rErrGs r.r+zFakeDirectory.__init__sE $g &92*UUU  ,. r/rFrHr(cV|jtj|jrrGr|r}EISDIRr)r,rFrHs r.rzFakeDirectory.set_contentsso,,U\49EEEr/c|jS)z/Return the list of contained directory entries.)rr_s r.entrieszFakeDirectory.entriess }r/chdt|jdDS)z^Return the list of contained directory entry names ordered by creation order. cg|] }|d Srr.0rs r. z.FakeDirectory.ordered_dirs..s,    G   r/c|djS)Nr)r9)entrys r.z,FakeDirectory.ordered_dirs..s ar/)r)sortedritemsr_s r. ordered_dirszFakeDirectory.ordered_dirssB   t}2244:W:WXXX    r/ path_objectc~tjs@|jtjzs,|jjs t tjd|j t|j }||j vr*|j tj|j ||j|<||_|j&|jxjdz c_|jj|_|xjdz c_|xjdz c_|j|_|jdkr-|j|j|j |jdSdS)a5Adds a child FakeFile to this directory. Args: path_object: FakeFile instance to add as a child of this directory. Raises: OSError: if the directory has no write permission (Posix only) OSError: if the file or directory to be added already exists zPermission DeniedNr)ris_rootr8 PERM_WRITErGrQOSErrorr}EACCESrrrErr|EEXISTrrZr9last_inor;r:rwrv)r,rpath_object_names r. add_entryzFakeDirectory.add_entrysC!! HL7#55 HO1 H %,(;TYGG G )+*: ; ; t| + + O * *5< C C C*5 &'!%    % O $ $ ) $ $!%!9K   !![   1 $ $ O - - +"2DK      % $r/ pathname_namec`||}|jt|S)a)Retrieves the specified child file or directory entry. Args: pathname_name: The basename of the child object to retrieve. Returns: The fake file or directory object. Raises: KeyError: if no child exists by the specified name. )_normalized_entrynamerr)r,rs r. get_entryzFakeDirectory.get_entrys,22=AA |Im4455r/cZ|jjsfd|jD}|r|dS)Nchg|].}|k,|/Sr)lower)rrErs r.rz7FakeDirectory._normalized_entryname.."s>ATATAVAV1V1V1V1V1Vr/r)rGis_case_sensitiver)r,rmatching_namess ` r.rz#FakeDirectory._normalized_entryname sT0 2!%N 2 .q 1 r/T recursivec||}||}|jjr}|jt jzdkr%|jtj ||j |r%|jtj |ntt j sa|jt jt j zzt jt j zkr%|jtj ||rQt|tr<|jr4|t#|jd|j4n2|jdkr'|j|j ||j|xjdzc_|xjdzc_|jdksJ|jt-|=dS)a&Removes the specified child file or directory. Args: pathname_name: Basename of the child object to remove. recursive: If True (default), the entries in contained directories are deleted first. Used to propagate removal errors (e.g. permission problems) from contained entries. Raises: KeyError: if no child exists by the specified name. OSError: if user lacks permission to delete the file, or (Windows only) the file is open. rrN)rrrGrQr8rrr|r}r has_open_filerPERM_EXErbr$r remove_entrylistr;rwrvr:r)r,rrrs r.rzFakeDirectory.remove_entry)s22=AA }-- ? ( L}w11Q66..u|]KKK,,U33 L..u|]KKK?$$ L  2W5E EF%(8899..u|]KKK  XE=99 X- ;""4 #6#6q#9:::- ; ^q O - -uzk=%, W W W   !~"""" L=11 2 2 2r/cbtd|jDS)zUReturn the total size of all files contained in this directory tree. c(g|]}|djS)r)rvrs r.rz&FakeDirectory.size..VsBBBTDGLBBBr/)sumrrr_s r.rvzFakeDirectory.sizeQs/ BBT\-?-?-A-ABBBCCCr/r>cV|jtj|j)z-Setting the size is an error for a directory.rrxs r.rvzFakeDirectory.sizeXs o,,U\49EEEr/ dir_objectc0|}|r||krdS|j}|dS)zmReturn `True` if dir_object is a direct or indirect parent directory, or if both are the same object.TF)rZ)r,rrs r.has_parent_objectzFakeDirectory.has_parent_object]s9(, !j  t.C !ur/ctt|dz}|jD]F}|j|}|dD]}|r |dz|zdz}G|S)Nz:  z )r*r$rrsplit)r, descriptionr item_descliner-s r.rzFakeDirectory.__str__gsM40088::UB L C CD T*2244I!-- C CC"-"4t";d"BK Cr/r)T)r0r1r2r3rPERM_DEFr4rrr+r rrrr r#rrrrAnyFilerrrrvrrrr5r6s@r.r$r$s@66 !)15 ////-. ////&FFVFx}FPTFFFFc8m,X d3i   X  X $    D 6s 6w 6 6 6 633&3&3#&3$&3$&3&3&3&3PDcDDDXD  [FCFDFFF[FOr/r$c eZdZdZ ddedddedeeffd Zed e e e ffd Z ed e ffd Zejd e d dfd ZxZS)FakeDirectoryFromRealDirectoryz~Represents a fake directory copied from the real file system. The contents of the directory are read on demand only. N source_pathrGr read_only target_pathc|p|}tj|}tt|t tj|d|j||j |_ |j |_ |j |_ |j |_ |j |_ ||_||_d|_dS)ao Args: source_path: Full directory path. filesystem: The fake filesystem where the directory is created. read_only: If set, all files under the directory are treated as read-only, e.g. a write access raises an exception; otherwise, writing to the files changes the fake files only as usually. target_path: If given, the target path of the directory, otherwise the target is the same as `source_path`. Raises: OSError: if the directory does not exist in the real file system r)rErrGFN)rrr*r r+rrrr8rAr?r@r=r<rrr)r,rrGrr real_statr-s r.r+z'FakeDirectoryFromRealDirectory.__init__ws*"0[ GK((  ,d33<<27==55a899'! =   "* !* !* & & &""r/r(c<|jsd|_|j}tj|jD]}tj|j|}tj||}tj|r|j||tj |r#|j ||j ||j ||j ||j S)z[Return the list of contained directory entries, loading them if not already loaded.T)r)rrrlistdirrrislinkrGadd_real_symlinkisdiradd_real_directoryr add_real_filer)r,baserrrs r.rz&FakeDirectoryFromRealDirectory.entriess! !%D 9DD$455   gll4+;UCC  gll477 7>>+.. O44[+NNNNW]];//O66#T^7O11#T^2}r/cJ|jsdStt|jSr{)rr*r rv)r,r-s r.rvz#FakeDirectoryFromRealDirectory.sizes)! 13T::??r/r>cV|jtj|jrrrxs r.rvz#FakeDirectoryFromRealDirectory.sizeso,,U\49EEEr/r)r0r1r2r3rrrr+rr r4r#rrrvrr5r6s@r.r r qs*. $#$#$#%$# $# g& $#$#$#$#$#$#Lc8m,X*@c@@@@@X@  [FCFDFFF[FFFFFr/r cJeZdZdZ d=dedededededed d d eed ed edeedeede dedefdZ d>dZ dee e dee deeddfdZdedefdZdefdZde fdZd?dZedefd Zd!e ddfd"Zd?d#Zd?d$Zd?d%Zd@d'e d(e ddfd)Zde fd*Zd?d+Zd,eddfd-Zd.ede fd/Z!d.ede fd0Z"d.ede fd1Z#d2e ddfd3Z$de fd4Z%de fd5Z&d.ede'fd6Z(de fd7Z)de fd8Z*defd9Z+d?d:Z,de-e.ee.effd;Z/d<Z0dS)ArzWrapper for a stream object for use by a FakeFile object. If the wrapper has any data written to it, it will propagate to the FakeFile object on close() or flush(). F file_objectr'updaterappenddelete_on_closerGrnewlinebinaryclosefdrHrI bufferingraw_io is_streamcR||_||_||_||_||_| |_|j|_||_| |_ ||_ d|_ | |_ |j dkr| std|j dks| stj|_ | o| dk|_|j}| pt%jd|_| pd} | rt+|nt-|| || |_d|_d|_d|_|rpt7||_|rZ|s|jdn=|j|j|j|_|r |s Jd||_||_|j |_!d|_"dS) NFrzcan't have unbuffered text I/OrrM)rHr"rIz(delete_on_close=True requires filesystem)#rr'_append_read allow_update_closefdrY _file_epochr&_binaryr'_changed _buffer_sizerOrDEFAULT_BUFFER_SIZE_use_line_bufferr`rerf _encodingrr_io _read_whence _read_seek _flush_posrXseektell _filesystemr!r\rEfiledes)r,rr'rrr r!rGr"r#r$rHrIr%r&r'rFs r.r+zFakeFileWrapper.__init__s$'"  " &,  " %   ! !& !=>> >  " $ $F $ " 6D $* =yA~,!GV%@%G%G#8 N8 $ $ $8WV   6!(mmDO 66HMM!$$$$HMM$/222&*hmmooDO  J I II I I:%. ) &* r/r(c|S)=To support usage of this fake file with the 'with' statement.rr_s r. __enter__zFakeFileWrapper.__enter__  r/exc_typeexc_valexc_tbNc.|dS)r>Ncloser,rArBrCs r.__exit__zFakeFileWrapper.__exit__ r/messagec|jr*|jtj|jt j|r)r&r;r|r}EBADFr'rUnsupportedOperation)r,rJs r._raisezFakeFileWrapper._raises; ; I   + +EK H H H%g...r/c|jS)zTReturn the FakeFile object that is wrapped by the current instance. rr_s r. get_objectzFakeFileWrapper.get_objects r/cR|j|jSttjdz.Return the file descriptor of the file object.NInvalid file descriptorr<rr}rLr_s r.filenozFakeFileWrapper.fileno"% < #< ek#<===r/c |sdS|jrK|jsD||jjr$|jrtj|j _ |j J|j r |j |j n0|jj|j }|J|||jr3|j|jdSdS)zClose the file.N)_is_openr,r&flushr;rQr0rrTrr@r<r-_close_open_file open_filesremover! remove_objectrQrr,r\s r.rFzFakeFileWrapper.close(s}}  F   :T[ : JJLLL- :$- :,3KMM )|''' = $   - -dl ; ; ; ;)4T\BJ)))   d # # #      * *!!&       r/c,| S)z(Simulate the `closed` attribute on file.)rYr_s r.closedzFakeFileWrapper.closed@s==??""r/old_posc|j} |dS#t$r<|j||j||_wxYw)z0Try to flush and reset the position if it fails.N)r8rZrr5r9truncate)r,rb flush_poss r. _try_flushzFakeFileWrapper._try_flushEslO   JJLLLLL    HMM' " " " H     'DO   s AA%c||jr0|js*|j}|jrL||jj}|J|||j dz}| |n|j |j ||j }||r?|jjrd|_n+t%j}||j_||j_|jj|_|js|dSdSdSdS)zFlush file contents to 'disk'.NT)_check_open_filer,r'r5getvaluer*_sync_iorr`r8_set_stream_contentsrZrr4update_flush_posr;rQr0rrTrAr@rYr._flush_related_files)r,rF old_contentsr current_times r.rZzFakeFileWrapper.flushQsc    ,T^ ,x((**H| ! #/= #///'(4?3D3D*EE))(3333   &33HdnMMG  ! ! # # # =#1=$(DMM#*;==L0 ,))+++++- , , , ,* , ,r/cB|j|_dSr)r5r:r8r_s r.rlz FakeFileWrapper.update_flush_posls(--//r/c|jjddD]M}|I|D]F}||ur@t|tr+|j|jkr|js|GNdSNr)r;r\rbrrr*rj)r,r\ open_files r.rmz$FakeFileWrapper._flush_related_filesos*5abb9 - -J%!+--I!--&y/BB. , 0EEE ) 1F"**,,, - -r/roffsetwhencec||js|j||n||_||_|js|dSdS)z"Move read/write pointer in 'file'.N)rhr*r5r9r7r6r'rZ)r,rtrus r.r9zFakeFileWrapper.seek{sk | ' HMM&& ) ) ) )$DO &D ~  JJLLLLL  r/c||js||js|jS|jr}|j}|j|j|j|j|_d|_|j||jS)zoReturn the file's current position. Returns: int, file's current position in bytes. r) rhr'rZr*r5r:r6r9r7)r, write_seeks r.r:zFakeFileWrapper.tells ~  JJLLL| #8==?? "   &J HMM$/4+< = = ="hmmooDO !D  HMM* % % %r/c|j|jjkrdS|jj}|J|||jj|_dS)z;Update the stream with changes to the file object contents.N)r.rrYr`rkrs r.rjzFakeFileWrapper._sync_iosZ  t/5 5 5 F#1### !!(++++1r/rFc|j}|jd|j|j||js|j|dSdSr{)r5r:r9rdputvaluer*)r,rFrus r.rkz$FakeFileWrapper._set_stream_contentss}  a  (###| " HMM& ! ! ! ! ! " "r/rEc@tj|fd}|S)a_Wrap a stream attribute in a read wrapper. Returns a read_wrapper which tracks our own read pointer since the stream object has no concept of a different read and write pointer. Args: name: The name of the attribute to wrap. Should be a read call. Returns: The read_wrapper function. cjjj|i|}j_d_jdd|S)aWrap all read calls to the stream object. We do this to track the read pointer separate from the write pointer. Anything that wants to read from the stream object while we're in append mode goes through this. Args: *args: pass through args **kwargs: pass through kwargs Returns: Wrapped stream object method r)r5r9r7r6r:)argskwargs ret_valueio_attrr,s r. read_wrapperz4FakeFileWrapper._read_wrappers..read_wrappersi HMM$/4+< = = =000I"hmmooDO !D  HMM!Q    r/rr5)r,rErrs` @r._read_wrapperszFakeFileWrapper._read_wrapperss=$(D))      (r/c@tj|fd}|S)zWrap a stream attribute in an other_wrapper. Args: name: the name of the stream attribute to wrap. Returns: other_wrapper which is described below. cj}|i|}|jkr%j_d_|S)Wrap all other calls to the stream Object. We do this to track changes to the write pointer. Anything that moves the write pointer in a file open for appending should move the read pointer as well. Args: *args: Pass through args. **kwargs: Pass through kwargs. Returns: Wrapped stream object method. r)r5r:r7r6)rrrxrrr,s r. other_wrapperz5FakeFileWrapper._other_wrapper..other_wrappers\J000ITX]]__,,"&(--//$%! r/r)r,rErrs` @r._other_wrapperzFakeFileWrapper._other_wrappers=$(D))      ,r/c@tj|fd}|S)zWrap a stream attribute in a write_wrapper. Args: name: the name of the stream attribute to wrap. Returns: write_wrapper which is described below. cj}|i|}j}jo d|dv}|jz jks|rd||z jkp|}|s3j|j||s|i|}jr%j_ d_ |S)rrr) r5r:r3r8r1r9rdrfr*r7r6) rrrbrnew_pos use_line_buf flush_allrr,s r. write_wrapperz5FakeFileWrapper._write_wrapper..write_wrappershmmooG000IhmmooG 0DTT!W_L(4+<<< <#g-0AAQ\ !(HMM'***H%%'''((( 9 ' 8 8 8I| &"&(--//$%! r/r)r,rErrs` @r._write_wrapperzFakeFileWrapper._write_wrappers>$(D))" " " " " " Hr/rvc|jjddD]\}|X|D]U}||urOt|tr:|j|jkr*t t|jr|xj|z c_V]dSrr)r;r\rbrrr r*r7)r,rvr\rss r._adapt_size_for_related_filesz-FakeFileWrapper._adapt_size_for_related_files$s*5abb9 5 5J%!+55I!--&y/BB. , 0EEE )<<DF",,4,, 5 5r/c.jjfd}|S)zwWrap truncate() to allow flush after truncate. Returns: Wrapper which is described below. c^jr%jjj|i|}js|j_tj }||krj|j d||z zj j j |_||z |S)z0Wrap truncate call to call flush after truncate.r)r*r5r9r7r6rZr'rrvrXrir{rr4r8r)rrrv buffer_sizerr,s r.truncate_wrapperz;FakeFileWrapper._truncate_wrapper..truncate_wrapper8s| B dot/@AAA7D+F++D JJLLL> K(, %!$("3"3"5"566 %%HMM+...H%%etk/A&BCCC$11$(2C2C2E2Et~VVV&*DO66tk7IJJJ JJLLLKr/)r5rd)r,rrs` @r._truncate_wrapperz!FakeFileWrapper._truncate_wrapper0s6 (#      & r/c|jjS)z5Return the content size in bytes of the wrapped file.)rr>r_s r.rvzFakeFileWrapper.sizeMs''r/c|jrt|j|dp|dk}|dk}|dp|}|s|r||js|r|S|js|r| S|rX| |j s| |j jstj|j_|r|S|jr.|r||S|s||S|r||St/|j|S)Nrnextrdwrite)rrr&r' startswithrhr+ _read_errorr, _write_errorrjr'rZr;rQrrTr?rr*rrrrr5)r,rEreadingrdwritings r.rzFakeFileWrapper.__getattr__Qs   ) ) + + ;*4>:: ://&));TV^:%//'**6h  $g $  ! ! # # #z &g &##%% %  'W '$$&& &  : MMOOO>  #1 :,3KMM )  ,))++ + < 1 1**4000 1**4000  -&&t,, ,tx&&&r/cfd}|S)Nc|r*|ddkrjjrjr jrdndSddS)z+Throw an error unless the argument is zero.rr/rNzFile is not open for reading.N)r;rQr&r/rNrrr,s r. read_errorz/FakeFileWrapper._read_error..read_errorssX 7Q1 #17dk7"&,633B6 KK7 8 8 8 8 8r/r)r,rs` r.rzFakeFileWrapper._read_errorrs$ 9 9 9 9 9r/cfd}|S)Ncjr)jjr|rt|ddkrdSddS)zThrow an error.rzFile is not open for writing.N)r&r;rQrXrNrs r. write_errorz1FakeFileWrapper._write_error..write_error}sT{ #1ds47||q?P?P1 KK7 8 8 8 8 8r/r)r,rs` r.rzFakeFileWrapper._write_error|s$ 9 9 9 9 9r/c|jA|jt|jjkr|jj|j}|||vrdSdS)NTF)r<rXr;r\r_s r.rYzFakeFileWrapper._is_opensP < # s4;K;V7W7W(W(W)4T\BJ%$**<*<tur/c^|js#|stddSdS)NzI/O operation on closed file)r'rYrOr_s r.rhz FakeFileWrapper._check_open_files>~ =dmmoo =;<< < = = = =r/cl|js|d|jSNzFile is not open for reading)r+rNr5__iter__r_s r.rzFakeFileWrapper.__iter__s3z 8 KK6 7 7 7x  """r/cb|js|dt|jSr)r+rNrr5r_s r.__next__zFakeFileWrapper.__next__s-z 8 KK6 7 7 7DH~~r/)F)r(rr(Nr)1r0r1r2r3r#r rrr4rr+r?r BaseExceptionrrHrrNrQrVrFrrarfrZrlrmr9r:rjrcrkrrrrrrrvr rrrrYrhr rrrrr/r.rrsH, !B+B+B+B+ B+  B+  B+B+%B+#B+B+B+3-B+ B+B+B+ !B+B+B+B+H4 ./-('   /c/h////  H    >>>>> 0####X# # $    ,,,,6**** - - - -  3  D    c(2222"U"t"""""3"8""""H!3!8!!!!F/3/8////b 5# 5$ 5 5 5 5 8    :(c((((''''''BXh$====#% x >?#### r/rc\eZdZdZdefdZdefdZdefdZd dede fd Z dd Z de fd Z d S)r!zCWrapper for a system standard stream to be used in open files list. stream_objectc"||_d|_dSr)_stream_objectr<)r,rs r.r+zStandardStreamWrapper.__init__s+&* r/r(c|jSr)rr_s r.rQz StandardStreamWrapper.get_objects ""r/cR|j|jSttjd)z:Return the file descriptor of the wrapped standard stream.NrTrUr_s r.rVzStandardStreamWrapper.filenorWr/r)ncZtt|jSr)r rcrr)r,rs r.rzStandardStreamWrapper.reads!E4.3355666r/NcdS)z+We do not support closing standard streams.Nrr_s r.rFzStandardStreamWrapper.closer/cdSrrr_s r.r'zStandardStreamWrapper.is_streamstr/r)r)r0r1r2r3rr+rQrrVrcrrFrr'rr/r.r!r!sMM+f++++#F####>>>>> 77c757777::::4r/r!cFeZdZdZdededdfdZdefdZdefd Z d d Z d S) r zAWrapper for a FakeDirectory object to be used in open files list.rr'rGrc>||_||_||_d|_dSr)rr'r;r<)r,rr'rGs r.r+zFakeDirWrapper.__init__s& '"%&* r/r(c|jS)zKReturn the FakeFile object that is wrapped by the current instance.rPr_s r.rQzFakeDirWrapper.get_objects r/cR|j|jSttjdrSrUr_s r.rVzFakeDirWrapper.filenorWr/NcV|jJ|j|jdS)zClose the directory.N)r<r;r[r_s r.rFzFakeDirWrapper.closes/|''' ))$,77777r/r) r0r1r2r3r$rr+rQrrVrFrr/r.r r sKK +" + +% + + + + M    >>>>> 888888r/r c eZdZdZ ddddededefdZdd Zd e e e d e e d e e d dfdZ ddZd efdZdded efdZddZded efdZddZd efdZd efdZd efdZdS) r"zdWrapper for a read or write descriptor of a real pipe object to be used in open files list. rNrGrfd can_writemodec||_||_||_d|_d|_d|_|rt |||_dSdSr)r;rrrr< real_filer)r,rGrrrs r.r+zFakePipeWrapper.__init__sU&"&*   ,!"d^^DNNN , ,r/r(c|S)=To support usage of this fake pipe with the 'with' statement.rr_s r.r?zFakePipeWrapper.__enter__r@r/rArBrCNc.|dS)rNrErGs r.rHzFakePipeWrapper.__exit__rIr/c|jSrrPr_s r.rQzFakePipeWrapper.get_objects r/cR|j|jSttjd)z3Return the fake file descriptor of the pipe object.NrTrUr_s r.rVzFakePipeWrapper.filenorWr/r)numBytescx|jr|j|Stj|j|S)zRead from the real pipe.)rrrr)r,rs r.rzFakePipeWrapper.reads6 > 1>&&x00 0wtw)))r/cdS)zFlush the real pipe?Nrr_s r.rZzFakePipeWrapper.flushrr/rFcx|jr|j|Stj|j|S)zWrite to the real pipe.)rrrrrs r.rzFakePipeWrapper.write s6 > 2>''11 1x***r/c|jJ|jj|j}|J|||jr|jdSt j|jdS)zClose the pipe descriptor.N)r<r;r\r]rrFrrr_s r.rFzFakePipeWrapper.closes~|'''%0> %%%$ >  N " " " " " HTW     r/c|j Sz0The pipe end can either be readable or writable.rr_s r.readablezFakePipeWrapper.readables >!!r/c|jSrrr_s r.writablezFakePipeWrapper.writables ~r/cdS)zA pipe is not seekable.Frr_s r.seekablezFakePipeWrapper.seekable"rr/)rN)r(r"rr)r0r1r2r3rrr4r+r?rrrrrHrQrVrcrrZrrFrrrrr/r.r"r"s ,,$, , ,  ,,,, 4 ./-('       >>>>> **S*%**** ####+e+++++    "$""""$$r/r")5r3r}rrerrrrrtypesrtypingrrrr r r r r rrrrrpyfakefsrpyfakefs.helpersrrrrrrrrrrpyfakefs.fake_filesystemrAnyFileWrapperr  Exceptionr&r#rrr$r rr!r r"rr/r.rs                           8777777 + ,      y    w4w4w4w4w4w4w4w4t     8   ,,,,,8,,,^gggggHgggTKFKFKFKFKF]KFKFKF\ZZZZZZZZz488888888>OOOOOOOOOOr/