��Pc@sZdZddlZddlZddlZddlZddlmZmZmZm Z ddlm
Z
ddlmZ
dZdadad�Zd�Zd �Zd
efd��YZd�Zded
�Zed�Zd�Zd�Ze
je de�e
jejde�e
jejde�e
jede�e
je
de�dS(s�discover and advertise repositories on the local network
Zeroconf-enabled repositories will be announced in a network without
the need to configure a server or a service. They can be discovered
without knowing their actual IP address.
To allow other people to discover your repository using run
:hg:`serve` in your repository::
$ cd test
$ hg serve
You can discover Zeroconf-enabled repositories by running
:hg:`paths`::
$ hg paths
zc-test = http://example.com:8000/test
i�N(tuithgtencodingtdispatch(t
extensions(tservertinternalcCsy=tjtjtj�}|jd�|j�d}|SWntjk
rSnXyAtjtj��dd}|jd�r�d|kr�|SWn#tj tj
fk
r�d}nXy=tjtjtj�}|jd �|j�d}|SWntjk
rnX|S(
Ns1.0.0.1iis127.t:s 127.0.0.1i(s1.0.0.1i(s1.0.0.1i(tsockettAF_INETt
SOCK_DGRAMtconnecttgetsocknameterrort
gethostbyaddrtgethostnamet
startswithtgaierrortherror(tstiptdumbip((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pytgetip)s*
cCs,tsCt�}|jd�r"dStj|�atj|�antj�jd�d}|d}d||f}tj d|dd|d |d
i|d6d|d
6dtdddd�}tj
|�tj d|dd|d |d
i|d6d|d
6dtdddd�}tj
|�dS(Ns127.t.is.locals%s-%ss_http._tcp.local.s._http._tcp.local.Rtportt
propertiestdescriptiont/tpathtaddresstweighttprioritys_hg._tcp.local.s._hg._tcp.local.(RRRRt inet_atontlocaliptZeroconfRtsplittServiceInfotregisterService(tnametdescRRRthostnamethosttsvc((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pytpublishFs2
cCsg|||�}|j}y
|j}Wn�tk
r�|jpStjj|jj�}|jj j
ddd�jd�}|jj j
dd|�}t||||�n�X|j j
ddd�jd�d} x�|D]�\}
}|j j
�}|jtjj|dd��tjj|
�}| |
jd�}|j
dd|�}t||||�q�W|S(NtwebtprefixtRRs.hgthgrc(RtrepostAttributeErrortreponametosRtbasenametrepotrootRtconfigtstripR+tcopyt
readconfigtjoin(t
create_serverRtappthttpdRR0R&RR'R-R5tu((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pytzc_create_serverhs$
!$%tlistenercBs#eZd�Zd�Zd�ZRS(cCs
i|_dS(N(tfound(tself((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyt__init__�scCs,t|�|jkr(|jt|�=ndS(N(treprRB(RCRttypeR&((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyt
removeService�scCs#|j||�|jt|�<dS(N(tgetServiceInfoRBRE(RCRRFR&((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyt
addService�s(t__name__t
__module__RDRGRI(((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyRA�s ccs�t�}|jd�rdStj|�}t�}tj|d|�tjd�|j�xp|jj �D]_}|j
|j
jd� }dtj
|j�|j|jjdd�f}d||fVqnWdS( Ns127.s_hg._tcp.local.iRshttp://%s:%s%sRRszc-(RRR"RAtServiceBrowserttimetsleeptcloseRBtvaluesR&tindexRt inet_ntoaRRRtget(RRtltvalueR&turl((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyt
getzcpaths�s
cCs^|dkrH|jd�rHx*t�D]\}}||kr%|Sq%Wn||||||�S(Ntpathsszc-(RRW(torigRCtsectiontkeytdefaultt untrustedR&R((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyR7�s
cCs2||||�}|dkr.|t�7}n|S(NRX(RW(RYRCRZR]R0((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pytconfigitems�scCs@x3t�D](\}}||kr
|jtj�Sq
W||�S(N(RWtencodeR(RYtsourceR&R((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pytdefaultdest�scCs2z|||||�SWdtr-tj�nXdS(N(RRO(RYRtoptionstcmdtcmdfunc((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pytcleanupafterdispatch�st_runcommandR7R^RaR<(t__doc__RRMR3R"t mercurialRRRRRtmercurial.hgwebRt servermodt
testedwithtNoneR!RR+R@tobjectRARWtFalseR7R^RaRetwrapfunction(((s;/sys/lib/python2.7/site-packages/hgext/zeroconf/__init__.pyt<module>s,$" "
|