Ticket #5852: 5852.3.patch

File 5852.3.patch, 2.3 KB (added by moijes12, 4 years ago)
  • twisted/mail/test/test_smtp.py

     
    15181518        client.sentMail(199, "Test response", 1, addresses, client.log)
    15191519
    15201520        return onDone
     1521
     1522
     1523
     1524class DeprecationTests(unittest.TestCase):
     1525    """
     1526    Test for deprecations.
     1527    """
     1528
     1529
     1530    def test_esmtpClientTlsModeDeprecation(self):
     1531        """
     1532        Test deprecation of ESMTPClient.tlsMode.
     1533        """
     1534        import warnings
     1535        with warnings.catch_warnings(record=True) as w:
     1536            warnings.simplefilter("default")
     1537            from twisted.mail.smtp import ESMTPClient
     1538            client = ESMTPClient('', '', '')
     1539            self.assertEqual(len(w), 1)
     1540            self.assertIdentical(w[-1].category, DeprecationWarning)
     1541            self.assertEqual(str(w[-1].message), "tlsMode attribute of
     1542                twisted.mail.smtp.ESMTPClient is deprecated since Twisted
     1543                12.2")
  • twisted/mail/topfiles/5852.removal

     
     1tlsMode attribute of twisted.mail.smtp.ESMTPClient was deprecated since Twisted 12.2.
     2 No newline at end of file
  • twisted/mail/smtp.py

     
    88
    99import time, re, base64, types, socket, os, random, rfc822
    1010import binascii
     11import warnings
    1112from email.base64MIME import encode as encode_base64
    1213
    1314from zope.interface import implements, Interface
     
    12391240    # ClientContextFactory to use for STARTTLS
    12401241    context = None
    12411242
     1243    def __setattr__(self, name, val):
     1244        if name == 'tlsMode':
     1245            warnings.warn("tlsMode attribute of twisted.mail.ESMTPClient is
     1246                    deprecated since Twisted 12.2",
     1247                    category=DeprecationWarning, stacklevel=2)
     1248
     1249
    12421250    def __init__(self, secret, contextFactory=None, *args, **kw):
    12431251        SMTPClient.__init__(self, *args, **kw)
    12441252        self.authenticators = []