def passwordmgr(ui): try: realm = hgutil.urlreq.httppasswordmgrwithdefaultrealm() return url.passwordmgr(ui, realm) except (TypeError, AttributeError): # compat with hg < 3.9 return url.passwordmgr(ui)
def _test(uri): print 'URI:', uri try: pm = url.passwordmgr(ui) print ' ', pm.find_user_password('test', uri) except Abort, e: print 'abort'
def _test(uri): print 'URI:', uri try: pm = url.passwordmgr(ui) u, authinfo = util.url(uri).authinfo() if authinfo is not None: pm.add_password(*authinfo) print ' ', pm.find_user_password('test', u) except Abort: print 'abort'
def _test(uri): print('URI:', uri) try: pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()) u, authinfo = util.url(uri).authinfo() if authinfo is not None: pm.add_password(*authinfo) print(' ', pm.find_user_password('test', u)) except error.Abort: print(' ', 'abort')
def _bb_apicall(ui, endpoint, data): uri = 'https://api.bitbucket.org/1.0/%s/' % endpoint # since bitbucket doesn't return the required WWW-Authenticate header when # making a request without Authorization, we cannot use the standard urllib2 # auth handlers; we have to add the requisite header from the start req = urllib2.Request(uri, urllib.urlencode(data)) # at least re-use Mercurial's password query passmgr = url.passwordmgr(ui) passmgr.add_password(None, uri, get_username(ui), '') upw = '%s:%s' % passmgr.find_user_password(None, uri) req.add_header('Authorization', 'Basic %s' % base64.b64encode(upw).strip()) return urllib2.urlopen(req).read()
def _bb_apicall(ui, endpoint, data, use_pass=True): uri = 'https://api.bitbucket.org/1.0/%s/' % endpoint # since bitbucket doesn't return the required WWW-Authenticate header when # making a request without Authorization, we cannot use the standard urllib2 # auth handlers; we have to add the requisite header from the start if data is not None: data = urllib.urlencode(data) req = urllib2.Request(uri, data) #ui.status("Accessing %s" % uri) if use_pass: # at least re-use Mercurial's password query passmgr = url.passwordmgr(ui) passmgr.add_password(None, uri, get_username(ui), '') upw = '%s:%s' % passmgr.find_user_password(None, uri) req.add_header('Authorization', 'Basic %s' % base64.b64encode(upw).strip()) return urllib2.urlopen(req).read()