
    6h'X                    R   S SK Jr  S SKrS SKrS SKJr  SSKJr  SSKJ	r	  SSK
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  \R2                  rS
 rS r " S S\R8                  5      r " S S\R<                  5      r " S S\R@                  \RB                  \RD                  5      r#g)    )annotationsN)futures   )_)bin)bundle2changegroupencodingerrorpushkeypycompatutilwireprototypes)
repository)hashutilc                \   ^  U 4S jn[        UST 5        [        UST R                  5        U$ )a|  annotation for batchable methods

Such methods must implement a coroutine as follows:

@batchable
def sample(self, one, two=None):
    # Build list of encoded arguments suitable for your wire protocol:
    encoded_args = [('one', encode(one),), ('two', encode(two),)]
    # Return it, along with a function that will receive the result
    # from the batched request.
    return encoded_args, decode

The decorator returns a function which wraps this coroutine as a plain
method, but adds the original method as an attribute called "batchable",
which is used by remotebatch to split the call into separate encoding and
decoding phases.
c                    > T" U 0 UD6u  p#U(       d  U$ U S   n[         R                  " TR                  5      nUR                  XR5      nU" U5      $ )Nr   )r   bytesurl__name__
_submitone)argsoptsencoded_args_or_resdecodeselfcmdencoded_resfs          ;/usr/lib/python3/dist-packages/mercurial/wireprotov1peer.pyplainbatchable.<locals>.plain5   sU    &'&6&6#&&Aw

+ooc?k""    	batchabler   )setattrr   )r   r    s   ` r   r#   r#   "   s+    &# E;"E:qzz*Lr"   c                  ^ [         R                  m/ nU  H_  u  p#[        U4S jU 5       5      (       d   eSR                  U4S jUR	                  5        5       5      nUR                  SX$4-  5        Ma     SR                  U5      $ )z;Return a ``cmds`` argument value for the ``batch`` command.c              3  :   >#    U  H  nT" U5      U:H  v   M     g 7fN ).0k	escapeargs     r   	<genexpr>"encodebatchcmds.<locals>.<genexpr>L   s     7h9Q<1$hs      ,c              3  N   >#    U  H  u  pS T" U5      T" U5      4-  v   M     g7f)s   %s=%sNr(   )r)   r*   vr+   s      r   r,   r-   N   s)      
@PH	!il33@Ps   "%s   %s %s   ;)r   escapebatchargalljoinitemsappend)reqcmdsopargsdictr   r+   s        @r   encodebatchcmdsr;   C   s    --ID 7h77777yy 
@H@P
 
 	Hz)*  99T?r"   c                  .    \ rS rSr% SrS\S'   SS jrSrg)	unsentfutureV   a  A Future variation to represent an unsent command.

Because we buffer commands and don't submit them immediately, calling
``result()`` on an unsent future could deadlock. Futures for buffered
commands are represented by this type, which wraps ``result()`` to
call ``sendcommands()``.
peerexecutor_peerexecutorNc                    U R                  5       (       a  [        R                  R                  X5      $ U R                  R                  5         U R                  U5      $ r'   )doner   Futureresultr@   sendcommands)r   timeouts     r   rD   unsentfuture.resulta   sE    99;;>>((77'')
 {{7##r"   r(   r'   )r   
__module____qualname____firstlineno____doc____annotations__rD   __static_attributes__r(   r"   r   r=   r=   V   s      	$r"   r=   c                  >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)r?   m   c                    Xl         SU l        SU l        / U l        [        R
                  " 5       U l        S U l        S U l        g )NF)	_peer_sent_closed_callsweakrefWeakSet_futures_responseexecutor
_responsef)r   peers     r   __init__peerexecutor.__init__n   s9    

)!%r"   c                    U $ r'   r(   r   s    r   	__enter__peerexecutor.__enter__w   s    r"   c                $    U R                  5         g r'   )close)r   exctypeexcvaleeexctbs       r   __exit__peerexecutor.__exit__z   s    

r"   c                .  ^ ^^^ T R                   (       a  [        R                  " S5      eT R                  (       a  [        R                  " S5      e[	        T R
                  [        R                  " T5      S 5      mT(       d  [        R                  " ST-  5      eUUUU 4S jn[	        TSS5      (       a  U" 5       n[        Ul	        T Ul
        U$ T R                  (       a  [        R                  " ST-  5      eU" 5       nT R                  5         U$ )Ns4   callcommand() cannot be used after commands are sents*   callcommand() cannot be used after close()sA   cannot call command %s: method of same name not available on peerc                    > [         R                  " 5       n TR                  R                  U 5        TR                  R                  TTTU 45        U $ r'   )r   rC   rW   addrT   r6   )r   r   commandfnr   s    r   addcall)peerexecutor.callcommand.<locals>.addcall   sA     AMMa KKr156Hr"   r#   FsX   %s is not batchable and cannot be called on a command executor along with other commands)rR   r   ProgrammingErrorrS   getattrrQ   r   sysstrr=   	__class__r@   rT   rE   )r   rk   r   rm   r   rl   s   ```  @r   callcommandpeerexecutor.callcommand}   s    ::((G  <<((= 
 TZZ!94@(($% 	 	 2{E**	A 'AK"AO  {{,,:<CD 
 	A r"   c                   U R                   (       a  g U R                  (       d  g SU l         U R                   H6  n[        U[        5      (       d  M  [
        R                  Ul        S Ul        M8     U R                  nS U l        [        U5      S:X  aM  US   u  p4pQUR                  5       (       d  g  U" S0 [        R                  " U5      D6nUR                  U5        g / n/ nU H  u  p4pQUR                  5       (       d  M   UR$                  " UR&                  40 [        R                  " U5      D6u  pU
(       d  UR                  U	5        Mk  UR)                  X945        UR)                  X1[$        U
45        M     U(       d  g U R*                  R-                  U5      n[
        R.                  " S5      U l        U R0                  R3                  U R4                  X5      U l        g ! [         a0    [        R                  " U[         R"                  " 5       SS  5         g f = f! [         a1    [        R                  " U[         R"                  " 5       SS  5           g f = f)NTr   r   r(   )rR   rT   rW   
isinstancer=   r   rC   rr   r@   lenset_running_or_notify_cancelr   	strkwargs
set_result	Exceptionfuture_set_exception_infosysexc_infor#   __self__r6   rQ   _submitbatchThreadPoolExecutorrX   submit_readbatchresponserY   )r   r   callsrk   r   rl   rD   requestsstatesr   r   wireresultss               r   rE   peerexecutor.sendcommands   s	   ::{{
 A!\**%nn"& 
  u:?#(8 G2 1133%7h0067 V$ $) G21133.0llKK/#+#5#5d#;/+# 01 >?w9f=># %*&  jj--h7 ")!;!;A!>0077##V
a  J221cllnQR6HI J4  221cllnQR6HIs$   3G* 3H'*7H$#H$'7I"!I"c           
        U R                  5         U R                  (       a  g SU l        U R                  (       d  g  U R                  R                  5         U R                  c   eU R                  R                  SS9  S U l        S U l        U R                   HI  nUR                  5       (       a  M  UR                  [        R                  " [        S5      S 5      5        MK     S U l        g ! U R                  c   eU R                  R                  SS9  S U l        S U l        U R                   HI  nUR                  5       (       a  M  UR                  [        R                  " [        S5      S 5      5        MK     S U l        f = f)NT)wait"   unfulfilled batch command response)rE   rS   rY   rD   rX   shutdownrW   rB   set_exceptionr   ResponseErrorr   )r   r   s     r   rb   peerexecutor.close  sF   <<	!OO""$ ))555""+++6"DO%)D" ]]vvxxOO++CDd # !DM ))555""+++6"DO%)D" ]]vvxxOO++CDd # !DMs   C. .AF;Fc           	     d   U H,  u  p4pV [        U5      n U" U5      nUR                  U5        M.     g ! [         a1    [        R                  " U[
        R                  " 5       SS  5         Mk  f = f! [         a3    UR                  [        R                  " [        S5      S 5      5         M  f = f)Nr   r   )nextrz   r{   r   r|   r}   r~   StopIterationr   r   r   r   )	r   r   r   rk   r   r#   r   remoteresultrD   s	            r   r   peerexecutor._readbatchresponse)  s     .4)G	)#K0)#L1F LL() .4" ! N66q#,,.:LMN !  ''?@$	s    A247A/.A/29B/.B/)rT   rS   rW   rQ   rX   rY   rR   N)r   rH   rI   rJ   r[   r_   rf   rs   rE   rb   r   rM   r(   r"   r   r?   r?   m   s)    5nP
d!!F)r"   r?   c                      \ rS rSrSrS rS rS rS r\	S 5       r
\	S 5       r\	S	 5       r\	S
 5       r\	S 5       r\	S 5       rS rS rS rS rS rS rS rS rS rSS jrS rS rS rS rS rS rSr g) wirepeeriC  zClient-side interface for communicating with a peer repository.

Methods commonly call wire protocol commands of the same name.

See also httppeer.py and sshpeer.py for protocol-specific
implementations of this interface.
c                    [        U 5      $ r'   )r?   r^   s    r   commandexecutorwirepeer.commandexecutorN  s    D!!r"   c                    U R                  S5      (       a  U R                  S5      $ U R                  S[        S5      5        U R                  S5      $ )Ns   clonebundles_manifests   clonebundless   clone bundles)capable_call
requirecapr   r^   s    r   clonebundleswirepeer.clonebundlesS  sE    <<011::677OOOQ/?-@A::o..r"   c                    g r'   r(   )r   streams     r   _finish_inline_clone_bundle$wirepeer._finish_inline_clone_bundleZ  s    r"   c              #     #    U R                  SUS9n[        R                  " U5      n[        R                  " X#S9 S h  vN   U R	                  U5        g  N7f)Ns   get_cached_bundle_inline)path)limit)_callstreamr   uvarintdecodestreamfilechunkiterr   )r   r   r   lengths       r   get_cached_bundle_inline!wirepeer.get_cached_bundle_inline]  sT     !!"=D!I))&1 %%f;;;((0 	<s   >A AAc                z   ^  T R                  S[        S5      5        U 4S jnS[        R                  " U5      0U4$ )Ns   lookups   look up remote revisionc                   > U S S R                  SS5      u  p[        U5      (       a  [        U5      $ TR                  [        R
                  " U5      5        g )N    r   )splitintr   _abortr   	RepoError)dsuccessdatar   s      r   r   wirepeer.lookup.<locals>.decodej  sC    crFLLq1MG7||4y EOOD12r"      key)r   r   r
   	fromlocal)r   keyr   s   `  r   lookupwirepeer.lookupf  s9    	1%?#@A	3 **3/0&88r"   c                   ^  U 4S jn0 U4$ )Nc                   >  [         R                  " U S S 5      $ ! [         a2    TR                  [        R
                  " [        S5      U 5      5         g f = f)Nr      unexpected response:)r   
decodelist
ValueErrorr   r   r   r   )r   r   s    r   r   wirepeer.heads.<locals>.decodeu  sP    P%003B88 PE//2I0JANOPs    9AAr(   r   r   s   ` r   headswirepeer.headss  s    	P 6zr"   c                D   ^  U 4S jnS[         R                  " U5      0U4$ )Nc                   >  [         R                  " U 5       Vs/ s H  n[        [        U5      5      PM     sn$ s  snf ! [         a2    TR                  [        R                  " [        S5      U 5      5         g f = f)Nr   )	r   iterbytestrboolr   r   r   r   r   r   )r   br   s     r   r   wirepeer.known.<locals>.decode  sf    P.6.B.B1.EF.ESV.EFFF PE//2I0JANOPs   A <A A 9A=<A=   nodes)r   
encodelist)r   nodesr   s   `  r   knownwirepeer.known}  s&    	P .33E:;VCCr"   c                   ^  U 4S jn0 U4$ )Nc                h  >  0 nU R                  5        HZ  nUR                  SS5      u  p4[        R                  " [        R                  U5      5      n[        R                  " U5      nXAU'   M\     U$ ! [         a2    TR                  [        R                  " [        S5      U 5      5         g f = f)Nr   r   r   )
splitlinesr   r
   tolocalurlrequnquoter   r   	TypeErrorr   r   r   r   )r   	branchmap
branchpart
branchnamebranchheadsr   s        r   r   "wirepeer.branchmap.<locals>.decode  s    	P	"#,,.J.8.>.>tQ.G+J!)!1!1&..2L!MJ"0";";K"HK,7j)	 #1
 !  PE//2I0JANOPs   A1A5 59B10B1r(   r   s   ` r   r   wirepeer.branchmap  s    
	P 6zr"   c                   ^ ^ T R                  S5      (       d  0 S 4$ T R                  R                  ST-  5        UU 4S jnS[        R                  " T5      0U4$ )N   pushkeys   preparing listkeys for "%s"
c                   > TR                   R                  ST[        U 5      4-  5        [        R                  " U 5      $ )Ns$   received listkey for "%s": %i bytes
)uidebugrw   
pushkeymod
decodekeys)r   	namespacer   s    r   r   !wirepeer.listkeys.<locals>.decode  s7    GGMM8Is1v;NN ((++r"   	   namespacer   r   r   r
   r   )r   r   r   s   `` r   listkeyswirepeer.listkeys  sS    ||J''t8O6BC	, h00;<fDDr"   c                .  ^  T R                  S5      (       d  gT R                  R                  SX4-  5        U 4S jn[        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      S.U4$ )Nr   )FNs   preparing pushkey for "%s:%s"
c                0  > U R                  SS5      u  p [        [        U 5      5      n UR                  S5       H(  nTR                  R                  [        S5      U5        M*     U $ ! [         a!    [        R
                  " [        S5      U 5      ef = f)N   
r   "   push failed (unexpected response):T   remote: )
r   r   r   r   r   r   r   r   r   status)r   outputlr   s      r   r    wirepeer.pushkey.<locals>.decode  s    q)IAQL
 &&t,q~q1 -H  ));<a s   A* *+B)r   r   s   olds   newr   )r   r   r   oldnewr   s   `     r   r   wirepeer.pushkey  s    ||J''8I;KKL
	 #,,Y7&&s+&&s+&&s+	

  	r"   c                $    U R                  S5      $ )Ns
   stream_out)r   r^   s    r   
stream_outwirepeer.stream_out  s    ..r"   c                N   [         R                  " U5      nU R                  S[        S5      5        0 nUR	                  S5      =(       d
    [        5       nUR                  5        H  u  pVUc  M
  [        R                  R	                  U5      nUc  [        R                  " SU-  5      eUS:X  a  [        R                  " U5      nObUS:X  a  SR                  U5      nOJUS:X  a  SR                  [        U5      5      nO)US	:X  a  S
[        U5      -  nOUS:w  a  [        SU-  5      eXcU'   M     U R                   " S0 [         R"                  " U5      D6n[%        S U 5       5      (       a!  [&        R(                  " U R*                  U5      $ [,        R.                  " US5      $ )N	   getbundle   look up remote changess
   bundlecapss$   Unexpectedly None keytype for key %sr   s   csvr.   s   scsvs   booleans   %is   plains    unknown getbundle option type %sc              3  B   #    U  H  oR                  S 5      v   M     g7f)s   HG2N)
startswith)r)   caps     r   r,   %wirepeer.getbundle.<locals>.<genexpr>  s     <#~~f%%s      UN)r   )r   byteskwargsr   r   getsetr5   r   GETBUNDLE_ARGUMENTSr   ro   r   r4   sortedr   KeyError_callcompressablery   anyr   getunbundlerr   changegroupmodcg1unpacker)	r   sourcekwargsr   
bundlecapsr   valuekeytyper   s	            r   	getbundlewirepeer.getbundle  sk   %%f-a(A&BCZZ.7#%
 ,,.JC}$88<<SAG,,;cA  H$&11%8F"		%(G#		&-0J&U+H$BWLMMI% )& ""L83E3Ed3KL<<<<''33!--a77r"   c           
        US/:w  ai  U R                  S5      (       aS  [        R                  " S[        R                  " SR                  [        U5      5      5      R                  5       /5      nO[        R                  " U5      n[        US5      (       a  U R                  SXS9u  pEUS:X  a   [        R                  " [        S5      U5      e [        U5      nUR                  S
5       H(  nU R                   R#                  [        S5      U5        M*     U$ U R%                  SXS9n[&        R(                  " U R                   U5      nU$ ! [         a!    [        R                  " [        S	5      U5      ef = f)a  Send cg (a readable file-like object representing the
changegroup to push, typically a chunkbuffer object) to the
remote server as a bundle.

When pushing a bundle10 stream, return an integer indicating the
result of the push (see changegroup.apply()).

When pushing a bundle20 stream, return a bundle20 stream.

`url` is the url the client thinks it's pushing to, which is
visible to hooks.
s   forces   unbundlehashs   hashedr"   deltaheaders   unbundle)r   s   push failed:r   Tr   )r   r   r   r   sha1r4   r  digesthasattr	_callpushr   r   r   r   r   r   r   r   _calltwowaystreamr   r  )r   bundler   urlretr   r   r   s           r   unbundlewirepeer.unbundle  sH    XJ4<<#@#@"--HMM#((6%=*ABIIKLE #--e4E6=))..f.JKCcz))!O*<fEE#h &&t,q~q1 - 
 ++K+MF&&tww7C
  ));<c s   E +E9c                V   [         R                  " U5      nU R                  SUS9n UR                  5        Vs/ s H"  n[	        [         R
                  " U5      5      PM$     nnU$ s  snf ! [         a2    U R                  [        R                  " [        S5      U5      5         g f = f)Ns   branches)r   r   )r   r   r   r   tupler   r   r   r   r   r   )r   r   nr   r   brs         r   brancheswirepeer.branches  s    %%e,JJ{!J,	L?@||~N~!%11!45~BNI O 	LKK++A.E,FJK	Ls"   A, )A'#A, 'A, ,9B('B(c           
        Sn/ n[        S[        U5      U5       Hu  nSR                  XXB-     Vs/ s H  n[        R                  " US5      PM     sn5      nU R                  SUS9n UR                  S UR                  5        5       5        Mw     U$ s  snf ! [         a3    U R                  [        R                  " [        S5      U5      5         M  f = f)	N   r   r      -s   between)pairsc              3  r   #    U  H-  nU=(       a    [         R                  " U5      =(       d    / v   M/     g 7fr'   )r   r   )r)   r   s     r   r,   #wirepeer.between.<locals>.<genexpr>!  s/      + 6.33A6<"<+s   57r   )rangerw   r4   r   r   r   extendr   r   r   r   r   r   )r   r*  batchripr#  r   s           r   betweenwirepeer.between  s    q#e*e,A		 #qy11 #--a61A 

:Q
/AP \\^  -   PE//2I0JANOPs   !B
*&B9CCc                |    [         R                  " U5      nU R                  SUS9n[        R                  " US5      $ )Ns   changegroup)rootsr  )r   r   r	  r  r  )r   r   r  r#  r   s        r   r	   wirepeer.changegroup)  s:    %%e,"">";))!U33r"   c                    U R                  S[        S5      5        [        R                  " U5      n[        R                  " U5      nU R	                  SXS9n[
        R                  " US5      $ )Ns   changegroupsubsetr   )basesr   r  )r   r   r   r   r	  r  r  )r   r9  r   r  r   s        r   changegroupsubsetwirepeer.changegroupsubset.  sf    ,a0I.JK))%0))%0""  # 
 ))!U33r"   c              #    #    U R                   nUR                  (       aS  UR                  SS5      (       a<  UR                  S5        U H%  u  p4SnUR                  XS[	        U5      4-  5        M'     [
        R                  nU R                  S[        U5      S9nUR                  S5      nU/n	U(       a  SU;  a8  U(       a1  UR                  S5      nU	R                  U5        SU;  a	  U(       a  M1  S	R                  U	5      n
SU
;   a&  U
R                  SS
5      u  pU" U5      v   SU
;   a  M&  UR                  S5      nX/n	U(       a  M  U" S	R                  U	5      5      v   g7f)zarun batch request <req> on the server

Returns an iterator of the raw responses from the server.
s   devels   debug.peer-requests$   devel-peer-request: batched-content
s+   devel-peer-request:    - %s (%d arguments)
s   batch)r8   i   r1   r"   r   N)r   	debugflag
configboolr   rw   r   unescapebatchargr   r;   readr6   r4   r   )r   r7   r   r9   r   msgunescapeargrspchunkworkmergedones               r   r   wirepeer._submitbatch9  s:    
 WW<<BMM(4IJJHH=>ECI./   %55xoc.BCwe#E" e# XXd^F&.$ll43!#&& &. HHTNE?D e #((4.))s   C1E)5;E)2E)E)c                P    U R                   " U40 [        R                  " U5      D6$ r'   )r   r   ry   )r   r9   r   s      r   r   wirepeer._submitoneV  s!    zz"9 2 24 899r"   Nc                J    0 nUb  X6S'   Ub  XFS'   U R                   " SXS.UD6$ )Nthreefour)rG  two)s   debugwireargs)r   )r   rG  rN  rL  rM  fiver   s          r   debugwireargswirepeer.debugwireargsY  s8    !MLzzEEEEr"   c                    [        5       e)zvexecute <cmd> on the server

The command is expected to return a simple string.

returns the server reply as a string.NotImplementedErrorr   r   r   s      r   r   wirepeer._callb  s     "##r"   c                    [        5       e)zexecute <cmd> on the server

The command is expected to return a stream. Note that if the
command doesn't return a stream, _callstream behaves
differently for ssh and http peers.

returns the server reply as a file like object.
rS  rU  s      r   r   wirepeer._callstreamj       "##r"   c                    [        5       e)a  execute <cmd> on the server

The command is expected to return a stream.

The stream may have been compressed in some implementations. This
function takes care of the decompression. This is the only difference
with _callstream.

returns the server reply as a file like object.
rS  rU  s      r   r	  wirepeer._callcompressableu  s     "##r"   c                    [        5       e)zexecute a <cmd> on server

The command is expected to be related to a push. Push has a special
return method.

returns the server reply as a (ret, output) tuple. ret is either
empty (error) or a stringified int.
rS  r   r   fpr   s       r   r  wirepeer._callpush  rY  r"   c                    [        5       e)zaexecute <cmd> on server

The command will send a stream to the server and get a stream in reply.
rS  r]  s       r   r  wirepeer._calltwowaystream  s    
 "##r"   c                    [        5       e)zBclearly abort the wire protocol connection and raise the exceptionrS  )r   	exceptions     r   r   wirepeer._abort  s    !##r"   r(   )NNN)!r   rH   rI   rJ   rK   r   r   r   r   r#   r   r   r   r   r   r   r   r  r  r%  r3  r	   r:  r   r   rP  r   r   r	  r  r  r   rM   r(   r"   r   r   r   C  s    "
/1 
9 
9   D D   E E  0/8<'ZL(4
4*::F$	$$	$$$r"   r   )$
__future__r   r}   rU   
concurrentr   i18nr   noder    r   r	   r  r
   r   r   r   r   r   r   
interfacesr   utilsr   r   r#   r;   rC   r=   ipeercommandexecutorr?   rZ   ipeercommandsipeerlegacycommandsr   r(   r"   r   <module>ro     s    # 
    	 	 	 	B&$7>> $.S):22 S)lS$OOZ--z/M/MS$r"   