^cUfddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZmZmZm Z mZejdZejZejZejZejZejZejZejZejZejZejZejZej j!Z!ej"Z"ej#Z#dZ$Gdd Z%Gd d Z&dej?Z@d#ZAd$ZBdaCdaDd%ZEd&ZFd'ZGd(ZHd)ZIejJejKhZLd*ZMd>d+ZNd>d,ZOd-ZPd.ZQd/ZRd0ZSd1ZTd2ZUGd3d4ZVd?d5ZWd6ZXd7ZYd8ZZd9Z[d:Z\d;Z]dS)@N)_)getattr)encodingerrorpolicypycompatwin32osutilcfeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdS)mixedfilemodewrappera)Wraps a file handle when it is opened in read/write mode. fopen() and fdopen() on Windows have a specific-to-Windows requirement that files opened with mode r+, w+, or a+ make a call to a file positioning function when switching between reads and writes. Without this extra call, Python will raise a not very intuitive "IOError: [Errno 0] Error." This class wraps posixfile instances when the file is opened in read/write mode and automatically adds checks or inserts appropriate file positioning calls when necessary. rrcvt|d|t|dddS)N_fp_lastopr)object __setattr__selffps 3/usr/lib/python3/dist-packages/mercurial/windows.py__init__zmixedfilemodewrapper.__init__Cs84+++4A.....c8|j|SNr __enter__rs rrzmixedfilemodewrapper.__enter__Gs  rc>|j|||dSrr__exit__)rexc_typeexc_valexc_tbs rr"zmixedfilemodewrapper.__exit__Ks" (GV44444rc,t|j|Srrrrnames r __getattr__z mixedfilemodewrapper.__getattr__Ntx&&&rc8|j||Sr)rr)rr)values rrz mixedfilemodewrapper.__setattr__Qsx##D%000rcP|jdtjdS)Nr)rseekosSEEK_CURrs r _noopseekzmixedfilemodewrapper._noopseekTs   a%%%%%rcht|d|j|jj|i|SNr)rrOPNONErr/rargskwargss rr/zmixedfilemodewrapper.seekWs54DK888tx}d-f---rc|j|jkr|t|d|j|j|Sr4)rOPREADr2rrOPWRITErwrite)rds rr<zmixedfilemodewrapper.write[sO <4; & & NN   4DL999x~~a   rc|j|jkr|t|d|j|jj|i|Sr4)rr: _noopeseekrrr;r writelinesr6s rr@zmixedfilemodewrapper.writelinesbsU <4; & & OO   4DL999"tx"D3F333rc|j|jkr|t|d|j|jj|i|Sr4)rr;r2rrr:rreadr6s rrBzmixedfilemodewrapper.readisT <4< ' ' NN   4DK888tx}d-f---rc|j|jkr|t|d|j|jj|i|Sr4)rr;r2rrr:rreadliner6s rrDzmixedfilemodewrapper.readlinepsU <4< ' ' NN   4DK888 tx $1&111rc|j|jkr|t|d|j|jj|i|Sr4)rr;r2rrr:r readlinesr6s rrFzmixedfilemodewrapper.readlineswsU <4< ' ' NN   4DK888!tx!426222rN)__name__ __module__ __qualname____doc__r5r:r;rrr"r*rr2r/r<r@rBrDrFrrrr2s  F FG///555'''111&&&...!!!444...22233333rrc0eZdZdZdZdZdZdZdZdS)fdproxyzeWraps osutil.posixfile() to override the name attribute to reflect the underlying file name. c"||_||_dSr)r)r)rr)rs rrzfdproxy.__init__s rc8|j|Srrrs rrzfdproxy.__enter__s  rc>|j|||dSrr!)rr# exc_value tracebacks rr"zfdproxy.__exit__s" (Iy99999rc*t|jSr)iterrrs r__iter__zfdproxy.__iter__sDH~~rc,t|j|Srr'r(s rr*zfdproxy.__getattr__r+rN) rGrHrIrJrrr"rUr*rKrrrMrMsi :::'''''rrMrcT t|||}t||}d|vr |dtjd|vrt |S|S#t$r6}t|j tj |d|j d}~wwxYw)z/Open a file with even more POSIX-like semanticsar+z: N) r posixfilerMr/r0SEEK_ENDr WindowsErrorIOErrorerrnor strfromlocalstrerror)r)mode bufferingrerrs rr\r\s   dD) 4 4T2   4<< GGAr{ # # # 4<<'++ +     I8#8#>#>#>#> M    sA"A'%A'' B'11B""B'cN |S#t$rYdSwxYwNF)isattyAttributeErrorrs r_isattyrks7yy{{ uus  $$cd} tj}|dks|dkrn$|dkrt|dkr |dd}n||z}Dtjdtjdt j|S) zPrompt for password with echo off, using Windows getch(). This shouldn't be called directly- use ``ui.getpass()`` instead, which checks if the session is interactive first. T  NrX)msvcrtgetwchKeyboardInterruptputwchr unitolocal)pwcs r get_passwordrys B  MOO ::e  <<# # ::CRCBBaB  M% M%  r " ""rc0eZdZdZdZdZdZdZdZdS) winstdoutzSome files on Windows misbehave. When writing to a broken pipe, EINVAL instead of EPIPE may be raised. When writing too many bytes to a console at the same, a "Not enough space" error may happen. Python 3 already works around that. c||_dSrrjrs rrzwinstdout.__init__s rc,t|j|Sr)rr)rkeys rr*zwinstdout.__getattr__stw$$$rc\ |jdS#t$rYdSwxYwr)rcloser_rs rrzwinstdout.closes<  GMMOOOOO    DD s  ++c |j|S#t$rS}|jdkrt j|s|ttjdd}~wwxYw)Nr Broken pipe)rr<r_r`r lasterrorwaspipeerrorrEPIPE)rsinsts rr<zwinstdout.writesv 67==## # 6 6 6zQu'B4'H'H JJLLL%+}55 5  6s A9AA44A9c |jS#t$r4}tj|stt jdd}~wwxYw)Nr)rflushr_r rr`r)rrs rrzwinstdout.flushs^ 67==?? " 6 6 6.t44 %+}55 5 6s A/AAN) rGrHrIrJrr*rr<rrKrrr{r{si%%% 66666666rr{cdSNTrKrKrr openhardlinksr 4rcF|dd}|ddkr |dd}|S)z$  rs^[a-z]:z^[a-z]:cttj|}t|trBt |r'|dd|ddz}nAt|r'|dd|ddz}|S)Nrr) r0rabspath isinstancebytes DRIVE_RE_Bmatchr DRIVE_RE_S)rabs_paths rrrAswt$$H (E""8   H % % <!}**,,x|;H   ( # #8AaC=&&((8ABB<7 OrcdSrgrK)s1s2s rsamestatrUrrctfddDsStjtjtjzdz}d}d}t }||krv||dz}|dkre|dzdt } d}|d d|zd zz }n#t$r||zz }|dz }YnwxYw|d krg|dzdt } d }d|}|d |zd zz }n#t$r|d zz }|dz }YnwxYw|d kr|dz|d zd kr|d zdt } d}d|}| |ddkr |d |zd zz }n |d|zdzz }n#t$r|dzz }|dz }YnwxYwd}|dz }||dz}|dkr%||vr!||z }|dz }||dz}|dkr||v!| |ddkr |d |zd zz }n|d |zz }|dkr|dz}nf|dkr!|dz|kr|dz|d zdvr|dz }n?|dkr4|dz|kr+|dz|d zdvr||dz|d zz }|dz }n||z }|dz }||kv|S)aConvert shell variables in the form $var and ${var} inside ``path`` to %var% form. Existing Windows style variables are left unchanged. The variables are limited to the given environment. Unknown variables are left unchanged. >>> e = {b'var1': b'v1', b'var2': b'v2', b'var3': b'v3'} >>> # Only valid values are expanded >>> shelltocmdexe(b'cmd $var1 ${var2} %var3% $missing ${missing} %missing%', ... e) 'cmd %var1% %var2% %var3% $missing ${missing} %missing%' >>> # Single quote prevents expansion, as does \$ escaping >>> shelltocmdexe(b"cmd '$var1 ${var2} %var3%' \$var1 \${var2} \\", e) 'cmd "$var1 ${var2} %var3%" $var1 ${var2} \\' >>> # $$ is not special. %% is not special either, but can be the end and >>> # start of consecutive variables >>> shelltocmdexe(b"cmd $$ %% %var1%%var2%", e) 'cmd $$ %% %var1%%var2%' >>> # No double substitution >>> shelltocmdexe(b"$var1 %var1%", {b'var1': b'%var2%', b'var2': b'boom'}) '%var1% %var1%' >>> # Tilde expansion >>> shelltocmdexe(b"~/dir ~\dir2 ~tmpfile \~/", {}) '%USERPROFILE%/dir %USERPROFILE%\\dir2 ~tmpfile ~/' c3 K|]}|vV dSrrK).0rxrs r z shelltocmdexe..ss'))QqDy))))))rs$'~s_-rrr'N"%$r{}s${~)rrs %USERPROFILE%r)rr) anyr sysbytesstring ascii_lettersdigitslenindex ValueErrorget)renvvarcharsresrpathlenrxvars` r shelltocmdexerYs 4 ))))&))) ) )  !5 !EFFNH C E$iiG '// " # :: $D$iiG $ 5))td6E6l*T11 $ $ $q4x!  $$YY $D$iiG ) 4(( 6E6ltczD((  $ $ $td{"!  $ $YYEAI )*d22EAIKK(d)) ( JJt,,Evv,CwwsC((C//tczD00us{T11!(((54<'C#aKEEE( *+3hh1==1HCQJEUUQY./A3hh1==773$$++4#:,,CC4#:%C88QJE II G##UQY*+}<< # #CC JJ G##UQY*+|;; 4 EAI-. .C QJEE 1HC  Y '//Z Js7(CCCD..E E AGG/.G/cttjdattjdja|r+t|st|s|Sdtd|zS)a >>> shellquote(br'C:\Users\xyz') '"C:\\Users\\xyz"' >>> shellquote(br'C:\Users\xyz/mixed') '"C:\\Users\\xyz/mixed"' >>> # Would be safe not to quote too, since it is all double backslashes >>> shellquote(br'C:\\Users\\xyz') '"C:\\\\Users\\\\xyz"' >>> # But this must be quoted >>> shellquote(br'C:\\Users\\xyz/abc') '"C:\\\\Users\\\\xyz/abc"' Ns (\\*)("|\\$)s[^a-zA-Z0-9._:/-]s"%s"s\1\1\\\2)_quotererecompile_needsshellquotesearchsubrs rrrs:.// :&;<<C!!$$X__Q-?-? X\\,22 22rcn|dr|dr |ddS|S)NrrrX)rendswithrs r_unquoters;||Dajj..2w Hrc^tjttj|dS)z3Parse a command string in cmd.exe way (best-effort)F)posix)r maplistr shlexsplitrs r shellsplitrs%  Hh&9!5&I&I&I J JJrcdSrrKsts risownerrrrctjdd}d|t jDtj |dvrdgfd}t j |vr ||Stjddt jD]1}|tj ||}||cS2|tj tj |S)a*Find executable for command searching like cmd.exe does. If command is a basename then PATH is searched for command. PATH isn't searched if command is an absolute or relative path. An extension from PATHEXT is found and added if not present. If command isn't found None is returned.sPATHEXTs.COM;.EXE;.BAT;.CMDcg|]}|SrKrK)rexts r zfindexe..sIIIIIIrrrcbD]*}||z}tj|r|cS+dS)z:Will append extension (if needed) and return existing fileN)r0rexists) pathcommandr executablepathextss r findexistingzfindexe..findexistingsH " "C$s*Jw~~j)) "!!!! "trsPATH)renvironrrsplitr ospathsepr0rsplitextrjoin expanduser expandvars)commandpathextrrrrs @rfindexer sN "":/EFFGIIw}}44X5GHHIIIH w  #))++x775~  |G$$$ $$Wc22889KLL!\"',,tW"="=>>  !    " <**27+=+=g+F+FGG H HHrc#Ki}tj|D]}t|}tj|\}}|sd}||d}|M fdt|dD}n#ttf$ri}YnwxYw| ||}||dVdS)zStat each file in files. Yield each stat, or None if a file does not exist or has a type we don't care about. Cluster and cache stat per directory to minimize number of OS stat calls..Ncfi|]-\}}}|jtvt||.SrK)st_mode _wantedkindsr)rnkrgetkinds r zstatfiles..8sH1awqy))\99QKK999rT) statS_IFMTrr0rr rlistdirFileNotFoundErrorNotADirectoryError setdefault)filesdircachenfdirbasecachedmaprs @r statfilesr))s  HkG$$ b\\GMM"%% T C S$'' = #*3#5#5 &'9:    ''T22Eiid######!$$s$BBBcv|s6 tjtjS#t$rYnwxYwdS)ziReturn the name of the user with the given uid. If uid is None, return the name of the current user.N)r fsencodegetpassgetuserModuleNotFoundError)uids rusernamer0CsS  $W_%6%677 7"    D   4s $) 66cdS)zkReturn the name of the group with the given gid. If gid is None, return the name of the current group.NrK)gids r groupnamer3Rs  4rctj|} tj|}n!#t$r}t |d}~wwxYwtj|Sr)r fsdecoder0readlinkrrir+)pathnamerlinkes rr6r6Ysj  X & &D {4      Q   T " ""s+ A AA ct|rdStj|tj|\}}|s"tj|\}}|ri|ri t|rdStj|n#t t f$rYdSwxYwtj|\}}|r|edSdSdSdS)zspecial version of os.removedirs that does not remove symlinked directories or junction points if they actually contain filesN)rr0rmdirrr rOSError)r)headtails r removedirsr?fst}}HTNNNt$$JD$ )W]]4(( d )4) t}}  HTNNNNG$    EE W]]4(( d )4)))))))))s1BBB,+B,c tj||dS#t$r(t|tj||YdSwxYw)z=atomically rename file src to dst, replacing dst if it existsN)r0renameFileExistsErrorunlink)rrs rrArAys` #s s  #ss.A  A cZdtjgtjddzDS)Nc6g|]}tj|SrK)r strtolocal)rargs rrzgethgcmd..s# P P PH  $ $ P P Prr)sysrargvrKrrgethgcmdrJs* P P0@38BQB<0O P P PPrctr)KeyError)r)s r groupmembersrMs NrcdSrgrK)rs risexecrOrrceZdZdZdZdS) cachestatcdSrrK)rrs rrzcachestat.__init__s rcdSrgrKrs r cacheablezcachestat.cacheablesurN)rGrHrIrrTrKrrrQrQs2   rrQc|tjtjf}nt|tt fs|f}|D]} tj|tj|5}d}|tj|}tj ||d}tj |cdddcS#1swxYwY#t$rYwxYwdS)a)Look up a key/value name in the Windows registry. valname: value name. If unspecified, the default value for the key is used. scope: optionally specify scope for registry lookup, this can be a sequence of scopes to look up in order. Default (CURRENT_USER, LOCAL_MACHINE). Nr) winregHKEY_CURRENT_USERHKEY_LOCAL_MACHINErlisttupleOpenKeyrra QueryValueExrvEnvironmentError)r~valnamescoperhkeyr)vals r lookupregrbs= })6+DE e} - -  8#8#=#=>> 0$&#099D)$55a8 *3// 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0     D s7'C 'AB=. C =C C C C  CCTcdS)z(check whether a stat result is a symlinkFrKrs r statislinkrd 5rcdS)z1check whether a stat result is an executable fileFrKrs r statisexecrgrerctrNotImplementedError)fdss rpollrls   rcg} tj|}|sn.||}|sn||Ed|S)z$Read all available data from a pipe.Tr)r peekpiperBappendr )pipechunkssizers rreadpiperssk F~d##   IIdOO   a 88F  rc td)Nzunsupported platformri)sockrs rbindunixsocketrvs 4 5 55r)rWrXrgr)NN)^r`r,rrr0rrrrHrVi18nrr rrmrrrr importmodr getvolumenamegetfsmountpoint getfstyper- hidewindowmakedirnlinksoslink samedevicesamefilesetsignalhandler spawndetachedrr testpidrCumaskrrMr\rrkryr{rrrrrrrrrrrrrrrr normcasespecsr normcasespec upperfallbacknormcasefallbackrrrrrrrrrS_IFREGS_IFLNKrr)r0r3r6r?rArJrMrOrQrb expandglobsrdrgrlrsrvrKrrrs    ( # #% O -   -     >)#    -  J3J3J3J3J3J3J3J3Z''''''''2    4 .###,$6$6$6$6$6$6$6$6N          +++...%%%,,,   RZ # # RZ " "     %+ )oooz 333<   KKKIII: dl+ $$$4     # # #)))&QQQ B         66666r