$Jc@s8ddkZddkZddkZddkZddkZddkZddkZddkZddkl Z ddk Z ddk Z dZ dZ dZdddZdZdadadZd eifd YZd eifd YZd efdYZdZeedZeo<yddkZeiZ Wqpe!j odZ qpXnde i"fdYZ#de i$fdYZ%eo<dei&fdYZ'de i(ei)fdYZ*ndei+fdYZ,dZ-gZ.ddZ/ei0dZ1ddZ2dS( iN(t_cCsUti|\}}}}}}tidd|}ti||||||fS(s$hide user credential in a url strings([^:]*):([^@]*)@(.*)s \1:***@\3(turlparsetretsubt urlunparse(turltschemetnetloctpathtparamstquerytfragment((s /sys/lib/python/mercurial/url.pyt hidepasswords!cCsWti|\}}}}}}||idd}ti||||||fS(s7remove all authentication information from a url stringt@i(RtfindR(RRRRR R R ((s /sys/lib/python/mercurial/url.pyt removeauths!c Cs|id}|djod\}}nz|| ||d}}|id}|djoti|d}}n+ti|| }ti||d}|id}|djo|d}}n|| ||d}}||||fS(s/split [user[:passwd]@]host[:port] into 4-tuple.R iit:N(NN(RtNoneturllibtunquote(Rtatusertpasswdtuserpasstcthosttport((s /sys/lib/python/mercurial/url.pyt netlocsplits   cCst|o|d|}n|}|oJ|o$ti|dti|}nti|}|d|Sn|S(s?turn host, port, user, passwd into [user[:passwd]@]host[:port].RR (Rtquote(RRRRthostportR((s /sys/lib/python/mercurial/url.pyt netlocunsplit/s$sBabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-/cCstdjottatdant|}xtt|D]}||}|djoE|dt|jo.||dtjo||dtjoqH|tjodt|||>> quotepath('abc def') 'abc%20def' >>> quotepath('abc%20def') 'abc%20def' >>> quotepath('abc%20 def') 'abc%20%20def' >>> quotepath('abc def%20') 'abc%20def%20' >>> quotepath('abc def%2') 'abc%20def%252' >>> quotepath('abc def%') 'abc%20def%25' tabcdefABCDEF0123456789t%iis%%%02XtN( t_safesetRtsett_safet_hextlisttxrangetlentordtjoin(RtltiR((s /sys/lib/python/mercurial/url.pyt quotepathBs    N t passwordmgrcBs,eZdZdZdZdZRS(cCstii|||_dS(N(turllib2tHTTPPasswordMgrWithDefaultRealmt__init__tui(tselfR2((s /sys/lib/python/mercurial/url.pyR1cscCstii|||}|\}}|o%|o|i||||fSn|p=|i|}|o#|id|id}}qn| p| o|iipti t dn|ii t d|ii t d||o|ii t d|n|ii t ddd}|p|ii}q^n|i|||||i||||fS( Ntusernametpasswordshttp authorization requiredshttp authorization required s realm: %s s user: %s suser:tdefault(R/R0tfind_user_passwordt _writedebugt readauthtokentgetR2t interactivetutiltAbortRtwritetstatustpromptRtgetpasst add_password(R3trealmtauthuritauthinfoRRtauth((s /sys/lib/python/mercurial/url.pyR7gs.  'cCsBtd}|ii|||odt|pdfdS(Ns http auth: user %s, password %s t*snot set(RR2tdebugR((R3RRtmsg((s /sys/lib/python/mercurial/url.pyR8s cCsot}xW|iidD]C\}}|idd\}}|i|t}|||}y"|tijoti|=nWqtj oqXqWtii||||_dS(Nt http_proxyRshttp:shttps:shttp://t/RRt localhosts 127.0.0.1tnotno_proxyR!t,talwaysthttpRMsproxying through http://%s:%s t HTTP_PROXY(RUtostgetenvRSRturlsplitRtextendt configlisttlowerRPtstript configbooltno_listt urlunsplitRRHRtenvirontOSErrorR/t ProxyHandlerR1R2(R3R2tproxyurltsnpqft proxyschemet proxynetloct proxypatht proxyqueryt proxyfragthpupt proxyhostt proxyportt proxyusert proxypasswdRst_[1]R^t_[2]tproxiestenv((s /sys/lib/python/mercurial/url.pyR1sL"   - .    csx|iidd}||ijodSn|idffdY}||_tii||||S(NRit_requestcseZfdZRS(cs6|idjo|i}ni|||S(Nsproxy-authorization(RpRqt add_header(R3RVRW(t baseclass(s /sys/lib/python/mercurial/url.pyRs(R_R`R((R(s /sys/lib/python/mercurial/url.pyRs(tget_hostRPRsRt __class__R/Rwt proxy_open(R3treqtproxyttype_RR((Rs /sys/lib/python/mercurial/url.pyRs  (R_R`R1R(((s /sys/lib/python/mercurial/url.pyRas 5t httpsendfilecBseZdZRS(cCsti|iiS(N(Rktfstattfilenotst_size(R3((s /sys/lib/python/mercurial/url.pyt__len__s(R_R`R(((s /sys/lib/python/mercurial/url.pyRscsfd}|S(Ncs_t|to;|idx;ti|D]}i||q-Wni||dS(Ni(t isinstanceRtseekR<t filechunkitertsend(R3tdatatchunk(t connection(s /sys/lib/python/mercurial/url.pyt _sendfiles  ((RR((Rs /sys/lib/python/mercurial/url.pyt _gen_sendfiles t HTTPSHandlercCs%ti|||}ti||S(N(tsockettsslthttplibt FakeSocket(tsocktkey_filet cert_fileR((s /sys/lib/python/mercurial/url.pyt_ssl_wrap_socketsthttpconnectioncBs2eZeeiZdZdZdZRS(c Cstg}|iD]4}|iido|||i|fqq~}|i|i|i|id|i|i fx%|i D]}|id|qW|id|i |i d|i d|i}xfto^|i\}}}|tijoPnx-to%|iii} | pPqqWqW||_|i|_|idjo8x-to%|ii} | djoPqqqqWtSn|djo d |_nG|id o d |_n*|d jo d |_nti||id jo;d|_d|_d|_titi |_!t"Snti|i|_!d|i!_|i!i#d} | o)| idjod|_d|_$n d|_|i%|_|i!i#d} | o^|i oSyt&| |_Wnt'j od|_qLX|idjo d|_qLn d|_|ti(jp>|ti)jp.d|jo djnp|idjo d|_n|i o(|i o|idjo d|_n||_*t"S(Nsproxy-sCONNECT %s:%d HTTP/1.0 s%s: %s s tstricttmethodisHTTP/1.0i sHTTP/1.i sHTTP/0.9i iistransfer-encodingtchunkedscontent-lengthidtHEAD(+RNtheadersRpRSt _set_hostportRRRtrealhosttrealportt iteritemstresponse_classRRt_methodtTruet _read_statusRtCONTINUEtfptreadlineRqR?treasontversiontUnknownProtocolRtlengthRt will_closet HTTPMessaget cStringIOtStringIORItFalset getheadert chunk_leftt _check_closetintt ValueErrort NO_CONTENTt NOT_MODIFIEDtproxyres( R3Rtxt proxyheaderstheadertresRR?RtskiptlinettrencR((s /sys/lib/python/mercurial/url.pyt _proxytunnel s:                             cCston|iodtititi|_|ii|i|if|i ot |idd|_qnt i i|dS(N(t has_httpsRRtAF_INETt SOCK_STREAMRtconnectRRRRRt keepalivetHTTPConnection(R3((s /sys/lib/python/mercurial/url.pyRjs   cCsRt|dd}|o)|io|ind|_|Sntii|S(NR(tgetattrRRtcloseRRRt getresponse(R3R((s /sys/lib/python/mercurial/url.pyRts  ( R_R`RRRRRRR(((s /sys/lib/python/mercurial/url.pyRs a t httphandlercBs#eZdZdZdZRS(cCs|it|S(N(tdo_openR(R3R((s /sys/lib/python/mercurial/url.pyt http_open~scCs|i|ijoti|i}|ddjod|djo)|did\}}t|}n|d}d}||_||_|ii|_|ii |i i t i i|||Sqnd|_d|_d|_t i i|||S(NiRMRii(t get_selectort get_full_urlRRPRRRRtcopytupdatetparentt addheadersRt HTTPHandlert_start_transactionR(R3thRturlpartsRR((s /sys/lib/python/mercurial/url.pyRs"      cCs|idS(N(t close_all(R3((s /sys/lib/python/mercurial/url.pyt__del__s(R_R`RRR(((s /sys/lib/python/mercurial/url.pyR}s  thttpsconnectioncBs eZeiZeeiZRS(( R_R`Rt HTTPResponseRRRtHTTPSConnectionR(((s /sys/lib/python/mercurial/url.pyRs t httpshandlercBs&eZdZdZddZRS(cCs?tii|tii|||_t|i|_dS(N(RtKeepAliveHandlerR1R/RR2R.tpwmgr(R3R2((s /sys/lib/python/mercurial/url.pyR1s cCs.|ii|i|_|i|i|S(N(RR9RRFRt_makeconnection(R3R((s /sys/lib/python/mercurial/url.pyt https_opensicOsd}d}|o|id}n|o|id}n|io>d|ijo.d|ijo|id}|id}nd|jo d|jp d|joF|idd\}}t|}d|jo|dd!}qnt||||||S( NiRVtcertRt[s]:ii(RtpopRFtrsplitRR(R3RRtargstkwargstkeyfiletcertfile((s /sys/lib/python/mercurial/url.pyRs* '  (R_R`R1RR(((s /sys/lib/python/mercurial/url.pyRs  thttpdigestauthhandlercBseZdZRS(c Csdy tii|||||SWn=tj o1}|id}|idodSnnXdS(Nis'AbstractDigestAuthHandler doesn't know (R/tHTTPDigestAuthHandlerthttp_error_auth_reqedRRRS(R3t auth_headerRRRtinsttarg((s /sys/lib/python/mercurial/url.pyRs  (R_R`R(((s /sys/lib/python/mercurial/url.pyRsc Csti|\}}}}}|p d}n|djot|}nt|\}}}} ti|t|||||f} |oB|}|o|d|7}nd| |f|| pdf} nd} | | fS(NRctfileRR!(RRmR-RRtRR( RRRturlpathR tfragRRRRRRE((s /sys/lib/python/mercurial/url.pyt getauthinfos  #c Cs1tg}to|it|n|it|t|}|d j oY|i||dd!\}}|it d||odt |pdfn|i t i |t|f|i g}tD]}||||q~t i|}d g|_|iid |S( se construct an opener suitable for urllib2 authinfo will be added to the password manager iis http auth: user %s, password %s RGsnot sets User-agentsmercurial/proto-1.0tAcceptsapplication/mercurial-0.1N(s User-agentsmercurial/proto-1.0(Rsapplication/mercurial-0.1(RRtappendRRaR.RRBRHRR(RnR/tHTTPBasicAuthHandlerRt handlerfuncst build_openerR( R2REthandlerstpassmgrRRRRtopener((s /sys/lib/python/mercurial/url.pyR s"    *1 s^([a-zA-Z0-9+-.]+)://cCsd}ti|}|o|idi}n|p8titii |}dt i |}d}nt |\}}t ||i||S(Nisfile://(Rt scheme_retsearchRXRpR<tnormpathRkRtabspathRt pathname2urlRR topen(R2RRRtmRRE((s /sys/lib/python/mercurial/url.pyR s (3RR/RRRkRRRti18nRRR<R RRRRR$R"R%R-R0R.RwRaRRRthasattrRRt wrap_socketRt ImportErrorRRRRRRRRRRRRRR tcompileR R(((s /sys/lib/python/mercurial/url.pys s@`    AG   x#&