[Python-checkins] r66180 - in python/trunk: Lib/logging/config.py Lib/test/test_logging.py Misc/NEWS

Brett Cannon brett at python.org
Wed Sep 3 21:27:54 CEST 2008


Who did the code review for this?

On Wed, Sep 3, 2008 at 2:20 AM, vinay.sajip <python-checkins at python.org> wrote:
> Author: vinay.sajip
> Date: Wed Sep  3 11:20:05 2008
> New Revision: 66180
>
> Log:
> Issue #3726: Allowed spaces in separators in logging configuration files.
>
> Modified:
>   python/trunk/Lib/logging/config.py
>   python/trunk/Lib/test/test_logging.py
>   python/trunk/Misc/NEWS
>
> Modified: python/trunk/Lib/logging/config.py
> ==============================================================================
> --- python/trunk/Lib/logging/config.py  (original)
> +++ python/trunk/Lib/logging/config.py  Wed Sep  3 11:20:05 2008
> @@ -22,7 +22,7 @@
>  Should work under Python versions >= 1.5.2, except that source line
>  information is not available unless 'sys._getframe()' is.
>
> -Copyright (C) 2001-2007 Vinay Sajip. All Rights Reserved.
> +Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.
>
>  To use, simply 'import logging' and log away!
>  """
> @@ -101,6 +101,8 @@
>             found = getattr(found, n)
>     return found
>
> +def _strip_spaces(alist):
> +    return map(lambda x: string.strip(x), alist)
>
>  def _create_formatters(cp):
>     """Create and return formatters"""
> @@ -108,9 +110,10 @@
>     if not len(flist):
>         return {}
>     flist = string.split(flist, ",")
> +    flist = _strip_spaces(flist)
>     formatters = {}
>     for form in flist:
> -        sectname = "formatter_%s" % string.strip(form)
> +        sectname = "formatter_%s" % form
>         opts = cp.options(sectname)
>         if "format" in opts:
>             fs = cp.get(sectname, "format", 1)
> @@ -136,10 +139,11 @@
>     if not len(hlist):
>         return {}
>     hlist = string.split(hlist, ",")
> +    hlist = _strip_spaces(hlist)
>     handlers = {}
>     fixups = [] #for inter-handler references
>     for hand in hlist:
> -        sectname = "handler_%s" % string.strip(hand)
> +        sectname = "handler_%s" % hand
>         klass = cp.get(sectname, "class")
>         opts = cp.options(sectname)
>         if "formatter" in opts:
> @@ -192,8 +196,9 @@
>     hlist = cp.get(sectname, "handlers")
>     if len(hlist):
>         hlist = string.split(hlist, ",")
> +        hlist = _strip_spaces(hlist)
>         for hand in hlist:
> -            log.addHandler(handlers[string.strip(hand)])
> +            log.addHandler(handlers[hand])
>
>     #and now the others...
>     #we don't want to lose the existing loggers,
> @@ -243,8 +248,9 @@
>         hlist = cp.get(sectname, "handlers")
>         if len(hlist):
>             hlist = string.split(hlist, ",")
> +            hlist = _strip_spaces(hlist)
>             for hand in hlist:
> -                logger.addHandler(handlers[string.strip(hand)])
> +                logger.addHandler(handlers[hand])
>
>     #Disable any old loggers. There's no point deleting
>     #them as other threads may continue to hold references
>
> Modified: python/trunk/Lib/test/test_logging.py
> ==============================================================================
> --- python/trunk/Lib/test/test_logging.py       (original)
> +++ python/trunk/Lib/test/test_logging.py       Wed Sep  3 11:20:05 2008
> @@ -587,6 +587,48 @@
>     # config5 specifies a custom handler class to be loaded
>     config5 = config1.replace('class=StreamHandler', 'class=logging.StreamHandler')
>
> +    # config6 uses ', ' delimiters in the handlers and formatters sections
> +    config6 = """
> +    [loggers]
> +    keys=root,parser
> +
> +    [handlers]
> +    keys=hand1, hand2
> +
> +    [formatters]
> +    keys=form1, form2
> +
> +    [logger_root]
> +    level=WARNING
> +    handlers=
> +
> +    [logger_parser]
> +    level=DEBUG
> +    handlers=hand1
> +    propagate=1
> +    qualname=compiler.parser
> +
> +    [handler_hand1]
> +    class=StreamHandler
> +    level=NOTSET
> +    formatter=form1
> +    args=(sys.stdout,)
> +
> +    [handler_hand2]
> +    class=FileHandler
> +    level=NOTSET
> +    formatter=form1
> +    args=('test.blah', 'a')
> +
> +    [formatter_form1]
> +    format=%(levelname)s ++ %(message)s
> +    datefmt=
> +
> +    [formatter_form2]
> +    format=%(message)s
> +    datefmt=
> +    """
> +
>     def apply_config(self, conf):
>         try:
>             fn = tempfile.mktemp(".ini")
> @@ -653,6 +695,9 @@
>     def test_config5_ok(self):
>         self.test_config1_ok(config=self.config5)
>
> +    def test_config6_ok(self):
> +        self.test_config1_ok(config=self.config6)
> +
>  class LogRecordStreamHandler(StreamRequestHandler):
>
>     """Handler for a streaming logging request. It saves the log message in the
>
> Modified: python/trunk/Misc/NEWS
> ==============================================================================
> --- python/trunk/Misc/NEWS      (original)
> +++ python/trunk/Misc/NEWS      Wed Sep  3 11:20:05 2008
> @@ -56,6 +56,8 @@
>  Library
>  -------
>
> +- Issue #3726: Allowed spaces in separators in logging configuration files.
> +
>  - Issue #3719: platform.architecture() fails if there are spaces in the
>   path to the Python binary.
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>


More information about the Python-checkins mailing list