
    	^cQ                     x   d dl Z d dlZd dlZd dlZd dlZd dlmZ ddlmZ ddl	m
Z
 ddlmZmZmZm	Z	mZmZmZmZ ddlmZ ej        Zej        Zej        Zd Z G d	 d
          Zd Zd Z G d dej                  Zd Z G d dej                   Z! G d dej"                  Z#d Z$dej%        fdZ&ddZ'dS )    N)futures   )_)getattr)bundle2errorhttpconnectionpycompatstatichttprepourlutilwireprotov1peer)urlutilc           
      Z   t          j        |          dz   }|t          |dz            z
  t          d          z
  }g }d}t          dt          |           |          D ]K}|dz  }|                    |t          |          z  t          j        | |||z                      f           L|S )ac  Encode a string value into multiple HTTP headers.

    ``value`` will be encoded into 1 or more HTTP headers with the names
    ``header-<N>`` where ``<N>`` 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-%s000s   : 
r   r   )r
   strurllenrangeappendstr)valueheaderlimitfmtvaluelenresultnis           4/usr/lib/python3/dist-packages/mercurial/httppeer.pyencodevalueinheadersr    $   s     /&
!
!F
*C s3;'''#i..8HF	A1c%jj(++ P P	QsSVV|X_U1q8|;K5L%M%MNOOOOM    c                   F    e Zd Zd Zed             ZddZej        fdZ	dS )
_multifilec                     |D ]5}t          j        |d          st          dt          |          |          6|| _        d| _        d S )N   lengthsO   _multifile only supports file objects that have a length but this one does not:r   )r   safehasattr
ValueErrortype	_fileobjs_index)selffileobjsfs      r   __init__z_multifile.__init__B   sb     	 	A#Ay11  <GG	   "r!   c                 >    t          d | j        D                       S )Nc              3   $   K   | ]}|j         V  d S N)length.0r-   s     r   	<genexpr>z$_multifile.length.<locals>.<genexpr>P   s$      4418444444r!   )sumr)   r+   s    r   r2   z_multifile.lengthN   s!    44T^444444r!   Nc                    |dk    r$d                     d | j        D                       S g }|r| j        t          | j                  k     r|                    | j        | j                                     |                     t          |d                   }||k     r| xj        dz  c_        ||z  }|r| j        t          | j                  k     d                     |          S )Nr   r!   c              3   >   K   | ]}|                                 V  d S r1   )readr3   s     r   r5   z"_multifile.read.<locals>.<genexpr>T   s*      ==AFFHH======r!   r   )joinr)   r*   r   r   r:   )r+   amtpartsgots       r   r:   z_multifile.readR   s    !8888==dn====== 	dkC$7$777LL499#>>???eBi..CSyyq 3JC  	dkC$7$777 xxr!   c                     |t           j        k    rt          d          |dk    rt          d          | j        D ]}|                    d           d| _        d S )NsP   _multifile does not support anything other than os.SEEK_SET for whence on seek()r   sQ   _multifile only supports seeking to start, but that could be fixed if you need it)osSEEK_SETNotImplementedErrorr)   seekr*   )r+   offsetwhencer-   s       r   rD   z_multifile.seek^   sw    R[  %:   Q;;%1    	 	AFF1IIIIr!   r1   )
__name__
__module____qualname__r.   propertyr2   r:   rA   rB   rD    r!   r   r#   r#   A   sm        
 
 
 5 5 X5
 
 
 
 #%+      r!   r#   c                    |dk    rd|d<   |                     dd          }|                     di           }|                     d|z             d|fg}	d}
|duod	|v }|r|rt                              t	          |                                                    }|s|}nwt          |t                    r*t          j	        |          }t          |          |_        |}t          j	        |          }t          |          |_        t          ||          }t          |          |d
<   n|r|dk    sJ  |d          }|r)t          |                    dd          d                   }
|
dk    rVt                              t	          |                                                    }t          |d|
          D ]
\  }}|||<   n$|	t	          |                                          z  }	dt                              |	          z  }d||fz  }d}t!          j        |d          r|j        }n|t          |          }|	d|vrd|d<   t%                      }t%                      }|Y |d          }|r7|                    d           t%          |                    d                    }|                    d           d|v r|                    d           d|v ri |d          r^d t           j                            t           j                  D             }|                    dd                    |          z             |r@t          d                    t	          |                    d|
pd          }|D ]
\  }}|||<   g }|D ]>}|                                                    d           r|                    |           ?|r%d!                    t	          |                    |d"<    |t7          j        |          ||          }|1|                     d#|z             |                    d$d%|z             |||fS )&aW  Make 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.
    s   pushkeyr!   s   dataNs   headerss   sending %s command
s   cmdr      httppostargszX-HgArgs-Post   capabilitiess
   httpheader   ,r   s   X-HgArgs   ?%ss   %s%sr%   Content-Typeapplication/mercurial-0.1s   httpmediatypes   0.1s   partial-pulls   0.2txs   0.2s   compressionc                 @    g | ]}|                                 j        S rK   )wireprotosupportname)r4   es     r   
<listcomp>z(makev1commandrequest.<locals>.<listcomp>   s7     
 
 
   %
 
 
r!   s   comp=%s    s	   X-HgProto   zx-hg,Varys   sending %d bytes
zContent-Lengthz%d)popdebugurlreq	urlencodesorteditems
isinstancebytesioBytesIOr   r2   r#   intsplitr    r   r&   setaddcompenginessupportedwireengines
CLIENTROLEr<   lower
startswithr   r
   r   add_unredirected_header)uirequestbuildercaps	capablefnrepobaseurlcmdargsdataheadersq
headersize
postargsokstrargsr   argsio
httpheaderencoded_argsr   r   qscusizeprotoparams
mediatypesmtcompsprotoheadersvaryheadersreqs                                r   makev1commandrequestr   n   s    jW88GT""Dhhz2&&GHH$s*+++
#AJ T!=o&=J   &d  &""6$**,,#7#788 		,DD$&& Jt$$t99Z((FLLFMfd++D#&w<<  	 & o%%%%Y}--
 	;Z--dA66q9::J >>!++F4::<<,@,@AAL!5j*" " ( ( #(( 

%%%A	&""1%%	%B	K$	$BDi(( {		4yyN'99"= %%KJY'(( 	-OOF###RXXd^^,,J(((::))N";";
 
%::4?KK
 
 
 	
TYYu%5%55666 $+IIf[))**L*:L
 
 * 	$ 	$MFE#GFOOK ' '<<>>$$V,, 	'v&&& 8((6+#6#677
.,,dG
<
<C
&-...##$4dTkBBBB;r!   c                    | j         }| j        rf|                     dd          rOd} ||dz  t          j        |                                          t          j        |                                          fz             d}t          |                                          D ]l\  }}t          j        |          }t          j        |          }|	                    d          r|d}|t          |          z  }Y ||dz  ||fz             m| ||d	z  |z             |j        }|3t          |d
d          }	|	t          |          }	 ||dz  |	z             t          j                    }
d}	 |                    |          }n# t           j        $ r2}|j        dk    r!t'          j        t+          d                     d}~wt,          j        $ re}|                      dt1          j        |                                          z             |                                  t7          d|          d}~ww xY w	 | j        rH|                     dd          r2|r|j        nd} ||dz  t          j                    |
z
  |fz             nV# | j        rI|                     dd          r4|r|j        nd} ||dz  t          j                    |
z
  |fz             w w w xY wt9          j        |           |S )zDSend a prepared HTTP request.

    Returns the response object.
    s   devels   debug.peer-requests   devel-peer-request: %s
s   %s %sNs   X-hgarg-r   s     %s %ss+     %d bytes of commands arguments in headersr2   s     %d bytes of datai  s   authorization faileds   http error requesting %s
r;   s     finished in %.4f seconds (%d))r\   	debugflag
configboolr
   bytesurl
get_methodget_full_urlr_   header_itemsrm   r   rv   r   r   timeropenurlerr	httperrorcoder   Abortr   httplibHTTPExceptionr   hidepassword	tracebackIOErrorurlmodwrapresponse)ro   openerr   dbgline
hgargssizer   r   rv   r2   startresinstr   s                 r   sendrequestr      s   
 (C	| #h0EFF #* !#.."2"233!#"2"2"4"455	
 	
 	
 
#C$4$4$6$677 	9 	9MFE&v..F%e,,E  -- 9%!"Jc%jj(

D:%78888!C@A  
 xT8T22F~TC,,v5666

Ckk#   9+a 788999  " " "
)"3#3#3#5#5667	
 	
 	
 	dD!!!" 	 < 	BMM(4IJJ 	"*388DC45:<<%'./   < 	BMM(4IJJ 	"*388DC45:<<%'./   	 	 Js8   9F J I-GIA H==IJ AK)c                        e Zd Z fdZ xZS )RedirectedRepoErrorc                 f    t          t          |                               |           || _        d S r1   )superr   r.   respurl)r+   msgr   	__class__s      r   r.   zRedirectedRepoError.__init__3  s-    !4((11#666r!   )rG   rH   rI   r.   __classcell__)r   s   @r   r   r   2  s8                r!   r   c                    d}t          j        |                                          }|                    |          r|d t	          |                    }d}nd}|                    d          |                    d          k    r.d}| j        s%|                     t          d          |z             	 t          j        |	                    dd                    }	n=# t          $ r0 t          j        |j                            dd                    }	Y nw xY wt          j        |          }
|	                    d          r&t!          j        |                                          |	                    d          s||                     d	t          j        |          z             t          d
          |
|	pd|                    d          fz  }|r|rt)          ||          t!          j        |          	 |	                    dd          d         }t/          d |                    d          D                       }n4# t0          $ r' t!          j        t          d          |
|	fz            w xY w|dk    r(|r%t2          j        d                             |          }n|dk    rxt9          j        dt3          j        |d                    d         }t3          j        ||          }t2          j                            |          }|                    |          }n&t!          j        t          d          |
|fz            ||	|fS )NFT   /s   real URL is %s
zcontent-type s   application/hg-error   application/mercurial-s   requested URL: '%s'
sI   '%s' does not appear to be an hg repository:
---%%<--- (%s)
%s
---%%<---
s   no content-typerX      -r   c                 ,    g | ]}t          |          S rK   )re   )r4   r   s     r   rV   z*parsev1commandresponse.<locals>.<listcomp>c  s    BBBc!ffBBBr!      .s+   '%s' sent a broken Content-Type header (%s))r   r   s   zlib)r         Br   s   '%s' uses newer protocol %s) r
   r   geturlendswithr   rstripquietwarnr   	getheaderAttributeErrorrw   getr   r   rm   r   OutOfBandErrorr:   r\   r   	RepoErrorrf   tupler'   r   ri   decompressorreaderstructunpackreadexactlyforwiretype)ro   baseurlrequrlr   respcompressible
redirectedr   	qsdroppedprotosafeurlr   subtypeversion_infoelenenameengines                    r   parsev1commandresponser   8  s]   J..G *SWWH*%			~~dw~~d3333
x 	6GGA)**W4555H!$.."D"DEE H H H!$,"2"2>2"F"FGGH "7++G/00 0"499;;/// 566 '
)G,@,H,HHIII/
 
 e11499T??CD  	') 	'%c7333/#&&&
++dA&&q)BBgmmD.A.ABBBCC 
 
 
o<==%@PP
 
 	

 v 	F#G,??EED			 }T4#3D!#<#<==a@ t,,!--e44((..o,--'0BB
 
 	
 E4s   6(C 7DD=AI 1I7c                   d    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
dd
Zd Zd Zd Zd Zd ZdS )httppeerc                 t    || _         || _        || _        || _        |d uod|v| _        || _        || _        d S )NrM   )ro   _path_url_capslimitedarguments
_urlopener_requestbuilder)r+   ro   pathr   r   rp   rq   s          r   r.   zhttppeer.__init__  sJ    
	
 $D 0 P_D5P -r!   c                     | j         j        D ]0}|                                  t          |dd                        1d S )N	close_allc                      d S r1   rK   rK   r!   r   <lambda>z"httppeer.__del__.<locals>.<lambda>  s    D r!   )r   handlerscloser   )r+   hs     r   __del__zhttppeer.__del__  sL    ) 	4 	4AGGIII1GA{LL113333	4 	4r!   c                     | j         S r1   )r   r7   s    r   r   zhttppeer.url  
    zr!   c                     d S r1   rK   r7   s    r   localzhttppeer.local      tr!   c                     | S r1   rK   r7   s    r   peerzhttppeer.peer  s    r!   c                     dS )NTrK   r7   s    r   canpushzhttppeer.canpush  r   r!   c                     	 | j         j        | j         j        | j         j        }}}n# t          $ r Y d S w xY w| j                            t          d          |||fz             d S )NsE   (sent %d HTTP requests and %d bytes; received %d bytes in responses)
)r   requestscountsentbytescountreceivedbytescountr   ro   noter   )r+   reqssentrecvs       r   r   zhttppeer.close  s    	-.2 $DD
  	 	 	FF	5  T4 	!	
 	
 	
 	
 	
s   $' 
55c                     | j         S r1   )r   r7   s    r   capabilitieszhttppeer.capabilities  r   r!   Fc           	         t          j        |          }t          | j        | j        | j        | j        | j        ||          \  }}}t          | j        | j	        |          }t          | j        | j        ||||          \  | _        }}|S r1   )r
   byteskwargsr   ro   r   r   capabler   r   r   r   )	r+   rt   _compressibleru   r   r   r   r   cts	            r   _callstreamzhttppeer._callstream  s    #D))*G JLI
 
R 47DOS994GTYBm
 
	2t r!   c                      | j         |fi |}	 |                                |                                 S # |                                 w xY wr1   )r   r:   r   )r+   rt   ru   fps       r   _callzhttppeer._call  sO    Tc**T**	7799 HHJJJJBHHJJJJs	   8 Ac                    |                      d          }	 |                    d          }n# t          $ r dg}Y nw xY w|D ]}|t          j        v r|} nt          j        | j        |d |          }t          j        | j        |d          }ddi}		  | j	        |f||	d|}
|
                    dd	          }t          |          d
k     r"t          j        t          d          |
          ||                                 t          j        |           S # t"          j        $ r  t&          j        $ rx}|j        d         t*          j        t*          j        fv r/t          j        t          d          |j        d	         z            t          j        |j        d	                   d }~ww xY w# |                                 t          j        |           w xY w)Ns   unbundlerO   r!      rbrP   rQ   rv   rw      
r   r   s   unexpected response:r   s   push failed: %s)r   rf   r   r   bundletypeswritebundlero   r	   httpsendfiler  r   r   ResponseErrorr   r   rA   unlinkr   r   socketru   errno
ECONNRESETEPIPEr   )r+   rt   cgru   typesxr(   tempnamer  rw   rvalserrs                r   	_callpushzhttppeer._callpush  s    [))	KK%%EE 	 	 	 EEEE		
  	 	AG''' ( &twD$??((EBB!#>?	 
3ARAADAAA775!$$D4yy1}})!,C*D*DaHHH HHJJJIh  	 	 	 | 	+ 	+ 	+x{u/===k!$6"7"7#(1+"EFFF+chqk***	+
 HHJJJIhs2   - ==AD F/7A3F**F//F2 2*Gc                 F   d }	 t          j        dd          \  }}t          j        |d          5 }|                    d          }|r,|                    |           |                    d          }|,d d d            n# 1 swxY w Y   t          j        | j        |d          5 }ddi}	 | j	        |f||	d	|cd d d            |t          j
        |           S S # 1 swxY w Y   	 |t          j
        |           d S d S # |t          j
        |           w w xY w)
Ns
   hg-bundle-s   .hg)prefixsuffixwbi   r  rP   rQ   r  )r
   mkstemprA   fdopenr:   writer	   r	  ro   r   r  )
r+   rt   r  ru   filenamefdfhdfp_rw   s
             r   _calltwowaystreamzhttppeer._calltwowaystream  s   	$#+=PPPLB2t$$ &GGDMM &HHQKKKA  && & & & & & & & & & & & & & &  ,TWhFF P#)+FG't'O#wOO$OOP P P P P P P #	(#### $	P P P P P P P P P #	(##### $#x#	(#### $sS   .D AB6D BD 	B
D (C!=D !C%%D (C%)D D c                 "     | j         |fddi|S )Nr   T)r   )r+   rt   ru   s      r   _callcompressablezhttppeer._callcompressable  s"    t@@4@4@@@r!   c                     |r1   rK   )r+   	exceptions     r   _abortzhttppeer._abort  s    r!   N)F)rG   rH   rI   r.   r   r   r   r   r   r   r   r   r  r  r$  r&  r)  rK   r!   r   r   r     s        . . .4 4 4        
 
 
*  
   *  &  &  & P$ $ $$A A A    r!   r   c                       e Zd ZdZddZdS )queuedcommandfuturez@Wraps result() on command futures to trigger submission on call.Nc                     |                                  r t          j                            | |          S | j                                         |                     |          S r1   )doner   Futurer   _peerexecutorsendcommands)r+   timeouts     r   r   zqueuedcommandfuture.result  sS    99;; 	8>((w777''))) {{7###r!   r1   )rG   rH   rI   __doc__r   rK   r!   r   r+  r+    s.        JJ$ $ $ $ $ $r!   r+  c           
         d }d }i }t          | ||||d|          \  }}}	t          | ||          }
	 t          | |||	|
d          \  }}}
n_# t          $ rR}t          | ||||j        d|          \  }}}	t          | ||          }
t          | |||	|
d          \  }}}
Y d }~nd }~ww xY w	 |
                                }|
                                 n# |
                                 w xY w|                    d          st          j	        d|z            dt          |                                          i}||fS )Nc                 *    t          j        d          )Ns   should not be called)r   ProgrammingError)r  s    r   r   z!performhandshake.<locals>.capable'  s    $%<===r!   rN   F)r   r   s   unexpected content-type: %s   v1capabilities)r   r   r   r   r   r:   r   rm   r   r5  rg   rf   )ro   r   r   rp   rq   r   ru   r   r   r   r   r   r   rU   rawdatainfos                   r   performhandshaker9  "  s    D> > > D*
ND'3 OC r63''D
2VRE
 
 
TT  
 
 
.gqy/4
 
VR 2vs++2VRE
 
 
TTTTTT
))++



==233 J$%Cb%HIIIs7==??334DD=s$   A 
B)AB$$B)-C C,c           	         t          j        |          }|j        s|j        r0t	          j        t          d          |j        p|j        z            |                                \  }}|                     d|z             |pt          j
        | |          }t          | |||          \  }}t          | |||||d                   S )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.
    s   unsupported URL component: "%s"s	   using %s
r6  )r   r   queryfragmentr   r   r   authinfor\   r   r   r9  r   )	ro   r   r   rp   ur   r=  r   r8  s	            r   makepeerr?  W  s     	DAw 
!* 
k011QW5J
K
 
 	

 JJLLMCHH]S !!!2v}R22F$RfnEEMGT
D'6>48I3J  r!   c                    |r!t          j        t          d                    	 |                    d          r-t          j        s!t          j        t          d                    t          | |          }|S # t           j        $ r]}	 t          j	        | d|z   |          }| 
                    t          d                     |cY d }~S # t           j        $ r |w xY wd }~ww xY w)Ns!   cannot create new http repositorys   https:s1   Python support for SSL and HTTPS is not installeds   static-s   (falling back to static-http)
)r   r   r   rm   r   	has_httpsr?  r   r   instancer   )ro   r   createintents
createoptsr   httpexceptionr  s           r   rB  rB  s  s	    Ck!@AABBB ??9%% 	f.> 	+FGG   D!!?      	 'J,=vFFAGGA899:::HHHHHH 	  	  	 	  s*   AA9 9C%	<CC%CC  C%)NN)(r  rc   rA   r  r   
concurrentr   i18nr   r
   r   r   r   r   r	   r   r   r   r   r   utilsr   r   r   r]   r    r#   r   r   r   r   r   wirepeerr   r.  r+  r9  requestr?  rB  rK   r!   r   <module>rL     sA    				 				                    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	      
,		  :* * * * * * * *Zy y yxE E EP    %/   D  D  D NR R R R R' R R Rj$ $ $ $ $'. $ $ $2 2 2j #6>    8           r!   