-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/smart/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyc


S:Qc@@sndZddlmZddlZddlmZddlZddlZddlZddl	Z	ddl
Z
ddl
mZmZm
Z
ddlmZmZddlmZmZddlmZmZd	Zd
ZdZeZZdZd
ZdZdefdYZ defdYZ!de!fdYZ"de"fdYZ#dZ$dZ%de&fdYZ'defdYZ(de(fdYZ)de(fd YZ*d!e!e ej+fd"YZ,d#e,fd$YZ-dd%Z/d&e(fd'YZ0d(efd)YZ1d*e1fd+YZ2d,Z3d-e1e fd.YZ4dS(/s\Wire-level encoding and decoding of requests and responses for the smart
client and server.
i(tabsolute_importN(tStringIO(tdebugterrorstosutils(tmessagetrequest(tlog_exception_quietlytmutter(tbdecode_as_tupletbencodesbzr request 2
sbzr response 2
sbzr message 3 (bzr 1.6)
cC@s|j}t|S(N(treadlinet
_decode_tuple(t	from_filetreq_line((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_recv_tuple3scC@sY|dks|dkrdS|ddkrBtjd|nt|d jdS(Ntis
srequest %r not terminateds(tNoneRtSmartProtocolErrorttupletsplit(R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR8s
cC@sHdj|d}t|tkrDtd||jd}n|S(s&Encode the tuple args to a bytestream.ss
s7response args contain unicode, should be only bytes: %rtascii(tjointtypetunicodeRtencode(targstjoined((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt
_encode_tuple@st	RequestercB@s2eZdZdZdZdZdZRS(sUAbstract base class for an object that can issue requests on a smart
    medium.
    cG@st|jdS(sNMake a remote call.

        :param args: the arguments of this call.
        N(tNotImplementedErrortcall(tselfR((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRPscC@st|jdS(sMake a remote call with a body.

        :param args: the arguments of this call.
        :type body: str
        :param body: the body to send with the request.
        N(Rtcall_with_body_bytes(R Rtbody((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR!WscC@st|jdS(sMake a remote call with a readv array.

        :param args: the arguments of this call.
        :type body: iterable of (start, length) tuples.
        :param body: the readv ranges to send with this request.
        N(Rtcall_with_body_readv_array(R RR"((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR#`scC@st|jdS(N(Rtset_headers(R theaders((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR$is(t__name__t
__module__t__doc__RR!R#R$(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRKs
					tSmartProtocolBasecB@s eZdZdZdZRS(s#Methods common to client and servercC@s djdt||dfS(s!Encode body as a bulk data chunk.Rs%d
sdone
(Rtlen(R R"((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_encode_bulk_datarscC@sAg}x+|D]#\}}|jd||fq
Wdj|S(sSerialise a readv offset list.s%d,%ds
(tappendR(R toffsetsttxttstarttlength((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_serialise_offsetsvs(R&R'R(R+R1(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR)ms	tSmartServerRequestProtocolOnecB@sJeZdZdddZdZdZdZdZdZ	RS(	s<Server-side encoding and decoding logic for smart version 1.t/cC@s^||_||_||_d|_t|_d|_t|_d|_	d|_
||_dS(NR(t_backing_transportt_root_client_patht
_jail_roottunused_datatFalset	_finishedt	in_buffert_has_dispatchedRRt
_body_decodert_write_func(R tbacking_transportt
write_functroot_client_patht	jail_root((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt__init__s									c	C@st|tst|n|j|7_|jsd|jkrIdSt|_y|jjdd\}|_|d7}t|}tj	|j
dtjd|jd|j
|_|jj||jjr|j|_d|_|j|jjnWqtk
rqtjk
rn}tjd|jf}tjd	t|f}|j|dStk
r}t|jtjd	t|fdSXn|jr|jr|j|j7_d|_dS|jdkrt|_n|jj|j|jj|_|jj }|jj!||jjru|jj"|jjsut#d
qun|jjdk	r|j|jj|j|_d|_q|jjrt#dqndS(swTake bytes, and advance the internal state machine appropriately.

        :param bytes: must be a byte string
        s
NitcommandsR@RARsbad request %rterrors"no more body, request not finisheds)no response and we have finished reading.($t
isinstancetstrt
ValueErrorR:R;tTrueRRRtSmartServerRequestHandlerR4trequest_handlersR5R6t
args_receivedtfinished_readingR7t_send_responsetresponsetKeyboardInterruptRtUnknownSmartMethodRtverbtFailedSmartServerResponset	ExceptionRR9R<RtLengthPrefixedBodyDecodertaccept_bytestread_pending_datataccept_bodytend_of_bodytAssertionError(	R tbytest
first_linetreq_argsterrtprotocol_errortfailuret	exceptiont	body_data((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRUsp		
		

			
cC@s|jrtdn|j}|j}t|_|j|j||jt||dk	rt
|tst|n|j
|}|j|ndS(s4Send a smart server response down the output stream.sresponse already sentN(R9RYRR"RHt_write_protocol_versiont _write_success_or_failure_prefixR=RRRERFRGR+(R RNRR"RZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRMs				

cC@sdS(shWrite any prefixes this protocol requires.

        Version one doesn't send protocol versions.
        N((R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRbscC@s|jdS(sWrite the protocol specific success/failure prefix.

        For SmartServerRequestProtocolOne this is omitted but we
        call is_successful to ensure that the response is valid.
        N(t
is_successful(R RN((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRcscC@s1|jr
dS|jdkr dS|jjSdS(Nii(R9R<Rtnext_read_size(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRes
	N(
R&R'R(RRBRURMRbRcRe(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR2~s	E			tSmartServerRequestProtocolTwocB@s5eZdZeZeZdZdZdZ	RS(sVersion two of the server side of the smart protocol.

    This prefixes responses with the value of RESPONSE_VERSION_TWO.
    cC@s-|jr|jdn
|jddS(s3Write the protocol specific success/failure prefix.ssuccess
sfailed
N(RdR=(R RN((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRcscC@s|j|jdS(sqWrite any prefixes this protocol requires.

        Version two sends the value of RESPONSE_VERSION_TWO.
        N(R=tresponse_marker(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRb
scC@s|jrtdnt|_|j|j||jt|j|jdk	rt
|jts~tdn|jdk	rtdn|j
|j}|j|n%|jdk	rt|j|jndS(s4Send a smart server response down the output stream.sresponse already sentsbody must be a strs'body_stream and body cannot both be setN(R9RYRHRbRcR=RRR"RRERFtbody_streamR+t_send_stream(R RNRZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRMs 		

(
R&R'R(tRESPONSE_VERSION_TWORgtREQUEST_VERSION_TWOtrequest_markerRcRbRM(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRfs		cC@s%|dt|||ddS(Nschunked
sEND
(t_send_chunks(tstreamR?((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRi%s

cC@sx|D]{}t|tr?dt||f}||qt|tjro|dt|j|dStjd|qWdS(Ns%x
%ssERR
s7Chunks must be str or FailedSmartServerResponse, got %r(	RERFR*RRRRmRRtBzrError(RnR?tchunkRZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRm+s


t_NeedMoreBytescB@seZdZddZRS(scRaise this inside a _StatefulDecoder to stop decoding until more bytes
    have been received.
    cC@s
||_dS(sConstructor.

        :param count: the total number of bytes needed by the current state.
            May be None if the number of bytes needed is unknown.
        N(tcount(R Rr((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRB?sN(R&R'R(RRB(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRq:st_StatefulDecodercB@s;eZdZdZdZdZdZdZRS(sBase class for writing state machines to decode byte streams.

    Subclasses should provide a self.state_accept attribute that accepts bytes
    and, if appropriate, updates self.state_accept to a different function.
    accept_bytes will call state_accept as often as necessary to make sure the
    state machine has progressed as far as possible before it returns.

    See ProtocolThreeDecoder for an example subclass.
    cC@s:t|_g|_d|_d|_d|_d|_dS(NiR(R8RLt_in_buffer_listt_in_buffer_lenR7Rt
bytes_leftt_number_needed_bytes(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRBSs					cC@svt|jdkr |jdSdj|j}t||jkrftd|jt|n|g|_|S(NiiRs7Length of buffer did not match expected value: %s != %s(R*RtRRuRY(R R:((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_get_in_buffer[scC@s`t|jdkr$tdnt|jd|krL|jd| S|j}|| S(sGGrab X bytes from the input_buffer.

        Callers should have already checked that self._in_buffer_len is >
        count. Note, this does not consume the bytes from the buffer. The
        caller will still need to call _get_in_buffer() and then
        _set_in_buffer() if they actually need to consume the bytes.
        isHCallers must be sure we have buffered bytes before calling _get_in_bytes(R*RtRYRx(R Rrtin_buf((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt
_get_in_bytesfs	cC@s@|dk	r*|g|_t||_ng|_d|_dS(Ni(RRtR*Ru(R tnew_buf((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_set_in_bufferys
	cC@sd|_|jj||jt|7_y@|j}|jx&||jkrl|j}|jqGWWntk
r}|j|_nXdS(s
Decode as much of bytes as possible.

        If 'bytes' contains too much data it will be appended to
        self.unused_data.

        finished_reading will be set when no more data is required.  Further
        data will be appended to self.unused_data.
        N(	RRwRtR,RuR*tstate_acceptRqRr(R RZt
current_statete((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRUs
		
	(R&R'R(RBRxRzR|RU(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRsHs					tChunkedBodyDecodercB@s_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
sDecoder for chunked body data.

    This is very similar the HTTP's chunked encoding.  See the description of
    streamed body data in `doc/developers/network-protocol.txt` for details.
    cC@sGtj||j|_d|_tj|_t	|_
d|_dS(N(RsRBt_state_accept_expecting_headerR}Rtchunk_in_progresstcollectionstdequetchunksR8RDterror_in_progress(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRBs
		cC@s|j|jkr|jdS|j|jkrI|jdkrBdSdSnX|j|jkr_dS|j|jkrtdtd|jSt	d|jfdS(Niiiischunked
sImpossible state: %r(
R}t_state_accept_reading_chunkRvt_state_accept_expecting_lengthRut_state_accept_reading_unusedRtmaxR*RY(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRescC@s*y|jjSWntk
r%dSXdS(N(Rtpopleftt
IndexErrorR(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytread_next_chunks
cC@sY|j}|jd}|dkr6tdn|| }|j||d|S(Ns
ii(RxtfindRqR|(R Rytpostline((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt
_extract_lines
cC@sw|j|_g|_d|_|j|_|jrjt|j}|j	j
tj|d|_nt|_dS(Ni(RxR7RtRuRR}RDRRRR,RRRRRHRL(R t
error_args((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR9s			cC@sA|j}|dkr'|j|_ntjd|fdS(NtchunkedsBad chunked body header: "%s"(RRR}RR(R tprefix((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs
cC@s}|j}|dkr8t|_g|_|jdS|dkrR|jdSt|d|_d|_|j	|_
dS(NtERRtENDiR(RRHRDRRR9tintRvRRR}(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs		

	cC@s|j}t|}|j||j 7_|j||j|j|8_|jdkrd|_|jr|jj|jn|j	j|jd|_|j
|_ndS(Ni(RxR*RRvR|RRDRR,RRR}(R Ryt
in_buffer_len((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs			cC@s"|j|j7_g|_dS(N(R7RxRt(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR
s(R&R'R(RBReRRR9RRRR(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs								RTcB@s_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s&Decodes the length-prefixed bulk data.cC@s;tj||j|_|j|_d|_d|_dS(NR(RsRBRR}t_state_read_no_datat
state_readt_bodyt_trailer_buffer(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRBs

	cC@s[|jdk	r|jdS|j|jkr=dt|jS|j|jkrSdSdSdS(Niii(RvRR}t_state_accept_reading_trailerR*RR(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRescC@s
|jS(s.Return any pending data that has been decoded.(R(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRV,scC@so|j}|jd}|dkr+dSt|| |_|j||d|j|_|j|_dS(Ns
ii(	RxRRRvR|t_state_accept_reading_bodyR}t_state_read_body_bufferR(R RyR((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR0scC@s|j}|j|7_|jt|8_|jd|jdkr|jdkr|j|j|_|j|j |_nd|_|j|_ndS(Ni(	RxRRvR*R|RRRR}(R Ry((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR:s
	cC@sf|j|j7_|jd|jjdrb|jtd|_|j|_t	|_
ndS(Nsdone
(RRxR|Rt
startswithR*R7RR}RHRL(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRGs
cC@s&|j|j7_|jddS(N(R7RxR|R(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRQscC@sdS(NR((R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRUscC@s|j}d|_|S(NR(R(R tresult((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRXs		(R&R'R(RBReRVRRRRRR(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRTs				
	
	
		tSmartClientRequestProtocolOnecB@seZdZdZdZdZdZdZdZdZ	dZ
ed	Zd
Z
dZdd
ZdZdZdZdZRS(s-The client-side protocol for smart version 1.cC@s1||_d|_d|_d|_d|_dS(sConstruct a SmartClientRequestProtocolOne.

        :param request: A SmartClientMediumRequest to serialise onto and
            deserialise from.
        N(t_requestRt_body_buffert_request_start_timet
_last_verbt_headers(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRBbs
				cC@st||_dS(N(tdictR(R R%((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR$nscG@sdtjkrrtdt|dd!t|jjdddk	r`td|jjjnt	j
|_n|j||jj
|d|_dS(Nthpssshpss call:   %siitbases             (to %s)i(Rtdebug_flagsRtreprtgetattrRt_mediumRRRt
timer_funcRt_write_argstfinished_writingR(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRqs

cC@sdtjkrtdt|dd!|d t|jjdddk	rgtd|jjjntdt	|t
j|_d	tjkrtd
|qn|j
||j|}|jj||jj|d|_dS(
sMake a remote call of args with body bytes 'body'.

        After calling this, call read_response_tuple to find the result out.
        Rshpss call w/body: %s (%r...)iiit_paths                  (to %s)s              %d bytest
hpssdetailshpss body content: %siN(RRRRRRRRRR*RRRRR+RURR(R RR"RZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR!{s!

cC@sdtjkrrtdt|dd!t|jjdd	d	k	r`td|jjjnt	j
|_n|j||j
|}|j|}|jj||jjdtjkrtdt|n|d|_d	S(
sMake a remote call with a readv array.

        The body is encoded with one line per readv offset pair. The numbers in
        each pair are separated by a comma, and no trailing \n is emitted.
        Rshpss call w/readv: %siiRs                  (to %s)s'              %d bytes in readv requestiN(RRRRRRRRRRRRRR1R+RURR*R(R RR"treadv_bytesRZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR#s

cC@s1|jj|jjtj|ddS(Ni(RRRLRRP(R RRn((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytcall_with_body_streams

cC@s|jjdS(sAfter expecting a body, a response code may indicate one otherwise.

        This method lets the domain client inform the protocol that no body
        will be transmitted. This is a terminal method: after calling it the
        protocol is not able to be used further.
        N(RRL(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytcancel_read_bodyscC@s|j}dtjkr}|jdk	r`tdtj|jt|dd!d|_q}tdt|dd!n|S(NRs   result:   %6.3fs  %siis   result:   %s(	RRRRRRRRR(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_read_response_tuplescC@s@|j}|j||j||s<|jjn|S(sWRead a response tuple from the wire.

        This should only be called once.
        (Rt_response_is_unknown_methodt_raise_args_if_errorRRL(R texpect_bodyR((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytread_response_tuples

cC@slddddddddd	d
ddd
ddddg}|d|krh|jjtj|ndS(Ntnorepositoryt
NoSuchFilet
FileExiststDirectoryNotEmptytShortReadvErrortUnicodeEncodeErrortUnicodeDecodeErrort
ReadOnlyErrortnobranchtNoSuchRevisiontnosuchrevisiontLockContentiontUnlockableTransportt
LockFailedt
TokenMismatcht	ReadErrortPermissionDeniedi(RRLRtErrorFromSmartServer(R tresult_tupletv1_error_codes((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs(	
cC@sX|dd|jfks2|dd|jfkrT|jjtj|jndS(s6Raise UnexpectedSmartServerResponse if the response is an 'unknonwn
        method' response to the request.

        :param response: The response from a smart client call_expecting_body
            call.
        :param verb: The verb used in that call.
        :raises: UnexpectedSmartServerResponse
        RDs2Generic bzr smart protocol error: bad request '%s's3Generic bzr smart protocol error: bad request u'%s'N(RRRLRRP(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs			
icC@s|jdk	r|jj|St}xP|jsz|jj|j}|dkrjtj	dn|j
|q+W|jjt|j|_dt
jkrtdt|jjn|jj|S(sRead bytes from the body, decoding into a byte stream.

        We read all bytes at once to ensure we've checked the trailer for
        errors, and then feed the buffer back as read_body_bytes is called.
        Rs,Connection lost while reading response body.Rs               %d body bytes readN(RRtreadRTRLRt
read_bytesReRtConnectionResetRURRVRRRR*tgetvalue(R RrR<RZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytread_body_bytess	
cC@st|jjS(s(Receive a tuple from the medium request.(RRt	read_line(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRscC@sS|jd|j}|d	kr)dS|d
kr9dStjd|fdS(s-Return protocol version number of the server.thellotokt1it2isbad response %rN(sokR(sokR(RRRR(R tresp((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt
query_versions
cC@s*|jt|}|jj|dS(N(RbRRRU(R RRZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR!s
cC@sdS(shWrite any prefixes this protocol requires.

        Version one doesn't send protocol versions.
        N((R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRb&s(R&R'R(RBR$RR!R#RRRR8RRRRRRRRb(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR^s"			
											tSmartClientRequestProtocolTwocB@s8eZdZeZeZedZdZ	dZ
RS(sVersion two of the client side of the smart protocol.

    This prefixes the request with the value of REQUEST_VERSION_TWO.
    cC@s|jj}||jkr=|jjtj|n|jj}tj|}|j||dkrt	|_
|s|jjn|S|dkrt|_
|jjtj|ntj
d|dS(sWRead a response tuple from the wire.

        This should only be called once.
        ssuccess
sfailed
sbad protocol status %rN(RRRgRLRtUnexpectedProtocolVersionMarkerRRRRHtresponse_statusR8RR(R RtversionRR((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR6s$

		
cC@s|jj|jdS(spWrite any prefixes this protocol requires.

        Version two sends the value of REQUEST_VERSION_TWO.
        N(RRURl(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRbOscc@st}x|js|jj|j}|dkrKtjdn|j|xVt|j	dD]B}dtjkrt
|tkrtdt|n|VqkWqW|jjdS(s?Read bytes from the body, decoding into a byte stream.
        Rs,Connection lost while reading streamed body.Rs               %d byte chunk readN(RRLRRReRRRUtiterRRRRRRFRR*(R R<RZt
body_bytes((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytread_streamed_bodyVs	
!
(R&R'R(RjRgRkRlR8RRbR(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR-s	cC@sLtj|dtjd|d|}t|}tj||}t|S(NRCR@RA(RRIRJtProtocolThreeResponderRtConventionalRequestHandlertProtocolThreeDecoder(R>R?R@RAtrequest_handlert	respondertmessage_handler((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pytbuild_server_protocol_threeksRcB@seZeZeZedZdZdZ	dZ
dZdZdZ
dZdZd	Zd
ZdZdZd
ZRS(cC@sptj|t|_|r>|j|_ttd|_n|j	|_d|_t|_
||_|_dS(Ni(
RsRBR8R;t(_state_accept_expecting_protocol_versionR}R*tMESSAGE_VERSION_THREERwt_state_accept_expecting_headerstdecoding_failedRR(R Rtexpect_version_marker((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRBzs
			cC@sd|_ytj||Wntk
r3ntjk
r}t|jtj	sdt
n|jj|j|jdnHt
k
r}t|_t|tjrnt
|jj|nXdS(NR(RRwRsRURORtSmartMessageHandlerErrorREt	exc_valueRPRRR^RSRHRR(R RZR`((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRUs 	

	cC@s|jdkrtdntjd|jd\}d|}|j|krdt|n|j}|d|!}|j|||S(Nis!L(RuRqtstructtunpackRzRxR|(R R0tend_of_bytesRyRZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_extract_length_prefixed_bytess

cC@sJ|j}yt|}Wn'tk
rEtjd|fnX|S(NsBytes %r not bencoded(RR	RGRR(R tprefixed_bytestdecoded((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_extract_prefixed_bencoded_datas
cC@sI|jdkrtdn|j}|d}|j|d|S(Nii(RuRqRxR|(R Rytone_byte((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_extract_single_bytes
cC@stt|j}|j}|dkratj|sLtj|ntttn|jtstj|n|j|tt|j	|_
dS(Ni(R*RRuRxRRRRqR|RR}(R tneeded_bytesRy((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs	cC@sz|j}t|tk	r7tjd|fn|j|_y|jj|Wntj	t
jnXdS(NsHeader object %r is not a dict(RRRRRt$_state_accept_expecting_message_partR}Rtheaders_receivedRtsystexc_info(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRscC@s|j}|dkr'|j|_ne|dkrB|j|_nJ|dkr]|j|_n/|dkrv|jntjd|fdS(NtotstbRsBad message kind byte: %r(Rt _state_accept_expecting_one_byteR}t!_state_accept_expecting_structuret_state_accept_expecting_bytestdoneRR(R tmessage_part_kind((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs
cC@sO|j}|j|_y|jj|WntjtjnXdS(N(	RRR}Rtbyte_part_receivedRRRR(R tbyte((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRscC@sO|j}|j|_y|jj|WntjtjnXdS(N(	RRR}Rtbytes_part_receivedRRRR(R R((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRscC@sO|j}|j|_y|jj|WntjtjnXdS(N(	RRR}Rtstructure_part_receivedRRRR(R t	structure((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR
scC@s\|j|_|jd|j|_y|jjWntj	t
jnXdS(N(RxR7R|RRR}Rtend_receivedRRRR(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs
cC@s&|j|j7_|jddS(N(R7RxR|R(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRscC@sP|j|jkrdS|jr#dS|jdk	r@|j|jStddS(Nis'don't know how many bytes are expected!(R}RRRwRRuRY(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRe"s	(R&R'tRESPONSE_VERSION_THREERgtREQUEST_VERSION_THREERlR8RBRURRRRRRRRRRRRe(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRus 	!										
				t_ProtocolThreeEncodercB@seZeZZdZdZdZdZdZ	dZ
dZdZdZ
d	Zd
ZdZdZd
ZRS(icC@sg|_d|_||_dS(Ni(t_buft_buf_lent_real_write_func(R R?((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRB7s		cC@sH|jj||jt|7_|j|jkrD|jndS(N(RR,RR*tBUFFER_SIZEtflush(R RZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR=<scC@s9|jr5|jdj|j|j2d|_ndS(NRi(RRRR(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRGs	cC@sAg}x+|D]#\}}|jd||fq
Wdj|S(sSerialise a readv offset list.s%d,%ds
(R,R(R R-R.R/R0((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR1MscC@s|jtdS(N(R=R(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRbTscC@s<t|}|jtjdt||j|dS(Ns!L(R
R=RtpackR*(R RRZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_prefixed_bencodeWscC@s|j|dS(N(R(R R%((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_headers\scC@sm|jdg}xF|D]>}t|tkrK|j|jdq|j|qW|j|dS(NRtutf8(R=RRR,RR(R Rt	utf8_argstarg((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_structure_s

cC@s|jd|jdS(NR(R=R(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt
_write_endis
cC@s=|jd|jtjdt||j|dS(NRs!L(R=RRR*(R RZ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_prefixed_bodyms
cC@s|jddS(NtoC(R=(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_chunked_body_startrscC@s|jddS(NtoE(R=(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_error_statususcC@s|jddS(NtoS(R=(R ((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_write_success_statusxsi(R&R'RRgRlRRBR=RR1RbRRRRRRR!R#(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR2s
								
				RcB@s2eZdZdedZdZdZRS(cC@sZtj||t|_itjd6|_dtjkrVt	j
|_d|_
ndS(NsSoftware versionR(RRBR8t
response_senttbzrlibt__version__RRRtthreadt	get_identt
_thread_idRt_response_start_time(R R?((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRB~s	cC@s|jdkr!tj|_n|rAdtj|j}nd}|dkr\d}n?dt|d }t|dkr|d |dd}ntd	||j	|||fdS(
Ns%5.3fs Rt i(i!iis...s%12s: [%s] %s%s%s(
R*RRRttimetclockRR*RR)(R tactionRtextra_bytestinclude_timetttextra((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt_traces	cC@s|jrtd|fnt|tjrZtjd|jf}|j|dSdt	j
kr|jdt|nt
|_|j|j|j|j|jdt|f|jdS(Ns1send_error(%s) called, but response already sent.t
UnknownMethodRRD(R$RYRERRPRRRRQt
send_responseRRR3RFRHRbRRR!RR(R R`R_((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt
send_errors"	
	

cC@s|jrtd|fnt|_|j|j|j|jr[|jn
|jdt	j
kr|jdt|j
n|j|j
|jdk	r|j|jdt	j
krY|jddt|jf|jdtqYnY|jdk	rYd}}d}xt|jD]\}}|d7}|dk	r|jtj|d}|j|Pq/t|tjr|j|j|j
Pn|t|7}|dkr|}n|j||jd	t	j
kr/|jd
dt|f|dtq/q/Wdt	j
krY|jdd
||f|qYn|jdt	j
kr|jdddtndS(Ns4send_response(%r) called, but response already sent.RRNR"s%d bytesR0iiRs
body chunkt
suppress_timesbody streams%d bytes %d chunkssresponse endR(R$RYRHRbRRRdR#R!RRR3RRRR"RRR*Rht_iter_with_errorsRt_translate_errorRERRRR(R RNRrt	num_bytestfirst_chunkRRpterror_struct((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR5s`		







	

		


N(R&R'RBRR8R3R6R5(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR|s		cc@st|}xtryd|jfVWqtk
r>dSttfk
rWqtk
rtdt	t
jdfVdSXqWdS(spHandle errors from iterable.next().

    Use like::

        for exc_info, value in _iter_with_errors(iterable):
            ...

    This is a safer alternative to::

        try:
            for value in iterable:
               ...
        except:
            ...

    Because the latter will catch errors from the for-loop body, not just
    iterable.next()

    If an error occurs, exc_info will be a exc_info tuple, and the generator
    will terminate.  Otherwise exc_info will be None, and value will be the
    value from iterable.next().  Note that KeyboardInterrupt and SystemExit
    will not be itercepted.
    Ns_iter_with_errors caught error(RRHRtnextt
StopIterationROt
SystemExitRSRRRR(titerabletiterator((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR8s	


tProtocolThreeRequestercB@s>eZdZdZdZdZdZdZRS(cC@s2tj||j||_i|_d|_dS(N(RRBRUt_medium_requestRRtbody_stream_started(R tmedium_request((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRB	s		cC@s|j|_dS(N(tcopyR(R R%((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR$scG@sdtjkrotdt|dd!t|jjdd}|dk	r]td|ntj	|_
n|j|j|j
|j||j|jjdS(NRshpss call:   %siiRs             (to %s)(RRRRRRCRRRRRRbRRRRR(R RR((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRs


cC@sdtjkrtdt|dd!|d t|jjdd	}|d	k	rdtd|ntdt|t	j
|_n|j|j
|j|j||j||j|jjd	S(
sMake a remote call of args with body bytes 'body'.

        After calling this, call read_response_tuple to find the result out.
        Rshpss call w/body: %s (%r...)iiiRs                  (to %s)s              %d bytesN(RRRRRRCRRR*RRRRbRRRRRR(R RR"tpath((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR!s!



cC@sdtjkrotdt|dd!t|jjdd}|dk	r]td|ntj	|_
n|j|j|j
|j||j|}dtjkrtdt|n|j||j|jjdS(	sMake a remote call with a readv array.

        The body is encoded with one line per readv offset pair. The numbers in
        each pair are separated by a comma, and no trailing \n is emitted.
        Rshpss call w/readv: %siiRs                  (to %s)s'              %d bytes in readv requestN(RRRRRRCRRRRRRbRRRR1R*RRR(R RR"RGR((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyR#2s



cC@sIdtjkrbtd|t|jjdd}|dk	rPtd|ntj|_	nt
|_|j|j
|j|j||jt|_xt|D]x\}}|dk	r|j|jd	|j|jj|d|d|dq|j||jqW|j|jjdS(
NRshpss call w/body stream: %rRs                  (to %s)RDiii(serror(RRRRRCRRRRRR8RDRbRRRRRHR8R!RRR(R RRnRGRtpart((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRHs.
	


	





(R&R'RBR$RR!R#R(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyRBs			
		(5R(t
__future__RRt	cStringIORRRR'R,R%RRRtbzrlib.smartRRtbzrlib.traceRRtbzrlib.bencodeR	R
RkRjRR
RRRRtobjectRR)R2RfRiRmRSRqRsRRTtResponseHandlerRRRRRRRR8RB(((s9/usr/lib/python2.7/dist-packages/bzrlib/smart/protocol.pyt<module>sL
			"|+		XrL	?	Jd	'

Copyright © 2017 || Recoded By Mr.Bumblebee