# HG changeset patch # User Mitsuhiro Koga # Date 1350990752 -32400 # Node ID 7561aef55a4b30c19a0f91ba215f9e50389034ba # Parent b748a0eed09aff62fc1a55388a78d253652947fc svnwrap: Improved handling of simple_prompt_provider diff --git a/hgsubversion/svnrepo.py b/hgsubversion/svnrepo.py --- 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: diff --git a/hgsubversion/svnwrap/subvertpy_wrapper.py b/hgsubversion/svnwrap/subvertpy_wrapper.py --- 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), ] diff --git a/hgsubversion/svnwrap/svn_swig_wrapper.py b/hgsubversion/svnwrap/svn_swig_wrapper.py --- 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), ]