mercurial/httprepo.py
changeset 2281 7761597b5da3
parent 2015 1a09814a5b1f
child 2294 ce67fa312f61
equal deleted inserted replaced
2279:51bfa0fd3a33 2281:7761597b5da3
     8 from node import *
     8 from node import *
     9 from remoterepo import *
     9 from remoterepo import *
    10 from i18n import gettext as _
    10 from i18n import gettext as _
    11 from demandload import *
    11 from demandload import *
    12 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib")
    12 demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib")
       
    13 
       
    14 class passwordmgr(urllib2.HTTPPasswordMgr):
       
    15     def __init__(self, ui):
       
    16         urllib2.HTTPPasswordMgr.__init__(self)
       
    17         self.ui = ui
       
    18 
       
    19     def find_user_password(self, realm, authuri):
       
    20         authinfo = urllib2.HTTPPasswordMgr.find_user_password(
       
    21             self, realm, authuri)
       
    22         if authinfo != (None, None):
       
    23             return authinfo
       
    24 
       
    25         self.ui.write(_("http authorization required\n"))
       
    26         self.ui.status(_("realm: %s\n") % realm)
       
    27         user = self.ui.prompt(_("user:"), default=None)
       
    28         passwd = self.ui.getpass()
       
    29 
       
    30         self.add_password(realm, authuri, user, passwd)
       
    31         return (user, passwd)
    13 
    32 
    14 class httprepository(remoterepository):
    33 class httprepository(remoterepository):
    15     def __init__(self, ui, path):
    34     def __init__(self, ui, path):
    16         # fix missing / after hostname
    35         # fix missing / after hostname
    17         s = urlparse.urlsplit(path)
    36         s = urlparse.urlsplit(path)
    51 
    70 
    52         proxy_handler = urllib2.BaseHandler()
    71         proxy_handler = urllib2.BaseHandler()
    53         if host and not no_proxy:
    72         if host and not no_proxy:
    54             proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host})
    73             proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host})
    55 
    74 
    56         authinfo = None
    75         proxyauthinfo = None
    57         if user and passwd:
    76         if user and passwd:
    58             passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    77             passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    59             passmgr.add_password(None, host, user, passwd)
    78             passmgr.add_password(None, host, user, passwd)
    60             authinfo = urllib2.ProxyBasicAuthHandler(passmgr)
    79             proxyauthinfo = urllib2.ProxyBasicAuthHandler(passmgr)
    61 
    80 
    62         opener = urllib2.build_opener(proxy_handler, authinfo)
    81         if ui.interactive:
       
    82             passmgr = passwordmgr(ui)
       
    83             opener = urllib2.build_opener(
       
    84                 proxy_handler, proxyauthinfo,
       
    85                 urllib2.HTTPBasicAuthHandler(passmgr),
       
    86                 urllib2.HTTPDigestAuthHandler(passmgr))
       
    87         else:
       
    88             opener = urllib2.build_opener(proxy_handler, proxyauthinfo)
       
    89 
    63         # 1.0 here is the _protocol_ version
    90         # 1.0 here is the _protocol_ version
    64         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
    91         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
    65         urllib2.install_opener(opener)
    92         urllib2.install_opener(opener)
    66 
    93 
    67     def dev(self):
    94     def dev(self):