]> granicus.if.org Git - python/commitdiff
Issue #8201: logging: Handle config errors when non-ASCII and Unicode logger names...
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 22 Mar 2010 13:02:28 +0000 (13:02 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 22 Mar 2010 13:02:28 +0000 (13:02 +0000)
Lib/logging/config.py
Lib/test/test_logging.py
Misc/NEWS

index 21e10c14f574ef2bd8cb6392d66ed06206bbbd30..4f55c53ead16e408a033b913a12a101cae6d3be3 100644 (file)
@@ -98,6 +98,9 @@ def _resolve(name):
 def _strip_spaces(alist):
     return map(lambda x: x.strip(), alist)
 
+def _encoded(s):
+    return s if isinstance(s, str) else s.encode('utf-8')
+
 def _create_formatters(cp):
     """Create and return formatters"""
     flist = cp.get("formatters", "keys")
@@ -208,7 +211,7 @@ def _install_loggers(cp, handlers, disable_existing_loggers):
     #avoid disabling child loggers of explicitly
     #named loggers. With a sorted list it is easier
     #to find the child loggers.
-    existing.sort()
+    existing.sort(key=_encoded)
     #We'll keep the list of existing loggers
     #which are children of named loggers here...
     child_loggers = []
@@ -580,7 +583,7 @@ class DictConfigurator(BaseConfigurator):
                 #avoid disabling child loggers of explicitly
                 #named loggers. With a sorted list it is easier
                 #to find the child loggers.
-                existing.sort()
+                existing.sort(key=_encoded)
                 #We'll keep the list of existing loggers
                 #which are children of named loggers here...
                 child_loggers = []
index e3b9718d03e7f4c2c8a18a3317377cd3cb463601..a918d6eca7073aaef2e6e39af07621d28f75dd60 100644 (file)
@@ -68,6 +68,12 @@ class BaseTest(unittest.TestCase):
         finally:
             logging._releaseLock()
 
+        # Set two unused loggers: one non-ASCII and one Unicode.
+        # This is to test correct operation when sorting existing
+        # loggers in the configuration code. See issue 8201.
+        logging.getLogger("\xab\xd7\xbb")
+        logging.getLogger(u"\u013f\u00d6\u0047")
+
         self.root_logger = logging.getLogger("")
         self.original_logging_level = self.root_logger.getEffectiveLevel()
 
index 385e341939ff093de59a364bad18b2a564ca1028..3450d29bb8dced6f69d075a97012ec1c5460f48c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #8201: logging: Handle situation of non-ASCII and Unicode
+  logger names existing at the same time, causing a Unicode error
+  when configuration code attempted to sort the existing loggers.
+
 - Issue #8200: logging: Handle errors when multiprocessing is not
   fully loaded when logging occurs.