^cSYddlZddlZddlmZddlmZmZmZm Z m Z m Z m Z m Z ddlmZmZe jZe jZe jZe jZd'dZGddZGd d ejZd Ze jed ZGd de jZdZd(dZGdde jZGdde jZ GddeZ!er,Gdde jZ"Gdde j#ej$Z$Gddej%Z%Gddej&Z&Gd d!ej'Z(gZ) d)d$Z*d*d%Z+d&Z,dS)+N)_)encodingerrorhttpconnection keepalivepycompatsslutil urllibcompatutil) stringutilurlutilc|dd}|dd}|dd}|r|dd}|S) a1Replace special characters "&", "<" and ">" to HTML-safe sequences. If the optional flag quote is true, the quotation mark character (") is also translated. This is the same as cgi.escape in Python, but always operates on bytes, whereas cgi.escape in Python 3 only works on unicodes. &s&s>"s")replace)squotes //usr/lib/python3/dist-packages/mercurial/url.pyescaper$s] $!!A $  A $  A ' IIdI & & Hc,eZdZdZdZdZdZdZdS) passwordmgrc"||_||_dSN)uipasswddb)selfrrs r__init__zpasswordmgr.__init__5s  rc<|j||||Sr)r add_password)r realmuriuserpasswds rr#zpasswordmgr.add_password9s}))%dFCCCrc0t|tdtfsJt|tsJ|j||}|\}}t j|t j|}}|r@|r>|||t j|t j|fS|r|sitj |j ||}|rL|\}}| d| d}}|j d|z|r|stjt j|} d| _|j sCt%jt)dtjt-| z|j t)dtjt-| z|j t)dt j|z|r+|j t)d|zn)|j t)dd }|s|j }|d S|j|||||||t j|t j|fS) Nsusernamespassword#using auth.%s.* for authentication s"http authorization required for %ss#http authorization required for %s s realm: %s s user: %s suser:)default)NN) isinstancetypestrrfind_user_passwordr bytesurl _writedebugstrurlhttpconnectionmodreadauthforurirgetdebugrurlquery interactiverAbortr hidepasswordbyteswritepromptgetpassr#) r r$authuriauthinfor&r'resgroupauthus rr.zpasswordmgr.find_user_password<s%$t**c!233333'3'''''=33E7CC f(..0A&0I0If  DF D   T6 * * *OD))8?6+B+BC C O6 O#247GTJJC O! t#xx 44dhh{6K6Kf EMNNN +6 + H-g6677AAG7&&(( k;<<*588445 GMM9::&uQxx001    GMM!N++h.?.F.FF G G G A a ..56666w~~akk4~@@ +** <: ""5'4@@@ v&&&%%xv'>'>??rctd}|j|||rdt|zpdfzdS)N http auth: user %s, password %s *not set)rrr5len)r r&r'msgs rr0zpasswordmgr._writedebugmsI455  cT6#@dS[[.@#NJOOPPPPPrc8|jd|Sr)rr.)r r?s rfind_stored_passwordz passwordmgr.find_stored_passwordqs}//g>>>rN)__name__ __module__ __qualname__r!r#r.r0rLrrrr4si!!!DDD/@/@/@bQQQ?????rrceZdZdZdZdS) proxyhandlerc|ddptjd}|r{|ds|dsd|zdz}t j|}|js6|dd|_|dd|_d d g}| d | dd D| d tjdd dD| ddrg|_ n||_ t|}||d}|dt jt#|zni}t$j||||_dS)Ns http_proxyshostshttp:shttps:shttp:///suserspasswds localhosts 127.0.0.1c6g|]}|SrP)lower.0ps r z)proxyhandler.__init__..s HHHqHHHrsnocg|]<}||=SrP)striprVrWs rrZz)proxyhandler.__init__..sHwwyyGGIIOO%%rsno_proxyr,salways)httphttpssproxying through %s )configrenvironr4 startswithrr6r&r'extend configlistsplit configboolno_listr-r5r:r;urlreqrRr!r)r rproxyurlproxyrgproxiess rr!zproxyhandler.__init__vs99]G44 8H8L8L 9 9  % ##H-- 8191D1DY1O1O 8&047K))E: CYY}g>> !yy BB $\2G NNHHBMM-$G$GHHH    NN%-11+sCCII$OO   }}]I66 '! & 5zzH'(;;G HH(7+?e +M+MM    G$$T7333rctjtj|dd}|jD]u}||krdS|dr ||ddrdS|dr ||ddrdSvtj ||||S)N:rs*..r) r r/r gethostrergrbendswithrhrR proxy_open)r reqrjtype_hostes rrrzproxyhandler.proxy_opens !5c!:!:;;AA$GGJ  Aqyytt||E"" t}}QqrrU';'; tt||D!! dmmAabbE&:&: tt"--dCFFFrN)rMrNrOr!rrrPrrrRrRus8...` G G G G GrrRcfd}|S)Nct|tjr:|dt j|D]}||dS||dSNr)r+r2 httpsendfileseekr filechunkiter)r datachunkorgsends r _sendfilez _gen_sendfile.._sendfiles{ d-: ; ; IIaLLL+D11 % %e$$$$ % % GD$     rrP)rrs` r _gen_sendfilers$      rs httpshandlerc8eZdZeejjZdS)rN)rMrNrOrrHTTPConnectionsendrPrrrrs# =16 7 7DDDrrc|j}|r|dddvrd|z}d}ntj|}d}|s|tj|krt jt j|}|s |jdkrld |j |j pdg|_ |j |_ |j |jjdSd|_ d|_ dS) N)zhttp://zhttps:/zhttps://TFshttpsrms443) _tunnel_hostr getselector getfullurlrr6r r/schemejoinruport realhostportheaderscopyupdateparent addheaders)handlerhrs tunnel_host new_tunnelrDs r_generic_start_transactionrs"K rr?"8 8 8${2K ".s33  [L$;C$@$@@@ K)+66 7 7  X--!YY1A6'CDDAN ((**AI I  W^6 7 7 7 FANAIIIrr httpsconnectionc|jfdD}|j}|d|z|D]}|d|z|d||j|j \}}}|tj krn!ttfddJ|d kr)ttj j ddS|tjd ||fz) Nci|]V}|d)tj|tj|WS)zproxy-)rVrbr bytestr)rXxrs r z(_generic_proxytunnel..sa 7799   ) )X-gaj99rsCONNECT %s HTTP/1.0 s%s: %s s )methodTcZjSr)fpreadliner\)rAsrz&_generic_proxytunnel..s#&//++1133rrzTunnel connection failed: %d %s)rrritemsresponse_classsock_method _read_statushttplibCONTINUElistiterrrclosesocketrr\) r proxyheadersrheaderversionstatusreasonrrAs @@r_generic_proxytunnelrsrlGL $LII(<7888$$&&** -&())))IIg   di  = =C;"%"2"2"4"4 W% % %  T3333S 9 9:::;}} T#&/7 + +,,,,, l -0H H   rceZdZdZdZdS) httphandlerc8|t|Sr)do_openrr rss r http_openzhttphandler.http_open s||NC000rcft|||tj|||Sr)rr HTTPHandler_start_transactionr rrss rrzhttphandler._start_transactions/"4C000$77aEEErN)rMrNrOrrrPrrrr s7111FFFFFrrceZdZdZdS)logginghttpconnectioncHtjj|g|Ri|||_dSr)rrr!_create_connection)r createconnargskwargss rr!zlogginghttpconnection.__init__s4 )$@@@@@@@",rN)rMrNrOr!rPrrrrs#-----rrc0eZdZdZdfd ZdZdZxZS)logginghttphandlerz"HTTP handler that logs socket I/O.Nctt||||_||_||_dSNtimeout)superrr!_logfh_logname _observeropts)r logfhname observeroptsr __class__s rr!zlogginghttphandler.__init__sA  $''000AAA  )rc8||j|Sr)r_makeconnectionrs rrzlogginghttphandler.http_open&s||D0#666rc.fd}t|g|Ri|S)Ncltj|i|}tjj|jfijSr)rcreate_connectionr makeloggingsocketrrr)rrrr s rcreateconnectionz.createconnection*sH+T  $ -dD$ P P P P P P P$DM&DNNNrc\tj|j|jf|_|j}|j}|r+t ||ddd}tj |j|j |j |j ||_tj |jdS)Nrmrr)rserverhostname)rrrurrrrrsplitr wrapsocketrrrvalidatesocket)r rurs rconnectzhttpsconnection.connectIs0$)TY1GHHDI9D,L 7$T***#**433A6*  7# DI  "49 - - - - -r)NNN)rMrNrOr HTTPResponserr HTTPS_PORT default_portrsafesendrwrapgetresponser getresponser!rrPrrrr5sy"/) }Y/00/i/0FGG  ' ' ' ' . . . . .rc*eZdZddZdZdZddZdS) httpshandlerNctj||tj|||_t |j|jj|_dSr) rKeepAliveHandlerr!rhrrrhttppasswordmgrdbpwmgr)r rrs rr!zhttpshandler.__init__[sX  & / /g / F F F   ( ( . . .DG$TWdg.GHHDJJJrcft|||tj|||Sr)rrrrrs rrzhttpshandler._start_transactionas/ &tQ 4 4 4-@@q#NN Nrc6tj|}|j|\}}t j|j||}|r*|\}}||_|jd|znd|_| |j |S)Nr)) r rrrLr2r3rrCr5rr)r rsr6r&passwordrArBrCs r https_openzhttpshandler.https_openes)#..C!Z<DgDGKrr)rMrNrOr!rrrrPrrrrZsa I I I I  O O O ; ; ;      rrc eZdZdZdZdZdS)httpdigestauthhandlercHtjj|g|Ri|d|_dSr)rhrr! retried_reqr rrs rr!zhttpdigestauthhandler.__init__s4$-dDTDDDVDDDrcdSrrPr s rreset_retry_countz'httpdigestauthhandler.reset_retry_count  rcv||jur||_d|_tj|||||Sry)rretriedrhrhttp_error_auth_reqedr auth_headerrursrs rrz+httpdigestauthhandler.http_error_auth_reqedsE d& & &"D DL+AA +tS'   rN)rMrNrOr!rrrPrrrrsA           rrc2eZdZdZdZdZdZdZdZdS)httpbasicauthhandlercVd|_tjj|g|Ri|d|_dSr)rCrhr r!rrs rr!zhttpbasicauthhandler.__init__s; #,TCDCCCFCCCrcT|jr ||j|j|SrrCadd_unredirected_headerrr requests r http_requestz!httpbasicauthhandler.http_request- 9 I  + +D,h/55x7H7L7LMMC0@0E0E0K0K0M0M N NND~~d.55==tDI  ' '(8$ ? ? ?;##C(( (4rN) rMrNrOr!rrrrrrPrrr r sn                rr c eZdZdZdZdZdS) cookiehandlercd|_|dd}|sdStj|} tjt j|}|||_dS#tjj $rD}| td|tj |fzYd}~dSd}~wwxYw)Nsauths cookiefiles?(error loading cookie file %s: %s; continuing without cookies) ) cookiejarr`r expandpath cookielibMozillaCookieJarr fsdecodeload LoadErrorwarnrr forcebytestr)r r cookiefiler"rvs rr!zcookiehandler.__init__sYYw 66   F_Z00  77!*--I NN   &DNNN~'    GG"z6q99: ;          sA BC9CCcH|jr|j||Srr"add_cookie_headerrs rrzcookiehandler.http_request' > 6 N , ,W 5 5 5rcH|jr|j||Srr-rs rrzcookiehandler.https_requestr/rN)rMrNrOr!rrrPrrr r sA. rr sTctdd}g}|r)|t|||pi|nN|t |t r$|t ||ttj |s|\} } } }  | d\} }| | ks| r | | | |  d| | rdt| zpdfz|tt!f|fd t"D|t%t'j|}d|_d|_d|_|s3d t1jz}d t5j|fg|_nd t5j|fg|_|r|jd |S) a@ construct an opener suitable for urllib2 authinfo will be added to the password manager The opener can be configured to log socket events if the various ``logging*`` arguments are specified. ``loggingfh`` denotes a file object to log events to. ``loggingname`` denotes the name of the to print when logging. ``loggingopts`` is a dict of keyword arguments to pass to the constructed ``util.socketobserver`` instance. ``sendaccept`` allows controlling whether the ``Accept`` request header is sent. The header is sent by default. shttpstimeoutrNrrFrGrHc(g|]}|SrPrP)rXrpassmgrrs rrZzopener..1s#:::QQr7^^:::rs"mercurial/proto-1.0 (Mercurial %s)z User-agent)Acceptzapplication/mercurial-0.1) configwithfloatappendrr has_httpsrrRrrrLr#r5rIrcr r handlerfuncsr rh buildopener requestscountsentbytescountreceivedbytescountr rr sysstrr)rr@ useragent loggingfh loggingname loggingopts sendacceptrhandlersr$urisr&r' saveduser savedpassopeneragentr4s` @rrIrIs0mmE7J77GH ? ; (9r7         G444555  ? OOLW=== > > > OOL$$%%%"b233G$,!tT6&;;DGDD 9 9     dF ; ; ;  0V2s6{{ 2@jA B    OO g & &(=g(F(FG OO:::::\:::;;; OOM"%%&&&   *FFF !F" I5 F*HOE,B,BCD*HOI,F,FGH J  !HIII Mrctj|}|jr6|j|_|\}}nit jt j|}dtj t tj |z}d}t|||tj||S)Nsfile://)rD)rr6rrVr@r normpathabspathr r/rh pathname2urlr&rIrr1)rurl_r}rDrDr@paths rrrYs DAx8>>##hh}T\$//00H-    1$ 7 7 8 8    "h: 6 6 6 ; ;t  rcN|jGfdd|j}||_dS)zWrap a response object with common error handlers. This ensures that any I/O from any consumer raises the appropriate error and messaging. ceZdZdfd ZdS)!wrapresponse..readerproxyNc |S#tj$rq}|jr3t|j}|j|z}t d||fz}nt d}t j|t dd}~wtj$r8}t jt d|zt dd}~wwxYw)NsBHTTP request error (incomplete response; expected %d bytes got %d)s(HTTP request error (incomplete response)svthis may be an intermittent network failure; if the error persists, consider contacting the network or server operator)hintsHTTP request error (%s)) rIncompleteReadexpectedrIpartialrrPeerTransportError HTTPException)r sizervgottotalrJorigreads rreadz&wrapresponse..readerproxy.readrs x~~%)   :Iai..CJ,E5 %CC GHHC.6(   .011A56 s! CA,B  C3CCr)rMrNrOr_)r^sr readerproxyrSqs3        rr`N)r_r)respr`r^s @r wrapresponserbisP yH       dn   D!DNNNrr)r r)NNNr1NT)NT)-rri18nrrrrr2rr r r r utilsr rrstringiourlerrrhrrrRr safehasattrr9rrrrrrrrrrrr  basehandlerr r:rIrrbrPrrrjs                      , =       >?>?>?>?>?>?>?>?B;G;G;G;G;G6&;G;G;G|    D V_ 5 5 88888Y-888,& & & & RFFFFF)'FFF-----I4--- HHHHHHHH4 T#.#.#.#.#.)2#.#.#.J-----y163F---`     F8   *.....66...b"""""F&"""J ^^^^B     *!*!*!*!*!r