~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-07 07:52:50 UTC
  • mfrom: (3340.1.1 208418-1.4)
  • Revision ID: pqm@pqm.ubuntu.com-20080407075250-phs53xnslo8boaeo
Return the correct knit serialisation method in _StreamAccess.
        (Andrew Bennetts, Martin Pool, Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
 
18
 
 
19
17
"""UI abstraction.
20
18
 
21
19
This tells the library how to display things to the user.  Through this
35
33
import getpass
36
34
 
37
35
from bzrlib import (
 
36
    errors,
 
37
    osutils,
38
38
    progress,
39
39
    trace,
40
40
    )
41
41
""")
42
42
 
43
 
from bzrlib.symbol_versioning import (deprecated_method, zero_eight)
44
 
 
45
43
 
46
44
class UIFactory(object):
47
45
    """UI abstraction.
54
52
        super(UIFactory, self).__init__()
55
53
        self._progress_bar_stack = None
56
54
 
57
 
    @deprecated_method(zero_eight)
58
 
    def progress_bar(self):
59
 
        """See UIFactory.nested_progress_bar()."""
60
 
        raise NotImplementedError(self.progress_bar)
61
 
 
62
55
    def get_password(self, prompt='', **kwargs):
63
56
        """Prompt the user for a password.
64
57
 
111
104
            current_format_name,
112
105
            basedir)
113
106
 
114
 
            
 
107
 
115
108
class CLIUIFactory(UIFactory):
116
109
    """Common behaviour for command line UI factories."""
117
110
 
131
124
                return False
132
125
 
133
126
    def get_non_echoed_password(self, prompt):
134
 
        return getpass.getpass(prompt)
 
127
        if not sys.stdin.isatty():
 
128
            raise errors.NotATerminal()
 
129
        encoding = osutils.get_terminal_encoding()
 
130
        return getpass.getpass(prompt.encode(encoding, 'replace'))
135
131
 
136
132
    def get_password(self, prompt='', **kwargs):
137
133
        """Prompt the user for a password.
144
140
                 canceled the request.
145
141
        """
146
142
        prompt += ': '
147
 
        prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
 
143
        prompt = (prompt % kwargs)
148
144
        # There's currently no way to say 'i decline to enter a password'
149
145
        # as opposed to 'my password is empty' -- does it matter?
150
146
        return self.get_non_echoed_password(prompt)
159
155
    This is the default UI, if another one is never registered.
160
156
    """
161
157
 
162
 
    @deprecated_method(zero_eight)
163
 
    def progress_bar(self):
164
 
        """See UIFactory.nested_progress_bar()."""
165
 
        return progress.DummyProgress()
166
 
 
167
158
    def get_password(self, prompt='', **kwargs):
168
159
        return None
169
160