
    6h                      % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJrJrJrJrJrJrJrJ r J!r!  SSK"J#r#  SSK$J%r%  \RL                  (       a  SSK%r%SSK'J(r(  SS	K)J*r*J+r+J,r,J-r-J.r.J/r/J0r0  SS
K1J2r3J4r5  SSK6J7r7J8r8J9r9J:r:  \\\\\/(       d   e\RL                  (       a  SSK;J<r<  \!" SSS9r=\-R|                  " S5      r?S\@S'   \-R|                  " S5      rA\?R                  rB\?R                  rC\.R                  rD\.R                  rE\.R                  rF\.R                  rG\	R                  rI\IrJ\.R                  rK\0R                  rL\0R                  rM\0R                  rN\.R                  rP\.R                  (       a  SSK)JRrS  OSSK)JTrS  \,R                  rU\SR                  rV\SR                  rW\SR                  rX\SR                  rY\SR                  rZ\SR                  r[\SR                  r\\SR                  r]\SR                  r^\SR                  r_\SR                  r`\SR                  ra\SR                  rb\SR                  rc\AR                  rd\SR                  re\SR                  rf\SR                  rg\SR                  rh\SR                  ri\SR                  rj\SR                  rk\SR                  rl\SR                  rm\SR                  rn\SR                  ro\SR                  rp\SR                  rq\SR                  rr\SR                  rs\SR                  rt\SR                  ru\SR                  rv\SR                  rw\SR                  rx\SR                  ry\SR                  rz\{" \AS\SR                  5      r|\SR                  r}\SR                  r~\SR                  q\SGR                   r\SGR                  r\RL                  (       a  \!" SSS9rSS jr\7GR                  r\7GR
                  r\7GR                  r\" 5       rS r\" \*GR                  GR                  S5      5      r\(       aB  \GR                  " SS\S5        \GR                  " SS\S5        \GR                  " SS\S5        \(       aB  \GR                  " S S!\S5        \GR                  " S S"\S5        \GR                  " S S#\S5        SS$ jr\GR"                  \8GR$                  \GR&                  S%.r/ S&Qr\ H  r\\;   a  M   e    " S' S(5      r " S) S*5      r \rS,r " S- S.5      rS/ rSS0 jr " S1 S25      r " S3 S45      r " S5 S6\5      r1 S7kr " S8 S95      r " S: S;5      r " S< S=\5      r SS? jr " S@ SA\5      r     SSB jrSC rSSD jrSE r " SF S5      r " SG SH\GRZ                  5      r " SI SJ\\5      r " SK SL\\5      r " SM SN\GRd                  5      r\GRh                  SSO j5       r\GRh                  SSP j5       r " SQ SR5      r " SS ST5      rSU r " SV SW5      rSX rSSZ jrS[ rS\ rSSS] jjr\GRh                  S^ 5       rS_ r\.GR                  (       a  S` rSSa jrSSb jr1 Sckr      SSd jrSSe jr1 SfkrSgrSSh jr\{" \SiS5      r\.R                  (       a  \r\(       d  \GR                  rO \SGR                  r\(       d  \R(                  rSSj jrSSk jrSl rSSm jrSn qSq SSKrSqSo r " Sp Sq5      r\" 5       r0 rSSr jrSSs jrSSt jrSSu jr   S         SSv jjr " Sw S5      r " Sx Sy5      rSz r S       SS{ jjrSS| jr S       SS} jjrSS~ jrSS jrSS jr " S S5      rSr\S4S jr " S S5      rS rSS jr\" SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SSY\U" S5      4SSY\U" S5      4SSY\U" S5      4SS\U" S5      45
      r " S S\/GR                  5      r\GR                  " S5      rSS jrSS jrSS jr\.GR                  S:X  a  \r\r\rO'\.GR                  r\.GR                  r\.GR                  r\RL                  (       a  SS jrSS jrSS jrS rSS jrSS jrSS jr\" SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      4SS\U" S5      45      r\%GR                    " S S5      5       Gr\GRh                  S 5       GrSG\Gl        S GrSGrSS jGr " S S\3GR                  5      GrSS jGr	SS\9GR                  \9GR                  SS4S jGrG\GrSS jGrS GrS GrS Gr\GRh                  S 5       GrSS jGrg! \ a	    SS+ jr GNf = f! \ a    S>q GNf = f)zMercurial utility functions and platform specific implementations.

This contains helper routines that are independent of the SCM core and
hide platform-specific details from the core.
    )annotationsN)
AnyBinaryIOCallableIterableIteratorListOptionalTupleTypeTypeVar   )hex)attr)tracing)encodingerrori18npolicypycompattypeliburllibcompat)miscmodules)compressionhashutilprocutil
stringutil)Self_Tcowcow)boundbase85zintmod.Base85osutil)windows)posix	statfiles
_Tfilestatfilestatc                |    [         R                  (       a  g[        R                  " U 5        U S-  =[        l        qg)z%updates the umask. used by chg serverNi  )r   	iswindowsosumaskplatform)vals    0/usr/lib/python3/dist-packages/mercurial/util.pysetumaskr1      s)    HHSM 5[(HNU    c                $    SnU  H  nX-  nM	     U$ Nr    )	containerbitsbits      r0   bitsfromr9      s    D Kr2   s   HGEMITWARNINGSdefault 	mercurialhgexthgext3rdignorez
bad escapezinvalid escape sequencezthe imp module is deprecatedc                    [         (       aZ  U SU-  -  n [        R                  " [        R                  " U 5      [
        US-   5        [        R                  R                  5         gg)zpIssue an python native deprecation warning

This is a noop outside of tests, use 'ui.deprecwarn' when possible.
sF   
(compatibility will be dropped after Mercurial-%s, update your code.)r   N)	_dowarnwarningswarnr   sysstrDeprecationWarningsysstderrflush)msgversion
stacklevels      r0   nouideprecwarnrL      sU    
 w# 	 	hooc*,>
QO

 r2   )   md5   sha1   sha512)rO   rN   rM   c                  D    \ rS rSrSrS
S jrS rS rS r\	S 5       r
Srg	)digesteri  af  helper to compute digests.

This helper can be used to compute one or more digests given their name.

>>> d = digester([b'md5', b'sha1'])
>>> d.update(b'foo')
>>> [k for k in sorted(d)]
['md5', 'sha1']
>>> d[b'md5']
'acbd18db4cc2f85cedef654fccc4a4d8'
>>> d[b'sha1']
'0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
>>> digester.preferred([b'md5', b'sha1'])
'sha1'
c                    0 U l         U HJ  nU[        ;  a"  [        R                  " [	        S5      U-  5      e[        U   " 5       U R                   U'   ML     U(       a  U R                  U5        g g Ns   unknown digest type: %s)_hashesDIGESTSr   Abort_update)selfdigestssks       r0   __init__digester.__init__  s]    Akk!$>"?!"CDD%ajlDLLO  KKN r2   c                h    U R                   R                  5        H  nUR                  U5        M     g N)rT   valuesrX   )rY   datahs      r0   rX   digester.update  s$    $$&AHHTN 'r2   c                    U[         ;  a&  [        R                  " [        S5      [        -  5      e[        U R                  U   R                  5       5      $ rS   )rU   r   rV   rW   r\   r   rT   digest)rY   keys     r0   __getitem__digester.__getitem__#  sA    g++a :;a?@@4<<$++-..r2   c                ,    [        U R                  5      $ r`   )iterrT   rY   s    r0   __iter__digester.__iter__(  s    DLL!!r2   c                0    [          H  nX;   d  M
  Us  $    g)z@returns the strongest digest type in both supported and DIGESTS.N)DIGESTS_BY_STRENGTH)	supportedr\   s     r0   	preferreddigester.preferred+  s     %A~ % r2   )rT   N)r2   )__name__
__module____qualname____firstlineno____doc__r]   rX   rh   rm   staticmethodrr   __static_attributes__r5   r2   r0   rQ   rQ     s/     /
"  r2   rQ   c                  .    \ rS rSrSrS rSS jrS rSrg)	digestcheckeri5  zfile handle wrapper that additionally checks content against a given
size and digests.

    d = digestchecker(fh, size, {'md5': '...'})

When multiple digests are given, all of them are validated.
c                    Xl         X l        SU l        [        U5      U l        [        U R                  R                  5       5      U l        g r4   )_fh_size_gotdict_digestsrQ   keys	_digester)rY   fhsizerZ   s       r0   r]   digestchecker.__init__>  s7    
	W!$--"4"4"67r2   c                    U R                   R                  U5      nU R                  R                  U5        U =R                  [        U5      -  sl        U$ r`   )r~   readr   rX   r   len)rY   lengthcontents      r0   r   digestchecker.readE  s=    ((--'g&		S\!	r2   c                t   U R                   U R                  :w  a8  [        R                  " [	        S5      U R                   U R                  4-  5      eU R
                  R                  5        HH  u  pX R                  U   :w  d  M  [        R                  " [	        S5      XU R                  U   4-  5      e   g )Ns"   size mismatch: expected %d, got %ds    %s mismatch: expected %s, got %s)r   r   r   rV   rW   r   itemsr   rY   r\   vs      r0   validatedigestchecker.validateK  s    ::"++78::tyy)*  MM'')DANN1%%kk9:T^^A./0  *r2   )r   r   r~   r   r   N)	rt   ru   rv   rw   rx   r]   r   r   rz   r5   r2   r0   r|   r|   5  s    8r2   r|   c                    Ub   [        U 5      XU-    nUR                  5       $ [        U 5      US  nUR                  5       $ r`   )
memoryview
toreadonly)	sliceableoffsetr   views       r0   bufferr   ^  sJ    i(6/BD    i(1D  r2   i   c                     ^  \ rS rSrSrU 4S jrS r\S 5       r\S 5       r	S r
S rS	 rS
 rS rS r\4S jrSrU =r$ )bufferedinputpipeii  a3  a manually buffered input pipe

Python will not let us use buffered IO and lazy reading with 'polling' at
the same time. We cannot probe the buffer state and select will not detect
that data are ready to read if they are already buffered.

This class let us work around that by implementing its own buffering
(allowing efficient readline) while offering a way to know if the buffer is
empty from the output (allowing collaboration of the buffer with polling).

This class lives in the 'util' module because it makes use of the 'os'
module from the python stdlib.
c                X   > [        U[        5      (       a  [        n [        TU ]  U 5      $ r`   )
isinstancefileobjectproxyobservedbufferedinputpipesuper__new__)clsr   	__class__s     r0   r   bufferedinputpipe.__new__x  s&     b/**+Cws##r2   c                :    Xl         / U l        SU l        SU l        g )NFr   )_input_buffer_eof_lenbuf)rY   inputs     r0   r]   bufferedinputpipe.__init__  s    	r2   c                ,    [        U R                  5      $ )zTrue is any data is currently buffered

This will be used externally a pre-step for polling IO. If there is
already data then no polling should be set in place.)boolr   rl   s    r0   	hasbufferbufferedinputpipe.hasbuffer  s     DLL!!r2   c                .    U R                   R                  $ r`   )r   closedrl   s    r0   r   bufferedinputpipe.closed  s    {{!!!r2   c                6    U R                   R                  5       $ r`   )r   filenorl   s    r0   r   bufferedinputpipe.fileno  s    {{!!##r2   c                6    U R                   R                  5       $ r`   )r   closerl   s    r0   r   bufferedinputpipe.close  s    {{  ""r2   c                    U R                   (       dC  U R                  U:  a3  U R                  5         U R                   (       d  U R                  U:  a  M3  U R                  U5      $ r`   )r   r   _fillbuffer_frombufferrY   r   s     r0   r   bufferedinputpipe.read  sE    994<<$#6 994<<$#6%%r2   c                    U R                   (       d/  U R                  S:X  a  U R                  [        U[        5      5        U R                  [        U R                  U5      5      $ r4   )r   r   r   max
_chunksizer   minr   s     r0   unbufferedread bufferedinputpipe.unbufferedread  sE    yyT\\Q.Sz23DLL$ 788r2   c                   [        U R                  5      S:  a>  SR                  U R                  5      /U l        [        U R                  S   5      U l        SnU R                  (       a  U R                  S   R	                  S5      nU R
                  (       d^  US:  aX  U R                  5         U R                  (       a  U R                  S   R	                  S5      nU R
                  (       d  US:  a  MX  US-   nUS:  a  U R                  nO@[        U R                  5      S:  a'  X@R                  [        U R                  S   5      -
  -  nU R                  U5      $ )Nr   r2   r   r      
)r   r   joinr   findr   r   r   )rY   argskwargslfir   s        r0   readlinebufferedinputpipe.readline  s	   t||q   HHT\\23DLt||A/DL<<,,r"''.C99#'||ll2&++E2 99#' Qw7<<D"LL3t||B'7#888D%%r2   c                @   US:X  d  U R                   (       d  gU R                   S   n[        U R                   5      S:  a  SR                  U R                   5      nUSU nU[        U5      S nU(       a  U/U l         [        U5      U l        U$ / U l         SU l        U$ )zQreturn at most 'size' data from the buffer

The data are removed from the buffer.r   r2   r   N)r   r   r   r   )rY   r   bufrb   s       r0   r   bufferedinputpipe._frombuffer  s     19DLLll1ot||q ((4<<(C5Dz#d)+5DLs8DL  DLDLr2   c                    [         R                  " U R                  R                  5       U5      nU(       d	  SU l        U$ U =R
                  [        U5      -  sl        U R                  R                  U5        U$ )zread data to the bufferT)	r,   r   r   r   r   r   r   r   append)rY   r   rb   s      r0   r   bufferedinputpipe._fillbuffer  s[    wwt{{))+T2DI
  LLCI%LLL%r2   )r   r   r   r   )rt   ru   rv   rw   rx   r   r]   propertyr   r   r   r   r   r   r   r   r   r   rz   __classcell__r   s   @r0   r   r   i  sg    $ " " " "$#&
9
&*(  * 	 	r2   r   c                 P    [        [        S5      =(       d    [        [        S5      $ )Nbackground_mmap_populateMAP_POPULATE)hasattrr$   mmapr5   r2   r0   has_mmap_populater     s#    656 'n; r2   c                  ^ ^^^ US:X  a  gUc  Sn[        T SU 4S j5      " 5       n[        R                  (       a  S nOL[        R                  m[        [        S5      mT(       a  T(       d  T[        [        SS5      -  mS	UUU4S jjn U" X15      $ ! [         a(    [        R                  " U5      R                  S:X  a   ge f = f)
a  Read a file content using mmap

The responsibility of checking the file system is mmap safe is the
responsibility of the caller (see `vfs.is_mmap_safe`).

In some case, a normal string might be returned.

If `pre_populate` is True (the default), the mmapped data will be
pre-populated in memory if the system support this option, this slow down
the initial mmapping but avoid potentially crippling page fault on later
access. If this is not the desired behavior, set `pre_populate` to False.
r   r2   r   c                    > T $ r`   r5   fps   r0   <lambda>mmapread.<locals>.<lambda>  s    rr2   c                H    [         R                   " X[         R                  S9$ )N)access)r   ACCESS_READ)fdr   s     r0   r   r     s    2D<L<L!Mr2   r   r   c                   > [         R                   " XT[         R                  S9nT(       a  T(       a  [        R                  U5        U$ )N)flagsprot)r   	PROT_READr$   r   )r   r   mbg_populater   pre_populates      r0   _mmapmmapread.<locals>._mmap  s1    		"%dnnEA//2Hr2   )returnz	mmap.mmap)getattrr   r+   r   MAP_PRIVATEr   r$   
ValueErrorr,   fstatst_size)r   r   r   r   r   r   r   s   ` `  @@r0   mmapreadr     s     qy 		Xz	*	,BM  f&@AWT>155E	 	R  88B<1$s   B .CCc                  4    \ rS rSr% S\S'   SS jrS	S jrSrg)
uncacheable_cachestati  Optional[os.stat_result]statc                    S U l         g r`   r   rl   s    r0   r]   uncacheable_cachestat.__init__  s	    	r2   c                    gNFr5   rl   s    r0   	cacheableuncacheable_cachestat.cacheable  s    r2   r   Nr   Noner   r   )rt   ru   rv   rw   __annotations__r]   r  rz   r5   r2   r0   r   r     s    
""r2   r   c                      \ rS rSrSrSrS rS rS r\r	S r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r Sr!g) r   i  zA proxy around file objects that tells a watcher when events occur.

This type is intended to only be used for testing purposes. Think hard
before using it in important code.
_orig	_observerc                `    [         R                  U SU5        [         R                  U SU5        g Nr
  r  object__setattr__)rY   r   observers      r0   r]   fileobjectproxy.__init__!  s&    4"-4h7r2   c                ~    1 SknX;   a  [         R                  X5      $ [        [         R                  U S5      U5      $ )N>   r   seektellr   rH   read1writedetachr   isattyreadallreadablereadintor   seekabletruncatewritabler  	readlines
writelinesr
  r  __getattribute__r   )rY   nameourss      r0   r#   fileobjectproxy.__getattribute__%  s<    
@ <**466v..tW=tDDr2   c                @    [        [        R                  U S5      5      $ Nr
  r   r  r#  rl   s    r0   __nonzero__fileobjectproxy.__nonzero__K      F++D':;;r2   c                B    [        [        R                  U S5      U5      $ r(  delattrr  r#  rY   r$  s     r0   __delattr__fileobjectproxy.__delattr__P      v..tW=tDDr2   c                B    [        [        R                  U S5      X5      $ r(  setattrr  r#  rY   r$  values      r0   r  fileobjectproxy.__setattr__S      v..tW=tKKr2   c                J    [         R                  U S5      R                  5       $ r(  )r  r#  rm   rl   s    r0   rm   fileobjectproxy.__iter__V  s    &&tW5>>@@r2   c                    [         R                  U S5      n[        XA5      " U0 UD6n[         R                  U S5      n[        XaS 5      nU(       a  U" U/UQ70 UD6  U$ r  r"  rY   r$  r   r   origresr  fns           r0   _observedcallfileobjectproxy._observedcallY  b    &&tW5d!4262 **4=XT*s$T$V$
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r   r  r#  rY   r   r   s      r0   r   fileobjectproxy.closeg  /    &&t_=

$
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r   rF  rG  s      r0   r   fileobjectproxy.filenol  /    &&t_=

%
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  rH   rF  rG  s      r0   rH   fileobjectproxy.flushq  rI  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.isattyv  rL  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.readable{  /    &&t_=

!'
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r   rF  rG  s      r0   r   fileobjectproxy.readline  rS  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r   rF  rG  s      r0   r   fileobjectproxy.readlines  /    &&t_=

"(
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.seek  /    &&t_=

#
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.seekable  rS  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.tell  r[  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.truncate  rS  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.writable  rS  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r!  rF  rG  s      r0   r!  fileobjectproxy.writelines  /    &&t_=

#)
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r   rF  rG  s      r0   r   fileobjectproxy.read  r[  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.readall  /    &&t_=

 &
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.readinto  rS  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.write  rI  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.detach  rL  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  fileobjectproxy.read1  rI  r2   r5   N)"rt   ru   rv   rw   rx   	__slots__r]   r#  r*  __bool__r1  r  rm   rB  r   r   rH   r  r  r   r   r  r  r  r  r  r!  r   r  r  r  r  r  rz   r5   r2   r0   r   r     s    I
8$EL< HELA




































r2   r   c                  J   ^  \ rS rSrSr\4U 4S jjrU 4S jrU 4S jrSr	U =r
$ )r   i  a  A variation of bufferedinputpipe that is aware of fileobjectproxy.

``bufferedinputpipe`` makes low-level calls to ``os.read()`` that
bypass ``fileobjectproxy``. Because of this, we need to make
``bufferedinputpipe`` aware of these operations.

This variation of ``bufferedinputpipe`` can notify observers about
``os.read()`` events. It also re-publishes other events, such as
``read()`` and ``readline()``.
c                   > [         TU ]  US9n[        U R                  R                  SS 5      nU(       a  U" X!5        U$ )N)r   osread)r   r   r   r   r  rY   r   r@  rA  r   s       r0   r   %observedbufferedinputpipe._fillbuffer  s<    g!t!,T[[**Hd;sM
r2   c                   > [         TU ]  U5      n[        U R                  R                  SS 5      nU(       a  U" X!5        U$ )Nbufferedread)r   r   r   r   r  ry  s       r0   r   observedbufferedinputpipe.read  s8    gl4 T[[**NDAsM
r2   c                   > [         TU ]  " U0 UD6n[        U R                  R                  SS 5      nU(       a  U" U5        U$ )Nbufferedreadline)r   r   r   r   r  )rY   r   r   r@  rA  r   s        r0   r   "observedbufferedinputpipe.readline  s?    g//T[[**,>EsG
r2   r5   )rt   ru   rv   rw   rx   r   r   r   r   rz   r   r   s   @r0   r   r     s!    	  *  r2   r   >   recvsendsendtosendallmakefilerecvfrom	recv_into
gettimeout
setsockopt
settimeoutsetblockingrecvfrom_intoc                      \ rS rSrSrSrS rS rS rS r	S r
\
rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSrg)socketproxyi  zA proxy around a socket that tells a watcher when events occur.

This is like ``fileobjectproxy`` except for sockets.

This type is intended to only be used for testing purposes. Think hard
before using it in important code.
r	  c                `    [         R                  U SU5        [         R                  U SU5        g r  r  )rY   sockr  s      r0   r]   socketproxy.__init__  s&    4$/4h7r2   c                    U[         ;   a  [        R                  X5      $ [        [        R                  U S5      U5      $ r(  )PROXIED_SOCKET_METHODSr  r#  r   r0  s     r0   r#  socketproxy.__getattribute__  s6    ))**466v..tW=tDDr2   c                B    [        [        R                  U S5      U5      $ r(  r.  r0  s     r0   r1  socketproxy.__delattr__  r3  r2   c                B    [        [        R                  U S5      X5      $ r(  r5  r7  s      r0   r  socketproxy.__setattr__  r:  r2   c                @    [        [        R                  U S5      5      $ r(  r)  rl   s    r0   r*  socketproxy.__nonzero__  r,  r2   c                    [         R                  U S5      n[        XA5      " U0 UD6n[         R                  U S5      n[        XaS 5      nU(       a  U" U/UQ70 UD6  U$ r  r"  r>  s           r0   rB  socketproxy._observedcall$  rD  r2   c           
        [         R                  U S5      " S/UQ70 UD6n[         R                  U S5      n[        UR                  UUR                  UR
                  UR                  UR                  UR                  S9$ )NrB  r  r  readswriteslogdatalogdataapis)	r  r#  makeloggingfileobjectr   r$  r  r  r  r  )rY   r   r   r@  r  s        r0   r  socketproxy.makefile2  s~    %%dO<

!'
 **4=$KKMM..??$$ ,,
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.recvD  r[  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.recvfromI  rS  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.recvfrom_intoN  s/    &&t_=
"
&,
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  	recv_inforF  rG  s      r0   r  socketproxy.recv_intoS  rX  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.sendX  r[  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.sendall]  rk  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.sendtob  rL  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.setblockingg  s/    &&t_=
 
$*
 	
r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.settimeoutl  rf  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.gettimeoutq  rf  r2   c                B    [         R                  U S5      " S/UQ70 UD6$ )NrB  r  rF  rG  s      r0   r  socketproxy.setsockoptv  rf  r2   r5   N)rt   ru   rv   rw   rx   rt  r]   r#  r1  r  r*  ru  rB  r  r  r  r  r  r  r  r  r  r  r  r  rz   r5   r2   r0   r  r    sr    I
8EEL< H
$




















r2   r  c                       \ rS rSrS rS rSrg)baseproxyobserveri|  c                4    Xl         X l        X0l        X@l        g r`   )r   r$  r  r  )rY   r   r$  r  r  s        r0   r]   baseproxyobserver.__init__}  s    	&r2   c                6   U R                   (       dG  U R                  (       a5  U R                  R                  S5        U R                  R	                  5         g SU;  a  U R                  (       a3  U R                  R                  S[
        R                  " U5      -  5        O>U R                  R                  SU R                  [
        R                  " U5      4-  5        U R                  R	                  5         g U R                  (       a  U R                  R                  S5        UR                  S5      nU HA  nU R                  R                  SU R                  [
        R                  " U5      4-  5        MC     U R                  R	                  5         g )Nr   s   : %s
s   %s>     %s
s   :
T)	r  r  r   r  rH   r   	escapestrr$  
splitlines)rY   rb   lineslines       r0   
_writedatabaseproxyobserver._writedata  s   ||e$ i**>*>t*DDE#tyy*2F2Ft2L&MM GGMMO GGMM&!%DGGMM499j.B.B4.H"II  	r2   )r   r  r  r$  N)rt   ru   rv   rw   r]   r  rz   r5   r2   r0   r  r  |  s    'r2   r  c                  d   ^  \ rS rSrSr SU 4S jjrSS jrSS jrS rS r	S r
S	 rS
 rSrU =r$ )fileobjectobserveri  zLogs file object activity.c                >   > [         TU ]  XXV5        X0l        X@l        g r`   )r   r]   r  r  )rY   r   r$  r  r  r  r  r   s          r0   r]   fileobjectobserver.__init__  s     	78
r2   c                    U R                   (       d  g Uc  SnUS:X  a  US:X  a  g U R                  (       a4  U R                  R                  SU R                  U[        U5      4-  5        U R                  U5        g )Nr2   r   s   %s> read(%d) -> %dr  r  r   r  r$  r   r  rY   r@  r   s      r0   r   fileobjectobserver.read  sb    zz;C2:#*
 GGMM/499dCH2MMNr2   c                    U R                   (       d  g U R                  (       a3  U R                  R                  SU R                  [        U5      4-  5        U R                  U5        g )Ns   %s> readline() -> %dr  )rY   r@  limits      r0   r   fileobjectobserver.readline  sD    zzGGMM1TYYC4IIJr2   c                2   U R                   (       d  g U R                  (       a4  U R                  R                  SU R                  [        U5      U4-  5        Ub  USU OSn[        U[        5      (       a  UR                  5       nU R                  U5        g )Ns   %s> readinto(%d) -> %rr   r2   )
r  r  r   r  r$  r   r   r   tobytesr  )rY   r@  destrb   s       r0   r  fileobjectobserver.readinto  su    zzGGMM)TYYD	3,GG "otAc{3 dJ''<<>Dr2   c                    U R                   (       d  g Uc  U(       a  [        U5      nU R                  (       a4  U R                  R	                  SU R
                  [        U5      U4-  5        U R                  U5        g )Ns   %s> write(%d) -> %r)r  r   r  r   r  r$  r  )rY   r@  rb   s      r0   r  fileobjectobserver.write  sX    {{ ;4d)CGGMM0DIIs4y#3NNOr2   c                |    U R                   (       d  g U R                  R                  SU R                  U4-  5        g )Ns   %s> flush() -> %r
)r  r   r  r$  rY   r@  s     r0   rH   fileobjectobserver.flush  s+    {{,		3/??@r2   c                    U R                   (       d  g U R                  (       a4  U R                  R                  SU R                  U[        U5      4-  5        U R                  U5        g )Ns   %s> bufferedread(%d) -> %dr  r  s      r0   r|  fileobjectobserver.bufferedread  sJ    zzGGMM-D#c(0KK 	r2   c                    U R                   (       d  g U R                  (       a3  U R                  R                  SU R                  [        U5      4-  5        U R                  U5        g )Ns   %s> bufferedreadline() -> %dr  r  s     r0   r  #fileobjectobserver.bufferedreadline  sH    zzGGMM/499c#h2GG 	r2   )r  r  TTFTr   )rt   ru   rv   rw   rx   r]   r   r   r  r  rH   r|  r  rz   r   r   s   @r0   r  r    s;    $ MQ&$A		 	r2   r  Fc           	     4    [        U UUUUUS9n[        X5      $ )z.Turn a file object into a logging file object.r  )r  r   )loghr   r$  r  r  r  r  r  s           r0   r  r    s-    
 "H 2((r2   c                     ^  \ rS rSrSr     SU 4S jjrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrS rS rS rS rSrU =r$ )socketobserveri  zLogs socket activity.c                J   > [         TU ]  XXg5        X0l        X@l        XPl        g r`   )r   r]   r  r  states)	rY   r   r$  r  r  r  r  r  r   s	           r0   r]   socketobserver.__init__  s#     	78
r2   c                |    U R                   (       d  g U R                  R                  SU R                  X#4-  5        g )Ns   %s> makefile(%r, %r)
r  r   r  r$  )rY   r@  modebufsizes       r0   r  socketobserver.makefile'  s+    {{/499d2LLMr2   c           	         U R                   (       d  g U R                  (       a4  U R                  R                  SU R                  X#[        U5      4-  5        U R                  U5        g )Ns   %s> recv(%d, %d) -> %dr  rY   r@  r   r   s       r0   r  socketobserver.recv-  sJ    zzGGMM)TYYSX,NN 	r2   c           
         U R                   (       d  g U R                  (       a7  U R                  R                  SU R                  X#[        US   5      4-  5        U R                  US   5        g )Ns   %s> recvfrom(%d, %d) -> %dr   r  r  s       r0   r  socketobserver.recvfrom7  sU    zzGGMM-99d3s1v;78
 	Ar2   c                    U R                   (       d  g U R                  (       a.  U R                  R                  SU R                  X4US   4-  5        U R                  USUS    5        g )Ns   %s> recvfrom_into(%d, %d) -> %dr   r  r  r   r  r$  r  rY   r@  r   r   r   s        r0   r  socketobserver.recvfrom_intoC  sW    zzGGMM299d3q623
 	AA(r2   c                    U R                   (       d  g U R                  (       a+  U R                  R                  SU R                  X4U4-  5        U R                  USU 5        g )Ns   %s> recv_into(%d, %d) -> %dr   r  r  s        r0   r  socketobserver.recv_intoO  sL    zzGGMM.$))T#1NN 	Ac
#r2   c           	         U R                   (       d  g U R                  R                  SU R                  [	        U5      U[	        U5      4-  5        U R                  U5        g )Ns   %s> send(%d, %d) -> %d)r  r   r  r$  r   r  rY   r@  rb   r   s       r0   r  socketobserver.sendZ  sG    {{%CIuc#h(OO	
 	r2   c                    U R                   (       d  g U R                  (       a4  U R                  R                  SU R                  [        U5      U4-  5        U R                  U5        g )Ns   %s> sendall(%d, %d)r  r  r   r  r$  r   r  r  s       r0   r  socketobserver.sendallc  sJ    {{GGMM&$))SY)FF 	r2   c                    U R                   (       d  g U(       a  UnOSnU R                  (       a5  U R                  R                  SU R                  [        U5      XTU4-  5        U R                  U5        g )Nr   s   %s> sendto(%d, %d, %r) -> %dr  )rY   r@  rb   flagsoraddressaddressr   s         r0   r  socketobserver.sendtoo  s\    {{"EEGGMM/99c$i=>
 	r2   c                |    U R                   (       d  g U R                  R                  SU R                  U4-  5        g )Ns   %s> setblocking(%r)
r  )rY   r@  flags      r0   r  socketobserver.setblocking  s+    {{.$))T1BBCr2   c                |    U R                   (       d  g U R                  R                  SU R                  U4-  5        g )Ns   %s> settimeout(%r)
r  )rY   r@  r8  s      r0   r  socketobserver.settimeout  s+    {{-E0BBCr2   c                |    U R                   (       d  g U R                  R                  SU R                  U4-  5        g )Ns   %s> gettimeout() -> %f
r  r  s     r0   r  socketobserver.gettimeout  s+    {{1TYY4DDEr2   c                ~    U R                   (       d  g U R                  R                  SU R                  X#XA4-  5        g )Ns!   %s> setsockopt(%r, %r, %r) -> %r
r  )rY   r@  leveloptnamer8  s        r0   r  socketobserver.setsockopt  s2    {{1yy%%56	
r2   )r  r  r  TTTFTNNr   )r   r   r`   )rt   ru   rv   rw   rx   r]   r  r  r  r  r  r  r  r  r  r  r  r  rz   r   r   s   @r0   r  r    sa     N
 
)	$
"DDF
 
r2   r  c           
     6    [        U UUUUUUS9n[        X5      $ )z$Turn a socket into a logging socket.)r  r  r  r  r  )r  r  )	r  r   r$  r  r  r  r  r  r  s	            r0   makeloggingsocketr    s0     H r$$r2   c                 d     SSK Jn   U R                  R                  5       $ ! [         a     gf = f)z(Return version information if available.r   __version__s   unknown)r;   r  rJ   encodeImportErrorr  s    r0   rJ   rJ     s3    ! ""))++ s   " 
//c                |   U (       d
  [        5       n [        R                  " SU 5      nU(       d  SU pCO;UR                  S5      (       a  UR	                  5       u  p4OUR                  S5      SpCUc   e/ nUR                  S5       H  n UR                  [        U5      5        M      [        U5      S:  a"  UR                  S5        [        U5      S:  a  M"  US:X  a
  US   US   4$ US:X  a  US   US   US   4$ US	:X  a  US   US   US   U4$ [        R                  " S
U-  5      e! [         a       M  f = f)a  Parses a Mercurial version string into an N-tuple.

The version string to be parsed is specified with the ``v`` argument.
If it isn't defined, the current Mercurial version string will be parsed.

``n`` can be 2, 3, or 4. Here is how some version strings map to
returned values:

>>> v = b'3.6.1+190-df9b73d2d444'
>>> versiontuple(v, 2)
(3, 6)
>>> versiontuple(v, 3)
(3, 6, 1)
>>> versiontuple(v, 4)
(3, 6, 1, '190-df9b73d2d444')

>>> versiontuple(b'3.6.1+190-df9b73d2d444+20151118')
(3, 6, 1, '190-df9b73d2d444+20151118')

>>> v = b'3.6'
>>> versiontuple(v, 2)
(3, 6)
>>> versiontuple(v, 3)
(3, 6, None)
>>> versiontuple(v, 4)
(3, 6, None, None)

>>> v = b'3.9-rc'
>>> versiontuple(v, 2)
(3, 9)
>>> versiontuple(v, 3)
(3, 9, None)
>>> versiontuple(v, 4)
(3, 9, None, 'rc')

>>> v = b'3.9-rc+2-02a8fea4289b'
>>> versiontuple(v, 2)
(3, 9)
>>> versiontuple(v, 3)
(3, 9, None)
>>> versiontuple(v, 4)
(3, 9, None, 'rc+2-02a8fea4289b')

>>> versiontuple(b'4.6rc0')
(4, 6, None, 'rc0')
>>> versiontuple(b'4.6rc0+12-425d55e54f98')
(4, 6, None, 'rc0+12-425d55e54f98')
>>> versiontuple(b'.1.2.3')
(None, None, None, '.1.2.3')
>>> versiontuple(b'12.34..5')
(12, 34, None, '..5')
>>> versiontuple(b'1.2.3.4.5.6')
(1, 2, 3, '.4.5.6')
s   (\d+(?:\.\d+){,2})[+-]?(.*)r2      r   N   .   r      s    invalid version part request: %d)rJ   remodmatchgroupgroupssplitr   intr   r   r   ProgrammingError)r   nr   vpartsextravintsis          r0   versiontupler'    s=   n I3Q7AQ	


DE\\$	LLQ    e*q.T e*q. 	Ava%(##Ava%(E!H--Ava%(E!He44

 
 !Dq!H
II  		s   D,,
D;:D;c                   ^ ^^ T R                   R                  S:X  a  / mU U4S jnU$ 0 mT R                   R                  S:X  a	  UU 4S jnU$ UU 4S jnU$ )z"cache the result of function callsr   c                 X   > [        T5      S:X  a  TR                  T " 5       5        TS   $ r4   )r   r   )func	listcaches   r0   fcachefunc.<locals>.f  s)    9~"  (Q<r2   r   c                0   > U T;  a  T" U 5      TU '   TU    $ r`   r5   )argcacher*  s    r0   r,  r-  &  s"    %!#Yc
:r2   c                 *   > U T;  a  T" U 6 TU '   TU    $ r`   r5   )r   r0  r*  s    r0   r,  r-  -  s"    5 "Dkd;r2   )__code__co_argcount)r*  r,  r0  r+  s   ` @@r0   	cachefuncr4    sW     }}  A%		 
 E}}  A%	 H	
 Hr2   c                  8    \ rS rSr% SrS\S'   S	S jrS
S jrSrg)r!   i5  zVhelper class to make copy-on-write easier

Call preparewrite before doing any writes.
r   _copiedc                v    [        U SS5      (       a&  U =R                  S-  sl        U R                  U 5      $ U $ )z;call this before writes, return self or a copied new objectr6  r   r   )r   r6  r   rl   s    r0   preparewritecow.preparewrite=  s3    4A&&LLAL>>$''r2   c                0    [        U SS5      S-   U l        U $ )zalways do a cheap copyr6  r   r   )r   r6  rl   s    r0   copycow.copyE  s    tY2Q6r2   )r6  N)rY   r    r   r    r   r   )	rt   ru   rv   rw   rx   r  r8  r;  rz   r5   r2   r0   r!   r!   5  s    
 Lr2   c                  Z   ^  \ rS rSrSrU 4S jr\R                  (       a  S rS r	Sr
U =r$ )sortdictiK  a7  a simple sorted dictionary

>>> d1 = sortdict([(b'a', 0), (b'b', 1)])
>>> d2 = d1.copy()
>>> list(d2.items())
[('a', 0), ('b', 1)]
>>> d2.update([(b'a', 2)])
>>> list(d2.keys()) # should still be in last-set order
['b', 'a']
>>> d1.insert(1, b'a.5', 0.5)
>>> list(d1.items())
[('a', 0), ('a.5', 0.5), ('b', 1)]
c                2   > X;   a  X	 [         TU ]  X5        g r`   )r   __setitem__)rY   rg   r8  r   s      r0   rA  sortdict.__setitem__Z  s    ;	C'r2   c                    [        U[        5      (       a  UR                  5       nU H	  u  p4X@U'   M     U H	  nX#   X'   M     g r`   )r   r   r   )rY   srcr,  r\   r   s        r0   rX   sortdict.updatea  s@    #t$$iikQ $ r2   c                    [        [        U R                  5       5      5       H  u  nu  pVXA:X  a  X0U'   XA:  d  M  X	 X`U'   M      g r`   )	enumeratelistr   )rY   positionrg   r8  r&  r\   r   s          r0   insertsortdict.inserti  s?    "4

#56IAv}!S	}GQ 7r2   r5   )rt   ru   rv   rw   rx   rA  r   ispypyrX   rJ  rz   r   r   s   @r0   r?  r?  K  s%    (
 	 r2   r?  c                      \ rS rSrSrSrg)cowdictir  aT  copy-on-write dict

Be sure to call d = d.preparewrite() before writing to d.

>>> a = cowdict()
>>> a is a.preparewrite()
True
>>> b = a.copy()
>>> b is a
True
>>> c = b.copy()
>>> c is a
True
>>> a = a.preparewrite()
>>> b is a
False
>>> a is a.preparewrite()
True
>>> c = c.preparewrite()
>>> b is c
False
>>> b is b.preparewrite()
True
r5   Nrt   ru   rv   rw   rx   rz   r5   r2   r0   rN  rN  r  s    r2   rN  c                      \ rS rSrSrSrg)cowsortdicti  zRcopy-on-write sortdict

Be sure to call d = d.preparewrite() before writing to d.
r5   NrO  r5   r2   r0   rQ  rQ    s    r2   rQ  c                  |    \ rS rSrSr\R                  S	S j5       r\R                  S	S j5       rS
S jr	S	S jr
Srg)transactionali  zBBase class for making a transactional type into a context manager.c                    g)z$Successfully closes the transaction.Nr5   rl   s    r0   r   transactional.close      r2   c                    g)z_Marks the end of the transaction.

If the transaction has not been closed, it will be aborted.
Nr5   rl   s    r0   releasetransactional.release  rV  r2   c                    U $ r`   r5   rl   s    r0   	__enter__transactional.__enter__      r2   c                v     Uc  U R                  5         U R                  5         g ! U R                  5         f = fr`   )r   rX  )rY   exc_typeexc_valexc_tbs       r0   __exit__transactional.__exit__  s)    	

LLNDLLNs   & 8r5   Nr  r=  )rt   ru   rv   rw   rx   abcabstractmethodr   rX  r[  rb  rz   r5   r2   r0   rS  rS    sA    L3 3 	 r2   rS  c              #     #    U (       d  Sv   g Sv   U R                  5          U R                  5         g! [        R                   a    U R                  5         e f = f! U R                  5         f = f7f)zA context manager that closes the transaction on InterventionRequired

If no transaction was provided, this simply runs the body and returns
N)r   r   InterventionRequiredrX  )trs    r0   acceptinterventionri    sZ      


 	

	 %% 

 	

s%   A46 A4&AA A11A4c              #     #    U v   g 7fr`   r5   )enter_results    r0   nullcontextmanagerrl    s     
s   c                  (    \ rS rSrSrSrS rS rSrg)_lrucachenodei  zA node in a doubly linked list.

Holds a reference to nodes on either side as well as a key-value
pair for the dictionary entry.
)nextprevrg   r8  costc                N    X l         X l        [        U l        S U l        SU l        g r4   )ro  rp  _notsetrg   r8  rq  rl   s    r0   r]   _lrucachenode.__init__  s!    		
	r2   c                6    [         U l        SU l        SU l        g)zMark the node as emptied.Nr   )rs  rg   r8  rq  rl   s    r0   	markempty_lrucachenode.markempty  s    
	r2   )rq  rg   ro  rp  r8  N)	rt   ru   rv   rw   rx   rt  r]   rv  rz   r5   r2   r0   rn  rn    s     9Ir2   rn  c                      \ rS rSrSrSS jrS rS rS rS r	SS jr
S	 rS
 r\4S jrSS jr\4S jrS rSS jrS rSS jrSS jrS rSrg)lrucachedicti  a  Dict that caches most recent accesses and sets.

The dict consists of an actual backing dict - indexed by original
key - and a doubly linked circular list defining the order of entries in
the cache.

The head node is the newest entry in the cache. If the cache is full,
we recycle head.prev and make it the new head. Cache accesses result in
the node being moved to before the existing head and being marked as the
new head node.

Items in the cache can be inserted with an optional "cost" value. This is
simply an integer that is specified by the caller. The cache can be queried
for the total cost of all items presently in the cache.

The cache can also define a maximum cost. If a cache insertion would
cause the total cost of the cache to go beyond the maximum cost limit,
nodes will be evicted to make room for the new code. This can be used
to e.g. set a max memory limit and associate an estimated bytes size
cost to each item in the cache. By default, no maximum cost is enforced.
c                d    0 U l         [        5       U l        SU l        Xl        SU l        X l        g )Nr   r   )_cachern  _headr   capacity	totalcostmaxcost)rY   r   r  s      r0   r]   lrucachedict.__init__  s*    "_

r2   c                ,    [        U R                  5      $ r`   )r   r{  rl   s    r0   __len__lrucachedict.__len__  s    4;;r2   c                    XR                   ;   $ r`   )r{  rY   r\   s     r0   __contains__lrucachedict.__contains__   s    KKr2   c              #     #    U R                   n[        [        U R                  5      5       H  nUR                  v   UR
                  nM     g 7fr`   )r|  ranger   r{  rg   ro  )rY   r"  r&  s      r0   rm   lrucachedict.__iter__  s8     JJs4;;'(A%%KA )s   AAc                Z    U R                   U   nU R                  U5        UR                  $ r`   )r{  _movetoheadr8  )rY   r\   nodes      r0   rh   lrucachedict.__getitem__
  s'    {{1~zzr2   c                   U R                   R                  U5      nUbs  U =R                  UR                  -  sl        X$l        X4l        U =R                  U-  sl        U R                  U5        U R                  (       a  U R                  5         gU R                  U R                  :  a  U R                  5       nOU R                  R                  nUR                  [        La6  U =R                  UR                  -  sl        U R                   UR                  	 Xl        X$l        X4l        U =R                  U-  sl        X@R                   U'   X@l        U R                  (       a  U R                  5         gg)z8Insert a new item in the cache with optional cost value.N)r{  getr~  rq  r8  r  r  _enforcecostlimitr   r}  _addcapacityr|  rp  rg   rs  )rY   r\   r   rq  r  s        r0   rJ  lrucachedict.insert  s   {{q!NNdii'NJINNd"NT"||&&(::%$$&D ::??D 887"NNdii'NDHH%
	$A 
<<""$ r2   c                &    U R                  X5        g r`   )rJ  r   s      r0   rA  lrucachedict.__setitem__6  s    Ar2   c                &    U R                  U5        g r`   )popr  s     r0   __delitem__lrucachedict.__delitem__9  s    r2   c                0    U R                   R                  U5      nUR                  nU =R
                  UR                  -  sl        UR                  5         U R                  U5        UR                  U l
        U$ ! [         a    U[        L a  e Us $ f = fr`   )r{  r  KeyErrorrs  r8  r~  rq  rv  r  ro  r|  )rY   r\   r:   r  r8  s        r0   r  lrucachedict.pop<  s    	;;??1%D 

$))# 	YY
  	'!N	s   A< <BBNc                J     U R                  U5      $ ! [         a    Us $ f = fr`   )rh   r  )rY   r\   r:   s      r0   r  lrucachedict.getQ  s,    	##A&& 	N	s    ""c                r     U R                   U   nUR                  $ ! [         a    U[        L a  e Us $ f = f)zGet the specified item without moving it to the head

Unlike get(), this doesn't mutate the internal state. But be aware
that it doesn't mean peek() is thread safe.
)r{  r8  r  rs  )rY   r\   r:   r  s       r0   peeklrucachedict.peekW  s=    	;;q>D:: 	'!N	s    66c                   U R                   nUR                  [        LaP  U =R                  UR                  -  sl        UR                  5         UR                  nUR                  [        La  MP  U R                  R                  5         g r`   )	r|  rg   rs  r~  rq  rv  ro  r{  clear)rY   r"  s     r0   r  lrucachedict.cleare  s[    JJee7"NNaff$NKKMA ee7"
 	r2   c                   U=(       d    U R                   nU=(       d    U R                  n[        XS9nU R                  R                  nUR
                  [        L a=  X@R                  La/  UR                  nUR
                  [        L a  X@R                  La  M/  [        [        U R                  5      5       H>  nUR                  UR
                  UR                  UR                  S9  UR                  nM@     U$ )a  Create a new cache as a copy of the current one.

By default, the new cache has the same capacity as the existing one.
But, the cache capacity can be changed as part of performing the
copy.

Items in the copy have an insertion/access order matching this
instance.
)r  )rq  )r}  r  ry  r|  rp  rg   rs  r  r   r{  rJ  r8  rq  )rY   r}  r  resultr"  r&  s         r0   r;  lrucachedict.copyn  s     ,t}})T\\h8 JJOOeew1JJ#6A eew1JJ#6
 s4;;'(AMM!%%qvvM6A ) r2   c                z   U R                   (       d  gU R                  R                  nUR                  [        L a!  UR                  nUR                  [        L a  M!  UR                  UR
                  p2U R                   UR                  	 U =R                  UR                  -  sl        UR                  5         X#4$ )zeRemove the oldest item from the cache.

Returns the (key, value) describing the removed cache entry.
N)	r{  r|  rp  rg   rs  r8  r~  rq  rv  )rY   r"  rg   r8  s       r0   	popoldestlrucachedict.popoldest  s    
 {{ JJOOeewA eew UUAGGU KK!&& 	zr2   c                ,   U R                   nUR                  UR                  l        UR                  UR                  l        UR                  Ul        UR                  R                  Ul        XR                  l        XR                  l        Xl         g)a  Mark a node as the newest, making it the new head.

When a node is accessed, it becomes the freshest entry in the LRU
list, which is denoted by self._head.

Visually, let's make ``N`` the new head node (* denotes head):

    previous/oldest <-> head <-> next/next newest

    ----<->--- A* ---<->-----
    |                       |
    E <-> D <-> N <-> C <-> B

To:

    ----<->--- N* ---<->-----
    |                       |
    E <-> D <-> C <-> B <-> A

This requires the following moves:

   C.next = D  (node.prev.next = node.next)
   D.prev = C  (node.next.prev = node.prev)
   E.next = N  (head.prev.next = node)
   N.prev = E  (node.prev = head.prev)
   N.next = A  (node.next = head)
   A.prev = N  (head.prev = node)
N)r|  ro  rp  )rY   r  heads      r0   r  lrucachedict._movetohead  s^    : zz				II	 IINN					
r2   c                    U R                   n[        5       nX!R                  l        UR                  Ul        Xl        X!l        U =R                  S-  sl        U$ )zXAdd a node to the circular linked list.

The new node is inserted before the head node.
r   )r|  rn  rp  ro  r   )rY   r  r  s      r0   r  lrucachedict._addcapacity  sD    
 zz		II			

a
r2   c                F   [        U 5      S::  d  U R                  U R                  ::  a  g [        U R                  S-  5      nU R                  R
                  nUR                  [        L a!  UR
                  nUR                  [        L a  M!  [        U 5      S:  a  U R                  U:  au  U R                  UR                  	 U =R                  UR                  -  sl        UR                  5         UR
                  n[        U 5      S:  a  U R                  U:  a  Ms  g g g g )Nr   g      ?)r   r~  r  r   r|  rp  rg   rs  r{  rq  rv  )rY   
targetcostr"  s      r0   r  lrucachedict._enforcecostlimit  s     t9>T^^t||; ,-
JJOOeewA eew $i!m ;AEE"NNaff$NKKMA	 $i!m ;m ;mr2   )r{  r|  r   r}  r  r~  r  r`   r4   )r  rn  )r   rn  )rt   ru   rv   rw   rx   r]   r  r  rm   rh   rJ  rA  r  rs  r  r  r  r  r;  r  r  r  r  rz   r5   r2   r0   ry  ry    sh    ,  
%%N % * & >0-^r2   ry  c                   ^ ^^ 0 m[         R                  " 5       mT R                  R                  S:X  a
  UU U4S jnU$ UU U4S jnU$ )z+cache most recent results of function callsr   c                   > U T;  a,  [        T5      S:  a  TTR                  5       	 T" U 5      TU '   OTR                  U 5        TR                  U 5        TU    $ N   r   popleftremover   )r/  r0  r*  orders    r0   r,  lrucachefunc.<locals>.f	  sS    %u:?emmo.!#Yc
S!LL:r2   c                    > U T;  a)  [        T5      S:  a  TTR                  5       	 T" U 6 TU '   OTR                  U 5        TR                  U 5        TU    $ r  r  )r   r0  r*  r  s    r0   r,  r    sS    5 u:?emmo."DkdT"LL;r2   )collectionsdequer2  r3  )r*  r,  r0  r  s   ` @@r0   lrucachefuncr    s@    EE}}  A%	, H	 Hr2   c                  *    \ rS rSrS rSS jrS rSrg)propertycachei"  c                2    Xl         UR                  U l        g r`   )r*  rt   r$  )rY   r*  s     r0   r]   propertycache.__init__#  s    	MM	r2   Nc                J    U R                  U5      nU R                  X5        U$ r`   )r*  
cachevalue)rY   objtyper  s       r0   __get__propertycache.__get__'  s     3$r2   c                4    X!R                   U R                  '   g r`   )__dict__r$  )rY   r  r8  s      r0   r  propertycache.cachevalue,  s    "'TYYr2   )r*  r$  r`   )rt   ru   rv   rw   r]   r  r  rz   r5   r2   r0   r  r  "  s    "
(r2   r  c                j    [         R                  " U5      nXR                  ;   a  U R                  U	 gg)z2clear a cached property value, if one has been setN)r   rD   r  )r  props     r0   clearcachedpropertyr  1  s+    ??4 D||LL r2      c              #  "  #    S n/ nSnU  Hc  nUR                  U5        U[        U5      -  nXQ:  d  M)  X:  a  US-  nSU" U5      -  nXq:  a  UnX:  a  UnSR                  U5      v   Sn/ nMe     U(       a  SR                  U5      v   gg7f)znreturn no less than min bytes per chunk while data remains,
doubling min after each chunk until it reaches maxc                T    U (       d  gSnU (       a  U S-  n US-  nU (       a  M  US-
  $ )Nr   r   r5   )xr&  s     r0   log2increasingchunks.<locals>.log2<  s4    !GAFA a 1ur2   r   r   r2   N)r   r   r   )sourcer   r   r  r   blenchunknmins           r0   increasingchunksr  8  s      CD

5E
;yQhDJ:C9C((3-DC  hhsm s   /BABc                    gNTr5   rA  s    r0   alwaysr  Y  s    r2   c                    gr  r5   r  s    r0   neverr  ]  s    r2   c                2    U c
  [        5       $ [        U 5      $ )a  disable garbage collector

Python's garbage collector triggers a GC each time a certain number of
container objects (the number being defined by gc.get_threshold()) are
allocated even when marked not to be tracked by the collector. Tracking has
no effect on when GCs are triggered, only on what objects the GC looks
into. As a workaround, disable GC while building complex (huge)
containers.

This garbage collector issue have been fixed in 2.7. But it still affect
CPython's performance.
)_nogc_context_nogc_decorator)r*  s    r0   nogcr  a  s     |t$$r2   c               #     #    [         R                  " 5       n [         R                  " 5          S v   U (       a  [         R                  " 5         g g ! U (       a  [         R                  " 5         f f = f7fr`   )gc	isenableddisableenable)	gcenableds    r0   r  r  t  sC     IJJLIIK 9IIK s   +A2A A2A//A2c                   ^  U 4S jnU$ )Nc                 ^   > [        5          T" U 0 UD6sS S S 5        $ ! , (       d  f       g = fr`   )r  )r   r   r*  s     r0   wrapper _nogc_decorator.<locals>.wrapper  s    _(( __s   
,r5   r*  r  s   ` r0   r  r    s    ) Nr2   c                    U $ r`   r5   r  s    r0   r   r     s    Qr2   c                6   U(       d  [        U5      $ [        R                  R                  U5      (       a  [        R                  R	                  U 5      S   [        R                  R	                  U5      S   :w  a)  [        R                  R                  U [        U5      5      $ SR                  [        U 5      U45      n[        U5      UR                  S5      pCUR                  5         UR                  5         U(       aO  U(       aH  US   US   :X  a<  UR                  5         UR                  5         U(       a  U(       a  US   US   :X  a  M<  UR                  5         [        R                  R                  S/[        U5      -  U-   5      =(       d    S$ )aA  return the relative path from one place to another.
root should use os.sep to separate directories
n1 should use os.sep to separate directories
n2 should use "/" to separate directories
returns an os.sep-separated path.

If n1 is a relative path, it's assumed it's
relative to root.
n2 should always be relative to root.
r      /r      ..r  )	localpathr,   pathisabs
splitdriver   pconvert	splitpathr  reverser  r   ossepr   )rootn1n2abs        r0   pathtor    s    }	ww}}R77d#A&"''*<*<R*@*CC77<<im44YY+,R="((4.qIIKIIK
aequn		 aequn IIK>>#a& 0A56>$>r2   c                   ^ ^ UU 4S jnU$ )z5wrap a function with code to check for calling errorsc                    >  T" U 0 UD6$ ! [          aK    [        [        R                  " [        R
                  " 5       S   5      5      T:X  a  [        R                  ee f = f)Nr  )	TypeErrorr   	traceback
extract_tbrF   exc_infor   SignatureError)r   r   depthr*  s     r0   checkchecksignature.<locals>.check  sY    	((( 	9''q(9:;uD***	s
    AA r5   )r*  r
  r  s   `` r0   checksignaturer    s     Lr2   >      hfs   jfs   ufs   xfs   zfs   NTFS   apfs   ext2   ext3   ext4   btrfs   tmpfs   reiserfsc                   U(       a	  U(       a   eSn[         R                  R                  U5      (       a0  U(       a  U=(       a    [        R	                  U5      n[        U5        U(       aF  U(       a?   [        [         R                  R                  U5      5      n	U	[        ;  a  Ub  U" 5         SnU(       a(   [        X5        Ub  Sn
[        R                  " U
5      eg[         R                  R                  U 5      (       aG  [         R                   " [         R"                  " U 5      U5        Ub  Sn
[        R                  " U
5      eg [$        R&                  " X5        U(       a  [$        R(                  " X5        O[$        R*                  " X5        U(       aw  UR,                  (       af  [        R	                  U5      nUR/                  U5      (       a;  UR,                  [,        R0                     S-   S-  n[         R2                  " XU45        Ub%  [5        USS9 nUR7                  U5        SSS5        gg! [         a    Sn	 GNf = f! [         a3  nUR                  [        R                  :w  a
  Ub  U" 5          SnAGNSnAff = f! , (       d  f       g= f! [$        R8                   a/  n[        R:                  " [<        R>                  " U5      5      eSnAff = f)	aJ  copy a file, preserving mode and optionally other stat info like
atime/mtime

checkambig argument is used with filestat, and is useful only if
destination file is guarded by any lock (e.g. repo.lock or
repo.wlock).

copystat and checkambig should be exclusive.

nb_bytes: if set only copy the first `nb_bytes` of the source file.
NFz7the `nb_bytes` argument is incompatible with `hardlink`z"cannot use `nb_bytes` on a symlinkr   zr+)r  ) r,   r  lexistsr)   frompathunlink	getfstypedirnameOSError_hardlinkfswhitelistoslinkr   r!  errnoEEXISTislinksymlinkreadlinkshutilcopyfilecopystatcopymoder   isambigST_MTIMEutimeopenr  ErrorrV   r   forcebytestr)rD  r  hardlinkr,  
checkambignb_bytesno_hardlink_cbcheck_fs_hardlinkoldstatfstyper   excnewstatadvancedr,  insts                   r0   r+  r+    s/   * Z((G	wwt <X%6%6t%<Gt%	rwwt45F --) H	!3#M,,Q//
 
ww~~c


2;;s#T* 4A((++  	=OOC&**w||&//5Gw// $LL7!;&$' (';<#$T*aJJx( +* $S  	F	  	!yyELL(^-G 	!: +*|| 	=++j55d;<<	=sa   6(I  <&I CJ$ $J6J$  II
J(JJ
J!J$ !J$ $K'8*K""K'c                h  ^^ SnUU4S jn[         R                  R                  U 5      (       a  Tc^  [         R                  " U 5      R                  [         R                  " [         R                  R                  U5      5      R                  :H  mU" 5         [         R                  " U5        [        U 5       HW  u  pg[         R                  R                  X5      n[         R                  R                  X5      n	[        XTT5      u  mn
XJ-  nMY     TU4$ Tc{  [         R                  " [         R                  R                  U 5      5      R                  [         R                  " [         R                  R                  U5      5      R                  :H  mU" 5         T(       a   [        X5        O[        R                  " X5        US-  nT(       a  TR!                  5         TU4$ ! [         a@  nUR                  [        R                  :w  a  Sm[        R                  " X5         SnANeSnAff = f)z2Copy a directory tree using hardlinks if possible.r   c                 Z   > T(       a#  T (       a  [        S5      O
[        S5      Tl        g g )Ns   linkings   copying)rW   topic)r4  progresss   r0   settopiccopyfiles.<locals>.settopic  s    .6Qz]AjMHN r2   NFr   )r,   r  isdirr   st_devr!  mkdirlistdirr   	copyfilesr$  r"  r%  r&  r*  r;  	increment)rD  dstr4  rB  numrC  r$  kindsrcnamedstnamer"  r;  s     ``        r0   rI  rI    s   
CJ 
ww}}S##rwwrwws/C'D'K'KK  	

!#,JDggll3-Gggll3-G#GhIKHaHC	 '6 S=+ ,-4477277??3/0778  	
&s  KK!q S=  &99,$HC%%	&s   %G' '
H116H,,H1>      aux   con   nul   prn   com1   com2   com3   com4   com5   com6   com7   com8   com9   lpt1   lpt2   lpt3   lpt4   lpt5   lpt6   lpt7   lpt8   lpt9s   :*?"<>|c                \   U R                  S5      (       a  [        S5      $ SU ;   a  [        S5      $ U R                  SS5      R                  S5       H  nU(       d  M  [	        U5       HT  nU[
        ;   a  [        S5      U-  s  s  $ [        U5      S::  d  M0  [        S5      [        R                  " U5      -  s  s  $    UR                  S	5      S
   nU(       a(  UR                  5       [        ;   a  [        S5      U-  s  $ USS nUS;   d  M  US;  d  M  [        S5      U-  s  $    g)a  Check that the base-relative path is a valid filename on Windows.
Returns None if the path is ok, or a UI string describing the problem.

>>> checkwinfilename(b"just/a/normal/path")
>>> checkwinfilename(b"foo/bar/con.xml")
"filename contains 'con', which is reserved on Windows"
>>> checkwinfilename(b"foo/con.xml/bar")
"filename contains 'con', which is reserved on Windows"
>>> checkwinfilename(b"foo/bar/xml.con")
>>> checkwinfilename(b"foo/bar/AUX/bla.txt")
"filename contains 'AUX', which is reserved on Windows"
>>> checkwinfilename(b"foo/bar/bla:.txt")
"filename contains ':', which is reserved on Windows"
>>> checkwinfilename(b"foo/bar/b\07la.txt")
"filename contains '\\x07', which is invalid on Windows"
>>> checkwinfilename(b"foo/bar/bla ")
"filename ends with ' ', which is not allowed on Windows"
>>> checkwinfilename(b"../bar")
>>> checkwinfilename(b"foo\\")
"filename ends with '\\', which is invalid on Windows"
>>> checkwinfilename(b"foo\\/bar")
"directory name ends with '\\', which is invalid on Windows"
   \s3   filename ends with '\', which is invalid on Windowss   \/s9   directory name ends with '\', which is invalid on Windowsr  s4   filename contains '%s', which is reserved on Windows   s3   filename contains '%s', which is invalid on Windowsr  r   r   Ns   . r  s8   filename ends with '%s', which is not allowed on Windows)endswithrW   replacer  _filenamebytestr_winreservedcharsordr   r  lower_winreservednames)r  r"  cbasets        r0   checkwinfilenamers  _  s-   0 }}UHII~NOO\\%&,,T2!!$A%%& 	 1v|J((+, , % wwt}QDJJL$55IJ bcF:!5." 	1 3r2   perf_counterc                    [         R                  " X5      $ ! [         a)  nUR                  [        R                  :X  a  e  SnAOSnAf[
         a     Of = f[         R                  [         R                  -  [         R                  -  [        [         SS5      -  n[         R                  " X5      n [         R                  " X@5        [         R                  " U5        g! [         R                  " U5        f = f)zCreate a lock file atomically if possible

This may leave a stale lock file if symlink isn't supported and signal
interrupt is enabled.
NO_BINARYr   )r,   r(  r"  r%  r&  AttributeErrorO_CREATO_WRONLYO_EXCLr   r1  r  r   )infopathnamewhyr   lds        r0   makelockr    s    zz$)) 99$ %  JJ$ryy072z13MME		!B

s&    
AAAA4C! !C9c                *    [        U 5      $ ! [         a9  nUR                  [        R                  [        R                  4;  a  e  S nAOS nAf[
         a     Of = f[        U S5       nUR                  5       sS S S 5        $ ! , (       d  f       g = f)N   rb)r)  r"  r%  EINVALENOSYSrw  	posixfiler   )r|  r}  r   s      r0   readlockr    so    !! 99U\\5<<88 9 	8U	#rwwy 
$	#	#s&   
 
A/AAA*B
Bc                     [         R                  " U R                  5       5      $ ! [         a#    [         R                  " U R
                  5      s $ f = f)z1stat file object that may not have fileno method.)r,   r   r   rw  r   r$  r   s    r0   r   r     s>     xx		$$  wwrww s   #& *AAc                `   [         R                  " U 5      n[         R                  R                  U 5      u  p#UR	                  5       nX4:X  a  UR                  5       nX4:X  a  g[         R                  R                  X$5      n [         R                  " U5      nXa:X  a  gg! [         a     gf = f)z
Return true if the given path is on a case-sensitive filesystem

Requires a path (like /foo/.hg) ending with a foldable final
directory component.
TF)r,   lstatr  r  upperrn  r   r"  )r  s1dr  b2p2s2s          r0   fscasesensitiver    s     
$B77==DA	
BwWWY7	a	BXXb\8 s   B   
B-,B-c                    U $ r`   r5   r  s    r0   r   r     s    qr2   c                 D    [         c  [        R                  5         [         $ )z0return True is re2 is available, False otherwise)_re2_re	_checkre2r5   r2   r0   has_re2r    s    |Kr2   c                  >    \ rS rSr\S 5       rSS jr\S 5       rSr	g)r  i 	  c                    [         b  g Sn Sn [        [        R                  " X5      5      q  [        R                  " 5       nSUl
        Uqg ! [         a    Sq  N.[
         a^    [        R                  " U 5      n [        R                  " U5      n[        [        R                  " X5      5      q [        R                  q Nf = f! [         a     g f = f)Ns   \[([^\[]+)\]s   [ui]F)r  r   re2r  r  r  r   rD   
_re2_inputOptions
log_errors_re2_optionsrw  )check_patterncheck_inputquiets      r0   r  _re._checkre2	  s    
 (	)		-=>D	KKME$E L  	D 	) %OOM:M"//+6K		-=>D!J	)  		s)   A C CA$CC
CCc                   [         c  U R                  5         [         (       a  U[        R                  [        R                  -  ) -  S:X  a  U[        R                  -  (       a  SU-   nU[        R                  -  (       a  SU-   n [        U5      n[        b  [        R                  " U[        S9nU$ [        R                  " U5      nU$ [        R                  " X5      $ ! [        R                   a     N,f = f)zCompile a regular expression, using re2 if possible

For best performance, use only re2-compatible regexp features. The
only flags from the re module that are re2-compatible are
IGNORECASE and MULTILINE.r   s   (?i)s   (?m))options)
r  r  r  
IGNORECASE	MULTILINEr  r  r  compiler   )rY   patr   input_regexcompileds        r0   r  _re.compile	  s     <NN4Uu//%//ABBqHu'''mu&m(o+"{{;MH    #{{;7H }}S(( 99 s   ,C" 4C" "C98C9c                    [         c  U R                  5         [         (       a  [        R                  $ [        R                  $ )zReturn the version of escape corresponding to self.compile.

This is imperfect because whether re2 or re is used for a particular
function depends on the flags, etc, but it's the best we can do.
)r  r  r  escaper  rl   s    r0   r  
_re.escape7	  s,     <NN4::<<r2   r5   Nr  )
rt   ru   rv   rw   ry   r  r  r  r  rz   r5   r2   r0   r  r   	  s-     :)0    r2   r  c                   S n[         R                  n[         R                  (       a  U[         R                  -   nUR                  SS5        [        R
                  " SX34-  5      n[        R                  R                  U5      n/ nUR                  U 5       H  u  pxU(       a  UR                  U5        M  U[        ;  a  U" U5      [        U'   [        U   n	U	R                  U5      n
U
(       d"  U" U5      =[        U'   n	U	R                  U5      n
UR                  U
=(       d    U5        [        R                  R                  XW5      nM     SR                  U5      $ )a   Get name in the case stored in the filesystem

The name should be relative to root, and be normcase-ed for efficiency.

Note that this function is unnecessary, and should not be
called, for case-sensitive filesystems (simply because it's expensive).

The root should be normcase-ed, too.
c                n    [         R                  " U 5       Vs0 s H  n[        U5      U_M     sn$ s  snf r`   )r,   rH  normcase)dirr"  s     r0   _makefspathcacheentry%fspath.<locals>._makefspathcacheentryW	  s*    (*

381Q888s   2rg  s   \\s   ([^%s]+)|([%s]+)r2   )r   r  osaltseprj  r  r  r,   r  normpathfindallr   _fspathcacher  r   )r$  r  r  sepspatternr  r  partsepcontentsfounds              r0   fspathr  L	  s   9 >>Dh'''LL mm0D<?@G
''

4
 CF__T*	MM#l" 5c :L$T" ,A+EELLL&Eemt$ggll3%# +& 88Fr2   c                "   Su  pn [         R                  " S[        R                  R	                  U 5      -  S[        R                  R                  U 5      S9u  pA[        R                  " U5        SUSS -  n[        X5        [        U5      n[        U5      S:  Ub  UR                  5         X4 H  n Ub  [        R                  " U5        M  M!     $ ! [         a     M1  f = f! [         aM     Ub  UR                  5         X4 H0  n Ub  [        R                  " U5        M  M!  ! [         a     M.  f = f   g	f = f! Ub  UR                  5         X4 H0  n Ub  [        R                  " U5        M  M!  ! [         a     M.  f = f   f = f)
z5check whether hardlink count reporting works properly)NNN   .%s-s   1~prefixsuffixr  s   %s2~Nr   F)r   mkstempr,   r  basenamer!  r   r$  r  nlinksr  r"  )testfilef1f2r   r   r,  s         r0   
checknlinkr  x	  st   
 "JBB!!RWW--h77)

 	r#2wr r]bzA~ >HHJA=IIaL !     >HHJA=IIaL ! 	  >HHJA=IIaL ! 	 sl   BC( 7C
C%$C%(
D?2E D**
D87D8>D??E FE:6F:
F	FF	Fc                    [        U R                  [        R                  5      =(       d6    [        R                  =(       a    U R                  [        R                  5      5      $ )z)Check path ends with os.sep or os.altsep.)r   ri  r   r  r  r  s    r0   endswithsepr  	  sD    hnn% 	- -MM(++, r2   c                @    U R                  [        R                  5      $ )zSplit path by os.sep.
Note that this function does not use os.altsep because this is
an alternative of simple "xxx.split(os.sep)".
It is recommended to use os.path.normpath() before using this
function if need.)r  r   r  r  s    r0   r  r  	  s     ::hnn%%r2   c                   [         R                  R                  U 5      u  pE[        R                  " SU-  SUS9u  pg[         R
                  " U5        [        XX#5        U(       a  U$   [        U S5      n[        US5      n
[        U5       H  nU
R                  U5        M     UR                  5         U
R                  5         U$ ! [         aC  n	U	R                  [        R                  :X  a  Us Sn	A	$ [        U	SS5      (       d  X	l        e Sn	A	ff = f!    [         R                  " U5        e ! [         a     e f = f= f)a  Create a temporary file with the same contents from name

The permission bits are copied from the original file.

If the temporary file is going to be truncated immediately, you
can use emptyok=True as an optimization.

Returns the name of the temporary file.
r     ~r  r  Nfilenames   wb)r,   r  r  r   r  r   r-  r  r"  r%  ENOENTr   r  filechunkiterr  r  )r$  emptyok
createmodeenforcewritabler  rA  r   tempifpr>  ofpr  s               r0   
mktempcopyr  	  s    GGMM$EAw|DaHHBHHRL T5	D%(C e$"3'EIIe (				 K#  	zzU\\)4T22 $		IIdO 	  		sa   *C 6AD 
DD0D1D 6DDD ED10E1
D>;E=D>>Ec                      \ rS rSrSrSS jr\SS j5       r\SS j5       r\	R                  r
SS jrSS jrSS jrSS	 jrS
rg)r)   i	  zhelp to exactly detect change of a file

'stat' attribute is result of 'os.stat()' if specified 'path'
exists. Otherwise, it is None. This can avoid preparative
'exists()' examination on client side of this class.
c                    Xl         g r`   r   )rY   r   s     r0   r]   filestat.__init__	  s    	r2   c                d     [         R                  " U5      nU " U5      $ ! [         a    S n Nf = fr`   )r,   r   FileNotFoundError)r   r  r   s      r0   r  filestat.frompath	  s6    	774=D 4y ! 	D	s     //c                Z    [         R                  " UR                  5       5      nU " U5      $ r`   )r,   r   r   )r   r   r   s      r0   fromfpfilestat.fromfp	  s     xx		$4yr2   c                    U R                   R                  UR                   R                  :H  =(       a}    U R                   [         R                     UR                   [         R                     :H  =(       a;    U R                   [         R                     UR                   [         R                     :H  $ ! [         a     Of = f U R                   S L =(       a    UR                   S L $ ! [         a     gf = fr  )r   r   ST_CTIMEr/  rw  rY   olds     r0   __eq__filestat.__eq__	  s    
	
 		!!SXX%5%55 HIIdmm,0GGHIIdmm,0GG
  			99$9T)99 		s$   B0B3 3
C ?C "C' '
C43C4c                     U R                   [         R                     UR                   [         R                     :H  $ ! [         a     gf = f)ag  Examine whether new (= self) stat is ambiguous against old one

"S[N]" below means stat of a file at N-th change:

- S[n-1].ctime  < S[n].ctime: can detect change of a file
- S[n-1].ctime == S[n].ctime
  - S[n-1].ctime  < S[n].mtime: means natural advancing (*1)
  - S[n-1].ctime == S[n].mtime: is ambiguous (*2)
  - S[n-1].ctime  > S[n].mtime: never occurs naturally (don't care)
- S[n-1].ctime  > S[n].ctime: never occurs naturally (don't care)

Case (*2) above means that a file was changed twice or more at
same time in sec (= S[n-1].ctime), and comparison of timestamp
is ambiguous.

Base idea to avoid such ambiguity is "advance mtime 1 sec, if
timestamp is ambiguous".

But advancing mtime only in case (*2) doesn't work as
expected, because naturally advanced S[n].mtime in case (*1)
might be equal to manually advanced S[n-1 or earlier].mtime.

Therefore, all "S[n-1].ctime == S[n].ctime" cases should be
treated as ambiguous regardless of mtime, to avoid overlooking
by confliction between such mtime.

Advancing mtime "if isambig(oldstat)" ensures "S[n-1].mtime !=
S[n].mtime", even if size of a file isn't changed.
F)r   r  rw  r  s     r0   r.  filestat.isambig
  s>    <	99T]]+sxx/FFF 		s   := 
A
	A
c                    UR                   [         R                     S-   S-  n [        R                  " XU45        g! [         a     gf = f)a  Change file stat of specified path to avoid ambiguity

'old' should be previous filestat of 'path'.

This skips avoiding ambiguity, if a process doesn't have
appropriate privileges for 'path'. This returns False in this
case.

Otherwise, this returns True, as "ambiguity is avoided".
r   r  FT)r   r/  r,   r0  PermissionError)rY   r  r  r=  s       r0   
avoidambigfilestat.avoidambig)
  sQ     HHT]]+a/:=	HHTh/0
 	  	 	s   > 
A
Ac                    X:X  + $ r`   r5   )rY   others     r0   __ne__filestat.__ne__=
  s      r2   r   N)r   r   r   r  )r   Type[_Tfilestat]r  bytesr   r(   )r   r  r   r   r   r(   r  )r  r(   r   r   )r  r  r  r(   r   r   )rt   ru   rv   rw   rx   r]   classmethodr  r  r  __hash__r  r.  r  r  rz   r5   r2   r0   r)   r)   	  sT         H"!F(!r2   c                  @    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
rg)atomictempfileiA
  a  writable file object that atomically updates a file

All writes will go to a temporary copy of the original file. Call
close() when you are done writing, and atomictempfile will rename
the temporary copy to the original name, making the changes
visible. If the object is destroyed without being closed, all your
writes are discarded.

checkambig argument of constructor is used with filestat, and is
useful only if target file is guarded by any lock (e.g. repo.lock
or repo.wlock).
Nc                   Xl         [        USU;   USU;   S9U l        [        U R                  U5      U l        X@l        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l	        U R                  R                  U l
        U R                  R                  U l        g )N   w)r  r  r  )_atomictempfile__namer  	_tempnamer  _fp_checkambigr   r  r!  r  r  r   )rY   r$  r  r  r5  s        r0   r]   atomictempfile.__init__O
  s    #T\!!T\	
 T^^T2% HHMM	XX^^
((--HHMM	HHMM	hhoor2   c                D   U R                   R                  (       Gd  U R                   R                  5         [        U R                  5      nU R
                  =(       a    [        R                  U5      nU(       a  UR                  (       a~  [        U R                  U5        [        R                  U5      nUR                  U5      (       a<  UR                  [        R                     S-   S-  n[        R                  " XU45        g g [        U R                  U5        g g )Nr   r  )r  r   r   r  r  r  r)   r  r   renamer  r.  r/  r,   r0  )rY   r  r9  r<  r=  s        r0   r   atomictempfile.closec
  s    xxHHNN -H&&F8+<+<X+FG7<<t~~x0"++H5??7++ 'T]] ;a ?:MHHHX(';< ,
 t~~x0 r2   c                    U R                   R                  (       d<   [        R                  " U R                  5        U R                   R                  5         g g ! [
         a     N(f = fr`   )r  r   r,   r  r  r"  r   rl   s    r0   discardatomictempfile.discardr
  sK    xx		$..) HHNN   s    A 
A&%A&c                H    [        U S5      (       a  U R                  5         g g )Nr  )r   r  rl   s    r0   __del__atomictempfile.__del__z
  s    4LLN  r2   c                    U $ r`   r5   rl   s    r0   r[  atomictempfile.__enter__~
  r]  r2   c                L    Ub  U R                  5         g U R                  5         g r`   )r  r   )rY   exctypeexcvaluer  s       r0   rb  atomictempfile.__exit__
  s    LLNJJLr2   )
__namer  r  r  r   r   r  r  r  r!  )s   w+bNF)rt   ru   rv   rw   rx   r]   r   r  r  r[  rb  rz   r5   r2   r0   r  r  A
  s%    &(1r2   r  c                     [        U 5        g ! [         aL  nUR                  [        R                  :w  a$  UR                  [        R                  :w  a  e  S nAg  S nAg S nAff = fr`   )
removedirsr"  r%  r  	ENOTEMPTY)r,  es     r0   tryrmdirr  
  sI    1 77ell"qww%//'A (B"s    
A$=AA$c                    U(       a  [        U 5        O[        U 5        U(       a*   [        [        R                  R                  U 5      5        gg! [         a     gf = f)z.unlink and remove the directory if it is emptyN)	tryunlinkr  r  r,   r  r!  r"  )r,  ignoremissingrmdirs      r0   
unlinkpathr  
  sK     !q		rwwq)*   		s   (A 
AAc                <     [        U 5        g! [         a     gf = f)zsAttempt to remove a file, ignoring FileNotFoundError.

Returns False in case the file did not exit, True otherwise
TF)r  r  )r,  s    r0   r  r  
  s#    
q	 s    
c                    [        X5        Ub  [
        R                  " X5        gg! [         a  nUR                  [        R                  :X  a   SnAgUR                  [        R                  :w  d  U (       d  e [
        R                  R                  [        U 5      5      nX@:X  a  e [        XAU5         [        X5         SnAN! [         a-  nUR                  [        R                  :X  a	   SnA SnAge SnAff = fSnAff = f)zrecursive directory creation with parent mode inheritance

Newly created directories are marked as "not to be indexed by
the content indexing service", if ``notindexed`` is specified
for "write" mode access.
N)makedirr"  r%  r&  r  r,   r  r!  abspathmakedirschmod)r$  r  
notindexederrparents        r0   r  r  
  s    !" 
 !  99$99$D/>z*	D%% 	yyELL(		sE   ( 
DD A D 6C
C=C8.D 7C88C==D  Dc                p    [        U S5       nUR                  5       sS S S 5        $ ! , (       d  f       g = f)Nrb)r1  r   )r  r   s     r0   readfiler&  
  s#    	dD	Rwwy 
		s   '
5c                r    [        U S5       nUR                  U5        S S S 5        g ! , (       d  f       g = f)Nwbr1  r  r  textr   s      r0   	writefiler,  
  %    	dD	R
 
		   (
6c                r    [        U S5       nUR                  U5        S S S 5        g ! , (       d  f       g = f)Nabr)  r*  s      r0   
appendfiler1  
  r-  r.  c                  8    \ rS rSrSrS rS rS	S jrS
S jrSr	g)chunkbufferi
  zkAllow arbitrary sized chunks of data to be efficiently read from an
iterator over chunks of arbitrary size.c                t    S nU" U5      U l         [        R                  " 5       U l        SU l        SU l        g)z?in_iter is the iterator that's iterating over the input chunks.c              3     #    U  HI  n[        U5      S:  a3  SnU[        U5      :  a   US-   nXU v   UnU[        U5      :  a  M  MC  ME  Uv   MK     g 7f)N   r      r   )chunksr  posends       r0   splitbig&chunkbuffer.__init__.<locals>.splitbig
  s\     u:%CE
*!Ek#n,! E
**
  K  s   AAAr   N)rk   r  r  _queue_chunkoffset_absolute_offset)rY   in_iterr<  s      r0   r]   chunkbuffer.__init__
  s5    		  W%	!'') !r2   c              #    #    U R                   (       ax  U R                   R                  5       nU R                  (       a  XR                  S  nOUnU =R                  [	        U5      -  sl        Uv   SU l        U R                   (       a  Mx  U R
                   H%  nU =R                  [	        U5      -  sl        Uv   M'     g 7fr4   )r>  r  r?  r@  r   rk   )rY   r  r  s      r0   rm   chunkbuffer.__iter__
  s     kkKK'')E  ++-.!!SV+!G !D kkk A!!SV+!G s   BC6Cc                    U R                   $ )z&tell how much data we have read so far)r@  rl   s    r0   r  chunkbuffer.tell
  s    $$$r2   Nc                   Uc;  SR                  U R                  5      nU =R                  [        U5      -  sl        U$ Un/ nU R                  nUS:  Ga  U(       dD  SnU R                   H*  nUR                  U5        U[        U5      -  nUS::  d  M*    O   U(       d  OUS   n[        U5      nU R                  n	U	S:X  a,  X8:  a'  X8-  nUR                  5         UR                  U5        M  X-
  n
X::  a/  X:-  nUR                  5         UR                  XyS 5        SU l        O.UR                  XyX-    5        U =R                  U-  sl        X:-  nUS:  a  GM  SR                  U5      nU =R                  [        U5      -  sl        U$ )zRead L bytes of data from the iterator of chunks of data.
Returns less than L bytes if the iterator runs dry.

If size parameter is omitted, read everythingNr2   r   r7  )r   rk   r@  r   r>  r   r?  r  )rY   lr  leftr   queuetargetr  chunklr   chunkremainings              r0   r   chunkbuffer.read  sx   
 9#A!!SV+!HQh!YYELL'c%j(F{	 '
  !HEZF&&F {t~

5!#_N %& 

5>*$%! 

5&-89!!T)!&[ Qh^ HHSMQ'r2   )r@  r?  r>  rk   )r   r   r`   )
rt   ru   rv   rw   rx   r]   rm   r  r   rz   r5   r2   r0   r3  r3  
  s    /"&%>r2   r3  i   c              #     #    US:  d   eUb  US:  d   e Uc  UnO[        X!5      nU=(       a    U R                  U5      nU(       d  gU(       a  U[        U5      -  nUv   MN  7f)aE  Create a generator that produces the data in the file size
(default 131072) bytes at a time, up to optional limit (default is
to read all data).  Chunks may be less than size bytes if the
chunk is the last chunk in the file, or the file is a socket or
some other type of file that sometimes reads less data than is
requested.r   N)r   r   r   )r,  r   r  nbytesr[   s        r0   r  r  G  sm      199=EQJ&&
=F%F%qvvf~SVOE s   A#A%c                  .    \ rS rSrSrS rSS jrS rSrg)	cappedreaderi]  a  A file object proxy that allows reading up to N bytes.

Given a source file object, instances of this type allow reading up to
N bytes from that source file object. Attempts to read past the allowed
limit are treated as EOF.

It is assumed that I/O is not performed on the original file object
in addition to I/O that is performed by this instance. If there is,
state tracking will get out of sync and unexpected results will ensue.
c                    Xl         X l        g)z,Allow reading up to <limit> bytes from <fh>.Nr~   _left)rY   r   r  s      r0   r]   cappedreader.__init__i  s    
r2   c                
   U R                   (       d  gUS:  a  U R                   nU R                  R                  [        XR                   5      5      nU =R                   [	        U5      -  sl         U R                   S:  d   eU$ )Nr2   r   )rU  r~   r   r   r   )rY   r"  rb   s      r0   r   cappedreader.readn  s^    zzq5

Axx}}SJJ/0

c$i
zzQr2   c                n    U R                  [        U5      5      nUc  g X!S[        U5      & [        U5      $ r4   )r   r   )rY   r  r@  s      r0   r  cappedreader.readinto{  s2    iiA;!c#h3xr2   rT  Nr   )	rt   ru   rv   rw   rx   r]   r   r  rz   r5   r2   r0   rR  rR  ]  s    	
r2   rR  c                    ^  U 4S jnU$ )z@return a function that renders a readable count of some quantityc                x   > T H)  u  pn[        U 5      X!-  :  d  M  X0[        U5      -  -  s  $    TS   S   U -  $ )Nr   r  )absfloat)count
multiplierdivisorformat	unittables       r0   gounitcountfn.<locals>.go  sI    +4'J5zW11w!788 ,5 }Q%''r2   r5   )rc  rd  s   ` r0   unitcountfnrf    s    ( Ir2   c                    X-
  S:  a  [         R                  " [        S5      5      eU S:  a  [         R                  " [        S5      5      eU S-
  U4$ )aZ  Check that linerange <fromline>:<toline> makes sense and return a
0-based range.

>>> processlinerange(10, 20)
(9, 20)
>>> processlinerange(2, 1)
Traceback (most recent call last):
    ...
ParseError: line range must be positive
>>> processlinerange(0, 5)
Traceback (most recent call last):
    ...
ParseError: fromline must be strictly positive
r   s   line range must be positiver   s"   fromline must be strictly positive)r   
ParseErrorrW   )fromlinetolines     r0   processlinerangerk    sS     1q!?@AA!|q!FGHHa<r2   d      @s   %.0f GB
   s   %.1f GBs   %.2f GBr6  s   %.0f MBs   %.1f MBs   %.2f MBs   %.0f KBs   %.1f KBs   %.2f KBs
   %.0f bytesc                  @    \ rS rSrSrS	S jrS
S jrS
S jrSS jrSr	g)transformingwriteri  z3Writable file wrapper to transform data by functionc                    Xl         X l        g r`   )r  _encode)rY   r   r  s      r0   r]   transformingwriter.__init__  s    r2   c                8    U R                   R                  5         g r`   )r  r   rl   s    r0   r   transformingwriter.close      r2   c                8    U R                   R                  5         g r`   )r  rH   rl   s    r0   rH   transformingwriter.flush  rv  r2   c                V    U R                   R                  U R                  U5      5      $ r`   )r  r  rr  )rY   rb   s     r0   r  transformingwriter.write  s    xx~~dll4011r2   )rr  r  N)r   r   r  zCallable[[bytes], bytes]r   r  r  )rb   r  r   r   )
rt   ru   rv   rw   rx   r]   r   rH   r  rz   r5   r2   r0   rp  rp    s    =2r2   rp  s   \r*\nc                .    [         R                  SU 5      $ )Nr   _eolresubr[   s    r0   tolfr    s    ::eQr2   c                .    [         R                  SU 5      $ )N   
r|  r  s    r0   tocrlfr    s    ::gq!!r2   c                "    [        U [        5      $ r`   )rp  r  r   s    r0   _crlfwriterr    s    b&))r2   r  c                    [         er`   NotImplementedErrorr  s    r0   tonativeeolr        !!r2   c                    [         er`   r  r  s    r0   fromnativeeolr    r  r2   c                    [         er`   r  r   s    r0   nativeeolwriterr    r  r2   c                    U $ r`   r5   r   s    r0   iterfiler    s    Ir2   c              #  R   #    U  H  nUR                  5        S h  vN   M     g  N	7fr`   )r  )iteratorr  s     r0   	iterlinesr    s$     ##%%% %s   '%
'c                z    [         R                  R                  [         R                  R                  U 5      5      $ r`   )r,   r  
expanduser
expandvarsr  s    r0   
expandpathr    s&    77bgg00677r2   c                  ^^ T=(       d    S mSR                  TR                  5       5      nU(       a$  USU -   -  n[        U 5      S:  a  U SS nOU nUTU'   [        R                  " SX4-  5      nUR                  UU4S jU5      $ )a  Return the result of interpolating items in the mapping into string s.

prefix is a single character string, or a two character string with
a backslash as the first character if the prefix needs to be escaped in
a regular expression.

fn is an optional function that will be applied to the replacement text
just before replacement.

escape_prefix is an optional flag that allows using doubled prefix for
its escaping.
c                    U $ r`   r5   r  s    r0   r   interpolate.<locals>.<lambda>  s    !r2      |r   Ns   %s(%s)c                <   > T" TU R                  5       SS     5      $ )Nr   )r  )r  rA  mappings    r0   r   r    s    2gaggim45r2   )r   r   r   r  r  r~  )r  r  r[   rA  escape_prefixpatternsprefix_charrs    ` `    r0   interpolater    s     
	Byy(HD6M!v;? *K K*jF#556A555q99r2   g     @@s   %.0f ss   %.1f ss   %.2f ss   %.3f sgMbP?s   %.1f mss   %.2f mss   %.3f msgư>s   %.1f uss   %.2f uss   %.3f usg&.>s   %.1f nss   %.2f nss   %.3f nsc                      \ rS rSrSr\R                  " \R                  " S 5      S9r\R                  " SS9r	\R                  " SS9r
S r\R                  " \5      rSrg	)
timedcmstatsi)  zFStats information produced by the timedcm context manager on entering.c                     [        5       $ r`   )timerr5   r2   r0   r   timedcmstats.<lambda>/  s    r2   )r:   r   r   c                R    U R                   (       a  [        U R                   5      $ S$ )Ns	   <unknown>)elapsed	timecountrl   s    r0   	__bytes__timedcmstats.__bytes__6  s    *.,,y&HLHr2   r5   N)rt   ru   rv   rw   rx   r   ibFactorystartr  r	  r  r   	strmethod__str__rz   r5   r2   r0   r  r  )  sT    P GGDLL9:E gga GGGAEI   +Gr2   r  c              '    #    [         =R                  S-  sl        [        [         R                  S9n [        R                  " U /UQ76    Uv   SSS5        [        5       UR                  -
  Ul        [         =R                  S-  sl        g! , (       d  f       ND= f! [        5       UR                  -
  Ul        [         =R                  S-  sl        f = f7f)zA context manager that produces timing information for a given context.

On entering a timedcmstats instance is produced.

This context manager is reentrant.

r   )r	  N)timedcm_nestedr  r   logr  r  r  )	whencefmt
whenceargstiming_statss      r0   r  r  <  s      OOqOgoo6L[[0Z0 1  %w););;1	 10  %w););;1s4   1CB BB 6C
BB 7CCc                   ^  U 4S jnU$ )zReport the execution time of a function call to stderr.

During development, use as a decorator when you need to measure
the cost of a function, e.g. as follows:

@util.timed
def foo(a, b, c):
    pass
c                 H  > [        [        R                  " TR                  5      5       nT" U 0 UD6nS S S 5        [        R
                  nUR                  SSWR                  -  S-  [        R                  " TR                  5      U4-  5        W$ ! , (       d  f       Ne= f)Ns	   %s%s: %s
    r  )r  r   bytestrrt   r   rG   r  r	  )r   r   
time_statsr  rG   r*  s        r0   r  timed.<locals>.wrapper^  s    X%%dmm454*6*F 6z'''!+  /	
  65s   	B
B!r5   r  s   ` r0   timedr  S  s     Nr2   ))   mr6  )   kr  )   grm  )s   kbr  )s   mbr6  )s   gbrm  )   br   c           
     L   U R                  5       R                  5       n [         HA  u  p#UR                  U5      (       d  M  [	        [        US[        U5      *  5      U-  5      s  $    [	        U5      $ ! [         a#    [        R                  " [        S5      U -  5      ef = f)z~Convert a space specifier to a byte count.

>>> sizetoint(b'30')
30
>>> sizetoint(b'2.2kb')
2252
>>> sizetoint(b'6M')
6291456
Ns   couldn't parse size: %s)striprn  
_sizeunitsri  r   r^  r   r   r   rh  rW   )r[   rr  r\   us       r0   	sizetointr  z  s     	
	ABDAzz!}}59c!fW.233  1v Bq!;<q@AABs   A6 %A6 )A6 6-B#c                  2    \ rS rSrSrS rSS jrS	S jrSrg)
hooksi  zA collection of hook functions that can be used to extend a
function's behavior. Hooks are called in lexicographic order,
based on the names of their sources.c                    / U l         g r`   _hooksrl   s    r0   r]   hooks.__init__  s	    r2   c                <    U R                   R                  X45        g r`   )r  r   )rY   r  hooks      r0   add	hooks.add  s    F>*r2   c                    U R                   R                  S S9  / nU R                    H  u  p4UR                  U" U6 5        M     U$ )Nc                    U S   $ r4   r5   r  s    r0   r    hooks.__call__.<locals>.<lambda>  s    qtr2   )rg   )r  sortr   )rY   r   resultsr  r  s        r0   __call__hooks.__call__  sA    ^, KKLFNN4;' (r2   r  N)r  r  r  r   r   r  )r   r	   )	rt   ru   rv   rw   rx   r]   r  r  rz   r5   r2   r0   r  r    s    ,+r2   r  c           
   #  ^  #    [         R                  " 5       SU * S-
    VVVVs/ s H7  u  pEpgU[        R                  " U5      U4-  [        R                  " U5      4PM9     snnnnU* S nU(       a1  [	        S U 5       5      n	U H  u  pUc  XU4v   M  XX4-  v   M     ggs  snnnnf 7f)a  Yields lines for a nicely formatted stacktrace.
Skips the 'skip' last entries, then return the last 'depth' entries.
Each file+linenumber is formatted according to fileline.
Each line is formatted according to line.
If line is None, it yields:
  length of longest filepath+line number,
  filepath+linenumber,
  function

Not be used in production code but very convenient while developing.
Nr   c              3  >   #    U  H  n[        US    5      v   M     g7fr   Nr8  ).0entrys     r0   	<genexpr>!getstackframes.<locals>.<genexpr>  s     7weCaMMws   )r  extract_stackr   sysbytesr   )skipr  fileliner
  rA  lnr*  _textentriesfnmaxfnlns              r0   getstackframesr    s      $-#:#:#<[uqy#I#IBD 
X&&r*B/	/1B1B41HI#I fgG 7w77!JD|D))T000	 " 	s   "B->B%
"AB-s
   stacktracer2   c                    U(       a  UR                  5         UR                  SXPR                  5       4-  5        [        US-   US9 H  nUR                  XV-   5        M     UR                  5         g)aC  Writes a message to f (stderr) with a nicely formatted stacktrace.
Skips the 'skip' entries closest to the call, then show 'depth' entries.
By default it will flush stdout first.
It can be used everywhere and intentionally does not require an ui object.
Not be used in production code but very convenient while developing.
s	   %s%s at:
r   )r
  N)rH   r  rstripr  )rI   r  r,  otherfr
  r  r  s          r0   debugstacktracer    sV     GGMVZZ\223taxu5	 6GGIr2   c                    Uc
  [        5       nSX4-  nXB;  a  XC;  a  U$ [        R                  " S5       H  nSXU4-  nXB;  d  M  XC;  d  M  Us  $    g)a  
Generate a name that it is safe to rename f to in the given context.

f:      filename to rename
tag:    a string tag that will be included in the new name
ctx:    a context, in which the new name must not exist
others: a set of other filenames that the new name must not be in

Returns a file name of the form oldname~tag[~number] which does not exist
in the provided context and is not in the set of other names.
Ns   %s~%sr   s   %s~%s~%s)set	itertoolsr_  )r,  tagctxothersrA  r"  s         r0   safenamer    s[     ~	QH	B	})	__QAA;&=R-I  r2   c                    U R                  U5      n[        U5      U:  a-  [        R                  " [	        S5      [        U5      U4-  5      eU$ )z=read n bytes from stream.read and abort if less was availables5   stream ended unexpectedly (got %d bytes, expected %d))r   r   r   rV   rW   )streamr"  r[   s      r0   readexactlyr    sK    AA
1vzkkFG1vqk
 	
 Hr2   c                H   U S:  a  [         R                  " SU -  5      eU S-  nU S-  n / nU (       a;  UR                  [        R                  " SU-  5      5        U S-  nU S-  n U (       a  M;  UR                  [        R                  " U5      5        SR                  U5      $ )a  Encode an unsigned integer value to a varint.

A varint is a variable length integer of 1 or more bytes. Each byte
except the last has the most significant bit set. The lower 7 bits of
each byte store the 2's complement representation, least significant group
first.

>>> uvarintencode(0)
'\x00'
>>> uvarintencode(1)
'\x01'
>>> uvarintencode(127)
'\x7f'
>>> uvarintencode(1337)
'\xb9\n'
>>> uvarintencode(65536)
'\x80\x80\x04'
>>> uvarintencode(-1)
Traceback (most recent call last):
    ...
ProgrammingError: negative value for uvarint: -1
r   s   negative value for uvarint: %d         r2   )r   r!  r   r   bytechrr   )r8  r7   r  s      r0   uvarintencoder    s    . qy$$%F%NOO4<D	aKEE
X%%dTk23t|! % 
LL!!$'(88E?r2   c                p    SnSn [        [        U S5      5      nXS-  U-  -  nUS-  (       d  U$ US-  nM2  )a  Decode an unsigned variable length integer from a stream.

The passed argument is anything that has a ``.read(N)`` method.

>>> from io import BytesIO
>>> uvarintdecodestream(BytesIO(b'\x00'))
0
>>> uvarintdecodestream(BytesIO(b'\x01'))
1
>>> uvarintdecodestream(BytesIO(b'\x7f'))
127
>>> uvarintdecodestream(BytesIO(b'\xb9\n'))
1337
>>> uvarintdecodestream(BytesIO(b'\x80\x80\x04'))
65536
>>> uvarintdecodestream(BytesIO(b'\x80'))
Traceback (most recent call last):
    ...
Abort: stream ended unexpectedly (got 0 bytes, expected 1)
r   r   r  r  r  )rm  r  )r   r  shiftbytes       r0   uvarintdecodestreamr    sM    * FE
;r1%&$;5((tM
 r2   c               #    #    [         R                  " [         R                  S 5      n U S:X  aQ    [         R                  " [         R                  S5        S v   [         R                  " [         R                  U 5        g S v   g ! [         R                   a     NEf = f! [         R                  " [         R                  U 5        f = f7f)NCr;   )locale	setlocaleLC_CTYPEr2  )oldlocs    r0   with_lc_ctyper	  F  s     foot4F}		6  "5
 V__f5 <<   V__f5s:   ,C%B B +CBB BB 'CCc                   ^^	 [         R                  R                  S5      (       ad  SSKJmJm	  SSKJn JnJ	nJ
n   " UU	4S jSU 5      nU" 5       nU" U5      Ul        UR                  R                  U" U5      5        UR                  $  [        R                   " [        R"                  S   5      n[        R                   " [        R"                  S   5      nXg-  $ ! [$         a     g	[&         a     g	f = f)
z}Provide an estimate for the available system memory in Bytes.

If no estimate can be provided on the platform, returns None.
s   winr   )c_longc_ulonglong)	Structurebyrefsizeofwindllc            
      b   > \ rS rSrS Y 4S Y 4S Y4S Y4S Y4S Y4S Y4S	 Y4S
 Y4/	rSrg)'_estimatememory.<locals>.MEMORYSTATUSEXih  dwLengthdwMemoryLoadullTotalPhysullAvailPhysullTotalPageFileullAvailPageFileullTotalVirtualullAvailVirtualullExtendedVirtualr5   N)rt   ru   rv   rw   _fields_rz   )DWORD	DWORDLONGs   r0   MEMORYSTATUSEXr  h  sR    U#'++#Y/#Y/"I."I.%y1
Hr2   r  SC_PAGE_SIZESC_PHYS_PAGESN)r   sysplatform
startswithctypesr  r  ctypes.wintypesr  r  r  r  r  kernel32GlobalMemoryStatusExr  r,   sysconfsysconf_namesr"  r  )
r  r  r  r  r  r  pagesizepagesr  r  s
           @@r0   _estimatememoryr,  X  s    
 &&v.. 	E	
 	
	 	Y 	 AY
,,U1X6~~
::b..~>?

2++O<=  s   AC 
C6*	C65C6)r/   r   r   r  )r   r  r  r  r  )Nr  r`   )r  i   )r   r   )r  r  r  r  r  r  r   r  )FFFNNTr  )r  r  r   zOptional[bytes])r{  r  r|  r  r   r  )r|  r  r   r  )r  r  r   r   )r$  r  r  r  r   r  )r  r  r   r   )r  r  r   zList[bytes])FNF)
r$  r  r  r   r  Optional[int]r  r   r   r  )FT)r,  r  r  r   r  r   r   r  )r,  r  r   r   r  )r$  r  r  r-  r!  r   r   r  )r  r  r   r  )r  r  r+  r  r   r  )ri  r   rj  r   r   zTuple[int, int])r[   r  r   r  )r   typelib.BinaryIO_Proxyr   r.  )r  zIterable[bytes]r   zIterator[bytes])r[   r  r   r   )r   s    %-*s in %s
s   %s:%dr   )r   r-  (  rx   
__future__r   rd  r  
contextlibr%  r  hashlibior  r  r   r,   picklerer  r*  r   rF   timer  typingrB   r   r   r   r   r   r	   r
   r   r   r   r  r   
thirdpartyr   TYPE_CHECKINGhgdemandimportr   r;   r   r   r   r   r   r   r   
interfacesr   int_miscr   intmodutilsr   r   r   r   typing_extensionsr   r    	importmodr#   r  r$   	b85decode	b85encode	cookielibhttplibsafehasattrsocketserverBytesIObytesiostringio	xmlrpclib
httpserverurlerrurlreqr  rk  r+   r%   r.   r&   rW   r  bindunixsocket	cachestat	checkexec	checklinkr-  expandglobsgetfsmountpointr   get_passwordgroupmembers	groupnameisexecisownerrH  r  	lookupregr  r  r  r  normcasespecnormcasefallbackopenhardlinksr$  parsepatchoutputr  pollr  r)  r  r  
samedevicesamefilesamestatsetflagsr  r   r'   
statisexec
statislinkr-   r  usernamer(   r1   compengines
SERVERROLE
CLIENTROLEr  rs  r9   r   environr  rA   filterwarningsrE   rL   md5sha1sha512rU   rp   r\   rQ   r|   r   	NameErrorr   r   r   r   r   r   r   r  r  r  r  r  r  r  rJ   r'  r4  r!   OrderedDictr?  r   rN  rQ  ABCrS  contextmanagerri  rl  rn  ry  r  r  r  r  r  r  r  r  r  rL  r  r  r#  r+  rI  ro  rl  rs  r  checkosfilenameclockr  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r)   r  r  r  r  r  r&  r,  r1  r3  DEFAULT_FILE_CHUNKr  rR  rf  rk  	bytecountBinaryIO_Proxyrp  r  r}  r  r  r  	oslinesepr  r  r  identityr  r  r  r  r  r[   r  r  r  r  r  r  IHooksr  r  rG   stdoutr  rK  r  r  r  r  r	  r,  r5   r2   r0   <module>rz     sH   # 
    	  	    	     
         
 "    	   
 G5)E((2 2			(	#			


""$$
**	$$
						 ## %#FF


((			""**	$$$$		



..		


	$$,, &&	,, }}		  
  
FK););<	  
  
	 
Z8J) %%##
##
 ( x##$56
7
 Ir+={KIr+=wGIr+=zJ
, 2K +-? &	  KK]]~~ 3 	A<< 
- -`" "J	!F 
k k\+\ o
 o
d' 1 'T  x
 x
v" "Ja* aJ IM) D
& D
V %0TJn> ,${&& $Nc4 6#x CGG 2  $   0c cL	>( (B%&   ???D?6 ( M=`*Z 0  :z 	nd+&O

 ..O		,	 0 
D
D  D N 	U)XB&  $!	-
-- - 	-
 -`c! c!LD DN :>!26	 	 AF
$9=	>


g gT #  -D ,$ $N	 , '1Z=!!J- :'1Z=!!J- :'1Z=!!J- :1]	2// 2( 
y	! "*  KM!O##K%%M''O	"""
&
8:4 Qy\!Qy\AiL1Y<%:*q}(AjM"1Z=!!J- +q}%a
m$Qz]#	" , , ,$  & 8
B(HOO &14 		
oo??
. 0"JT  ",y_  !!!r<  Ds$   7h$ !h6 $h32h36ii