Merged revisions 66141,66145,66150,66180,66211,66217,66219,66226,66231,66244,66246,66249-66250,66264,66268,66272,66294,66306 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66141 | gregory.p.smith | 2008-09-02 00:29:51 -0500 (Tue, 02 Sep 2008) | 3 lines
Issue #3678: Correctly pass LDFLAGS and LDLAST to the linker on shared
library targets in the Makefile.
........
r66145 | marc-andre.lemburg | 2008-09-02 05:32:34 -0500 (Tue, 02 Sep 2008) | 5 lines
Add quotes around the file name to avoid issues with spaces.
Closes #3719.
........
r66150 | marc-andre.lemburg | 2008-09-02 07:11:19 -0500 (Tue, 02 Sep 2008) | 3 lines
Add news item for #3719.
........
r66180 | vinay.sajip | 2008-09-03 04:20:05 -0500 (Wed, 03 Sep 2008) | 1 line
Issue #3726: Allowed spaces in separators in logging configuration files.
........
r66211 | vinay.sajip | 2008-09-04 02:31:21 -0500 (Thu, 04 Sep 2008) | 1 line
Issue #3772: Fixed regression problem in StreamHandler.emit().
........
r66217 | andrew.kuchling | 2008-09-04 08:26:24 -0500 (Thu, 04 Sep 2008) | 1 line
#3671: various corrections and markup fixes noted by Kent Johnson
........
r66219 | hirokazu.yamamoto | 2008-09-04 09:25:30 -0500 (Thu, 04 Sep 2008) | 1 line
Added NEWS
........
r66226 | benjamin.peterson | 2008-09-04 18:31:27 -0500 (Thu, 04 Sep 2008) | 1 line
flesh out the documentation on using 2to3
........
r66231 | andrew.kuchling | 2008-09-05 10:15:56 -0500 (Fri, 05 Sep 2008) | 1 line
#3671: Typo fix
........
r66244 | jesse.noller | 2008-09-05 20:20:11 -0500 (Fri, 05 Sep 2008) | 2 lines
Fix typo in multiprocessing doc, cancel_join_thread was missing _thread
........
r66246 | benjamin.peterson | 2008-09-05 22:00:00 -0500 (Fri, 05 Sep 2008) | 1 line
actually tell the name of the flag to use
........
r66249 | andrew.kuchling | 2008-09-06 07:50:05 -0500 (Sat, 06 Sep 2008) | 1 line
Various corrections
........
r66250 | andrew.kuchling | 2008-09-06 08:04:02 -0500 (Sat, 06 Sep 2008) | 1 line
#3040: include 'dest' argument in example; trim some trailing whitespace
........
r66264 | benjamin.peterson | 2008-09-06 14:42:39 -0500 (Sat, 06 Sep 2008) | 1 line
docs are pretty good about new-style classes these days
........
r66268 | andrew.kuchling | 2008-09-06 15:28:01 -0500 (Sat, 06 Sep 2008) | 1 line
#3669 from Robert Lehmann: simplify use of iterator in example
........
r66272 | andrew.kuchling | 2008-09-06 16:26:02 -0500 (Sat, 06 Sep 2008) | 1 line
#1317: describe the does_esmtp, ehlo_resp, esmtp_features, and helo_resp attributes
........
r66294 | georg.brandl | 2008-09-07 12:00:17 -0500 (Sun, 07 Sep 2008) | 2 lines
Add a new howto about Python and the web, by Marek Kubica.
........
r66306 | mark.summerfield | 2008-09-08 09:45:37 -0500 (Mon, 08 Sep 2008) | 3 lines
Added xrefs to each other.
........
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 552ce18..499c954 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -753,7 +753,7 @@
self.stream.write(fs % msg)
else:
try:
- if hasattr(self.stream, 'encoding'):
+ if getattr(self.stream, 'encoding', None) is not None:
self.stream.write(fs % msg.encode(self.stream.encoding))
else:
self.stream.write(fs % msg)
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index a9a4e62..93d68a3 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -19,7 +19,7 @@
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
by Apache's log4j system.
-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!
"""
@@ -98,6 +98,8 @@
found = getattr(found, n)
return found
+def _strip_spaces(alist):
+ return map(lambda x: x.strip(), alist)
def _create_formatters(cp):
"""Create and return formatters"""
@@ -105,9 +107,10 @@
if not len(flist):
return {}
flist = flist.split(",")
+ flist = _strip_spaces(flist)
formatters = {}
for form in flist:
- sectname = "formatter_%s" % form.strip()
+ sectname = "formatter_%s" % form
opts = cp.options(sectname)
if "format" in opts:
fs = cp.get(sectname, "format", 1)
@@ -133,10 +136,11 @@
if not len(hlist):
return {}
hlist = hlist.split(",")
+ hlist = _strip_spaces(hlist)
handlers = {}
fixups = [] #for inter-handler references
for hand in hlist:
- sectname = "handler_%s" % hand.strip()
+ sectname = "handler_%s" % hand
klass = cp.get(sectname, "class")
opts = cp.options(sectname)
if "formatter" in opts:
@@ -189,8 +193,9 @@
hlist = cp.get(sectname, "handlers")
if len(hlist):
hlist = hlist.split(",")
+ hlist = _strip_spaces(hlist)
for hand in hlist:
- log.addHandler(handlers[hand.strip()])
+ log.addHandler(handlers[hand])
#and now the others...
#we don't want to lose the existing loggers,
@@ -240,8 +245,9 @@
hlist = cp.get(sectname, "handlers")
if len(hlist):
hlist = hlist.split(",")
+ hlist = _strip_spaces(hlist)
for hand in hlist:
- logger.addHandler(handlers[hand.strip()])
+ logger.addHandler(handlers[hand])
#Disable any old loggers. There's no point deleting
#them as other threads may continue to hold references
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 55502d6..75d1366 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -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
@@ -814,6 +859,31 @@
('foo', 'DEBUG', '3'),
])
+class EncodingTest(BaseTest):
+ def test_encoding_plain_file(self):
+ # In Python 2.x, a plain file object is treated as having no encoding.
+ log = logging.getLogger("test")
+ fn = tempfile.mktemp(".log")
+ # the non-ascii data we write to the log.
+ data = "foo\x80"
+ try:
+ handler = logging.FileHandler(fn, encoding="utf8")
+ log.addHandler(handler)
+ try:
+ # write non-ascii data to the log.
+ log.warning(data)
+ finally:
+ log.removeHandler(handler)
+ handler.close()
+ # check we wrote exactly those bytes, ignoring trailing \n etc
+ f = open(fn, encoding="utf8")
+ try:
+ self.failUnlessEqual(f.read().rstrip(), data)
+ finally:
+ f.close()
+ finally:
+ if os.path.isfile(fn):
+ os.remove(fn)
# Set the locale to the platform-dependent default. I have no idea
# why the test does this, but in any case we save the current locale
@@ -822,7 +892,8 @@
def test_main():
run_unittest(BuiltinLevelsTest, BasicFilterTest,
CustomLevelsAndFiltersTest, MemoryHandlerTest,
- ConfigFileTest, SocketHandlerTest, MemoryTest)
+ ConfigFileTest, SocketHandlerTest, MemoryTest,
+ EncodingTest)
if __name__ == "__main__":
test_main()