~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""A convenience class around smtplib."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from email import Utils
20
22
import errno
21
23
import smtplib
33
35
    )
34
36
 
35
37
 
 
38
smtp_password = config.Option('smtp_password', default=None,
 
39
        help='''\
 
40
Password to use for authentication to SMTP server.
 
41
''')
 
42
smtp_server = config.Option('smtp_server', default=None,
 
43
        help='''\
 
44
Hostname of the SMTP server to use for sending email.
 
45
''')
 
46
smtp_username = config.Option('smtp_username', default=None,
 
47
        help='''\
 
48
Username to use for authentication to SMTP server.
 
49
''')
 
50
 
 
51
 
36
52
class SMTPConnection(object):
37
53
    """Connect to an SMTP server and send an email.
38
54
 
48
64
        if self._smtp_factory is None:
49
65
            self._smtp_factory = smtplib.SMTP
50
66
        self._config = config
51
 
        self._config_smtp_server = config.get_user_option('smtp_server')
 
67
        self._config_smtp_server = config.get('smtp_server')
52
68
        self._smtp_server = self._config_smtp_server
53
69
        if self._smtp_server is None:
54
70
            self._smtp_server = self._default_smtp_server
55
71
 
56
 
        self._smtp_username = config.get_user_option('smtp_username')
57
 
        self._smtp_password = config.get_user_option('smtp_password')
 
72
        self._smtp_username = config.get('smtp_username')
 
73
        self._smtp_password = config.get('smtp_password')
58
74
 
59
75
        self._connection = None
60
76