[Python-checkins] r76690 - in python: branches/py3k/Lib/logging/handlers.py branches/py3k/Misc/NEWS trunk/Lib/logging/handlers.py trunk/Misc/NEWS

vinay.sajip python-checkins at python.org
Sun Dec 6 18:57:11 CET 2009


Author: vinay.sajip
Date: Sun Dec  6 18:57:11 2009
New Revision: 76690

Log:
logging: Added optional 'secure' parameter to SMTPHandler.

Modified:
   python/branches/py3k/Lib/logging/handlers.py
   python/branches/py3k/Misc/NEWS
   python/trunk/Lib/logging/handlers.py
   python/trunk/Misc/NEWS

Modified: python/branches/py3k/Lib/logging/handlers.py
==============================================================================
--- python/branches/py3k/Lib/logging/handlers.py	(original)
+++ python/branches/py3k/Lib/logging/handlers.py	Sun Dec  6 18:57:11 2009
@@ -803,7 +803,8 @@
     """
     A handler class which sends an SMTP email for each logging event.
     """
-    def __init__(self, mailhost, fromaddr, toaddrs, subject, credentials=None):
+    def __init__(self, mailhost, fromaddr, toaddrs, subject,
+                 credentials=None, secure=False):
         """
         Initialize the handler.
 
@@ -811,7 +812,9 @@
         line of the email. To specify a non-standard SMTP port, use the
         (host, port) tuple format for the mailhost argument. To specify
         authentication credentials, supply a (username, password) tuple
-        for the credentials argument.
+        for the credentials argument.  To specify the use of a secure
+        protocol (TLS), pass in True for the secure argument. This will
+        only be used when authentication credentials are supplied.
         """
         logging.Handler.__init__(self)
         if isinstance(mailhost, tuple):
@@ -827,6 +830,7 @@
             toaddrs = [toaddrs]
         self.toaddrs = toaddrs
         self.subject = subject
+        self.secure = secure
 
     def getSubject(self, record):
         """
@@ -878,6 +882,10 @@
                             self.getSubject(record),
                             formatdate(), msg)
             if self.username:
+                if self.secure:
+                    smtp.ehlo()
+                    smtp.starttls()
+                    smtp.ehlo()
                 smtp.login(self.username, self.password)
             smtp.sendmail(self.fromaddr, self.toaddrs, msg)
             smtp.quit()

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Dec  6 18:57:11 2009
@@ -154,6 +154,9 @@
 Library
 -------
 
+- logging: Added optional `secure` parameter to SMTPHandler, to enable use of
+  TLS with authentication credentials.
+
 - Issue #1923: Fixed the removal of meaningful spaces when PKG-INFO is 
   generated in Distutils. Patch by Stephen Emslie.
 

Modified: python/trunk/Lib/logging/handlers.py
==============================================================================
--- python/trunk/Lib/logging/handlers.py	(original)
+++ python/trunk/Lib/logging/handlers.py	Sun Dec  6 18:57:11 2009
@@ -809,7 +809,8 @@
     """
     A handler class which sends an SMTP email for each logging event.
     """
-    def __init__(self, mailhost, fromaddr, toaddrs, subject, credentials=None):
+    def __init__(self, mailhost, fromaddr, toaddrs, subject,
+                 credentials=None, secure=False):
         """
         Initialize the handler.
 
@@ -817,7 +818,9 @@
         line of the email. To specify a non-standard SMTP port, use the
         (host, port) tuple format for the mailhost argument. To specify
         authentication credentials, supply a (username, password) tuple
-        for the credentials argument.
+        for the credentials argument. To specify the use of a secure
+        protocol (TLS), pass in True for the secure argument. This will
+        only be used when authentication credentials are supplied.
         """
         logging.Handler.__init__(self)
         if isinstance(mailhost, tuple):
@@ -833,6 +836,7 @@
             toaddrs = [toaddrs]
         self.toaddrs = toaddrs
         self.subject = subject
+        self.secure = secure
 
     def getSubject(self, record):
         """
@@ -884,6 +888,10 @@
                             self.getSubject(record),
                             formatdate(), msg)
             if self.username:
+                if self.secure:
+                    smtp.ehlo()
+                    smtp.starttls()
+                    smtp.ehlo()
                 smtp.login(self.username, self.password)
             smtp.sendmail(self.fromaddr, self.toaddrs, msg)
             smtp.quit()

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Dec  6 18:57:11 2009
@@ -507,6 +507,9 @@
 Library
 -------
 
+- logging: Added optional `secure` parameter to SMTPHandler, to enable use of
+  TLS with authentication credentials.
+
 - Issue #1923: Fixed the removal of meaningful spaces when PKG-INFO is 
   generated in Distutils. Patch by Stephen Emslie.
 


More information about the Python-checkins mailing list