[MERGE] Add a get_login method to UIFactory and test get_password

Martin Pool mbp at sourcefrog.net
Wed Feb 21 01:15:28 GMT 2007

John Arbash Meinel wrote:

>>     >> """See UIFactory.nested_progress_bar()."""
>>     >> raise NotImplementedError(self.progress_bar)
>>     >> 
>>     >> +    def get_login(self, prompt='', **kwargs):
>>     >> +        """Prompt the user for a login (generally on a remote host).
>>     >> +
>>     >> +        :param prompt: The prompt to present the user
>>     >> +        :param kwargs: Arguments which will be expanded into the prompt.
>>     >> +                       This lets front ends display different things if
>>     >> +                       they so choose.
>>     >> +
>>     Martin> Rather than passing the prompt and kwargs to these
>>     Martin> methods why not let the caller combine them?
>> I think the original intent in get_password (which I duplicated)
>> was to "let different front ends display different things". I'm
>> +0.5 on this until I see useful examples.
>> Note that get_boolean add a '[y\n] ?' and that get_login and
>> get_password add a ': ' at the end of the prompt which seems
>> appropriate for CLI.
>> But that's a different point than kwargs though.
> That was the original intent. It means that the string being used is
> relatively fixed, so if you want to replace it with something else
> because of a GUI, it is easy to do, while inspecting an already expanded
> string is difficult.
> At this point it was a bit of "future proofing" that hasn't done
> anything yet, so it may not be the best way to go about it. But since
> ui_factory was meant to be a way to change the interface from CLI to
> something else, it seemed reasonable.
> To me, the alternative is to make the interface more specific and not
> allow a prompt at all. Rather the prompt is defined by the function. So
> we would have "get_password_for_user_at_host()" (which may just be
> get_password()).

I agree that it's probably premature generalization.  If there are going
to be parameters I'd rather (user,host) or rather (user,resource) to
better accomodate things like http auth.

> v- I'm concerned about this being tested on multiple platforms, since it
> seems pretty OS specific. What would happen on Windows, Mac or FreeBSD?
> Also, if we do something like this, it might be better if we exposed a
> fake file descripter (tempfile.mkstemp comes to mind).

That would be cleaner but apparently will not work with getpass:

  mbp at kapu% python -c 'import
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.5/getpass.py", line 32, in unix_getpass
    old = termios.tcgetattr(fd)     # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')
zsh: exit 1     python -c

Creating a pseudotty might work but that is obviously not portable and
really seems like we're getting into testing getpass rather than our own


More information about the bazaar mailing list