-=[ Mr. Bumblebee ]=-
_Indonesia_

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


:Nc@@s*dZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZmZddlmZddlmZeedd	efd
YZdefdYZee_d
ZdefdYZeeeedZdS(s!Server for smart-server protocol.i(tabsolute_importN(tHooks(terrorsttracet	transport(tgettext(tlazy_imports
from bzrlib.smart import (
    medium,
    signals,
    )
from bzrlib.transport import (
    chroot,
    pathfilter,
    )
from bzrlib import (
    config,
    urlutils,
    )
tSmartTCPServercB@seZdZdZdZdZejZdddZ	dZ
dZddZddZ
d	Zd
ZddZd
ZdZddZdZddZdZRS(sListens on a TCP socket and accepts connections from smart clients.

    Each connection will be served by a SmartServerSocketStreamMedium running in
    a thread.

    hooks: An instance of SmartServerHooks.
    g?g$@t/cC@s1||_||_||_g|_t|_dS(sConstruct a new server.

        To actually start it running, call either start_background_thread or
        serve.

        :param backing_transport: The transport to serve.
        :param root_client_path: The client path that will correspond to root
            of backing_transport.
        :param client_timeout: See SmartServerSocketStreamMedium's timeout
            parameter.
        N(tbacking_transporttroot_client_patht_client_timeoutt_active_connectionstFalset_gracefully_stopping(tselfR	R
tclient_timeout((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt__init__Fs

				cC@spddlm}ddlm}||_||_tj||tjtjdtjd}|\}}}}	}
tj||||_	t
jdkr|j	jtj
tjdny|j	j|
Wn+|jk
r}tj|||nX|j	j|_|jd|_|j	jd|j	j|jtj|_tj|_tj|_dS(sCreate the server listening socket.

        :param host: Name of the interface to listen on.
        :param port: TCP port to listen on, or 0 to allocate a transient port.
        i(ttimeout(terrortwin32iN(tsocketRRt
_socket_errort_socket_timeouttgetaddrinfot	AF_UNSPECtSOCK_STREAMt
AI_PASSIVEt_server_sockettsystplatformt
setsockoptt
SOL_SOCKETtSO_REUSEADDRtbindRtCannotBindAddresstgetsocknamet	_socknametporttlistent
settimeoutt_ACCEPT_TIMEOUTt	threadingtEventt_startedt_stoppedt_fully_stopped(RthostR&tsocket_timeouttsocket_errortaddrstfamilytsocktypetprotot	canonnametsockaddrtmessage((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytstart_server[s,			cC@sD|jjg}y|j|jjWntjk
r?nX|S(N(R	tbasetappendtexternal_urlRtInProcessTransport(Rturls((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt
_backing_urlsscC@so|dkr|j}nx(tjdD]}|||jq)Wx"tjdD]}|||qTWdS(Ntserver_startedtserver_started_ex(tNoneR?Rthookstget_url(Rtbacking_urlsthook((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytrun_server_started_hooksscC@sJ|dkr|j}nx(tjdD]}|||jq)WdS(Ntserver_stopped(RBR?RRCRD(RRERF((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytrun_server_stopped_hooksscC@sMtjtdt|_t|_x!|jD]\}}|jq/WdS(NsRequested to stop gracefully(RtnoteRtTruet_should_terminateRRt_stop_gracefully(Rthandlert_((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyRMs
		cC@s|j|jsdStjtdt|jf|j|j}xh|jr|j}||krtjtdt|jf||j}n|j|jqPWdS(Ns"Waiting for %d client(s) to finishs(Still waiting for %d client(s) to finish(	t_poll_active_connectionsRRRJRtlent_timert_LOG_WAITING_TIMEOUTt_SHUTDOWN_POLL_TIMEOUT(Rt
t_next_logtnow((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_wait_for_clients_to_disconnects
	tcC@s|j}tjt||t|_|j|jjzyx|jsy|j	j
\}}Wne|jk
rny|jk
r}|j
dtjtjfkrtjtd|fqn(X|jr|jPn|j|||jqHWWnBtk
rn/tk
rL}tjtjtjnXWdy|j	jWn|jk
rxnX|jjtjt||jX|j r|j!n|j"jdS(Nislistening socket error: %s(#RMtsignalstregister_on_hanguptidR
RLRGR,tsetRtacceptRRtargsterrnotEBADFtEINTRRtwarningRtcloset
serve_connRPtKeyboardInterruptt	Exceptiontreport_exceptionRtexc_infotstderrR-tunregister_on_hangupRIRRWR.(Rtthread_name_suffixtstop_gracefullytconntclient_addrte((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytservesH		

	


	
cC@sd|jd|jdfS(sReturn the url of the serversbzr://%s:%s/ii(R%(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyRDscC@s"tj||j|jd|jS(NR(tmediumtSmartServerSocketStreamMediumR	R
R(RRm((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt
_make_handlersgcC@s\g}xF|jD];\}}|j||jr|j||fqqW||_dS(saCheck to see if any active connections have finished.

        This will iterate through self._active_connections, and update any
        connections that are finished.

        :param timeout: The timeout to pass to thread.join(). By default, we
            set it to 0, so that we don't hang if threads are not done yet.
        :return: None
        N(RtjointisAliveR;(RRtstill_activeRNtthread((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyRPs

cC@s|jt|jtjtjdd|}|j|}tjd|j
d|}|jj||f|j
t|j|S(Nissmart-server-childtname(tsetblockingRKRRtIPPROTO_TCPtTCP_NODELAYRsR*tThreadRBRpRR;t	setDaemontstart(RRmRktthread_nameRNtconnection_thread((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyRds



cC@sl|jjtjd|jd|fdd|j|_|jjt	|jj
|jjdS(NR^Rxsserver-(R,tclearR*R|RBRpRDt_server_threadR}RKR~twait(RRk((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytstart_background_thread s
	
cC@s|jjt|_y|jjWn|jk
r=nX|jjstj}|j	tj
tjd|j|j
s|jqn|jj|jjdS(Ni(R-RRKRLRRcRtisSetRRRzR{t
connect_exR%RRRt(Rttemp_socket((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytstop_background_thread)s
	
N(t__name__t
__module__t__doc__R)RTRSttimeRRRBRR9R?RGRIRMRWRpRDRsRPRdRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyR4s(		(			:				tSmartServerHookscB@seZdZdZRS(sHooks for the smart server.cC@sctj|dd|jddd|jddd|jddd|jd
dddS(sCreate the default hooks.

        These are all empty initially, because by default nothing should get
        notified.
        sbzrlib.smart.serversSmartTCPServer.hooksR@sCalled by the bzr server when it starts serving a directory. server_started is called with (backing urls, public url), where backing_url is a list of URLs giving the server-specific directory locations, and public_url is the public URL for the directory being served.iiRAsvCalled by the bzr server when it starts serving a directory. server_started is called with (backing_urls, server_obj).iiRHsCalled by the bzr server when it stops serving a directory. server_stopped is called with the same parameters as the server_started hook: (backing_urls, public_url).tserver_exceptionsCalled by the bzr server when an exception occurs. server_exception is called with the sys.exc_info() tuple return true for the hook if the exception has been handled, in which case the server will exit normally.iiN(ii(ii(ii(ii(RRtadd_hook(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyRFs				(RRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyRCscC@s}y|j}Wntjtfk
r-dSX|jdrP|td}nytj|SWntj	k
rxdSXdS(s5Return a local path for transport, if reasonably possible.
    
    This function works even if transport's url has a "readonly+" prefix,
    unlike local_path_from_url.
    
    This essentially recovers the --directory argument the user passed to "bzr
    serve" from the transport passed to serve_bzr.
    s	readonly+N(
R<RR=tNotImplementedErrorRBt
startswithRQturlutilstlocal_path_from_urlt
InvalidURL(Rtbase_url((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_local_path_for_transportds	tBzrServerFactorycB@seeZdZd
d
dZdZdZdZdZdZ	dZ
dZd	ZRS(sHelper class for serve_bzr.cC@sag|_d|_d|_|dkr6tjj}n||_|dkrTt}n||_	dS(N(
tcleanupsRBt	base_pathR	tostpatht
expandusertuserdir_expanderRt
get_base_path(RRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyR~s					cC@so|}|jdrk|j|}|jds@|d7}n|j|jrk|t|j}qkn|S(sTranslate /~/ or /~user/ to e.g. /home/foo, using
        self.userdir_expander (os.path.expanduser by default).

        If the translated path would fall outside base_path, or the path does
        not start with ~, then no translation is applied.

        If the path is inside, it is adjusted to be relative to the base path.

        e.g. if base_path is /home, and the expanded path is /home/joe, then
        the translated path is joe.
        t~R(RRtendswithRRQ(RRtresulttexpanded((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_expand_userdirss
cC@stj||jS(N(t
pathfiltertPathFilteringServerR(RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_make_expand_userdirs_filterscC@s|j||_tj|}|j|jj|jtj	|j
}|jdk	r|j|}|j|jj|jtj	|j
}n||_
dS(s5Chroot transport, and decorate with userdir expander.N(RRtchroottChrootServerR9RR;tstop_servert_mod_transporttget_transport_from_urlRDRBRR(RRt
chroot_servertexpand_userdirs((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_make_backing_transports

cC@stjtjfS(N(Rtstdintstdout(R((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_get_stdin_stdoutsc	C@s|dkr*tj}|jd}n|rc|j\}}tj|||jd|}no|dkr{tj}n|dkrtj	}nt
|jd|}|j||tj
td|j||_dS(Nsserve.client_timeoutRRslistening on port: %s(RBtconfigtGlobalStacktgetRRqtSmartServerPipeStreamMediumRtBZR_DEFAULT_INTERFACEtBZR_DEFAULT_PORTRR9RRJRR&tsmart_server(	RR/R&tinetRtcRRR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_make_smart_servers 	c@sddlmmjjfd}|jj|j_d_tj	fd}|jj|dS(Ni(tlockdirtuic@s__dS(N(t
ui_factoryt_DEFAULT_TIMEOUT_SECONDS((Rtold_factorytold_lockdir_timeoutR(s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt.restore_default_ui_factory_and_lockdir_timeouts	c@stjdS(N(RYtrestore_sighup_handler((torig(s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytrestore_signalss(
tbzrlibRRRRRR;tSilentUIFactoryRYtinstall_sighup_handler(RRR((RRRRRs7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt_change_globalss			cC@s1|j||j|||||jdS(N(RRR(RRR/R&RR((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pytset_ups
cC@s%xt|jD]
}|qWdS(N(treversedR(Rtcleanup((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt	tear_downsN(
RRRRBRRRRRRRRR(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyR{s							cC@st}zty*|j||||||jjWnCt}x'tjdD]}|tj}qPW|s|q|nXWd|j	XdS(sThis is the default implementation of 'bzr serve'.

    It creates a TCP or pipe smart server on 'transport, and runs it.  The
    transport will be decorated with a chroot and pathfilter (using
    os.path.expanduser).
    RN(
RRRRpR
RRCRRhR(RR/R&RRt
bzr_serverthook_caught_exceptionRF((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt	serve_bzrs	(Rt
__future__RR_tos.pathRRRRR*tbzrlib.hooksRRRRRRtbzrlib.i18nRtbzrlib.lazy_importRtglobalstobjectRRRCRRRBR
R(((s7/usr/lib/python2.7/dist-packages/bzrlib/smart/server.pyt<module>s(	
	i

Copyright © 2017 || Recoded By Mr.Bumblebee