Mercurial > hgsubversion
changeset 966:7561aef55a4b
svnwrap: Improved handling of simple_prompt_provider
author | Mitsuhiro Koga <shiena.jp@gmail.com> |
---|---|
date | Tue, 23 Oct 2012 20:12:32 +0900 |
parents | b748a0eed09a |
children | 0b6a6a7c26f3 |
files | hgsubversion/svnrepo.py hgsubversion/svnwrap/subvertpy_wrapper.py hgsubversion/svnwrap/svn_swig_wrapper.py |
diffstat | 3 files changed, 25 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/svnrepo.py +++ b/hgsubversion/svnrepo.py @@ -202,6 +202,20 @@ class SubversionPrompt(object): def __init__(self, ui): self.ui = ui + def maybe_print_realm(self, realm): + if realm: + self.ui.write('Authentication realm: %s\n' % (realm,)) + self.ui.flush() + + def simple(self, realm, default_username, may_save, pool=None): + self.maybe_print_realm(realm) + if default_username: + username = default_username + else: + username = self.ui.prompt('Username: ', default='') + password = self.ui.getpass('Password for \'%s\': ' % (username,), default='') + return (username, password, bool(may_save)) + def ssl_server_trust(self, realm, failures, cert_info, may_save, pool=None): msg = 'Error validating server certificate for \'%s\':\n' % (realm,) if failures & svnwrap.SSL_UNKNOWNCA:
--- a/hgsubversion/svnwrap/subvertpy_wrapper.py +++ b/hgsubversion/svnwrap/subvertpy_wrapper.py @@ -1,5 +1,4 @@ import cStringIO -import getpass import errno import os import shutil @@ -208,11 +207,12 @@ class SubversionRepo(object): def getclientstring(): return 'hgsubversion' # TODO: handle certificate authentication, Mercurial style - def getpass(realm, username, may_save): - return self.username or username, self.password or '', False def getuser(realm, may_save): return self.username or '', False + def simple(realm, username, may_save): + return _prompt.simple(realm, username, may_save) + def ssl_server_trust(realm, failures, cert_info, may_save): creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save) if creds is None: @@ -231,10 +231,10 @@ class SubversionRepo(object): ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_username_prompt_provider(getuser, 0), - ra.get_simple_prompt_provider(getpass, 0), ] if _prompt: providers += [ + ra.get_simple_prompt_provider(simple, 2), ra.get_ssl_server_trust_prompt_provider(ssl_server_trust), ]
--- a/hgsubversion/svnwrap/svn_swig_wrapper.py +++ b/hgsubversion/svnwrap/svn_swig_wrapper.py @@ -1,5 +1,4 @@ import cStringIO -import getpass import errno import os import shutil @@ -93,26 +92,17 @@ def ieditor(fn): raise return fun -def user_pass_prompt(realm, default_username, ms, pool): # pragma: no cover - # FIXME: should use getpass() and username() from mercurial.ui - creds = core.svn_auth_cred_simple_t() - creds.may_save = ms - if default_username: - sys.stderr.write('Auth realm: %s\n' % (realm,)) - creds.username = default_username - else: - sys.stderr.write('Auth realm: %s\n' % (realm,)) - sys.stderr.write('Username: ') - sys.stderr.flush() - creds.username = sys.stdin.readline().strip() - creds.password = getpass.getpass('Password for %s: ' % creds.username) - return creds - _prompt = None def prompt_callback(callback): global _prompt _prompt = callback +def _simple(realm, default_username, ms, pool): + ret = _prompt.simple(realm, default_username, ms, pool) + creds = core.svn_auth_cred_simple_t() + (creds.username, creds.password, creds.may_save) = ret + return creds + def _ssl_server_trust(realm, failures, cert_info, may_save, pool): cert = [ cert_info.hostname, @@ -171,11 +161,11 @@ def _create_auth_baton(pool, password_st client.get_ssl_client_cert_file_provider(), client.get_ssl_client_cert_pw_file_provider(), client.get_ssl_server_trust_file_provider(), - client.get_simple_prompt_provider(user_pass_prompt, 2), ] if _prompt: providers += [ + client.get_simple_prompt_provider(_simple, 2), client.get_ssl_server_trust_prompt_provider(_ssl_server_trust), ]