mercurial/url.py
changeset 10282 08a0f04b56bd
parent 10263 25e572394f5c
child 10408 50fb1fe143ff
equal deleted inserted replaced
10281:e7d3b509af8b 10282:08a0f04b56bd
    28 
    28 
    29     a = netloc.find('@')
    29     a = netloc.find('@')
    30     if a == -1:
    30     if a == -1:
    31         user, passwd = None, None
    31         user, passwd = None, None
    32     else:
    32     else:
    33         userpass, netloc = netloc[:a], netloc[a+1:]
    33         userpass, netloc = netloc[:a], netloc[a + 1:]
    34         c = userpass.find(':')
    34         c = userpass.find(':')
    35         if c == -1:
    35         if c == -1:
    36             user, passwd = urllib.unquote(userpass), None
    36             user, passwd = urllib.unquote(userpass), None
    37         else:
    37         else:
    38             user = urllib.unquote(userpass[:c])
    38             user = urllib.unquote(userpass[:c])
    39             passwd = urllib.unquote(userpass[c+1:])
    39             passwd = urllib.unquote(userpass[c + 1:])
    40     c = netloc.find(':')
    40     c = netloc.find(':')
    41     if c == -1:
    41     if c == -1:
    42         host, port = netloc, None
    42         host, port = netloc, None
    43     else:
    43     else:
    44         host, port = netloc[:c], netloc[c+1:]
    44         host, port = netloc[:c], netloc[c + 1:]
    45     return host, port, user, passwd
    45     return host, port, user, passwd
    46 
    46 
    47 def netlocunsplit(host, port, user=None, passwd=None):
    47 def netlocunsplit(host, port, user=None, passwd=None):
    48     '''turn host, port, user, passwd into [user[:passwd]@]host[:port].'''
    48     '''turn host, port, user, passwd into [user[:passwd]@]host[:port].'''
    49     if port:
    49     if port:
    87         _safeset = set(_safe)
    87         _safeset = set(_safe)
    88         _hex = set('abcdefABCDEF0123456789')
    88         _hex = set('abcdefABCDEF0123456789')
    89     l = list(path)
    89     l = list(path)
    90     for i in xrange(len(l)):
    90     for i in xrange(len(l)):
    91         c = l[i]
    91         c = l[i]
    92         if c == '%' and i + 2 < len(l) and (l[i+1] in _hex and l[i+2] in _hex):
    92         if (c == '%' and i + 2 < len(l) and
       
    93             l[i + 1] in _hex and l[i + 2] in _hex):
    93             pass
    94             pass
    94         elif c not in _safeset:
    95         elif c not in _safeset:
    95             l[i] = '%%%02X' % ord(c)
    96             l[i] = '%%%02X' % ord(c)
    96     return ''.join(l)
    97     return ''.join(l)
    97 
    98 
   146         scheme, hostpath = uri.split('://', 1)
   147         scheme, hostpath = uri.split('://', 1)
   147         bestlen = 0
   148         bestlen = 0
   148         bestauth = None
   149         bestauth = None
   149         for auth in config.itervalues():
   150         for auth in config.itervalues():
   150             prefix = auth.get('prefix')
   151             prefix = auth.get('prefix')
   151             if not prefix: continue
   152             if not prefix:
       
   153                 continue
   152             p = prefix.split('://', 1)
   154             p = prefix.split('://', 1)
   153             if len(p) > 1:
   155             if len(p) > 1:
   154                 schemes, prefix = [p[0]], p[1]
   156                 schemes, prefix = [p[0]], p[1]
   155             else:
   157             else:
   156                 schemes = (auth.get('schemes') or 'https').split()
   158                 schemes = (auth.get('schemes') or 'https').split()
   178             if not proxyuser:
   180             if not proxyuser:
   179                 proxyuser = ui.config("http_proxy", "user")
   181                 proxyuser = ui.config("http_proxy", "user")
   180                 proxypasswd = ui.config("http_proxy", "passwd")
   182                 proxypasswd = ui.config("http_proxy", "passwd")
   181 
   183 
   182             # see if we should use a proxy for this url
   184             # see if we should use a proxy for this url
   183             no_list = [ "localhost", "127.0.0.1" ]
   185             no_list = ["localhost", "127.0.0.1"]
   184             no_list.extend([p.lower() for
   186             no_list.extend([p.lower() for
   185                             p in ui.configlist("http_proxy", "no")])
   187                             p in ui.configlist("http_proxy", "no")])
   186             no_list.extend([p.strip().lower() for
   188             no_list.extend([p.strip().lower() for
   187                             p in os.getenv("no_proxy", '').split(',')
   189                             p in os.getenv("no_proxy", '').split(',')
   188                             if p.strip()])
   190                             if p.strip()])
   434         def connect(self):
   436         def connect(self):
   435             if self.realhost: # use CONNECT proxy
   437             if self.realhost: # use CONNECT proxy
   436                 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   438                 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   437                 self.sock.connect((self.host, self.port))
   439                 self.sock.connect((self.host, self.port))
   438                 if _generic_proxytunnel(self):
   440                 if _generic_proxytunnel(self):
   439                     self.sock = _ssl_wrap_socket(self.sock, self.cert_file, self.key_file)
   441                     self.sock = _ssl_wrap_socket(self.sock, self.cert_file,
       
   442                                                  self.key_file)
   440             else:
   443             else:
   441                 BetterHTTPS.connect(self)
   444                 BetterHTTPS.connect(self)
   442 
   445 
   443     class httpshandler(keepalive.KeepAliveHandler, urllib2.HTTPSHandler):
   446     class httpshandler(keepalive.KeepAliveHandler, urllib2.HTTPSHandler):
   444         def __init__(self, ui):
   447         def __init__(self, ui):