0gdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZdd lmZmZdd lmZd Zd ZdZ dZ! ej"Z#n #e$$re%Z#YnwxYwGdde#Z&e&Z'e j(dkr1ej)Z*Gdde*Z+Gdde+Z,Gdde+Z-Gddej.Z/GddZ0GddZ1Gdd ej.Z2e j(d!krOd"e d#e fd$Z3ej4e2ej5D]0\Z6Z7e68d%se9e2e6e3e71Gd&d'Z:Gd(d)Z;dS)*aA fake implementation for pathlib working with FakeFilesystem. New in pyfakefs 3.0. Usage: * With fake_filesystem_unittest: If using fake_filesystem_unittest.TestCase, pathlib gets replaced by fake_pathlib together with other file system related modules. * Stand-alone with FakeFilesystem: `filesystem = fake_filesystem.FakeFilesystem()` `fake_pathlib_module = fake_filesystem.FakePathlibModule(filesystem)` `path = fake_pathlib_module.Path('/foo/bar')` Note: as the implementation is based on FakeFilesystem, all faked classes (including PurePosixPath, PosixPath, PureWindowsPath and WindowsPath) get the properties of the underlying fake filesystem. N)PurePath)Callable)quote_from_bytes) fake_scandir) use_scandir)FakeFilesystem) FakeFileOpen) FakeOsModuleuse_original_os)IS_PYPYc*|t_tjdkr>t |t j_t|t j _dSt|}|j }|t j_|t j _dS)z6Initializes the fake module with the fake file system. N) FakePath filesystemsys version_info_FakeWindowsFlavourFakePathlibModulePureWindowsPath_flavour_FakePosixFlavour PurePosixPathr path)rfake_os fake_paths /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_pathlib.py init_moduler5s|%H '!!5H5T5T)23DZ3P3P'000z**L 5>)23<'000c`tjfd}t|S)NcB|jt|g|Ri|SNrstr)pathobjargskwargsstrfuncs r_wrappedz_wrap_strfunc.._wrappedFs.ww)3w<<I$III&IIIr  functoolswraps staticmethodr)r*s` r _wrap_strfuncr0EsF_WJJJJJ  ! !!r c`tjfd}t|S)NcX|jt|t|g|RSr#r$pathobj1pathobj2r'r)s rr*z&_wrap_binary_strfunc.._wrappedN.wx*CMM3x==P4PPPPr r+r/s` r_wrap_binary_strfuncr7MF_WQQQQQ  ! !!r c`tjfd}t|S)NcX|jt|t|g|RSr#r$r3s rr*z._wrap_binary_strfunc_reverse.._wrappedVr6r r+r/s` r_wrap_binary_strfunc_reverser;Ur8r ceZdZdZeejZedZeejZe ree j Z e e dr edZndZdZeejZeejZeejZeejZedZedZd ejkr ed Zejd kred Zd ZeejZeej Z dS) _FakeAccessorzQAccessor which forwards some of the functions to FakeFilesystem methods. c0tj||dSNF)follow_symlinks)rstat)fsrs rz_FakeAccessor.ks,RuMMMr lchmodc2tj|||dSr?)rchmod)rBrmodes rrCz_FakeAccessor.us!>#7D$$$$r c td)z+Raises not implemented for Windows systems.z%lchmod() not available on this systemNotImplementedErrorselfr&r'r(s rrDz_FakeAccessor.lchmod{s%&MNN Nr cd|vrUtjdkrtd|ds.tjtjvst rtd|jjt|g|Ri|S)Nr@r zs!~'< ($( ( ( r c2tj|||dS)NF)create_missing_dirs)rcreate_symlink)rBfpathtarget target_is_dirs rrCz_FakeAccessor.s!1N v52 2 2 r )rc.tj|||Sr#rlinkrB file_path link_targets rrCz_FakeAccessor.~/BI{00r rNc.tj|||Sr#r`rbs rrCz_FakeAccessor.rer c(tjSr#)rQgetcwdrLs rrhz_FakeAccessor.getcwds9;; r N)!__name__ __module__ __qualname____doc__r0rrAlstatlistdirrrscandirhasattrrQrDrFmakedirmkdirremoveunlinkrmdirr7rUreplacer;symlinkrrlink_torarhreadlinkutimer rr=r=cs =, - -D MMM  EmN233G6- 455wr8 O     O O O G G G M.0 1 1E ]>0 1 1F M.. / /E ! !."7 8 8F""  G +*  G !!!&&      7""##       }^455H M.. / /EEEr r=rcFeZdZdZdZdZdZdZdZde e de dd zDd e e d e d d zDzZ fd Z e efdZdZe dZddZdZdZdZdZdZdZxZS) _FakeFlavourz9Fake Flavour implementation used by PurePath and _FlavourN/Fz\\?\c,h|]}t|Sr|chr.0xs r z_FakeFlavour.sGGGAQGGGr azc,h|]}t|Sr|rrs rrz_FakeFlavour.s1K K K CFFK K K r AZc||_|j|_|j|_|j|_tt| dSr#) rpath_separatorsepalternative_path_separatoraltsep is_windows_fshas_drvsuperr~__init__)rLr __class__s rrz_FakeFlavour.__init__sJ(DO!0DH$?DK%3DL , % % . . 0 0 0 0 0r cd}||rC|dd}|dd}|dr||ddz }d|ddz}||fS)NzUNC\r\) startswith)r ext_prefixprefixs r_split_extended_pathz!_FakeFlavour._split_extended_pathsvFz** +bqbABBx??7+++d2A2h&F$qrr(?D4< r c|dd}|dd}||kr3||kr-||\}}|dd}|dd}nd}|dd}||kr||kr||kr||d}|dkrl|||dz}||dzkrJ|dkrt|}|r||d|z|||dzdfS|d||||dzdfSdx} } |dkr||jvr|dd} |dd}|}||kr|} ||}|| z| |fS)Nrrrr:)rfindlen drive_letterslstrip) rLrrfirstsecondrthirdindexindex2drvroots r_splitroot_with_drivez"_FakeFlavour._splitroot_with_drives1IE!A#YF}}# $88>> QqS ac1IE}}#%3,,  #q))B;;!YYsEAI66F**!R<<%(YYF!T#)D6N#:CfqjllAS#SS#GVG}c4 3EEEOC$}}$*z/_FakeFlavour.casefold_parts..s 111a 111r )rrrLpartss rcasefold_partsz_FakeFlavour.casefold_partss(, 21151111Lr cjifd|rdn jj}|t |pS)Nc| rd}| D]}|r|dkr |dkr| \}}}+| z|z}|vr|}|Btd|z j|}d|<||}||<#t $r$}|jtjkr r|}Yd}~d}~wwxYw|S)Nr.z..zSymlink loop from %r) rsplit rpartition RuntimeErrorrrzOSErrorerrnoEINVAL) rrestname_newpathr\e_resolveseenrLrstricts rrz-_FakeFlavour._resolve_posix.._resolve&s;??3''D JJsOO--D!43;; t||%)__S%9%9 a "Sj4/G$#G}+$++AG+KLLL -!%!9!9'!B!B)-W 'xf55(,W #'''7el22v2! ' ' sB44 C">CC"r)r is_absolutercwdr%)rLrrbaserrrs` ` @@@r_resolve_posixz_FakeFlavour._resolve_posix"s(CD$ $ $ $ $ $ $ $ $ P))++D221DD8D#d)),,3 3r ct|}|stjSd}|rY|j|s%|jt j||j|S |j|}||S|j |tj |S#t$r%|}|j |d}YnwxYw)NTr)r%rQrhrexistsraise_os_errorrENOENT resolve_path joinpathsrbasenamer splitpath)rLrr previous_ss r_resolve_windowsz_FakeFlavour._resolve_windowsQst99D #y{{"J --d33GO225<FFF33D999  #;;DAA &-#'K#88 "'"2"2:">">   #BBB%) #88>>qAB sC,D D cr|jjr|||S|||S)z/Make the path absolute, resolving any symlinks.)rrrr)rLrrs rresolvez_FakeFlavour.resolvehs;, ;,,T6:::&&tV44 4r c(|sR tjdS#t$r2ddl}|tjjcYSwxYwddl} ||jS#t$rtd|zwxYw).Return the home directory of the current user.HOMErN%Can't determine home directory for %r rQenvironKeyErrorpwdgetpwuidgetuidpw_dirgetpwnamrrLusernamers r gethomedirz_FakeFlavour.gethomedirn <:f--<<<JJJ<< 44;;;;<  <<1188&BXM9AAA44Br#)rjrkrlrmrrrrext_namespace_prefixrangeordrrr.rrrrrrrrrr __classcell__)rs@rr~r~sGG (GGss3xxSA)F)FGGGK K !E##c((CCHHqL99K K K   1 1 1 1 1 2F     $ ,$ ,$ ,L  $ $  $ 4 4 4 4        - 4- 4- 4^   . 5 5 5        r r~ceZdZdZhddeddDzdeddDzZeZdZdZ d Z d Z d S) rzFlavour used by PureWindowsPath with some Windows specific implementations independent of FakeFilesystem properties. >AUXCONNULPRNch|]}d|zS)zCOM%dr|ris rrz_FakeWindowsFlavour.111qw{111r rrOch|]}d|zS)zLPT%dr|rs rrz_FakeWindowsFlavour.rr c|sdS|jjr|ddrdS|ddd|jvS)z=Return True if the path is considered reserved under Windows.Fr\\rr)rrr partitionupperreserved_namesrs r is_reservedz_FakeWindowsFlavour.is_reservedsm u, q1D1DV1L1L u9&&s++A.4466$:MM Mr cj|j}t|dkrc|ddkrW|ddd}d|dt |dSdt |dzS) z$Return a file URI for the given pathrrrNrzfile:///zutf-8zfile:)driveras_posixrurlquote_from_bytesencode)rLrrrs rmake_uriz_FakeWindowsFlavour.make_uris JE5zzQ58s??}}qrr*11#66EE' G(<(<=== !4T]]__5K5KG5T5T!U!UUUr cdtjvrtjd}nzdtjvrtjd}nYdtjvr< tjd}n#t$rd}YnwxYw|tjdz}ntd|rtjd|kr||f\}}}|dtjdkrtd |z||d<|s|r$||z||d d z}n||}|S) rr USERPROFILEHOMEPATH HOMEDRIVErzCan't determine home directoryUSERNAMErrrN)rQrrr parse_partsjoin)rLruserhomerrrs rrz_FakeWindowsFlavour.gethomedirs\##:f-"*,,:m4rz))*[1CCCCCJ!77"#CDDD 4 :j)X55'+'7'7 'D'D$CuRyBJz$:::*FQ!)E"I4d4#&: %)0D0D#D#'99U#3#3OsA%% A43A4cntjtj|tjjSr#)recompilefnmatch translate IGNORECASE fullmatchrLpatterns rcompile_patternz#_FakeWindowsFlavour.compile_patterns$:g/88"-HHR Rr N) rjrkrlrmrrntpathpathmodrr rrr|r rrrs  ) ( (11EE!RLL111 211EE!RLL111 2   N N N V V V"! ! ! F S S S S Sr rc.eZdZdZeZdZdZdZdZ dS)rzFlavour used by PurePosixPath with some Unix specific implementations independent of FakeFilesystem properties. cdS)NFr|rs rrz_FakePosixFlavour.is_reserveds5r cDt|}dt|zS)Nzfile://)bytesr)rLrbpaths rr z_FakePosixFlavour.make_uris#$KKE25999 9r c(|sR tjdS#t$r2ddl}|tjjcYSwxYwddl} ||jS#t$rtd|zwxYw)Nrrrrrs rrz_FakePosixFlavour.gethomedirrrcXtjtj|jSr#)rrrrrrs rrz!_FakePosixFlavour.compile_patterns :g/8899C Cr N) rjrkrlrm posixpathrrr rrr|r rrrsf      : : :    & D D D D Dr rcBeZdZdZdZdZejdddkredZ edZ ejdkrdd Z d Z ed Z ejd krdd ZddZdZd dZdZd!dZedZdZdZdZd"dZejd kr dZdZdSdS)#rzReplacement for pathlib.Path. Reimplement some methods to use fake filesystem. The rest of the methods work as they are, as they will use the fake accessor. New in pyfakefs 3.0. Nc|tjur$|jjr tjn tj}t jdkr||St |S))Creates the correct subclass based on OS.r) rPathrr WindowsPath PosixPathrr _from_partsobject__new__clsr'r(s rr.zFakePath.__new__sh #( ( (>/1!--&0   g % %??4(( (>>#&& &r rrNct|}|||\}}}||_||_||_|Sr#)r-r._init _parse_args_drv_root_parts)r0r'rLrrrs rr,zFakePath._from_partssT>>#&&D JJLLL#//55 CuDIDJDKKr ct|}||_||_||_||Sr#)r-r.r4r5r6r2)r0rrrrLs r_from_parsed_partszFakePath._from_parsed_partss:>>#&&DDIDJDK JJLLLKr )r c,t|_d|_dS)z#Initializer called from base class.FN)_fake_accessor _accessor_closed)rLtemplates rr2zFakePath._init(s,DN DLLLr c t|S)zSReturns the underlying path string as used by the fake filesystem. )r%ris r_pathzFakePath._path/s4yyr c,||jjS)zjReturn a new path pointing to the current working directory (as returned by os.getcwd()). )rr)r0s rrz FakePath.cwd5s s3>%&&&r rcrtjdkr|d}n|tdd}||j||}|5|t|}|j |}t|S)aMake the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows). Args: strict: If False (default) no exception is raised if the path does not exist. New in Python 3.6. Raises: OSError: if the path doesn't exist (strict=True or Python < 3.6) )rNFz5resolve() got an unexpected keyword argument 'strict'T)r) rrrP_raise_on_closedrrrAr%absoluter absnormpathr)rLrrs rrzFakePath.resolve>s6))>"F%#O  ! ! # # #=((V)D| 4==??++?..t44DD>> !r rrc|t|j||||||S)zOpen the file pointed by this path and return a fake file object. Raises: OSError: if the target object is a directory, the path is invalid or permission is denied. )rDr rr@)rLrG bufferingencodingerrorsnewlines ropenz FakePath.open^sI ,|DO,, JJLL$ 8VW   r ct|j|d5}|cdddS#1swxYwYdS)zOpen the fake file in bytes mode, read it, and close the file. Raises: OSError: if the target object is a directory, the path is invalid or permission is denied. rbrGNr rr@read)rLfs r read_byteszFakePath.read_bytesjs+\$/ * * JJLLt     6688                  sAAAct|j|d||5}|cdddS#1swxYwYdS)zO Open the fake file in text mode, read it, and close the file. rG)rGrJrKNrQ)rLrJrKrSs r read_textzFakePath.read_textvs+\$/ * * JJLLsXf     6688                  sAAAct|}t|j|d5}||cdddS#1swxYwYdS)a Open the fake file in bytes mode, write to it, and close the file. Args: data: the bytes to be written Raises: OSError: if the target object is a directory, the path is invalid or permission is denied. wbrPN) memoryviewr rr@write)rLdataviewrSs r write_byteszFakePath.write_bytess$ *\$/ * * JJLLt    ! 774== ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !sA##A'*A'clt|tstd|jjz|t jdkrtdt|j| d|||5}| |cdddS#1swxYwYdS)atOpen the fake file in text mode, write to it, and close the file. Args: data: the string to be written encoding: the encoding used for the string; if not given, the default locale encoding is used errors: (str) Defines how encoding errors are handled. newline: Controls universal newlines, passed to stream object. New in Python 3.10. Raises: TypeError: if data is not of type 'str'. OSError: if the target object is a directory, the path is invalid or permission is denied. zdata must be str, not %sNrNz9write_text() got an unexpected keyword argument 'newline'w)rGrJrKrL) isinstancer%rPrrjrrr rr@rZ)rLr[rJrKrLrSs r write_textzFakePath.write_texts $$$ R69PPQQ Q  3#3g#=#=N +\$/ * * JJLL     ! 774== ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !sB))B-0B-c0tjd}|jjtjdkkrtj|d}|jjr"tjdd|}n tjd|}|j|s|j ||| tj |jj S)zrReturn a new path pointing to the user's home directory (as returned by os.path.expanduser('~')). ~ntrzC:Usershome) rQr expanduserrrrrrr create_dirrwrr)r0rfrs rrfz FakePath.homes w!!#&& > 'BGtO < <w}}T**1-H~+ 6w||D'8<<w||FH55>((.. 0))$///s4<<(EFFGGGr c|} |}n*#t$r|j|}YnwxYw|j|jko|j|jkS)a/Return whether other_path is the same or not as this file (as returned by os.path.samefile()). Args: other_path: A path object or string of the file object to be compared with Raises: OSError: if the filesystem object doesn't exist. )rAAttributeErrorrst_inost_dev)rL other_pathstother_sts rsamefilezFakePath.samefilesxYY[[ 8!((HH 8 8 8++J77HHH 8yHO+L X_0LLs+$AActtj|tjj|jjS)zkReturn a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser) ) rrQrrgr@rwrrrris rrgzFakePath.expandusersO G  tzz|| , , 4 4 T_;     r cdtjdkr|jr|dSdSdS)N)r )rrr= _raise_closedris rrDzFakePath._raise_on_closeds=  f $ $ $     % $ $ $r Tc||rk|r0|j|ddS|jt j|dS|d}| | |dS)aCreate a fake file for the path with the given access mode, if it doesn't exist. Args: mode: the file mode for the file if it does not exist exist_ok: if the file already exists and this is True, nothing happens, otherwise FileExistError is raised Raises: FileExistsError: if the file exists and exits_ok is False. N)timesr_) rDrrr{r@rrEEXISTrMcloserF)rLrGexist_ok fake_files rtouchzFakePath.touchs  ;;==  K%%djjll$%?????..u|TZZ\\JJJJJ #I OO    JJt     r c|jjr|jo|jStj|Sr#)rrrrrQrisabsr@ris rrzFakePath.is_absolutes:, 0z/di/7==.. .r cT|jjr|jsdS|jddrdS|jdddddd}|tjvS)NFrrrrr ) rr_tailrrrstriprpathlib_WIN_RESERVED_NAMESrLrs rrzFakePath.is_reserveds?0   uz!}''// u:b>++C003==cBB1ELLSQQD::<<7#>> >r r#)rGrNNN)NN)NNN)ruT)rjrkrlrmrr.rr classmethodr,r8r2r@rrrMrTrVr]rarfrprgrDr|rrr|r rrrsJ ' ' ' w&&           '!! ! ! ! ! ''['  '!! " " " "@         ! ! !!!!!> H H[ HMMM$   !!!. 7""  / / /  ? ? ? ? ?#"r rceZdZdZdZGddeZGddeZGddeeZ Gd d eeZ eZ d Z d S) raaUses FakeFilesystem to provide a fake pathlib module replacement. Can be used to replace both the standard `pathlib` module and the `pathlib2` package available on PyPi. You need a fake_filesystem to use this: `filesystem = fake_filesystem.FakeFilesystem()` `fake_pathlib_module = fake_filesystem.FakePathlibModule(filesystem)` c<t|t|_dS)z Initializes the module with the given filesystem. Args: filesystem: FakeFilesystem used to provide file system information N)rr_pathlib_modulerLrs rrzFakePathlibModule.__init__s  J&r ceZdZdZdZdS)FakePathlibModule.PurePosixPathzLA subclass of PurePath, that represents non-Windows filesystem pathsr|Nrjrkrlrm __slots__r|r rrrs   r rceZdZdZdZdS)!FakePathlibModule.PureWindowsPath@A subclass of PurePath, that represents Windows filesystem pathsr|Nrr|r rrr"NN r rc(eZdZdZdZdZdZdZdS)FakePathlibModule.WindowsPathzjA subclass of Path and PureWindowsPath that represents concrete Windows filesystem paths. r|c td)Nz*Path.owner() is unsupported on this systemrIris rownerz#FakePathlibModule.WindowsPath.owner.%&RSS Sr c td)Nz*Path.group() is unsupported on this systemrIris rgroupz#FakePathlibModule.WindowsPath.group1rr c td)Nz-Path.is_mount() is unsupported on this systemrIris ris_mountz&FakePathlibModule.WindowsPath.is_mount4s%&UVV Vr N)rjrkrlrmrrrrr|r rr*r's]    T T T T T T W W W W Wr r*c"eZdZdZdZdZdZdS)FakePathlibModule.PosixPathzlA subclass of Path and PurePosixPath that represents concrete non-Windows filesystem paths. r|clddl}||jjS)zReturn the username of the file owner. It is assumed that `st_uid` is related to a real user, otherwise `KeyError` is raised. rN)rrrAst_uidpw_name)rLrs rrz!FakePathlibModule.PosixPath.owner>- JJJ<< 233; ;r clddl}||jjS)zReturn the group name of the file group. It is assumed that `st_gid` is related to a real group, otherwise `KeyError` is raised. rN)grpgetgrgidrAst_gidgr_name)rLrs rrz!FakePathlibModule.PosixPath.groupGrr N)rjrkrlrmrrrr|r rr+r7sC    < < < < < < < >#&& &r N)rjrkrlrmrrrQrr_WindowsFlavour _PosixFlavourrrr%r.r|r rrrls  '!!w$ $G # % % %&&((   W__66) ' ' ' ' 'r rrNrSreturncFtjfd}|S)zuDecorator used for real pathlib Path methods to ensure that real os functions instead of faked ones are used.cdt5|i|cdddS#1swxYwYdSr#)r )r'r(rSs rwrappedz!with_original_os..wrappeds "" * *q$)&)) * * * * * * * * * * * * * * * * * *s %)))r,r-)rSrs` rwith_original_osrs:    * * * *   *r __c>eZdZdZdZedZdZdZdZ dS)RealPathlibPathModulezAPatches `pathlib.Path` by passing all calls to RealPathlibModule.Nc,t|tSr#rrs rrz'RealPathlibPathModule.__instancecheck__s(H---r cH|jt|j_dSdSr#) real_pathlibrrris rrzRealPathlibPathModule.__init__s)   $*;*=*=DN ' ' ' % $r ct|i|Sr#)rrs rrzRealPathlibPathModule.__call__s((((r c6t|jj|Sr#)rrr)rs rrz!RealPathlibPathModule.__getattr__rr ) rjrkrlrmrrrrrrr|r rrrseKKL..[. >>>)))55555r rceZdZdZdZGddeZGddeZej dkrGdd e eZ nGd d e eZ e Z d Zd S)rzUsed to replace `pathlib` for skipped modules. As the original `pathlib` is always patched to use the fake path, we need to provide a version which does not do this. ct|_dSr#)rrris rrzRealPathlibModule.__init__s&r ceZdZdZdZdS)RealPathlibModule.PurePosixPathz>A subclass of PurePath, that represents Posix filesystem pathsr|Nrr|r rrrsLL r rceZdZdZdZdS)!RealPathlibModule.PureWindowsPathrr|Nrr|r rrrrr rwin32ceZdZdZdZdS)RealPathlibModule.WindowsPathzrA subclass of Path and PureWindowsPath that represents concrete Windows filesystem paths. r|Nrr|r rr*r  IIIr r*ceZdZdZdZdS)RealPathlibModule.PosixPathztA subclass of Path and PurePosixPath that represents concrete non-Windows filesystem paths. r|Nrr|r rr+rrr r+c,t|j|Srrrs rrzRealPathlibModule.__getattr__rr N)rjrkrlrmrrrrrplatformrr*r+r)rr|r rrrs ''' (  |w     (O         -    D33333r r)rs!$   @@@@@@!!!!!!//////333333++++++::::::::$$$$$$ = = = """"""""" HHHHHS0S0S0S0S0HS0S0S0lgGAAAAAwAAAFOSOSOSOSOSlOSOSOSb$D$D$D$D$DL$D$D$DNL?L?L?L?L?w|L?L?L?^L3L3L3L3L3L3L3L3^........*'''''w|''':g H     'G&x1CDD::bt$$ : GHd$4$4R$8$8 9 9 955555555,)3)3)3)3)3)3)3)3)3)3s0A88BB