Rev 6391: (jelmer) Convert bzrlib.smtp_connection to use config stacks. (Jelmer in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Tue Dec 20 18:47:36 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6391 [merge]
revision-id: pqm at pqm.ubuntu.com-20111220184735-nvjnbab2d88i60ca
parent: pqm at pqm.ubuntu.com-20111220182239-wi7jfqqrxj76f0w9
parent: jelmer at samba.org-20111216191839-eg681lxqibi1qxu1
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2011-12-20 18:47:35 +0000
message:
  (jelmer) Convert bzrlib.smtp_connection to use config stacks. (Jelmer
   Vernooij)
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/smtp_connection.py      smtp_connection.py-20070618204456-nu6wag1ste4biuk2-1
  bzrlib/tests/blackbox/test_merge_directive.py test_merge_directive-20070302012039-zh7uhy39biairtn0-1
  bzrlib/tests/test_email_message.py test_email_message.p-20070718143823-660zfcl54xi1v65u-2
  bzrlib/tests/test_smtp_connection.py test_smtp_connection-20070618204509-wuyxc0r0ztrecv7e-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2011-12-19 13:23:58 +0000
+++ b/bzrlib/builtins.py	2011-12-20 18:47:35 +0000
@@ -5581,7 +5581,7 @@
                 self.outf.writelines(directive.to_lines())
         else:
             message = directive.to_email(mail_to, branch, sign)
-            s = SMTPConnection(branch.get_config())
+            s = SMTPConnection(branch.get_config_stack())
             s.send_email(message)
 
 

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-12-19 16:41:49 +0000
+++ b/bzrlib/config.py	2011-12-20 18:47:35 +0000
@@ -2737,7 +2737,12 @@
 to physical disk.  This is somewhat slower, but means data should not be
 lost if the machine crashes.  See also dirstate.fdatasync.
 '''))
-
+option_registry.register_lazy('smtp_server',
+    'bzrlib.smtp_connection', 'smtp_server')
+option_registry.register_lazy('smtp_password',
+    'bzrlib.smtp_connection', 'smtp_password')
+option_registry.register_lazy('smtp_username',
+    'bzrlib.smtp_connection', 'smtp_username')
 option_registry.register(
     Option('selftest.timeout',
         default='600',

=== modified file 'bzrlib/smtp_connection.py'
--- a/bzrlib/smtp_connection.py	2011-12-19 13:23:58 +0000
+++ b/bzrlib/smtp_connection.py	2011-12-20 18:47:35 +0000
@@ -35,6 +35,20 @@
     )
 
 
+smtp_password = config.Option('smtp_password', default=None,
+        help='''\
+Password to use for authentication to SMTP server.
+''')
+smtp_server = config.Option('smtp_server', default=None,
+        help='''\
+Hostname of the SMTP server to use for sending email.
+''')
+smtp_username = config.Option('smtp_username', default=None,
+        help='''\
+Username to use for authentication to SMTP server.
+''')
+
+
 class SMTPConnection(object):
     """Connect to an SMTP server and send an email.
 
@@ -50,13 +64,13 @@
         if self._smtp_factory is None:
             self._smtp_factory = smtplib.SMTP
         self._config = config
-        self._config_smtp_server = config.get_user_option('smtp_server')
+        self._config_smtp_server = config.get('smtp_server')
         self._smtp_server = self._config_smtp_server
         if self._smtp_server is None:
             self._smtp_server = self._default_smtp_server
 
-        self._smtp_username = config.get_user_option('smtp_username')
-        self._smtp_password = config.get_user_option('smtp_password')
+        self._smtp_username = config.get('smtp_username')
+        self._smtp_password = config.get('smtp_password')
 
         self._connection = None
 

=== modified file 'bzrlib/tests/blackbox/test_merge_directive.py'
--- a/bzrlib/tests/blackbox/test_merge_directive.py	2010-06-17 09:23:19 +0000
+++ b/bzrlib/tests/blackbox/test_merge_directive.py	2011-12-16 19:18:39 +0000
@@ -223,7 +223,7 @@
 
     def test_mail_uses_config(self):
         tree1, tree2 = self.prepare_merge_directive()
-        tree1.branch.get_config().set_user_option('smtp_server', 'bogushost')
+        tree1.branch.get_config_stack().set('smtp_server', 'bogushost')
         md_text, errr, connect_calls, sendmail_calls =\
             self.run_bzr_fakemail('merge-directive --mail-to'
                                   ' pqm at example.com --plain ../tree2 .')

=== modified file 'bzrlib/tests/test_email_message.py'
--- a/bzrlib/tests/test_email_message.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_email_message.py	2011-12-16 19:18:39 +0000
@@ -150,7 +150,7 @@
 
     def test_send(self):
         class FakeConfig:
-            def get_user_option(self, option):
+            def get(self, option):
                 return None
 
         messages = []

=== modified file 'bzrlib/tests/test_smtp_connection.py'
--- a/bzrlib/tests/test_smtp_connection.py	2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_smtp_connection.py	2011-12-16 16:40:10 +0000
@@ -87,12 +87,20 @@
         self._calls.append(('login', user, password))
 
 
+class StringStack(config.Stack):
+
+    def __init__(self, text):
+        store = config.IniFileStore()
+        store._load_from_string(text)
+        super(StringStack, self).__init__([store.get_sections])
+
+
 class TestSMTPConnection(tests.TestCaseInTempDir):
 
     def get_connection(self, text, smtp_factory=None):
-        my_config = config.GlobalConfig.from_string(text)
-        return smtp_connection.SMTPConnection(my_config,
-                                              _smtp_factory=smtp_factory)
+        my_config = StringStack(text)
+        return smtp_connection.SMTPConnection(
+            my_config, _smtp_factory=smtp_factory)
 
     def test_defaults(self):
         conn = self.get_connection('')
@@ -161,8 +169,8 @@
         utf8_pass = unicode_pass.encode('utf-8')
         factory = WideOpenSMTPFactory()
         conn = self.get_connection(
-            u'[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
-            % (user, unicode_pass), smtp_factory=factory)
+            '[DEFAULT]\nsmtp_username=%s\nsmtp_password=%s\n'
+            % (user, utf8_pass), smtp_factory=factory)
         self.assertEqual(unicode_pass, conn._smtp_password)
         conn._connect()
         self.assertEqual([('connect', 'localhost'),
@@ -254,22 +262,18 @@
             'pperez at ejemplo.com', 'user at localhost']), sorted(to))
 
     def test_destination_address_required(self):
-        class FakeConfig:
-            def get_user_option(self, option):
-                return None
-
         msg = Message()
         msg['From'] = '"J. Random Developer" <jrandom at example.com>'
         self.assertRaises(
             errors.NoDestinationAddress,
-            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
+            smtp_connection.SMTPConnection(StringStack("")).send_email, msg)
 
         msg = email_message.EmailMessage('from at from.com', '', 'subject')
         self.assertRaises(
             errors.NoDestinationAddress,
-            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
+            smtp_connection.SMTPConnection(StringStack("")).send_email, msg)
 
         msg = email_message.EmailMessage('from at from.com', [], 'subject')
         self.assertRaises(
             errors.NoDestinationAddress,
-            smtp_connection.SMTPConnection(FakeConfig()).send_email, msg)
+            smtp_connection.SMTPConnection(StringStack("")).send_email, msg)




More information about the bazaar-commits mailing list