diff options
-rwxr-xr-x | main.py | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -22,6 +22,7 @@ if __name__ == '__main__': | |||
22 | del sys.argv[-1] | 22 | del sys.argv[-1] |
23 | del magic | 23 | del magic |
24 | 24 | ||
25 | import getpass | ||
25 | import netrc | 26 | import netrc |
26 | import optparse | 27 | import optparse |
27 | import os | 28 | import 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 | ||
280 | def _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 | |||
279 | class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): | 293 | class _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 | ||
297 | class _DigestAuthHandler(urllib2.HTTPDigestAuthHandler): | 316 | class _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 |