Commits

Mitsuhiro Koga committed 7561aef

svnwrap: Improved handling of simple_prompt_provider

Comments (0)

Files changed (3)

hgsubversion/svnrepo.py

     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:

hgsubversion/svnwrap/subvertpy_wrapper.py

 import cStringIO
-import getpass
 import errno
 import os
 import shutil
         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:
             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),
             ]
 

hgsubversion/svnwrap/svn_swig_wrapper.py

 import cStringIO
-import getpass
 import errno
 import os
 import shutil
             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,
         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),
             ]
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.