o ]LbR@s(ddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZm Z mZmZmZmZddlmZejZejZejZdd ZGd d d eZd d ZddZddZGddde jZ ddZ!Gdddej"Z#Gddde j$j%Z&ddZ'dej(fddZ)d ddZ*dS)!)absolute_importN)_)getattr)bundle2errorhttpconnectionpycompatstatichttprepourlutilwireprotov1peer)urlutilc Cszt|d}|t|dtd}g}d}tdt||D]}|d7}||t|t||||fq |S)acEncode a string value into multiple HTTP headers. ``value`` will be encoded into 1 or more HTTP headers with the names ``header-`` where ```` is an integer starting at 1. Each header name + value will be at most ``limit`` bytes long. Returns an iterable of 2-tuples consisting of header names and values as native strings. z-%s000s: rr)r strurllenxrangeappendstr)valueheaderlimitfmtvaluelenresultnir4/usr/lib/python3/dist-packages/mercurial/httppeer.pyencodevalueinheaders$s *rc@s8eZdZddZeddZd ddZejfdd Z dS) _multifilecGs6|D]}t|dstdt||q||_d|_dS)NlengthsO_multifile only supports file objects that have a length but this one does not:r)r safehasattr ValueErrortype _fileobjs_index)selffileobjsfrrr__init__Bs  z_multifile.__init__cCstdd|jDS)Ncss|]}|jVqdSN)length.0r)rrr Psz$_multifile.length..)sumr%r'rrrr,Nsz_multifile.lengthNcCs|dkrddd|jDSg}|rF|jt|jkrF||j|j|t|d}||kr8|jd7_||8}|rF|jt|jksd|S)Nrcss|]}|VqdSr+)readr-rrrr/Tsz"_multifile.read..r)joinr%r&rrr3)r'amtpartsgotrrrr3Rs  z_multifile.readcCsB|tjkr td|dkrtd|jD]}|dqd|_dS)NsP_multifile does not support anything other than os.SEEK_SET for whence on seek()rsQ_multifile only supports seeking to start, but that could be fixed if you need it)osSEEK_SETNotImplementedErrorr%seekr&)r'offsetwhencer)rrrr<^s    z_multifile.seekr+) __name__ __module__ __qualname__r*propertyr,r3r9r:r<rrrrr As    r cCs|dkrd|d<|dd}|di}|d|d|fg} d} |duo)d |v} | rc|rctt|} |s<| }n t|trMt |} t || _ | }t | }t | |_ t ||}t | |d <n=|r|d kskJ|d }|r{t |d dd} | dkrtt|}t|d| D]\}}|||<qn| t|7} dt| }d||f}d}t|dr|j }n|durt |}|durd|vrd|d<t}t}|dur|d}|r|dt|d }|dd|vr|dd|vr|drddtjtjD}|dd ||r4tdt|d| p&d }|D] \}}|||<q*g}|D]}|d!rG||q8|rUd"t||d#<|t|||}|durr|d$||d%d&||||fS)'aWMake an HTTP request to run a command for a version 1 client. ``caps`` is a set of known server capabilities. The value may be None if capabilities are not yet known. ``capablefn`` is a function to evaluate a capability. ``cmd``, ``args``, and ``data`` define the command, its arguments, and raw data to pass to it. spushkeyr2sdataNsheadersssending %s command scmdr httppostargsz X-HgArgs-Post capabilitiess httpheader,rsX-HgArgs?%ss%s%sr! Content-Typeapplication/mercurial-0.1s httpmediatypes0.1s partial-pulls0.2txs0.2s compressioncSsg|]}|jqSr)wireprotosupportname)r.errr sz(makev1commandrequest..scomp=%s s X-HgProtozx-hg,Varyssending %d bytes zContent-Lengthz%d)popdebugurlreq urlencodesorteditems isinstancebytesioBytesIOrr,r intsplitrr r"setadd compenginessupportedwireengines CLIENTROLEr5lower startswithrr radd_unredirected_header)uirequestbuildercaps capablefn repobaseurlcmdargsdataheadersq headersize postargsokstrargsrargsio httpheader encoded_argsrrqscusize protoparams mediatypesmtcomps protoheaders varyheadersreqrrrmakev1commandrequestns                       r~cCs tjr|jS|s dS|S)z3Get request data, if any. If no data, returns None.N)r ispy3rkhas_dataget_data)r}rrr_reqdatas rc Cs&|j}|jr|ddrd}||dt|t|fd}t|D]*\}}t|}t|}| drJ|durCd}|t |7}q*||d||fq*|dura||d |t |}|durt |d d} | durwt |} ||d | t } d} zcz||} Wn;tjy} z | jd krttd d} ~ wtjy} z|dt||td| d} ~ wwW|jr|ddr| r| jnd} ||dt | | fn#|jr |ddr | r| jnd} ||dt | | fwwwt| | S)zDSend a prepared HTTP request. Returns the response object. sdevelsdebug.peer-requestsdevel-peer-request: %s s%s %sNsX-hgarg-rs %s %ss+ %d bytes of commands arguments in headersr,s %d bytes of dataisauthorization failedshttp error requesting %s r4s finished in %.4f seconds (%d))rQ debugflag configboolr bytesurl get_method get_full_urlrT header_itemsrbrrrr timeropenurlerr httperrorcoderAbortrhttplib HTTPExceptionr hidepassword tracebackIOErrorurlmod wrapresponse)rdopenerr}dbgline hgargssizerrrkr,startresinstrrrr sendrequests           rcseZdZfddZZS)RedirectedRepoErrorcstt||||_dSr+)superrr*respurl)r'msgr __class__rrr*<s zRedirectedRepoError.__init__)r?r@rAr* __classcell__rrrrr;src Csd}t|}||r|dt| }d}nd}|d|dkr4d}|js4|td|z t| dd} Wnt yRt|j dd} Ynwt |} | drdt|| ds|d t |td | | pzd |d f} |r|rt| |t| z| d dd} tdd| dD} Wntyttd| | fw| dkr|rtjd|}n-| dkrtdt|dd}t||}tj|}||}n ttd| | f|| |fS)NFT/sreal URL is %s z content-typesapplication/hg-errorapplication/mercurial-srequested URL: '%s' sI'%s' does not appear to be an hg repository: ---%%<--- (%s) %s ---%%<--- sno content-typerM-rcSsg|]}t|qSr)rZ)r.rrrrrKlsz*parsev1commandresponse...s+'%s' sent a broken Content-Type header (%s))rrszlib)rBrs'%s' uses newer protocol %s) r rgeturlendswithrrstripquietwarnr getheaderAttributeErrorrlgetrrrbrOutOfBandErrorr3rQr RepoErrorr[tupler#r r^decompressorreaderstructunpack readexactly forwiretype)rdbaseurlrequrlrtresp compressible redirectedr qsdroppedprotosafeurlrsubtype version_infoelenenameenginerrrparsev1commandresponseAsb            rc@s~eZdZddZddZddZddZd d Zd d Zd dZ ddZ dddZ ddZ ddZ ddZddZddZdS) httppeercCs:||_||_||_||_|duod|v|_||_||_dS)NrC)rd_path_url_capslimitedarguments _urlopener_requestbuilder)r'rdpathr rrerfrrrr*s zhttppeer.__init__cCs,|jjD]}|t|dddqdS)N close_allcSdSr+rrrrrsz"httppeer.__del__..)rhandlerscloser)r'hrrr__del__s zhttppeer.__del__cC|jSr+)rr1rrrr z httppeer.urlcCrr+rr1rrrlocalzhttppeer.localcCs|Sr+rr1rrrpeerrz httppeer.peercCsdS)NTrr1rrrcanpushrzhttppeer.canpushcCsTz|jj|jj|jj}}}Wn tyYdSw|jtd|||fdS)NsE(sent %d HTTP requests and %d bytes; received %d bytes in responses) )r requestscountsentbytescountreceivedbytescountrrdnoter)r'reqssentrecvrrrrs zhttppeer.closecCrr+)rr1rrr capabilitiesrzhttppeer.capabilitiesFc Ks`t|}t|j|j|j|j|j||\}}}t|j|j |}t |j|j||||\|_}}|Sr+) r byteskwargsr~rdrrcapablerrrr) r'ri _compressiblerjr}rurtrctrrr _callstreams    zhttppeer._callstreamcKs0|j|fi|}z |W|S|wr+)rr3r)r'rirjfprrr_callszhttppeer._callc KsR|d}z|d}Wn tydg}Ynw|D] }|tjvr&|}nqt|j|d|}t|j|d}ddi} zbz-|j |f|| d|} | dd } t | d kr^t t d | | WW|t|Stjystj y} z| jd tjtjfvrt t d | jd t | jd d} ~ ww|t|w)NsunbundlerEr2rbrFrGrkrl rrsunexpected response:rspush failed: %s)rr[rr bundletypes writebundlerdr httpsendfilerrr ResponseErrorrrr9unlinkrrsocketrjerrno ECONNRESETEPIPEr) r'ricgrjtypesxr$tempnamerrlrvalserrrrr _callpushs@        zhttppeer._callpushc Ksd}zstjddd\}}t|d}|d}|r&|||d}|sWdn1s0wYt|j|d#}ddi} |j |f|| d |WdW|dur_t |SS1scwYW|durtt |dSdS|durt |ww) Ns hg-bundle-s.hg)prefixsuffixwbirrFrGr) r mkstempr9fdopenr3writerrrdrr) r'rirrjfilenamefdfhdfp_rlrrr_calltwowaystreams0     zhttppeer._calltwowaystreamcKs|j|fddi|S)NrT)r)r'rirjrrr_callcompressableszhttppeer._callcompressablecCs|r+r)r' exceptionrrr_abortrzhttppeer._abortN)F)r?r@rAr*rr rrrrrrrrr rrrrrrrs  ( rc@seZdZdZdddZdS)queuedcommandfuturez@Wraps result() on command futures to trigger submission on call.NcCs,|r tjj||S|j||Sr+)doner futuresFuturer _peerexecutor sendcommands)r'timeoutrrrr s  zqueuedcommandfuture.resultr+)r?r@rA__doc__rrrrrrsrc Cs d}dd}i}t|||||d|\}}} t|||} zt|||| | dd\} } } Wn3ty]} z't||||| jd|\}}} t|||} t|||| | dd\} } } WYd} ~ nd} ~ wwz | }W| n| w| dszt d| dt | i}| |fS) NcSs td)Nsshould not be called)rProgrammingError)rrrrr0s z!performhandshake..capablerDF)rrsunexpected content-type: %sv1capabilities) r~rrrrr3rrbrrr\r[)rdr rrerfrrjr}rrtrrrrJrawdatainforrrperformhandshake+s8      rc Cst|}|js |jrttd|jp|j|\}}|d||p,t ||}t ||||\}}t ||||||dS)a-Construct an appropriate HTTP peer instance. ``opener`` is an ``url.opener`` that should be used to establish connections, perform HTTP requests. ``requestbuilder`` is the type used for constructing HTTP requests. It exists as an argument so extensions can override the default. sunsupported URL component: "%s"s using %s r) rr queryfragmentrrrauthinforQrrrr) rdrrreur r rrrrrmakepeer`s  r"c Cs|r ttdz|drtjsttdt||}|WStjyQ}z$zt |d||}| td|WWYd}~StjyL|wd}~ww)Ns!cannot create new http repositoryshttps:s1Python support for SSL and HTTPS is not installedsstatic-s(falling back to static-http) ) rrrrbr has_httpsr"rr instancer)rdrcreateintents createoptsr httpexceptionrrrrr$|s& r$)NN)+ __future__rrrXr9rri18nrr rrrrrr r rr r utilsrrrrRrobjectr r~rrrrrwirepeerrrrrrrequestr"r$rrrrs4   ( -| HG5