��Qc@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm Z m
Z
ddlmZddl
mZd�Zdefd��YZdejfd ��YZd
efd��YZdefd
��YZy$ddlmZe�ejZWnEek
ree jed�rLejZqfdefd��YZnXd�Zdeeejfd��YZdefd��YZ d�Z!dS(i�N(tutilterror(tcommon(t_cCsGd|kr'|jdd�\}}n
|d}}tj|�|fS(s�Return path and query that has been split from uri
Just like CGI environment, the path is unquoted, the query is
not.
t?it(tsplitturllibtunquote(turitpathtquery((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyt _splitURIs
t
_error_loggercBs,eZd�Zd�Zd�Zd�ZRS(cCs
||_dS(N(thandler(tselfR((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyt__init__scCsdS(N((R((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytflushscCs|j|jd��dS(Ns
(t
writelinesR(Rtstr((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytwritescCs(x!|D]}|jjd|�qWdS(Ns
HG error: %s(Rt log_error(Rtseqtmsg((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR!s
(t__name__t
__module__RRRR(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR
s t_httprequesthandlercBs�eZdZed��Zd�Zd�Zd�Zd�Zddd�Z d�Z
d �Zd
�Zd�Z
d�Zdd
�Zd�Zd�ZRS(thttpcCsdS(s*Prepare .socket of new HTTPServer instanceN((t
httpservertssl_cert((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytpreparehttpserver)scOs#d|_tjj|||�dS(NsHTTP/1.1(tprotocol_versiontBaseHTTPServertBaseHTTPRequestHandlerR(Rtargstkargs((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR.s cGs9|jd|jd|j�||f�|j�dS(Ns%s - - [%s] %s
i(Rtclient_addresstlog_date_time_stringR(RtfptformatR"((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyt_log_any2s cGs|j|jj||�dS(N(R(tserverterrorlog(RR'R"((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR8scGs|j|jj||�dS(N(R(R)t accesslog(RR'R"((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytlog_message;st-c
Cs�g|jj�D]}|djd�r|^q}|jd|jt|�t|�djgt|�D]}d|^qi��dS(Nisx-s"%s" %s %s%sRs %s:%s(theaderstitemst
startswithR,trequestlineRtjointsorted(Rtcodetsizethtxheaders((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytlog_request>s5 cCsDy|j�Wn/tjk
r?}|dtjkr@�q@nXdS(Ni(tdo_hgwebtsocketRterrnotEPIPE(Rtinst((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytdo_writeDs
cCswy|j�Wnbtk
rr|jdg�|jd�djtjtj���}|j d|j
|�nXdS(Ns500 Internal Server ErrorsInternal Server ErrorRs5Exception happened during processing request '%s':
%s(R>t Exceptiont_start_responset_writeR2t tracebacktformat_exceptiontsystexc_infoRR
(Rttb((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytdo_POSTKs
cCs|j�dS(N(RG(R((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytdo_GETUsc
Cs�t|j�\}}i}d|d<|j|d<|jj|d<t|jj�|d<|j|d<|jj|d<|t|jj�|d<|j d |d
<|j d |d<|r�||d<n|j
jdkr�j
j
|d
<n|j
j|d
<|j
jd�}|r||d<nx�g|j
j�D]}|d!kr1|^q1D]_}d|jdd�j�}|j
j|�}|jdd�j�}|rM|||<qMqMW|j|d<d"|d<|j|d<|jdd�j�dkrtj|j|jj�|_n|j|d<t|�|d<t|jtj�|d<t|jtj �|d<d |d <d|_!g|_"t#|_$d|_%d|_&x-|jj'||j(�D]} |j)| �q�W|j$s�|j*�n|j+�dS(#NsCGI/1.1tGATEWAY_INTERFACEtREQUEST_METHODtSERVER_NAMEtSERVER_PORTtREQUEST_URItSCRIPT_NAMEt PATH_INFOitREMOTE_HOSTtREMOTE_ADDRtQUERY_STRINGtCONTENT_TYPEscontent-lengthtCONTENT_LENGTHscontent-typetHTTP_R-Rs
RtSERVER_PROTOCOLiswsgi.versionswsgi.url_schemetHTTP_EXPECTs100-continues
wsgi.inputswsgi.errorsswsgi.multithreadswsgi.multiprocesss
wsgi.run_once(scontent-typescontent-length(ii(,RR
tcommandR)tserver_nameRtserver_porttprefixtlenR$R.t
typeheadertNonettypet getheadertkeystreplacetuppertstriptrequest_versiont
url_schemetgettlowerRtcontinuereadertrfiletwfileRR
t
isinstancetSocketServertThreadingMixIntForkingMixIntsaved_statust
saved_headerstFalsetsent_headerstlengtht_chunkedtapplicationR@RAtsend_headerst_done(
RR
RtenvRtR6theaderthkeythvaltchunk((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR9Xs`
!
cCs1|jstd��n|jjdd�}t|d�|d<|j|�d|_t|_xJ|j D]?}|j
|�|dj�dkrjt|d�|_qjqjW|jdkr|dtj
kr|jo�jdk|_|jr|j
dd�q|j
dd �n|j�t|_dS(
Ns.Sending headers before start_response() callediiscontent-lengthsHTTP/1.1sTransfer-Encodingtchunkedt
Connectiontclose(RptAssertionErrorRR^tintt
send_responseRtRrRuRqtsend_headerRhRtHTTP_NOT_MODIFIEDtclose_connectionRetend_headerstTrueRs(RRpR6((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyRw�s(
cCsl|jdd�\}}t|�}||_d}g|D]"}|dj�|kr:|^q:|_|jS(Nit
connectionstransfer-encodingi(s
connectionstransfer-encoding(RR^R�RpRhRqRA(Rthttp_statusR.RER4Rtbad_headersR6((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR@�s
%cCs�|jstd��n|js.|j�n|jdk rzt|�|jkratd��n|jt|�|_n(|jr�|r�dt|�|f}n|jj |�|jj
�dS(Ns+data written before start_response() calledsLContent-length header sent, but more bytes than specified are being written.s%x
%s
(RpR�RsRwRtR^R\RuRkRR(Rtdata((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyRA�s
cCs-|jr)|jjd�|jj�ndS(Ns0
(RuRkRR(R((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyRx�s N(RRRftstaticmethodRRR(RR,R8R>RGRHR9RwR^R@RARx(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR%s
7 t_httprequesthandleropensslcBs>eZdZdZed��Zd�Zd�Zd�ZRS(s HTTPS handler based on pyOpenSSLthttpscCs�yddl}|jjWn&tk
rBtjtd���nX|jj|jj�}|j|�|j |�t
j
|j|j�}|jj
||�|_
|j�|j�dS(Ni�sSSL support is unavailable(tOpenSSLtSSLtContexttImportErrorRtAbortRt
SSLv23_METHODtuse_privatekey_filetuse_certificate_fileR:taddress_familytsocket_typeRtserver_bindtserver_activate(RRR�tctxtsock((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR�s
cCsL|j|_tj|jd|j�|_tj|jd|j�|_dS(Ntrbtwb(trequestR�R:t_fileobjecttrbufsizeRjtwbufsizeRk(R((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytsetup�scCsYddl}ytj|�Wn5|jjk
rT}|jdtjkrU�qUnXdS(Ni�i(R�RR>R�tSysCallErrorR"R;R<(RR�R=((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR>�scCsPddl}ytj|�Wn,|jj|jjfk
rKt|_nXdS(Ni�(R�Rthandle_one_requestR�R�tZeroReturnErrorR�R�(RR�((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR��s ( RRt__doc__RfR�RR�R>R�(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR��s t_httprequesthandlersslcBs,eZdZdZed��Zd�ZRS(s=HTTPS handler based on Pythons ssl module (introduced in 2.6)R�cCsnyddl}|jWn&tk
r?tjtd���nX|j|jdtd|d|j�|_dS(Ni�sSSL support is unavailabletserver_sidetcertfiletssl_version( tssltwrap_socketR�RR�RR:R�tPROTOCOL_SSLv23(RRR�((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR�s
cCsL|j|_tj|jd|j�|_tj|jd|j�|_dS(NR�R�(R�R�R:R�R�RjR�Rk(R((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR��s(RRR�RfR�RR�(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR��s
(tactiveCounttforkt_mixincBseZRS((RR(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR� scCs#|r|dkrt|d�S|S(NR-ta(topen(topttdefault((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pytopenlogs
tMercurialHTTPServercBs)eZejdkrdZnd�ZRS(tntic Kstjj||||�t|_||_|j||jdd��|jddd�}|rxd|jd�}n||_ t
|jddd�tj�}t
|jddd�tj
�}||_||_|jj�d d
!\|_|_tj|d �|_dS(NtwebtcertificateR[Rt/R+R-R*ii(R t
HTTPServerRR�tdaemon_threadsRvRtconfigRdR[R�RDtstdouttstderrR+R*R:tgetsocknametaddrtporttgetfqdntfqaddr( RtuitappR�RtkwargsR[talogtelog((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyRs !! "(RRtostnametallow_reuse_addressR(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR�s tIPv6HTTPServercBs#eZeedd�Zd�ZRS(tAF_INET6cOsD|jdkr'tjtd���ntt|�j||�dS(Ns$IPv6 is not available on this system(R�R^Rt RepoErrorRtsuperR�R(RR"R�((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR-sN(RRtgetattrR:R^R�R(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyR�+scCs|jdd�r3tjd
kr*t}q9t}nt}|jdd�rTt}nt}ddl }|j
�|jddd�}tj|jdd d
��}y|||||f|�SWn?t
jk
r}tjtd�|||jdf��nXdS(NR�R�iitipv6i�taddressRR�i@s"cannot start server at '%s:%d': %si(ii(R�RDtversion_infoR�R�Rt
configboolR�R�t mimetypestinitRtgetportR:RR�RR"(R�R�RtclsR�R�R�R=((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyt
create_server2s"
("R�RDR;RR R:RmRBt mercurialRRtmercurial.hgwebRtmercurial.i18nRRtobjectR
R!RR�R�t threadingR�RnR�R�tsafehasattrRoR�R�R�R�R�(((s:/sys/lib/python2.7/site-packages/mercurial/hgweb/server.pyt<module> s(` �)
|