summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-09-02 00:31:15 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-09-02 00:31:15 (GMT)
commit3e4f055602496a7388058b4d5020b27d9ac7bd4b (patch)
treed9051f212b8f58d3932109e562651cba7dd306cb /Lib
parentd098ff2324398d47863ec9884433f16e8faab62e (diff)
downloadcpython-3e4f055602496a7388058b4d5020b27d9ac7bd4b.zip
cpython-3e4f055602496a7388058b4d5020b27d9ac7bd4b.tar.gz
cpython-3e4f055602496a7388058b4d5020b27d9ac7bd4b.tar.bz2
Merged revisions 66045,66048-66049,66053,66060,66062-66063,66065,66067,66071-66074,66080,66082-66083,66090-66093,66097-66099,66103,66105,66110,66118 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r66045 | andrew.kuchling | 2008-08-26 19:27:18 -0500 (Tue, 26 Aug 2008) | 1 line Trim whitespace; add a few updates ........ r66048 | andrew.kuchling | 2008-08-26 19:45:02 -0500 (Tue, 26 Aug 2008) | 1 line Add an item and a note ........ r66049 | andrew.kuchling | 2008-08-26 21:12:18 -0500 (Tue, 26 Aug 2008) | 1 line Add various items ........ r66053 | georg.brandl | 2008-08-28 04:40:18 -0500 (Thu, 28 Aug 2008) | 2 lines #3711: .dll isn't a valid Python extension anymore. ........ r66060 | armin.rigo | 2008-08-29 16:21:52 -0500 (Fri, 29 Aug 2008) | 3 lines A collection of crashers, all variants of the idea of issue #3720. ........ r66062 | georg.brandl | 2008-08-30 04:49:36 -0500 (Sat, 30 Aug 2008) | 2 lines #3730: mention "server" attribute explicitly. ........ r66063 | georg.brandl | 2008-08-30 04:52:44 -0500 (Sat, 30 Aug 2008) | 2 lines #3716: fix typo. ........ r66065 | georg.brandl | 2008-08-30 05:03:09 -0500 (Sat, 30 Aug 2008) | 2 lines #3569: eval() also accepts "exec"able code objects. ........ r66067 | georg.brandl | 2008-08-30 08:17:39 -0500 (Sat, 30 Aug 2008) | 2 lines super() actually returns a super object. ........ r66071 | andrew.kuchling | 2008-08-30 10:19:57 -0500 (Sat, 30 Aug 2008) | 1 line Partial edits from revision and tidying pass ........ r66072 | andrew.kuchling | 2008-08-30 10:21:23 -0500 (Sat, 30 Aug 2008) | 1 line Tidy up some sentences ........ r66073 | andrew.kuchling | 2008-08-30 10:25:47 -0500 (Sat, 30 Aug 2008) | 1 line Correction from Antoine Pitrou: BufferedWriter and Reader support seek() ........ r66074 | andrew.kuchling | 2008-08-30 11:44:54 -0500 (Sat, 30 Aug 2008) | 1 line Edit four more sections ........ r66080 | georg.brandl | 2008-08-30 17:00:28 -0500 (Sat, 30 Aug 2008) | 2 lines Fix markup. ........ r66082 | andrew.kuchling | 2008-08-30 17:56:54 -0500 (Sat, 30 Aug 2008) | 1 line More edits; markup fixes ........ r66083 | andrew.kuchling | 2008-08-30 21:24:08 -0500 (Sat, 30 Aug 2008) | 1 line More edits ........ r66090 | andrew.kuchling | 2008-08-31 09:29:31 -0500 (Sun, 31 Aug 2008) | 1 line Edit the library section, rearranging items to flow better and making lots of edits ........ r66091 | andrew.kuchling | 2008-08-31 10:41:48 -0500 (Sun, 31 Aug 2008) | 1 line Last batch of edits; remove the 'other changes' section ........ r66092 | andrew.kuchling | 2008-08-31 10:48:44 -0500 (Sun, 31 Aug 2008) | 1 line Update patch/bug count ........ r66093 | gregory.p.smith | 2008-08-31 11:34:18 -0500 (Sun, 31 Aug 2008) | 3 lines issue3715: docstring representation of hex escaped string needs to be double escaped. ........ r66097 | benjamin.peterson | 2008-09-01 09:13:43 -0500 (Mon, 01 Sep 2008) | 4 lines #3703 unhelpful _fileio.FileIO error message when trying to open a directory Reviewer: Gregory P. Smith ........ r66098 | georg.brandl | 2008-09-01 09:15:55 -0500 (Mon, 01 Sep 2008) | 2 lines #3749: fix c'n'p errors. ........ r66099 | benjamin.peterson | 2008-09-01 09:18:30 -0500 (Mon, 01 Sep 2008) | 4 lines Fix compilation when --without-threads is given #3683 Reviewer: Georg Brandl, Benjamin Peterson ........ r66103 | vinay.sajip | 2008-09-01 09:30:10 -0500 (Mon, 01 Sep 2008) | 1 line logging: fixed lack of use of encoding attribute specified on a stream. ........ r66105 | vinay.sajip | 2008-09-01 09:33:59 -0500 (Mon, 01 Sep 2008) | 1 line logging: fixed lack of use of encoding attribute specified on a stream. ........ r66110 | vinay.sajip | 2008-09-01 10:08:07 -0500 (Mon, 01 Sep 2008) | 1 line Added section about configuring logging in a library. Thanks to Thomas Heller for the idea. ........ r66118 | vinay.sajip | 2008-09-01 12:44:14 -0500 (Mon, 01 Sep 2008) | 1 line Bug #3738: Documentation is now more accurate in describing handler close methods. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/logging/__init__.py15
-rw-r--r--Lib/test/crashers/iter.py53
-rw-r--r--Lib/test/test_fileio.py11
3 files changed, 74 insertions, 5 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index bd6c7f2..552ce18 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -715,6 +715,7 @@ class StreamHandler(Handler):
to a stream. Note that this class does not close the stream, as
sys.stdout or sys.stderr may be used.
"""
+
def __init__(self, strm=None):
"""
Initialize the handler.
@@ -739,10 +740,11 @@ class StreamHandler(Handler):
Emit a record.
If a formatter is specified, it is used to format the record.
- The record is then written to the stream with a trailing newline
- [N.B. this may be removed depending on feedback]. If exception
- information is present, it is formatted using
- traceback.print_exception and appended to the stream.
+ The record is then written to the stream with a trailing newline. If
+ exception information is present, it is formatted using
+ traceback.print_exception and appended to the stream. If the stream
+ has an 'encoding' attribute, it is used to encode the message before
+ output to the stream.
"""
try:
msg = self.format(record)
@@ -751,7 +753,10 @@ class StreamHandler(Handler):
self.stream.write(fs % msg)
else:
try:
- self.stream.write(fs % msg)
+ if hasattr(self.stream, 'encoding'):
+ self.stream.write(fs % msg.encode(self.stream.encoding))
+ else:
+ self.stream.write(fs % msg)
except UnicodeError:
self.stream.write(fs % msg.encode("UTF-8"))
self.flush()
diff --git a/Lib/test/crashers/iter.py b/Lib/test/crashers/iter.py
new file mode 100644
index 0000000..081dcbc
--- /dev/null
+++ b/Lib/test/crashers/iter.py
@@ -0,0 +1,53 @@
+# Calls to PyIter_Next, or direct calls to tp_iternext, on an object
+# which might no longer be an iterable because its 'next' method was
+# removed. These are all variants of Issue3720.
+
+"""
+Run this script with an argument between 1 and <N> to test for
+different crashes.
+"""
+N = 8
+
+import sys
+
+class Foo(object):
+ def __iter__(self):
+ return self
+ def next(self):
+ del Foo.next
+ return (1, 2)
+
+def case1():
+ list(enumerate(Foo()))
+
+def case2():
+ x, y = Foo()
+
+def case3():
+ filter(None, Foo())
+
+def case4():
+ map(None, Foo(), Foo())
+
+def case5():
+ max(Foo())
+
+def case6():
+ sum(Foo(), ())
+
+def case7():
+ dict(Foo())
+
+def case8():
+ sys.stdout.writelines(Foo())
+
+# etc...
+
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ print __doc__.replace('<N>', str(N))
+ else:
+ n = int(sys.argv[1])
+ func = globals()['case%d' % n]
+ func()
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index a676bc2..0404a19 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -100,6 +100,17 @@ class AutoFileTests(unittest.TestCase):
# should raise on closed file
self.assertRaises(ValueError, method)
+ def testOpendir(self):
+ # Issue 3703: opening a directory should fill the errno
+ # Windows always returns "[Errno 13]: Permission denied
+ # Unix calls dircheck() and returns "[Errno 21]: Is a directory"
+ try:
+ _fileio._FileIO('.', 'r')
+ except IOError as e:
+ self.assertNotEqual(e.errno, 0)
+ else:
+ self.fail("Should have raised IOError")
+
class OtherFileTests(unittest.TestCase):