[Python-checkins] cpython (merge 3.2 -> default): Merged fix for issue #12168 from 3.2.

vinay.sajip python-checkins at python.org
Thu Jun 9 17:55:55 CEST 2011


http://hg.python.org/cpython/rev/ac1217099b3f
changeset:   70740:ac1217099b3f
parent:      70737:7f218ed216e2
parent:      70739:260b84851d1f
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Thu Jun 09 16:55:23 2011 +0100
summary:
  Merged fix for issue #12168 from 3.2.

files:
  Lib/logging/handlers.py  |  6 +++++-
  Lib/test/test_logging.py |  8 ++++++--
  Misc/NEWS                |  3 +++
  3 files changed, 14 insertions(+), 3 deletions(-)


diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -769,6 +769,8 @@
         """
         return self.priority_map.get(levelName, "warning")
 
+    append_nul = True   # some old syslog daemons expect a NUL terminator
+
     def emit(self, record):
         """
         Emit a record.
@@ -776,7 +778,9 @@
         The record is formatted, and then sent to the syslog server. If
         exception information is present, it is NOT sent to the server.
         """
-        msg = self.format(record) + '\000'
+        msg = self.format(record)
+        if self.append_nul:
+            msg += '\000'
         """
         We need to convert record level to lowercase, maybe this will
         change in the future.
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -1399,8 +1399,7 @@
         pointing to that server's address and port."""
         BaseTest.setUp(self)
         addr = ('localhost', 0)
-        self.server = server = TestUDPServer(addr, self.handle_datagram,
-                                                0.01)
+        self.server = server = TestUDPServer(addr, self.handle_datagram, 0.01)
         server.start()
         server.ready.wait()
         self.sock_hdlr = logging.handlers.DatagramHandler('localhost',
@@ -1478,6 +1477,11 @@
         logger.error("sp\xe4m")
         self.handled.wait()
         self.assertEqual(self.log_output, b'<11>\xef\xbb\xbfsp\xc3\xa4m\x00')
+        self.handled.clear()
+        self.sl_hdlr.append_nul = False
+        logger.error("sp\xe4m")
+        self.handled.wait()
+        self.assertEqual(self.log_output, b'<11>\xef\xbb\xbfsp\xc3\xa4m')
 
 
 @unittest.skipUnless(threading, 'Threading required for this test.')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -187,6 +187,9 @@
 Library
 -------
 
+- Issue #12168: SysLogHandler now allows NUL termination to be controlled using
+  a new 'append_nul' attribute on the handler.
+
 - Issue #11583: Speed up os.path.isdir on Windows by using GetFileAttributes
   instead of os.stat.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list