\x89\x50\x4E\x47\x0D\x0A\x1A\x0A PNG  \x89\x50\x4E\x47\x0D\x0A\x1A\x0A  13\c@@sddlmZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z ddlmZmZdZd ZdZd Zd Zied 6ed 6ed6ZdZd ZdZdZdZdZdZdZied6ed6ed6ed6ed6ed6ed6ed6ZdZ d Z!d Z"dZ#ie d6e!d6e"d6e#d6Z$dZ%d Z&ie%d6e&d 6Z'dZ(d Z)ie(d6e)d 6Z*dZ+d Z,ie+d6e,d 6Z-dZ.d Z/ie.d6e/d 6Z0ie$e6e'e6e*e6ie6ie6ie6e-e6e0e6Z1ej2d!Z3d"Z4ej5d#e6d$e7fd%YZ8ej5d#e6d&e9d'e7fd(YZ:d)Z;d*Z<d+Z=d,Z>e?ee?d-Z@d.ZAed/ZBd0ZCe?d1ZDd2ZEed3ZFd4e7fd5YZGd6e7fd7YZHd8e7fd9YZId:e7fd;YZJd<e7fd=YZKd>e7fd?YZLd@eLfdAYZMdBe7fdCYZNdDeNfdEYZOiZPgZQdFZRdGe7fdHYZSdIeSfdJYZTdKeSfdLYZUdMZVidNgdO6ZWdPe7fdQYZXdRe7fdSYZYdTe7fdUYZZdS(Vi(tabsolute_importNi(t_(tattr(tencodingterrortpycompattutiltwireprototypes(tcborutilt stringutiliiiis stream-begins stream-endtencodediiiii scommand-requests command-datascommand-responseserror-responses text-outputtprogressssender-protocol-settingssstream-settingstnewt continuationtmores have-datateoss~s ist|(t iteritemstappendtgettjoin(tmappingtvaluetnamemaptflagstval((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyt humanflags|s  tslotst frameheadercB@sVeZdZejZejZejZejZejZ ejZ RS(s&Represents the data in a frame header.( t__name__t __module__t__doc__Rtibtlengtht requestidtstreamidt streamflagsttypeidR(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs     treprtframecB@sheZdZejZejZejZejZejZ ejZ e j dZ RS(sRepresents a parsed frame.c C@sd|j}x3tjD]%\}}||jkr|}PqqWdt|j|j|jtt|j |tt j |ji|j fS(NssHframe(size=%d; request=%d; stream=%d; streamflags=%s; type=%s; flags=%s)( R(t FRAME_TYPESRtlentpayloadR%R&Rt STREAM_FLAGSR'tFRAME_TYPE_FLAGSRR(tselfttypenametnameR((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyt__repr__s (R R!R"RR#R%R&R'R(RR-Rt strmethodR3(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyR*s      cC@s~ttt|}tjdt|}|dd!|dd+tjd|d||||d>|B|d<||d)|S(s#Assemble a frame into a byte array.s This can be used by user-facing applications and tests for creating frames easily without having to type out a bunch of constants. Request ID and stream IDs are integers. Stream flags, frame type, and flags can be specified by integer or named constant. Flags can be delimited by `|` to bitwise OR them together. If the payload begins with ``cbor:``, the following string will be evaluated as Python literal and the resulting object will be fed into a CBOR encoder. Otherwise, the payload is interpreted as a Python byte string literal. t iiRscbor:tR%R&R'R(RR-( tsplittintR.R+R/t startswithRRt streamencodeR tevalpythonliteralt unescapestrR;( tstfieldsR%R&R't frametypet frameflagsR-tfinalstreamflagstflagt finalflagst validflags((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pytmakeframefromhumanstrings2          cC@s{|dd|dd|d}tjd|d\}}}|d}|d @d ?}|d @}t||||||S( sParse a unified framing protocol frame header from a buffer. The header is expected to be in the buffer at offset 0 and the buffer is expected to be large enough to hold a full header. iiii@isddlm}||_|jd|}|j|_dS(Ni(tzstdtlevel(R=Rt_zstdtZstdCompressorRR(R0RRtcctx((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs cC@s|jj|S(N(RR(R0RN((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRsscC@s|jj|jjS(N(RRxRtCOMPRESSOBJ_FLUSH_BLOCK(R0((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRxscC@s%|jj|jj}d|_|S(N(RRxRtCOMPRESSOBJ_FLUSH_FINISHRS(R0R((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs (R R!RRsRxR(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs   tzstd8mbencodercB@seZdZRS(cC@stt|jddS(Ni(tsuperRR(R0R((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs(R R!R(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRstzstdbasedecodercB@seZdZdZRS(cC@s5ddlm}|jd|}|j|_dS(Ni(Rtmax_window_size(R=RtZstdDecompressorRR(R0t maxwindowsizeRtdctx((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRscC@s|jj|S(N(RR(R0RN((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs(R R!RR(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs tzstd8mbdecodercB@seZdZRS(cC@s;|rtjtdntt|jdddS(Ns5zstd8mb decoder received unexpected additional valuesRiii(RRTRRRR(R0RR((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs(R R!R(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRscC@str dSyddlm}|jWntk r>d}nX|rettftd Holds state of a server handling frame-based protocol requests. This class is the "brain" of the unified frame-based protocol server component. While the protocol is stateless from the perspective of requests/commands, something needs to track which frames have been received, what frames to expect, etc. This class is that thing. Instances are modeled as a state machine of sorts. Instances are also reactionary to external events. The point of this class is to encapsulate the state of the connection and the exchange of frames, not to perform work. Instead, callers tell this class when something occurs, like a frame arriving. If that activity is worthy of a follow-up action (say *run a command*), the return value of that handler will say so. I/O and CPU intensive operations are purposefully delegated outside of this class. Consumers are expected to tell instances when events occur. They do so by calling the various ``on*`` methods. These methods return a 2-tuple describing any follow-up action(s) to take. The first element is the name of an action to perform. The second is a data structure (usually a dict) specific to that action that contains more information. e.g. if the server wants to send frames back to the client, the data structure will contain a reference to those frames. Valid actions that consumers can be instructed to take are: sendframes Indicates that frames should be sent to the client. The ``framegen`` key contains a generator of frames that should be sent. The server assumes that all frames are sent to the client. error Indicates that an error occurred. Consumer should probably abort. runcommand Indicates that the consumer should run a wire protocol command. Details of the command to run are given in the data structure. wantframe Indicates that nothing of interest happened and the server is waiting on more frames from the client before anything interesting can be done. noop Indicates no additional action is required. Known Issues ------------ There are no limits to the number of partially received commands or their size. A malicious client could stream command request data and exhaust the server's memory. Partially received commands are not acted upon when end of input is reached. Should the server error if it receives a partial request? Should the client send a message to abort a partially transmitted request to facilitate graceful shutdown? Active requests that haven't been responded to aren't tracked. This means that if we receive a command and instruct its dispatch, another command with its request ID can come in over the wire and there will be a race between who responds to what. cC@sw||_||_d|_d|_g|_i|_i|_i|_t|_ d|_ t t |_tdS(sConstruct a new server reactor. ``deferoutput`` can be used to indicate that no output frames should be instructed to be sent until input has been exhausted. In this mode, events that would normally generate output frames (such as a command response being ready) will instead defer instructing the consumer to send those frames. This is useful for half-duplex transports where the sender cannot receive until all data has been transmitted. tinitialiN(t_uit _deferoutputt_statet_nextoutgoingstreamidt_bufferedframegenst_incomingstreamst_outgoingstreamst_receivingcommandstsett_activecommandsRSt_protocolsettingsdecodertdicttDEFAULT_PROTOCOL_SETTINGSt_sendersettingsR(R0Rt deferoutput((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs          cC@s?|jds0d|_|jtd|jS|j|jkr|jt@skd|_|jtdSt|j|j|j 1 C tcommandrequestcB@seZdZdddZRS(s&Represents a request to run a command.cC@s:||_||_||_||_||_d|_dS(Ntpending(R%R2R[RkR\R+(R0R%R2R[RkR\((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyRs      N(R R!R"RSR(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyR;st clientreactorcB@seeZdZeed dZd d dZdZdZ dZ dZ dZ dZ RS( sHolds state of a client issuing frame-based protocol requests. This is like ``serverreactor`` but for client-side state. Each instance is bound to the lifetime of a connection. For persistent connection transports using e.g. TCP sockets and speaking the raw framing protocol, there will be a single instance for the lifetime of the TCP socket. For transports where there are multiple discrete interactions (say tunneled within in HTTP request), there will be a separate instance for each distinct interaction. Consumers are expected to tell instances when events occur by calling various methods. These methods return a 2-tuple describing any follow-up action(s) to take. The first element is the name of an action to perform. The second is a data structure (usually a dict) specific to that action that contains more information. e.g. if the reactor wants to send frames to the server, the data structure will contain a reference to those frames. Valid actions that consumers can be instructed to take are: noop Indicates no additional action is required. sendframes Indicates that frames should be sent to the server. The ``framegen`` key contains a generator of frames that should be sent. The reactor assumes that all frames in this generator are sent to the server. error Indicates that an error occurred. The ``message`` key contains an error message describing the failure. responsedata Indicates a response to a previously-issued command was received. The ``request`` key contains the ``commandrequest`` instance that represents the request this data is for. The ``data`` key contains the decoded data from the server. ``expectmore`` and ``eos`` evaluate to True when more response data is expected to follow or we're at the end of the response stream, respectively. cC@s||_||_||_||_t|_t|_t|_d|_ t d|_ t j |_i|_i|_i|_tdS(sCreate a new instance. ``hasmultiplesend`` indicates whether multiple sends are supported by the transport. When True, it is possible to send commands immediately instead of buffering until the caller signals an intent to finish a send operation. ``buffercommands`` indicates whether sends should be buffered until the last request has been issued. ``clientcontentencoders`` is an iterable of content encoders the client will advertise to the server and that the server can use for encoding data. If not defined, the client will not advertise content encoders to the server. iN(Rt_hasmultiplesendt _buffersendst_clientcontentencodersR]t_canissuecommandst_cansendRdt_protocolsettingssentt_nextrequestidRt_outgoingstreamt collectionstdequet_pendingrequestst_activerequestsRt_streamsettingsdecodersR(R0Rthasmultiplesendt buffersendstclientcontentencoders((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyR3s           cC@s|jstjdn|j}|jd7_t|||d|d|}|jrw|jj||difS|jstjdn|j st |_t |_n|di|j |d6fSd S( sRequest that a command be executed. Receives the command name, a dict of arguments to pass to the command, and an optional file object containing the raw data for the command. Returns a 3-tuple of (request, action, action data). scannot issue new commandsiRkR\Rs*sends cannot be performed on this instanceRRN( RARRRDR;R?RHRRBR>Rdt_makecommandframes(R0R2R[RkR\R%R(((s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyt callcommandWs           c@sojsdifSjs.tjdnjsLt_t_nfd}di|d6fS(s_Request that all queued commands be sent. If any commands are buffered, this will instruct the caller to send them over the wire. If no commands are buffered it instructs the client to no-op. If instances aren't configured for multiple sends, no new command requests are allowed after this is called. Rs*sends cannot be performed on this instancec3@sBx;jr=jj}xj|D] }|Vq+WqWdS(N(RHtpopleftRN(R(R*(R0(s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyt makeframess RR(RHRBRRR>RdRA(R0RQ((R0s@/usr/lib64/python2.7/site-packages/mercurial/wireprotoframing.pyt flushcommandsxs      c c@s||j|j           cC@s|jtkst|jt@}|jt@}|rR|rRditdd6fS| rw| rwditdd6fS|j|jkrt j }||j|j s  (            ;   @      4i     M  u