~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-30 16:41:08 UTC
  • mto: (1185.50.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1518.
  • Revision ID: john@arbash-meinel.com-20051130164108-f5d8517a01eee379
Added get_password to the UIFactory, using it inside of sftp.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""Text UI, write output to the console.
20
20
"""
21
21
 
 
22
import getpass
 
23
import sys
 
24
 
22
25
import bzrlib.progress
23
26
from bzrlib.ui import UIFactory
24
27
 
30
33
        # bar depending on what we think of the terminal
31
34
        return bzrlib.progress.ProgressBar()
32
35
 
 
36
    def get_password(self, prompt='', **kwargs):
 
37
        """Prompt the user for a password.
 
38
 
 
39
        :param prompt: The prompt to present the user
 
40
        :param kwargs: Arguments which will be expanded into the prompt.
 
41
                       This lets front ends display different things if
 
42
                       they so choose.
 
43
        :return: The password string, return None if the user 
 
44
                 canceled the request.
 
45
        """
 
46
        prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
 
47
        prompt += ': '
 
48
        try:
 
49
            return getpass.getpass(prompt)
 
50
        except KeyboardInterrupt:
 
51
            return None
 
52