summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/main.py b/main.py
index 665a655b..34dd27dc 100755
--- a/main.py
+++ b/main.py
@@ -22,6 +22,7 @@ if __name__ == '__main__':
22 del sys.argv[-1] 22 del sys.argv[-1]
23del magic 23del magic
24 24
25import getpass
25import netrc 26import netrc
26import optparse 27import optparse
27import os 28import os
@@ -276,7 +277,25 @@ class _UserAgentHandler(urllib2.BaseHandler):
276 req.add_header('User-Agent', _UserAgent()) 277 req.add_header('User-Agent', _UserAgent())
277 return req 278 return req
278 279
280def _AddPasswordFromUserInput(handler, msg, req):
281 # If repo could not find auth info from netrc, try to get it from user input
282 url = req.get_full_url()
283 user, password = handler.passwd.find_user_password(None, url)
284 if user is None:
285 print msg
286 try:
287 user = raw_input('User: ')
288 password = getpass.getpass()
289 except KeyboardInterrupt:
290 return
291 handler.passwd.add_password(None, url, user, password)
292
279class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): 293class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler):
294 def http_error_401(self, req, fp, code, msg, headers):
295 _AddPasswordFromUserInput(self, msg, req)
296 return urllib2.HTTPBasicAuthHandler.http_error_401(
297 self, req, fp, code, msg, headers)
298
280 def http_error_auth_reqed(self, authreq, host, req, headers): 299 def http_error_auth_reqed(self, authreq, host, req, headers):
281 try: 300 try:
282 old_add_header = req.add_header 301 old_add_header = req.add_header
@@ -295,6 +314,11 @@ class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler):
295 raise 314 raise
296 315
297class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler): 316class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler):
317 def http_error_401(self, req, fp, code, msg, headers):
318 _AddPasswordFromUserInput(self, msg, req)
319 return urllib2.HTTPDigestAuthHandler.http_error_401(
320 self, req, fp, code, msg, headers)
321
298 def http_error_auth_reqed(self, auth_header, host, req, headers): 322 def http_error_auth_reqed(self, auth_header, host, req, headers):
299 try: 323 try:
300 old_add_header = req.add_header 324 old_add_header = req.add_header