^cUddlZddlZddlmZddlmZddlmZddlm Z m Z ddl m Z m ZmZmZmZmZmZmZddlmZmZdd lmZejZd Zd ZGd d ejZejej GddZ!ejej"ej#Gddej$Z%dS)N)futures)_)bin)getattrsetattr)bundle2 changegroupencodingerrorpushkeypycompatutilwireprototypes) repositoryr)hashutilc`fd}t|dt|dj|S)aannotation 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|i|\}}|s|S|d}tjj}|||}||S)Nr)rbytesurl__name__ _submitone)argsoptsencoded_args_or_resdecodeselfcmd encoded_resfs ;/usr/lib/python3/dist-packages/mercurial/wireprotov1peer.pyplainzbatchable..plain9sj&'a&6&6&6#V '& &Aw ++ooc+>?? vk""" batchabler)rr)rr!s` r r#r#&sI&##### E;""" E:qz*** Lr"c.tjg}|D]o\}}tfd|DsJdfd|D}|d||fzpd|S)z;Return a ``cmds`` argument value for the ``batch`` command.c36K|]}||kVdSN).0k escapeargs r z"encodebatchcmds..Ps07799Q<<1$777777r",c3PK|] \}}d||fzV!dS)s%s=%sNr')r(r)vr*s r r+z"encodebatchcmds..RsR  8<1H ! iill3 3      r"s%s %s;)rescapebatchargalljoinitemsappend)reqcmdsopargsdictrr*s @r encodebatchcmdsr9Gs-I D + + H7777h77777777yy    @H@P@P      HDz)**** 99T??r"ceZdZdZddZdS) unsentfuturea0A 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()``. Nc|r tj||S|j||Sr&)donerFutureresult _peerexecutor sendcommands)rtimeouts r r?zunsentfuture.resultcsS 99;; 8>((w77 7 ''))) {{7###r"r&)r __module__ __qualname____doc__r?r'r"r r;r;Zs2 $ $ $ $ $ $r"r;c8eZdZdZdZdZdZdZdZdZ dS) peerexecutorc||_d|_d|_g|_t j|_d|_d|_dS)NF) _peer_sent_closed_callsweakrefWeakSet_futures_responseexecutor _responsef)rpeers r __init__zpeerexecutor.__init__qs@    )) !%r"c|Sr&r'rs r __enter__zpeerexecutor.__enter__zs r"c.|dSr&)close)rexctypeexcvaleeexctbs r __exit__zpeerexecutor.__exit__}s r"cjrtjdjrtjdt jt jdstjdzfd}t ddr|}t|_ |_ n<j rtjdz|} |S)Ns4callcommand() cannot be used after commands are sents*callcommand() cannot be used after close()sAcannot call command %s: method of same name not available on peerctj}j|j|f|Sr&)rr>rOaddrLr4)rrcommandfnrs r addcallz)peerexecutor.callcommand..addcallsJ  A M  a K  r15 6 6 6Hr"r#FsX%s is not batchable and cannot be called on a command executor along with other commands) rJr ProgrammingErrorrKrrIrsysstrr; __class__r@rLrA)rr`rrbrras``` @r callcommandzpeerexecutor.callcommandsC : (G  < (=  TZ!9!94 @ @ ($%          2{E * *  A'AK"AOO{ ,:#t$r1tj|t!jddYnwxYwdSg}g}|D]\}}}}| s |j|jfitj |\} } n@#t$r3tj|t!jddYdSwxYw| s| | ||| f|||t$| f|sdS|j|} t jd|_|j|j|| |_dS)NTrrr')rJrLrO isinstancer;rr>rer@lenset_running_or_notify_cancelr strkwargs set_result Exceptionfuture_set_exception_infosysexc_infor#__self__r4rI _submitbatchThreadPoolExecutorrPsubmit_readbatchresponserQ) rrcallsr`rrar?requestsstatesrr wireresultss r rAzpeerexecutor.sendcommandss :  F{  F  ' 'A!\** '%n "&   u::??#(8 GT2q1133  %77h06677 V$$$$ J J J21clnnQRR6HIIIII J F$) ? ? GT2q1133  .:blK//#+#5d#;#;//+#VV   21clnnQRR6HIII  ? 01111*= >??? w9f=>>>>  Fj--h77 ")!;A!>!>077  #V[  s$C8DD)(E8FFc ||jrdSd|_|jsdS |j|jdd|_d|_|jD]K}|s5|tj tddLd|_dS#|jdd|_d|_|jD]K}|s5|tj tddLd|_wxYw)NT)wait"unfulfilled batch command response) rArKrQr?rPshutdownrOr= set_exceptionr ResponseErrorr)rrs r rXzpeerexecutor.close sy  <  F   F ! O " " $ $ $  " + + + 6 6 6"DO%)D "]  vvxxOO+CDDd !DMMM  " + + + 6 6 6"DO%)D "]  vvxxOO+CDDd !DM s C BEc |D]\}}}} t|} ||}||9#t$r1tj|t jddYswxYw#t$r8|tj tddYwxYwdS)Nrr|) nextrlrmrrnrorp StopIterationr~r rr) rrxryr`rr#r remoteresultr?s r ruzpeerexecutor._readbatchresponse)s .4 ) ) )GQ 6 )#K00 )#VL11FLL((((!NNN6q#,..:LMMMMMN!   '?@@$    ) )s A: <8A76A7:?B<;B<N) rrCrDrSrVr\rfrArXrur'r"r rGrGos555nP P P d!!!@)))))r"rGceZdZdZdZdZedZedZedZ edZ edZ ed Z d Z d Zd Zd ZdZdZdZdZdZddZdZdZdZdZdZdZdS)wirepeerzClient-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 t|Sr&)rGrUs r commandexecutorzwirepeer.commandexecutorOsD!!!r"cr|dtd|dS)Ns clonebundless clone bundles) requirecapr_callrUs r clonebundleszwirepeer.clonebundlesTs1 +;)<)<===zz/***r"cdtdfd}dtj|i|fS)Nslookupslook up remote revisionc|dddd\}}t|rt|St j|dS)N r)splitintr_abortr RepoError)dsuccessdatars r rzwirepeer.lookup..decode\s^crcFLLq11MGT7|| 34yy  EOD1122222r"key)rrr fromlocal)rkeyrs` r lookupzwirepeer.lookupXsV  1%?#@#@AAA 3 3 3 3 3*3//0&88r"cfd}i|fS)Nc tj|ddS#t$r9t jt d|YdSwxYw)Nrunexpected response:)r decodelist ValueErrorrr rrrrs r rzwirepeer.heads..decodegsr P%03B3888 P P P E/2I0J0JANNOOOOOO Ps?A"!A"r'rrs` r headszwirepeer.headses- P P P P P 6zr"c>fd}dtj|i|fS)Nc dtj|DS#t$r9t jt d|YdSwxYw)NcFg|]}tt|Sr')boolrr(bs r z2wirepeer.known..decode..ss$FFFSVV FFFr"r)r iterbytestrrrr rrrs r rzwirepeer.known..decodeqsx PFFh.B1.E.EFFFF P P P E/2I0J0JANNOOOOOO Ps!?A$#A$nodesr encodelist)rnodesrs` r knownzwirepeer.knownos> P P P P P .3E::;VCCr"cfd}i|fS)Nc i}|D]`}|dd\}}tjt|}t j|}|||<a|S#t$r9 tj td|YdSwxYw)Nrrr) splitlinesrr tolocalurlrequnquoterr TypeErrorrr rr)r branchmap branchpart branchname branchheadsrs r rz"wirepeer.branchmap..decode{s P "#,,..88J.8.>.>tQ.G.G+J !)!1&..2L2L!M!MJ"0";K"H"HK,7Ij))   P P P E/2I0J0JANNOOOOOO PsA8A<B?r'rs` r rzwirepeer.branchmapys- P P P P P6zr"cdsidfSjdzfd}dtji|fS)Npushkeyspreparing listkeys for "%s" cjdt|fztj|S)Ns$received listkey for "%s": %i bytes )uidebugri pushkeymod decodekeys)r namespacers r rz!wirepeer.listkeys..decodesA GMM8Is1vv;NN   (++ +r" namespacecapablerrr r)rrrs`` r listkeyszwirepeer.listkeyssv||J'' t8O  6BCCC , , , , , , h0;;.decodesq))IAv QLL   );<.s.==3v&&======r"UN)r)r byteskwargsrrgetsetr3rGETBUNDLE_ARGUMENTSr rcrr2sortedrKeyError_callcompressablerkanyr getunbundlerrchangegroupmod cg1unpacker) rsourcekwargsr bundlecapsrvaluekeytypers r getbundlezwirepeer.getbundles%f--  a(A&B&BCCCZZ ..7#%%  ,,..  JC}$8< > 8'33 3!-a77 7r"c 4|dgkrp|dr[tjdtjdt |g}ntj|}tj |dr| d||\}}|dkr"tj td| t|}n0#t$r#tj td |wxYw|d D]*}|jtd |+n2|d||}t)j|j|}|S) aSend 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. sforces unbundlehashshashedr"s deltaheadersunbundle)rs push failed:rTr)rrrrsha1r2rdigestr safehasattr _callpushr rrrrrrr_calltwowaystreamr r)rbundlerurlretrrstreams r unbundlezwirepeer.unbundles XJ  4<<#@#@ "-HM#((6%==*A*ABBIIKKLEE#-e44E  FN 3 3 8..fE.JJKCczz)!O*<*.s+NNN!%1!4455NNNr"r) rrrrrrr rr)rrnrbrs r brancheszwirepeer.branchess  %e , , JJ{!J , , LNNq||~~NNNBI L L L KK+A.E,F,FJJ K K K K K K LsA ?BBc d}g}tdt||D]}dd||||zD}|d|} |d|Dv#t $r8|tj td|YwxYw|S) Nrrc8g|]}tj|dS)-r)r(ps r rz$wirepeer.between.. s5#-a66r"sbetween)pairsc3FK|]}|rtj|pgVdSr&)rr)r(rs r r+z#wirepeer.between..sK6.3A66<"r"r) rangerir2rextendrrrr rr)rrbatchrirrs r betweenzwirepeer.betweens q#e**e,, P PA "1q5y=1A  :Q //A P\\^^ P P P E/2I0J0JANNOOOOO Ps'1B?CCctj|}|d|}tj|dS)Ns changegroup)rootsr)rrrrr)rrrrrs r r zwirepeer.changegroups=  %e , ,  " "> " ; ;)!U333r"c|dtdtj|}tj|}|d||}t j|dS)Nschangegroupsubsetr)basesrr)rrrrrrr)rr rrrs r changegroupsubsetzwirepeer.changegroupsubset sv ,a0I.J.JKKK)%00)%00  " " U #  )!U333r"c#K|j}|jr\|ddrF|d|D].\}}d}|||t |fz/t j}|dt|}| d}|g} |rd|vr2|r0| d}| |d|vr|0d | } d| vr*| dd \} } || Vd| v*| d}| |g} ||d | Vd S) zqrun batch request on the server Returns an iterator of the raw responses from the server. sdevelsdebug.peer-requests$devel-peer-request: batched-content s+devel-peer-request: - %s (%d arguments) sbatch)r6ir/r"rN) r debugflag configboolrrirunescapebatchargrr9readr4r2r) rr5rr7rmsg unescapeargrspchunkworkmergedones r rrzwirepeer._submitbatch+s W < 0BMM(4IJJ 0 HH= > > > 0 0DECII.////$5 xoc.B.BCCw #e### E"""e###XXd^^F&..$ll433 V!k#&&&&&&..HHTNNEE?D #k#((4..)))))))r"cB|j|fitj|Sr&)rrrk)rr7rs r rzwirepeer._submitoneHs'tz"99 24 8 8999r"NcBi}|||d<|||d<|jd||d|S)Nthreefour debugwireargs)rtwo)r)r)rrr rrfivers r debugwireargszwirepeer.debugwireargsKsD  !DM  DLtzEEEEEEr"c t)zexecute on the server The command is expected to return a simple string. returns the server reply as a string.NotImplementedErrorrrrs r rzwirepeer._callTs "###r"c t)a execute 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. r$r&s r rzwirepeer._callstream\"###r"c t)aEexecute 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. r$r&s r rzwirepeer._callcompressablegs"###r"c t)zexecute a 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. r$rrfprs r rzwirepeer._callpushtr(r"c t)zqexecute on server The command will send a stream to the server and get a stream in reply. r$r+s r rzwirepeer._calltwowaystreams "###r"ct)zBclearly abort the wire protocol connection and raise the exceptionr$)r exceptions r rzwirepeer._aborts!###r")NNN)rrCrDrErrr#rrrrrr rrrrr r rrrrr"rrrrrrr'r"r rrCs""" +++ 9 9Y 9YDDYD  Y  E EY EY0///888<'''ZLLL(444 444***::::FFFF$$$ $ $ $ $ $ $ $ $ $$$$$$$$$r"r)&rorM concurrentri18nrnoderrrrr r rr r r rrr interfacesr interfaceutilutilsrrr#r9r>r; implementeripeercommandexecutorrG ipeercommandsipeerlegacycommandsrRrr'r"r r;s                       B&$$$$$7>$$$*::;;P)P)P)P)P)P)P)<;P)fj<B$B$B$B$B$zB$B$B$B$B$r"