-=[ Mr. Bumblebee ]=-
_Indonesia_

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


S:Qc@@sJdZddlmZddlZddlZddlZddlZddlZddlm	Z	e	e
dddlmZejZ
dZdZd	efd
YZejfZejdkrdZeef7Znd
efdYZdefdYZdefdYZdefdYZdefdYZdefdYZdadadefdYZdefdYZ de fdYZ!defd YZ"d!e fd"YZ#dZ$d#Z%d$e fd%YZ&d&e&fd'YZ'd(e&fd)YZ(d*efd+YZ)dS(,ssThe 'medium' layer for the smart servers and clients.

"Medium" here is the noun meaning "a means of transmission", not the adjective
for "the quality between big and small."

Media carry the bytes of the requests somehow (e.g. via TCP, wrapped in HTTP, or
over SSH), and pass them to and from the protocol logic.  See the overview in
bzrlib/transport/smart/__init__.py.
i(tabsolute_importN(tlazy_imports
import select
import socket
import thread
import weakref

from bzrlib import (
    debug,
    errors,
    trace,
    transport,
    ui,
    urlutils,
    )
from bzrlib.i18n import gettext
from bzrlib.smart import client, protocol, request, signals, vfs
from bzrlib.transport import ssh
(tosutilscC@su|jtjr1tj}|ttj}n:|jtjrbtj}|ttj}n	tj}||fS(sDetermine the right protocol factory for 'bytes'.

    This will return an appropriate protocol factory depending on the version
    of the protocol being used, as determined by inspecting the given bytes.
    The bytes should have at least one newline byte (i.e. be a whole line),
    otherwise it's possible that a request will be incorrectly identified as
    version 1.

    Typical use would be::

         factory, unused_bytes = _get_protocol_factory_for_bytes(bytes)
         server_protocol = factory(transport, write_func, root_client_path)
         server_protocol.accept_bytes(unused_bytes)

    :param bytes: a str of bytes of the start of the request.
    :returns: 2-tuple of (protocol_factory, unused_bytes).  protocol_factory is
        a callable that takes three args: transport, write_func,
        root_client_path.  unused_bytes are any bytes that were not part of a
        protocol version marker.
    (t
startswithtprotocoltMESSAGE_VERSION_THREEtbuild_server_protocol_threetlentREQUEST_VERSION_TWOtSmartServerRequestProtocolTwotSmartServerRequestProtocolOne(tbytestprotocol_factory((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_get_protocol_factory_for_bytes>s			cC@sd}d}xK|dkrY|d}||7}|dkrG|dfS|jd}qW||d }||d}||fS(sRead bytes using read_bytes_func until a newline byte.

    This isn't particularly efficient, so should only be used when the
    expected size of the line is quite short.

    :returns: a tuple of two strs: (line, excess)
    itis
(tfind(tread_bytes_functnewline_posRt	new_bytestlinetexcess((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt	_get_line^s

tSmartMediumcB@sMeZdZdZdZdZdZdZdZdZ	RS(sBBase class for smart protocol media, both client- and server-side.cC@s
d|_dS(N(tNonet_push_back_buffer(tself((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt__init__wscC@sE|jdk	r(td|jfn|dkr8dS||_dS(sReturn unused bytes to the medium, because they belong to the next
        request(s).

        This sets the _push_back_buffer to the given bytes.
        s3_push_back called when self._push_back_buffer is %rRN(RRtAssertionError(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt
_push_backzscC@s;|jdkr%td|fn|j}d|_|S(NRsU%s._push_back_buffer should never be the empty string, which can be confused with EOF(RRR(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_get_push_back_buffers		cC@s5|jdk	r|jSt|t}|j|S(sRead some bytes from this medium.

        :returns: some bytes, possibly more or less than the number requested
            in 'desired_count' depending on the medium.
        N(RRRtmint_MAX_READ_SIZEt_read_bytes(Rt
desired_countt
bytes_to_read((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt
read_bytess
cC@st|jdS(N(tNotImplementedErrorR (Rtcount((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR scC@s&t|j\}}|j||S(s
Read bytes from this request's response until a newline byte.

        This isn't particularly efficient, so should only be used when the
        expected size of the line is quite short.

        :returns: a string of bytes ending in a newline (byte 0x0A).
        (RR#R(RRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
cC@stjj|||dS(sRNotify that this medium has activity.

        Implementations should call this from all methods that actually do IO.
        Be careful that it's not called twice, if one method is implemented on
        top of another.

        :param bytes: Number of bytes read or written.
        :param direction: 'read' or 'write' or None.
        N(tuit
ui_factorytreport_transport_activity(RRt	direction((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_report_activitys
(
t__name__t
__module__t__doc__RRRR#R RR*(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRts							twin32i6'tSmartServerStreamMediumcB@sweZdZejZdddZdZdZdZ	dZ
dZdZd	Z
d
ZdZRS(
sHandles smart commands coming over a stream.

    The stream may be a pipe connected to sshd, or a tcp socket, or an
    in-process fifo for testing.

    One instance is created for each connected client; it can serve multiple
    requests in the lifetime of the connection.

    The server passes requests through to an underlying backing transport,
    which will typically be a LocalTransport looking at the server's filesystem.

    :ivar _push_back_buffer: a str of bytes that have been read from the stream
        but not used yet, or None if there are no buffered bytes.  Subclasses
        should make sure to exhaust this buffer before reading more bytes from
        the stream.  See also the _push_back method.
    t/cC@sf||_||_t|_|dkr6tdn||_t|dd|_t	j
|dS(seConstruct new server.

        :param backing_transport: Transport for the directory served.
        sYou must supply a timeout.g$@g?N(tbacking_transporttroot_client_pathtFalsetfinishedRRt_client_timeoutRt_client_poll_timeoutRR(RR1R2ttimeout((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs				cC@sddlm}y-x&|js;|j}|j|qWWnktjk
r~}tjd|ftj	|j
dStk
r}|jd||fnX|j
dS(s,Serve requests until the client disconnects.i(tstderrs%sNs%s terminating on exception %s
(
tsysR8R4t_build_protocolt_serve_one_requestterrorstConnectionTimeoutttracetnotetlog_exception_quietlyt_disconnect_clientt	Exceptiontwrite(RR8tserver_protocolte((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytserves

cC@s!tjd|ft|_dS(s3When we finish this message, stop looking for more.sStopping %sN(R>tmuttertTrueR4(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_stop_gracefullyscC@sdS(s>Close the current connection. We stopped due to a timeout/etc.N((R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRAscC@st|jdS(sWait for more bytes to be read, but timeout if none available.

        This allows us to detect idle connections, and stop trying to read from
        them, without setting the socket itself to non-blocking. This also
        allows us to specify when we watch for idle timeouts.

        :return: Did we timeout? (True if we timed out, False if there is data
            to be read)
        N(R$t_wait_for_bytes_with_timeout(Rttimeout_seconds((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRJs
cC@sg|j|j|jrdS|j}t|\}}||j|j|j}|j	||S(s3Identifies the version of the incoming request, and returns an
        a protocol object that can interpret it.

        If more bytes than the version prefix of the request are read, they will
        be fed into the protocol before it is returned.

        :returns: a SmartServerRequestProtocol.
        N(
RJR5R4RRR
R1t
_write_outR2taccept_bytes(RRRtunused_bytesR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR:s		
c
C@sE|j|}t||j}d}}x|r|r|j|kr|jr\dSy+tj|gg|g|\}}}Wq/tjtjfk
r}t|dd}	|	dkrt|dddk	r|j	d}	n|	t
krdS|	tjkrq/nq/Xq/W|s'|r+dSt
jd|fdS(sselect() on a file descriptor, waiting for nonblocking read()

        This will raise a ConnectionTimeout exception if we do not get a
        readable handle before timeout_seconds.
        :return: None
        Nterrnotargsis'disconnecting client after %.1f seconds(t_timerRR6RR4tselectterrortsockettgetattrRPt_bad_file_descriptorROtEINTRR<R=(
RtfdRKtt_endtpoll_timeouttrstxst_REterr((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_wait_on_descriptor"s*
#	+$	cC@sX|dkrdSy|j|Wn0tk
r7ntk
rS}|jnXdS(s|Read one request from input, process, send back a response.

        :param protocol: a SmartServerRequestProtocol.
        N(Rt_serve_one_request_unguardedtKeyboardInterruptRBtterminate_due_to_error(RRRE((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR;As
cC@st|jdS(s<Called when an unhandled exception from the protocol occurs.N(R$Rb(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRbOscC@st|jdS(shGet some bytes from the medium.

        :param desired_count: number of bytes we want to read.
        N(R$R (RR!((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR SsN(R+R,R-ttimeRQRRRFRIRARJR:R_R;RbR (((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR/s									tSmartServerSocketStreamMediumcB@s_eZdd
dZdZdZdZdZdZdZ	dZ
d	ZRS(R0cC@sitj||d|d||jt||_y|j|_Wntjk
rdd|_nXdS(sConstructor.

        :param sock: the socket the server will read from.  It will be put
            into blocking mode.
        R2R7s	<unknown>N(R/RtsetblockingRHRTtgetpeernamet_client_infoRS(RtsockR1R2R7((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR]s
	cC@sd|jj|jfS(Ns
%s(client=%s)(t	__class__R+Rg(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt__str__oscC@sd|j|jj|jfS(Ns%s.%s(client=%s)(R,RiR+Rg(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt__repr__rscC@s_xH|jrJ|jtj}|dkr:t|_dS|j|qW|j|jdS(NR(	tnext_read_sizeR#RtMAX_SOCKET_CHUNKRHR4RMRtunused_data(RRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR`vs	cC@s|jjdS(s>Close the current connection. We stopped due to a timeout/etc.N(RTtclose(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRAscC@s|j|j|S(sWait for more bytes to be read, but timeout if none available.

        This allows us to detect idle connections, and stop trying to read from
        them, without setting the socket itself to non-blocking. This also
        allows us to specify when we watch for idle timeouts.

        :return: None, this will raise ConnectionTimeout if we time out before
            data is available.
        (R_RT(RRK((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRJs
cC@stj|j|jS(N(Rtread_bytes_from_socketRTR*(RR!((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR scC@s|jjt|_dS(N(RTRoRHR4(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRbs
cC@sttj}tj|j||jdtjkrptj}t	j
dd|t|tj|fndS(Nthpsss*%12s: [%s] %d bytes to the socket in %.3fstwrote(Rt
timer_functsend_allRTR*tdebugtdebug_flagstthreadt	get_identR>RGR(RRttstartt	thread_id((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRLs	N(R+R,RRRjRkR`RARJR RbRL(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRd[s			
				tSmartServerPipeStreamMediumcB@sSeZddZdZdZdZdZdZdZ	dZ
RS(	cC@stj||d|tjdkr|ddl}xH||fD]7}t|dd}|r>|j|tj	q>q>Wn||_
||_dS(sConstruct new server.

        :param in_file: Python file from which requests can be read.
        :param out_file: Python file to write responses.
        :param backing_transport: Transport for the directory served.
        R7R.iNtfileno(R/RR9tplatformtmsvcrtRURtsetmodetostO_BINARYt_int_out(Rtin_filetout_fileR1R7R~tfR|((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs 	cC@sQ|j}tjt||ztt|jSWdtjt|XdS(s!See SmartServerStreamMedium.serveN(RItsignalstregister_on_hanguptidtsuperR{RFtunregister_on_hangup(Rtstop_gracefully((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRFs
	cC@s|xutrw|j}|dkr2|jjdS|j|}|dkrgt|_|jjdS|j|qWdS(NiR(RHRlRtflushR#R4RM(RRR"R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR`s	
	
cC@s+|jj|jj|jjdS(N(RRoRR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRAs

cC@sAt|jdddks*tjdkr.dS|j|j|S(sWait for more bytes to be read, but timeout if none available.

        This allows us to detect idle connections, and stop trying to read from
        them, without setting the socket itself to non-blocking. This also
        allows us to specify when we watch for idle timeouts.

        :return: None, this will raise ConnectionTimeout if we time out before
            data is available.
        R|R.N(RURRR9R}R_(RRK((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRJs
cC@s|jj|S(N(Rtread(RR!((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR scC@s|jjt|_dS(N(RRoRHR4(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRbs
cC@s|jj|dS(N(RRC(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRLsN(R+R,RRRFR`RARJR RbRL(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR{s						tSmartClientMediumRequestcB@sqeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
RS(sMA request on a SmartClientMedium.

    Each request allows bytes to be provided to it via accept_bytes, and then
    the response bytes to be read via read_bytes.

    For instance:
    request.accept_bytes('123')
    request.finished_writing()
    result = request.read_bytes(3)
    request.finished_reading()

    It is up to the individual SmartClientMedium whether multiple concurrent
    requests can exist. See SmartClientMedium.get_request to obtain instances
    of SmartClientMediumRequest, and the concrete Medium you are using for
    details on concurrency and pipelining.
    cC@s||_d|_dS(s;Construct a SmartClientMediumRequest for the medium medium.twritingN(t_mediumt_state(Rtmedium((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR
s	cC@s2|jdkr!tj|n|j|dS(spAccept bytes for inclusion in this request.

        This method may not be called after finished_writing() has been
        called.  It depends upon the Medium whether or not the bytes will be
        immediately transmitted. Message based Mediums will tend to buffer the
        bytes until finished_writing() is called.

        :param bytes: A bytestring.
        RN(RR<tWritingCompletedt
_accept_bytes(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRMs
cC@st|jdS(sHelper for accept_bytes.

        Accept_bytes checks the state of the request to determing if bytes
        should be accepted. After that it hands off to _accept_bytes to do the
        actual acceptance.
        N(R$R(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR#scC@sY|jdkr!tj|n|jdkrBtj|nd|_|jdS(sInform the request that all desired data has been read.

        This will remove the request from the pipeline for its medium (if the
        medium supports pipelining) and any further calls to methods on the
        request will raise ReadingCompleted.
        RtreadingtdoneN(RR<tWritingNotCompletetReadingCompletedt_finished_reading(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytfinished_reading,s	cC@st|jdS(sHelper for finished_reading.

        finished_reading checks the state of the request to determine if
        finished_reading is allowed, and if it is hands off to _finished_reading
        to perform the action.
        N(R$R(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR:scC@s8|jdkr!tj|nd|_|jdS(sFinish the writing phase of this request.

        This will flush all pending data for this request along the medium.
        After calling finished_writing, you may not call accept_bytes anymore.
        RRN(RR<Rt_finished_writing(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytfinished_writingCs	cC@st|jdS(sHelper for finished_writing.

        finished_writing checks the state of the request to determine if
        finished_writing is allowed, and if it is hands off to _finished_writing
        to perform the action.
        N(R$R(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRNscC@sO|jdkr!tj|n|jdkrBtj|n|j|S(s>Read bytes from this requests response.

        This method will block and wait for count bytes to be read. It may not
        be invoked until finished_writing() has been called - this is to ensure
        a message-based approach to requests, for compatibility with message
        based mediums like HTTP.
        RR(RR<RRR (RR%((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR#Ws
cC@s|jj|S(sVHelper for SmartClientMediumRequest.read_bytes.

        read_bytes checks the state of the request to determing if bytes
        should be read. After that it hands off to _read_bytes to do the
        actual read.

        By default this forwards to self._medium.read_bytes because we are
        operating on the medium's stream.
        (RR#(RR%((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR es
cC@s1|j}|jds-tjdn|S(Ns
skUnexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.(t
_read_linetendswithR<tConnectionReset(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt	read_lineqs
cC@s
|jjS(sHelper for SmartClientMediumRequest.read_line.

        By default this forwards to self._medium._get_line because we are
        operating on the medium's stream.
        (RR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRzs(R+R,R-RRMRRRRRR#R RR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs														t_VfsRefusercB@s eZdZdZdZRS(s.An object that refuses all VFS requests.

    cC@s tjjjd|jddS(Ntcallsvfs refuser(tclientt_SmartClientthookstinstall_named_hookt	check_vfs(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s_ytjj|j}Wntk
r-dSXt|tjr[tj	|j|j
ndS(N(trequesttrequest_handlerstgettmethodtKeyErrort
issubclasstvfst
VfsRequestR<tHpssVfsRequestNotAllowedRP(Rtparamstrequest_method((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
(R+R,R-RR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs	t
_DebugCountercB@s;eZdZdZdZdZdZdZRS(sAn object that counts the HPSS calls made to each client medium.

    When a medium is garbage-collected, or failing that when
    bzrlib.global_state exits, the total number of calls made on that medium
    are reported via trace.note.
    cC@sEtj|_tjjjd|jdtj	j
j|jdS(NRshpss call counter(
tweakreftWeakKeyDictionarytcountsRRRRtincrement_call_counttbzrlibtglobal_statetcleanupstadd_cleanupt	flush_all(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@sGt|}tddddd||j|<tj||j}dS(sStart tracking calls made to a medium.

        This only keeps a weakref to the medium, so shouldn't affect the
        medium's lifetime.
        R%it	vfs_counttmedium_reprN(treprtdictRRtrefR(RRRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyttrackscC@sw|j|j}|dcd7<ytjj|j}Wntk
rMdSXt|tj	rs|dcd7<ndS(NR%iR(
RRRRRRRRRR(RRtvalueR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
cC@sv|j|}|d|d|d}}}d|d<d|d<|dkrrtjtdj|||ndS(NR%RRisHPSS calls: {0} ({1} vfs) {2}(RR>R?tgettexttformat(RRRR%RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
 

cC@s1x*t|jjD]}|j|qWdS(N(tlistRtkeysR(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs(R+R,R-RRRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs				
tSmartClientMediumcB@sMeZdZdZdZdZdZdZdZdZ	RS(sBSmart client is a medium for sending smart protocol requests over.cC@stt|j||_d|_d|_t|_d|_	dt
jkrwtdkrgt
antj|ndt
jkrtdkrtaqndS(NRqthpss_client_no_vfs(RRRtbaseRt_protocol_version_errort_protocol_versionR3t_done_hellot_remote_version_is_beforeRuRvt_debug_counterRRt_vfs_refuserR(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs					cC@s |jdkrtS||jkS(sIs it possible the remote side supports RPCs for a given version?

        Typical use::

            needed_version = (1, 2)
            if medium._is_remote_before(needed_version):
                fallback_to_pre_1_2_rpc()
            else:
                try:
                    do_1_2_rpc()
                except UnknownSmartMethod:
                    medium._remember_remote_is_before(needed_version)
                    fallback_to_pre_1_2_rpc()

        :seealso: _remember_remote_is_before
        N(RRR3(Rt
version_tuple((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_is_remote_beforescC@st|jdk	rg||jkrgtjd||jdtjkrctjjd||jfndS||_dS(soTell this medium that the remote side is older the given version.

        :seealso: _is_remote_before
        s`_remember_remote_is_before(%r) called, but _remember_remote_is_before(%r) was called previously.RqN(	RRR>RGRuRvR&R'tshow_warning(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt_remember_remote_is_befores
	cC@s|jdk	r|jn|js~y2|j}tj|}|jt|_Wq~tj	k
rz}||_q~XndS(s(Find out if 'hello' smart request works.t2N(
RRRtget_requestRtSmartClientRequestProtocolOnet
query_versionRHR<tSmartProtocolError(Rtmedium_requesttclient_protocolRE((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytprotocol_versions	

	
cC@stS(sShould RemoteBzrDirFormat.probe_transport send a smart request on
        this medium?

        Some transports are unambiguously smart-only; there's no need to check
        if the transport is able to carry smart requests, because that's all
        it is for.  In those cases, this method should return False.

        But some HTTP transports can sometimes fail to carry smart requests,
        but still be usuable for accessing remote bzrdirs via plain file
        accesses.  So for those transports, their media should return True here
        so that RemoteBzrDirFormat can determine if it is appropriate for that
        transport.
        (R3(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytshould_probe.scC@sdS(svIf this medium maintains a persistent connection, close it.

        The default implementation does nothing.
        N((R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt
disconnect>scC@s7tj|jd}tj||j}tj|S(sConvert transport into a path suitable for using in a request.

        Note that the resulting remote path doesn't encode the host name or
        anything but path, so it is only safe to use it in requests sent over
        the medium from the matching transport.
        R0(turlutilstjoinRtrelative_urltunquote(Rt	transporttmedium_basetrel_url((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytremote_path_from_transportDs(
R+R,R-RRRRRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs						tSmartClientStreamMediumcB@sDeZdZdZdZdZdZdZdZRS(sStream based medium common class.

    SmartClientStreamMediums operate on a stream. All subclasses use a common
    SmartClientStreamMediumRequest for their requests, and should implement
    _accept_bytes and _read_bytes to allow the request objects to send and
    receive bytes.
    cC@stj||d|_dS(N(RRRt_current_request(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRYscC@s|j|dS(N(R(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRM]scC@s|jdS(sgThe SmartClientStreamMedium knows how to close the stream when it is
        finished with it.
        N(R(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt__del__`scC@st|jdS(sFlush the output stream.

        This method is used by the SmartClientStreamMediumRequest to ensure that
        all data for a request is sent, to avoid long timeouts or deadlocks.
        N(R$t_flush(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRfscC@s
t|S(sSee SmartClientMedium.get_request().

        SmartClientStreamMedium always returns a SmartClientStreamMediumRequest
        for get_request.
        (tSmartClientStreamMediumRequest(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRnscC@s|jd|_dS(sWe have been disconnected, reset current state.

        This resets things like _current_request and connected state.
        N(RRR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pytresetvs
(	R+R,R-RRMRRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRPs					tSmartSimplePipesClientMediumcB@s2eZdZdZdZdZdZRS(syA client medium using simple pipes.

    This client does not manage the pipes: it assumes they will always be open.
    cC@s&tj||||_||_dS(N(RRt_readable_pipet_writeable_pipe(Rt
readable_pipetwriteable_pipeR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs	cC@swy|jj|WnFtk
r\}|jtjtjfkrVtjd|nnX|jt	|ddS(s)See SmartClientStreamMedium.accept_bytes.s#Error trying to write to subprocessRCN(
RRCtIOErrorROtEINVALtEPIPER<RR*R(RRRE((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s|jjdS(s%See SmartClientStreamMedium._flush().N(RR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s;t|t}|jj|}|jt|d|S(s(See SmartClientStreamMedium._read_bytes.R(RRRRR*R(RR%R"R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR s(R+R,R-RRRR (((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
			t	SSHParamscB@s#eZdZdddddZRS(s6A set of parameters for starting a remote bzr via SSH.tbzrcC@s1||_||_||_||_||_dS(N(thosttporttusernametpasswordtbzr_remote_path(RRRRRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
				N(R+R,R-RR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs	tSmartSSHClientMediumcB@sPeZdZddZdZdZdZdZdZ	dZ
RS(	sA client medium using SSH.

    It delegates IO to a SmartSimplePipesClientMedium or
    SmartClientAlreadyConnectedSocketMedium (depending on platform).
    cC@sAd|_||_d|_tj||||_d|_dS(sCreates a client that will connect on the first use.

        :param ssh_params: A SSHParams instance.
        :param vendor: An optional override for the ssh vendor to use. See
            bzrlib.transport.ssh for details on ssh vendors.
        sbzr+sshN(Rt_real_mediumt_ssh_paramst_schemeRRt_vendort_ssh_connection(RRt
ssh_paramstvendor((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs				cC@s||jjdkrd}nd|jj}|jjdkrFd}nd|jj}d|jj|j||jj|fS(NRs:%ss%s@s%s(%s://%s%s%s/)(RRRRRiR+RR(Rt
maybe_portt
maybe_user((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRks				cC@s|j|jj|dS(s)See SmartClientStreamMedium.accept_bytes.N(t_ensure_connectionRRM(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
cC@sT|jdk	r(|jjd|_n|jdk	rP|jjd|_ndS(s#See SmartClientMedium.disconnect().N(RRRRRo(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs

cC@s6|jdk	rdS|jdkr1tj}n	|j}|j|jj|jj|jj	|jj
d|jjddddg|_|jj
\}}|dkrt|j||_nL|dkr|\}}t|||j|_ntd	||jfx"tjjd
D]}||qWdS(s-Connect this medium if not already connected.NtcommandRFs--inets
--directory=/s--allow-writesRTtpipessUnexpected io_kind %r from %rtpost_connect(RRRtssht_get_ssh_vendortconnect_sshRRRRRRRtget_sock_or_pipest'SmartClientAlreadyConnectedSocketMediumRRRRt	TransportR(RRtio_kindt	io_objectt	read_fromtwrite_tothook((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs.	cC@s|jjdS(s%See SmartClientStreamMedium._flush().N(RR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s1|jdkr!tj|n|jj|S(s'See SmartClientStreamMedium.read_bytes.N(RRR<tMediumNotConnectedR#(RR%((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR sN(R+R,R-RRRkRRRRR (((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs						i;tSmartClientSocketMediumcB@sDeZdZdZdZdZdZdZdZRS(soA client medium using a socket.

    This class isn't usable directly.  Use one of its subclasses instead.
    cC@s&tj||d|_t|_dS(N(RRRt_socketR3t
_connected(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs	cC@s'|jtj|j||jdS(s#See SmartClientMedium.accept_bytes.N(RRRtRR*(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
cC@st|jdS(s-Connect this medium if not already connected.N(R$R(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR$scC@sdS(sSee SmartClientStreamMedium._flush().

        For sockets we do no flushing. For TCP sockets we may want to turn off
        TCP_NODELAY and add a means to do a flush, but that can be done in the
        future.
        N((R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR(scC@s1|jstj|ntj|j|jS(s!See SmartClientMedium.read_bytes.(RR<RRRpRR*(RR%((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR 0s	cC@s0|js
dS|jjd|_t|_dS(s#See SmartClientMedium.disconnect().N(RRRoRR3(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR7s
	
	(	R+R,R-RRRRR R(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs					tSmartTCPClientMediumcB@s eZdZdZdZRS(s.A client medium that creates a TCP connection.cC@s&tj||||_||_dS(s4Creates a client that will connect on the first use.N(RRt_hostt_port(RRRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRCs	cC@s|jr
dS|jdkr%t}nt|j}y+tj|j|tjtj	dd}Wn;tj
k
r\}}tjd|j||fnXtj
d|j}x|D]\}}}}	}
yHtj||||_|jjtjtjd|jj|
WnAtj
k
rZ}|jdk	rK|jjnd|_qnXPqW|jdkrt|jtkr|j}n
|jd}tjd|j||fnt|_x"tjjdD]}||qWdS(s-Connect this medium if not already connected.Nisfailed to lookup %s:%d: %ssno address found for %sisfailed to connect to %s:%d: %sR
(RRRtBZR_DEFAULT_PORTtintRTtgetaddrinfoRt	AF_UNSPECtSOCK_STREAMtgaierrorR<tConnectionErrorRSRt
setsockopttIPPROTO_TCPtTCP_NODELAYtconnectRottypeRPtstrRHRRR(RRt	sockaddrsterr_numterr_msgR^tfamilytsocktypetprotot	canonnametsockaddrR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRIsB			
	
		(R+R,R-RR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyR@s	RcB@s eZdZdZdZRS(sA client medium for an already connected socket.
    
    Note that this class will assume it "owns" the socket, so it will close it
    when its disconnect method is called.
    cC@s&tj||||_t|_dS(N(RRRRHR(RRRh((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRzs	cC@sdS(N((R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs(R+R,R-RR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRss	RcB@s2eZdZdZdZdZdZRS(sFA SmartClientMediumRequest that works with an SmartClientStreamMedium.cC@sGtj|||jjdk	r7tj|jn||j_dS(N(RRRRRR<tTooManyConcurrentRequests(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s|jj|dS(sSee SmartClientMediumRequest._accept_bytes.

        This forwards to self._medium._accept_bytes because we are operating
        on the mediums stream.
        N(RR(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s.|jj|k	rtnd|j_dS(sSee SmartClientMediumRequest._finished_reading.

        This clears the _current_request on self._medium to allow a new
        request to be created.
        N(RRRR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRscC@s|jjdS(sSee SmartClientMediumRequest._finished_writing.

        This invokes self._medium._flush to ensure all bytes are transmitted.
        N(RR(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs(R+R,R-RRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyRs
			
(*R-t
__future__RRORR9RcRtbzrlib.lazy_importRtglobalsRRmRR
RtobjectRtEBADFRVR}tWSAENOTSOCKR/RdR{RRRRRRRRRRRtBZR_DEFAULT_INTERFACERRRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/medium.pyt<module>sJ			 	DLT;{/%`,3

Copyright © 2017 || Recoded By Mr.Bumblebee