
bQc           @   s  d  d l  Z  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 Z d  d l	 Z	 d  d l
 Z
 d  d l Z d e j f d     YZ d e j f d     YZ d   Z e	 j e d  Z e ry e j Z Wqe k
 re   Z e d d	  Z qXn  d
 e j f d     YZ d   Z d   Z d e j f d     YZ e rd e j f d     YZ  d e j! e j" f d     YZ# n  d e j$ f d     YZ% d e j& f d     YZ' g  Z( d d  Z) d d  Z* d S(   iN(   t   _t   passwordmgrc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   t  j j |   | |  _ d  S(   N(   t   urllib2t   HTTPPasswordMgrWithDefaultRealmt   __init__t   ui(   t   selfR   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR      s    c   	      C   s  t  j j |  | |  } | \ } } | rJ | rJ |  j | |  | | f S| sX | r t j |  j | |  } | r | \ } } | j d  | j d  } } |  j j d |  q n  | s | r||  j j	   s t
 j t d    n  |  j j t d   |  j j t d  |  | rC|  j j t d  |  n |  j j t d  d	 d  } | s||  j j   } q|n  |  j | | | |  |  j | |  | | f S(
   Nt   usernamet   passwords#   using auth.%s.* for authentication
s   http authorization requireds   http authorization required
s
   realm: %s
s	   user: %s
s   user:t   default(   R   R   t   find_user_passwordt   _writedebugt   httpconnectionmodt   readauthforuriR   t   gett   debugt   interactivet   utilt   AbortR    t   writet   promptt   Nonet   getpasst   add_password(	   R   t   realmt   authurit   authinfot   usert   passwdt   rest   groupt   auth(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR
      s2    	
c         C   s@   t  d  } |  j j | | | r1 d t |  p4 d f  d  S(   Ns    http auth: user %s, password %s
t   *s   not set(   R    R   R   t   len(   R   R   R   t   msg(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   4   s    c         C   s   t  j j |  d  |  S(   N(   R   R   R
   R   (   R   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt   find_stored_password8   s    	(   t   __name__t
   __module__R   R
   R   R#   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR      s   		 	t   proxyhandlerc           B   s   e  Z d    Z d   Z RS(   c         C   s  | j  d d  p t j d  } | r| j d  pB | j d  sV d | d } n  t j |  } | j s | j  d d  | _ | j  d d  | _ n  d	 d
 g } | j g  | j	 d d  D] } | j
   ^ q  | j g  t j d d  j d  D]$ } | j   r | j   j
   ^ q  | j d d  rDg  |  _ n	 | |  _ t |  } i | d 6| d 6} | j d | j | j f  n i  } | j  d d  rxN d d d g D]: } y  | t j k rt j | =n  Wqt k
 rqXqWn  t j j |  |  | |  _ d  S(   Nt
   http_proxyt   hosts   http:s   https:s   http://t   /R   R   t	   localhosts	   127.0.0.1t   not   no_proxyt    t   ,t   alwayst   httpt   httpss   proxying through http://%s:%s
t
   HTTP_PROXY(   t   configt   ost   getenvt
   startswithR   t   urlR   R   t   extendt
   configlistt   lowert   splitt   stript
   configboolt   no_listt   strR   R(   t   portt   environt   OSErrorR   t   ProxyHandlerR   R   (   R   R   t   proxyurlt   proxyR>   t   pt   proxiest   env(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   =   s@    !		)	%		c            ss   | j    j d  d } | |  j k r, d  S| j   d   f   f d     Y} | | _ t j j |  | | |  S(   Nt   :i    t   _requestc              s   e  Z   f d    Z RS(   c            s4   | j    d k r! | j   } n    j |  | |  S(   Ns   proxy-authorization(   R:   R<   t
   add_header(   R   t   keyt   val(   t	   baseclass(    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRK   v   s    (   R$   R%   RK   (    (   RN   (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRJ   u   s   (   t   get_hostR;   R>   R   t	   __class__R   RC   t
   proxy_open(   R   t   reqRE   t   type_R(   RJ   (    (   RN   s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRQ   m   s    		(   R$   R%   R   RQ   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR&   <   s   	0c            s     f d   } | S(   Nc            sZ   t  | t j  rI | j d  x4 t j |  D] }   |  |  q/ Wn   |  |  d  S(   Ni    (   t
   isinstanceR   t   httpsendfilet   seekR   t   filechunkiter(   R   t   datat   chunk(   t   orgsend(    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt	   _sendfile   s
    (    (   RZ   R[   (    (   RZ   s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt   _gen_sendfile~   s    	t   HTTPSHandlerc         C   s   d } |  \ } } x t  j | | d t  j  D] } | \ } } }	 }
 } d  } y\ t  j  | | |	  } | t k	 r | j |  n  | r | j |  n  | j |  | SWq. t  j k
 r } | d  k	 r | j	   q q. Xq. Wt  j |   d  S(   Ns!   getaddrinfo returns an empty listi    (
   t   sockett   getaddrinfot   SOCK_STREAMR   t   _GLOBAL_DEFAULT_TIMEOUTt
   settimeoutt   bindt   connectt   errort   close(   t   addresst   timeoutt   source_addressR"   R(   R@   R   t   aft   socktypet   protot	   canonnamet   sat   sock(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt   _create_connection   s"    "t   httpconnectionc           B   s,   e  Z e e j j  Z d    Z d   Z RS(   c         C   s   t  rs |  j rs t j t j t j  |  _ |  j j |  j |  j f  t	 |   r t
 j |  j d  d   |  _ q n t j j |   d  S(   N(   t	   has_httpst   realhostportR^   t   AF_INETR`   Ro   Rd   R(   R@   t   _generic_proxytunnelt   sslutilt   ssl_wrap_socketR   t	   keepalivet   HTTPConnection(   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRd      s    !c         C   sK   t  |  d d   } | r; | j r. |  j   n  d  |  _ | St j j |   S(   Nt   proxyres(   t   getattrR   t
   will_closeRf   Rz   Rx   Ry   t   getresponse(   R   Rz   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR}      s    		(   R$   R%   R\   Rx   Ry   t   sendRd   R}   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRq      s   	
c         C   s   t  | d d   } | r> | d  d	 k r5 d | } n  t } n | j   } t } | sh | | j   k r t j |  } | s | j d k r d j	 | j
 | j p d g  | _ | j j   | _ | j j |  j j  d  Sn  d  | _ d  | _ d  S(
   Nt   _tunnel_hosti   s   http://s   https:/s   https://R1   RI   t   443(   s   http://s   https:/(   R{   R   t   Truet   get_selectort   Falset   get_full_urlR   R7   t   schemet   joinR(   R@   Rs   t   headerst   copyt   updatet   parentt
   addheaders(   t   handlert   hRR   t   tunnel_hostt
   new_tunnelt   u(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt   _generic_start_transaction   s     	$	c      
   C   s  t  g  |  j D]. } | j   j d  r | |  j | f ^ q  } |  j |  j |  j  |  j d |  j  x% | j	   D] } |  j d |  q{ W|  j d  |  j
 |  j d |  j d |  j } x^ t r'| j   \ } } } | t j k r Pn  x) t r#| j j   j   } | s Pq q Wq W| | _ | j   | _ | j d k rx) t rz| j j   }	 |	 d k rRPqRqRWt S| d k rd	 | _ nB | j d
  rd | _ n' | d k rd | _ n t j |   | j d k rd  | _ d | _ d | _ t j t j    | _  t! St j | j  | _  d  | j  _ | j  j" d  }
 |
 r|
 j   d k rd | _ d  | _# n	 d | _ | j$   | _ | j  j" d  } | r| j ry t% |  | _ Wn t& k
 rd  | _ qX| j d k  rd  | _ qn	 d  | _ | t j' k sY| t j( k sYd | k oEd k  n sY| j d k red | _ n  | j r| j r| j d  k rd | _ n  | |  _) t! S(   Ns   proxy-s   CONNECT %s HTTP/1.0
s   %s: %s
s   
t   strictt   methodi   s   HTTP/1.0i
   s   HTTP/1.i   s   HTTP/0.9i	   i    i   s   transfer-encodingt   chunkeds   content-lengthid   t   HEAD(*   t   dictR   R:   R6   t   _set_hostportR(   R@   R~   Rs   t	   iteritemst   response_classRo   R   t   _methodR   t   _read_statust   httplibt   CONTINUEt   fpt   readlineR<   t   statust   reasont   versiont   UnknownProtocolR   t   lengthR   R|   t   HTTPMessaget	   cStringIOt   StringIOR"   R   t	   getheadert
   chunk_leftt   _check_closet   intt
   ValueErrort
   NO_CONTENTt   NOT_MODIFIEDRz   (   R   t   xt   proxyheaderst   headerR   R   R   R   t   skipt   linet   trencR   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRu      s    1											

	t   httphandlerc           B   s   e  Z d    Z d   Z RS(   c         C   s   |  j  t |  S(   N(   t   do_openRq   (   R   RR   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt	   http_open:  s    c         C   s&   t  |  | |  t j j |  | |  S(   N(   R   Rx   t   HTTPHandlert   _start_transaction(   R   R   RR   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   =  s    (   R$   R%   R   R   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   9  s   	t   httpsconnectionc           B   s;   e  Z e j Z e e j  Z e j e	 j
  Z d    Z RS(   c         C   s   t  |  j |  j f  |  _ |  j } |  j rS t |   |  j j d d  d } n  t j |  j |  j	 |  j
 t j |  j |   |  _ t j |  j |  |  j  d  S(   NRI   i   i    (   Rp   R(   R@   Ro   Rs   Ru   t   rsplitRv   Rw   t   key_filet	   cert_filet	   sslkwargsR   t	   validator(   R   R(   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyRd   H  s    		
(   R$   R%   Rx   t   HTTPResponseR   R\   t   safesendR~   t   wrapgetresponseR   t   HTTPSConnectionR}   Rd   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   B  s   	t   httpshandlerc           B   s/   e  Z d    Z d   Z d   Z d d  Z RS(   c         C   s?   t  j j |   t j j |   | |  _ t |  j  |  _ d  S(   N(   Rx   t   KeepAliveHandlerR   R   R]   R   R   t   pwmgr(   R   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   U  s    	c         C   s&   t  |  | |  t j j |  | |  S(   N(   R   Rx   R   R   (   R   R   RR   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   [  s    c         C   s   | j    } |  j j |  \ } } t j |  j | |  } | rn | \ } } | |  _ |  j j d |  n	 d  |  _ |  j	 |  j
 |  S(   Ns#   using auth.%s.* for authentication
(   R   R   R#   R   R   R   R   R   R   R   t   _makeconnection(   R   RR   R7   R   R   R   R   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt
   https_open_  s    		c      	   O   s   d  } d  } t |  d k r+ | d } n  t |  d k rJ | d } n  | d } |  j r d |  j k r d |  j k r |  j d } |  j d } n  t | | | | | |  } |  j | _ | S(   Ni   i    i   RL   t   cert(   R   R!   R   R   R   (   R   R(   R@   t   argst   kwargst   keyfilet   certfilet   conn(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   m  s    
'	N(   R$   R%   R   R   R   R   R   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR   T  s   			t   httpdigestauthhandlerc           B   s#   e  Z d    Z d   Z d   Z RS(   c         O   s#   t  j j |  | |  d  |  _ d  S(   N(   R   t   HTTPDigestAuthHandlerR   R   t   retried_req(   R   R   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s    c         C   s   d  S(   N(    (   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt   reset_retry_count  s    c         C   s   | |  j  k	 r$ | |  _  d |  _ n  y  t j j |  | | | |  SWn6 t k
 r| } | j d } | j d  rv d  S  n Xd  S(   Ni    s'   AbstractDigestAuthHandler doesn't know (   R   t   retriedR   R   t   http_error_auth_reqedR   R   R6   (   R   t   auth_headerR(   RR   R   t   instt   arg(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s    		(   R$   R%   R   R   R   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s   		t   httpbasicauthhandlerc           B   s#   e  Z d    Z d   Z d   Z RS(   c         O   s#   t  j j |  | |  d  |  _ d  S(   N(   R   t   HTTPBasicAuthHandlerR   R   R   (   R   R   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s    c         C   s   d  S(   N(    (   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s    c         C   s@   | |  j  k	 r$ | |  _  d |  _ n  t j j |  | | | |  S(   Ni    (   R   R   R   R   R   (   R   R   R(   RR   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s
    		(   R$   R%   R   R   R   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s   		c         C   sM  |  j  d d t  r3 t j |  t |    g } n( t   g } t r[ | j t |    n  | j t	 |    t |   } | d k	 r | j |   | d d !\ } } |  j d | | r d t |  p d f  n  | j t |  t |  f  | j g  t D] } | |  |  ^ q t j |   } d g | _ | j j d  | S(   se   
    construct an opener suitable for urllib2
    authinfo will be added to the password manager
    R   t   usehttp2i   i   s    http auth: user %s, password %s
R    s   not sets
   User-agents   mercurial/proto-1.0t   Accepts   application/mercurial-0.1N(   s
   User-agents   mercurial/proto-1.0(   R   s   application/mercurial-0.1(   R=   R   R   t   http2handlerR   R   Rr   t   appendR   R&   R   R   R   R!   R8   R   R   t   handlerfuncsR   t   build_openerR   (   R   R   t   handlerst   passmgrR   R   R   t   opener(    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s&    	')c         C   s   t  j |  } | j r? | j j   | _ | j   \ } } n4 t  j t j j |   } d t	 j
 |  } d  } t |  |  j | |  S(   Ns   file://(   R   R7   R   R:   R   t   normpathR4   t   patht   abspatht   urllibt   pathname2urlR   R   t   open(   R   t   url_RX   R   R   R   (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyR     s    	(+   R   R   R   R4   R^   R   t   i18nR    Rx   R   Rv   Rq   R   R   R   RC   R&   R\   t   safehasattrRr   t   create_connectionRp   t   AttributeErrort   objectRa   R   Ry   R   Ru   R   R   R   R   R   R]   R   R   R   R   R   R   R   R   (    (    (    s1   /sys/lib/python2.7/site-packages/mercurial/url.pyt   <module>
   s4   H$-B				b".