/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-18 20:54:18 UTC
  • mto: (2961.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2962.
  • Revision ID: v.ladeuil+lp@free.fr-20071018205418-mj1g30cn3n4u1ge1
Make smtp aware of authentication config.

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Try the authentication config
before prompting the user.

* bzrlib/tests/test_smtp_connection.py:
Fix some imports.
(everybody_is_welcome): Fake auth smtp server.
(TestSMTPConnection): Now inherits from tests.TestCaseInTempDir so
that we can create an authentication.conf in a protected env.
(TestSMTPConnection.test_smtp_password_from_auth_config): New test.
(TestSMTPConnectionWithUI): New test for prompting user.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import smtplib
22
22
import socket
23
23
 
24
 
from bzrlib import ui
 
24
from bzrlib import (
 
25
    config,
 
26
    ui,
 
27
    )
25
28
from bzrlib.errors import (
26
29
    NoDestinationAddress,
27
30
    SMTPError,
89
92
        if self._smtp_username is None:
90
93
            return
91
94
 
92
 
        if self._smtp_password is None:
93
 
            self._smtp_password = ui.ui_factory.get_password(
94
 
                'Please enter the SMTP password: %(user)s@%(host)s',
95
 
                user=self._smtp_username,
96
 
                host=self._smtp_server)
 
95
        password = self._smtp_password
 
96
        if password is None:
 
97
            auth = config.AuthenticationConfig()
 
98
            config_credentials = auth.get_credentials('smtp', self._smtp_server,
 
99
                                                      user=self._smtp_username)
 
100
            if config_credentials is not None:
 
101
                password = config_credentials['password']
 
102
            else:
 
103
                password = ui.ui_factory.get_password(
 
104
                    'Please enter the SMTP password: %(user)s@%(host)s',
 
105
                    user=self._smtp_username,
 
106
                    host=self._smtp_server)
 
107
 
 
108
        self._smtp_password = password
97
109
 
98
110
        self._connection.login(self._smtp_username, self._smtp_password)
99
111