Python-checkins
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
December 2009
- 12 participants
- 629 discussions
Dec. 31, 2009
Author: ezio.melotti
Date: Thu Dec 31 14:22:41 2009
New Revision: 77179
Log:
Merged revisions 77178 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77178 | ezio.melotti | 2009-12-31 15:00:43 +0200 (Thu, 31 Dec 2009) | 1 line
cleanup and refactoring
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_zipfile.py
Modified: python/branches/py3k/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_zipfile.py (original)
+++ python/branches/py3k/Lib/test/test_zipfile.py Thu Dec 31 14:22:41 2009
@@ -6,6 +6,7 @@
import io
import os
+import time
import shutil
import struct
import zipfile
@@ -36,9 +37,8 @@
self.data = b'\n'.join(self.line_gen) + b'\n'
# Make a source file with some lines
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
def make_test_archive(self, f, compression):
# Create the ZIP archive
@@ -61,39 +61,40 @@
zipfp.printdir(file=fp)
directory = fp.getvalue()
lines = directory.splitlines()
- self.assertEquals(len(lines), 4) # Number of files + header
+ self.assertEqual(len(lines), 4) # Number of files + header
self.assertTrue('File Name' in lines[0])
self.assertTrue('Modified' in lines[0])
self.assertTrue('Size' in lines[0])
- fn, date, time, size = lines[1].split()
- self.assertEquals(fn, 'another.name')
- # XXX: timestamp is not tested
- self.assertEquals(size, str(len(self.data)))
+ fn, date, time_, size = lines[1].split()
+ self.assertEqual(fn, 'another.name')
+ self.assertTrue(time.strptime(date, '%Y-%m-%d'))
+ self.assertTrue(time.strptime(time_, '%H:%M:%S'))
+ self.assertEqual(size, str(len(self.data)))
# Check the namelist
names = zipfp.namelist()
- self.assertEquals(len(names), 3)
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
# Check infolist
infos = zipfp.infolist()
- names = [ i.filename for i in infos ]
- self.assertEquals(len(names), 3)
+ names = [i.filename for i in infos]
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
for i in infos:
- self.assertEquals(i.file_size, len(self.data))
+ self.assertEqual(i.file_size, len(self.data))
# check getinfo
for nm in (TESTFN, "another.name", "strfile"):
info = zipfp.getinfo(nm)
- self.assertEquals(info.filename, nm)
- self.assertEquals(info.file_size, len(self.data))
+ self.assertEqual(info.filename, nm)
+ self.assertEqual(info.file_size, len(self.data))
# Check that testzip doesn't raise an exception
zipfp.testzip()
@@ -239,7 +240,7 @@
@skipUnless(zlib, "requires zlib")
def test_low_compression(self):
- # Checks for cases where compressed data is larger than original
+ """Check for cases where compressed data is larger than original."""
# Create the ZIP archive
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED) as zipfp:
zipfp.writestr("strfile", '12')
@@ -258,7 +259,7 @@
self.assertEqual(zipfp.namelist(), ["absolute"])
def test_append_to_zip_file(self):
- # Test appending to an existing zipfile
+ """Test appending to an existing zipfile."""
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
zipfp.write(TESTFN, TESTFN)
@@ -267,30 +268,32 @@
self.assertEqual(zipfp.namelist(), [TESTFN, "strfile"])
def test_append_to_non_zip_file(self):
- # Test appending to an existing file that is not a zipfile
+ """Test appending to an existing file that is not a zipfile."""
# NOTE: this test fails if len(d) < 22 because of the first
# line "fpin.seek(-22, 2)" in _EndRecData
- d = b'I am not a ZipFile!'*10
- f = open(TESTFN2, 'wb')
- f.write(d)
- f.close()
+ data = b'I am not a ZipFile!'*10
+ with open(TESTFN2, 'wb') as f:
+ f.write(data)
+
with zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED) as zipfp:
zipfp.write(TESTFN, TESTFN)
- f = open(TESTFN2, 'rb')
- f.seek(len(d))
- with zipfile.ZipFile(f, "r") as zipfp:
- self.assertEqual(zipfp.namelist(), [TESTFN])
+ with open(TESTFN2, 'rb') as f:
+ f.seek(len(data))
+ with zipfile.ZipFile(f, "r") as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
def test_write_default_name(self):
- # Check that calling ZipFile.write without arcname specified produces the expected result
+ """Check that calling ZipFile.write without arcname specified
+ produces the expected result."""
with zipfile.ZipFile(TESTFN2, "w") as zipfp:
zipfp.write(TESTFN)
self.assertEqual(zipfp.read(TESTFN), open(TESTFN, "rb").read())
@skipUnless(zlib, "requires zlib")
def test_per_file_compression(self):
- # Check that files within a Zip archive can have different compression options
+ """Check that files within a Zip archive can have different
+ compression options."""
with zipfile.ZipFile(TESTFN2, "w") as zipfp:
zipfp.write(TESTFN, 'storeme', zipfile.ZIP_STORED)
zipfp.write(TESTFN, 'deflateme', zipfile.ZIP_DEFLATED)
@@ -300,8 +303,8 @@
self.assertEqual(dinfo.compress_type, zipfile.ZIP_DEFLATED)
def test_write_to_readonly(self):
- # Check that trying to call write() on a readonly ZipFile object
- # raises a RuntimeError
+ """Check that trying to call write() on a readonly ZipFile object
+ raises a RuntimeError."""
with zipfile.ZipFile(TESTFN2, mode="w") as zipfp:
zipfp.writestr("somefile.txt", "bogus")
@@ -417,19 +420,18 @@
self.data = b'\n'.join(line_gen)
# Make a source file with some lines
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
def large_file_exception_test(self, f, compression):
with zipfile.ZipFile(f, "w", compression) as zipfp:
self.assertRaises(zipfile.LargeZipFile,
- zipfp.write, TESTFN, "another.name")
+ zipfp.write, TESTFN, "another.name")
def large_file_exception_test2(self, f, compression):
with zipfile.ZipFile(f, "w", compression) as zipfp:
self.assertRaises(zipfile.LargeZipFile,
- zipfp.writestr, "another.name", self.data)
+ zipfp.writestr, "another.name", self.data)
def test_large_file_exception(self):
for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
@@ -455,39 +457,40 @@
directory = fp.getvalue()
lines = directory.splitlines()
- self.assertEquals(len(lines), 4) # Number of files + header
+ self.assertEqual(len(lines), 4) # Number of files + header
self.assertTrue('File Name' in lines[0])
self.assertTrue('Modified' in lines[0])
self.assertTrue('Size' in lines[0])
- fn, date, time, size = lines[1].split()
- self.assertEquals(fn, 'another.name')
- # XXX: timestamp is not tested
- self.assertEquals(size, str(len(self.data)))
+ fn, date, time_, size = lines[1].split()
+ self.assertEqual(fn, 'another.name')
+ self.assertTrue(time.strptime(date, '%Y-%m-%d'))
+ self.assertTrue(time.strptime(time_, '%H:%M:%S'))
+ self.assertEqual(size, str(len(self.data)))
# Check the namelist
names = zipfp.namelist()
- self.assertEquals(len(names), 3)
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
# Check infolist
infos = zipfp.infolist()
- names = [ i.filename for i in infos ]
- self.assertEquals(len(names), 3)
+ names = [i.filename for i in infos]
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
for i in infos:
- self.assertEquals(i.file_size, len(self.data))
+ self.assertEqual(i.file_size, len(self.data))
# check getinfo
for nm in (TESTFN, "another.name", "strfile"):
info = zipfp.getinfo(nm)
- self.assertEquals(info.filename, nm)
- self.assertEquals(info.file_size, len(self.data))
+ self.assertEqual(info.filename, nm)
+ self.assertEqual(info.file_size, len(self.data))
# Check that testzip doesn't raise an exception
zipfp.testzip()
@@ -531,12 +534,12 @@
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
fn = __file__
- if fn.endswith('.pyc') or fn.endswith('.pyo'):
+ if fn.endswith(('.pyc', '.pyo')):
fn = fn[:-1]
zipfp.writepy(fn, "testpackage")
- bn = "%s/%s"%("testpackage", os.path.basename(fn))
+ bn = "%s/%s" % ("testpackage", os.path.basename(fn))
self.assertTrue(bn not in zipfp.namelist())
self.assertTrue(bn + 'o' in zipfp.namelist() or
bn + 'c' in zipfp.namelist())
@@ -548,7 +551,8 @@
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
zipfp.writepy(packagedir)
- # Check for a couple of modules at different levels of the hieararchy
+ # Check for a couple of modules at different levels of the
+ # hierarchy
names = zipfp.namelist()
self.assertTrue('email/__init__.pyo' in names or
'email/__init__.pyc' in names)
@@ -558,17 +562,14 @@
def test_write_python_directory(self):
os.mkdir(TESTFN2)
try:
- fp = open(os.path.join(TESTFN2, "mod1.py"), "w")
- fp.write("print(42)\n")
- fp.close()
-
- fp = open(os.path.join(TESTFN2, "mod2.py"), "w")
- fp.write("print(42 * 42)\n")
- fp.close()
-
- fp = open(os.path.join(TESTFN2, "mod2.txt"), "w")
- fp.write("bla bla bla\n")
- fp.close()
+ with open(os.path.join(TESTFN2, "mod1.py"), "w") as fp:
+ fp.write("print(42)\n")
+
+ with open(os.path.join(TESTFN2, "mod2.py"), "w") as fp:
+ fp.write("print(42 * 42)\n")
+
+ with open(os.path.join(TESTFN2, "mod2.txt"), "w") as fp:
+ fp.write("bla bla bla\n")
zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
zipfp.writepy(TESTFN2)
@@ -619,28 +620,26 @@
def test_close_erroneous_file(self):
# This test checks that the ZipFile constructor closes the file object
- # it opens if there's an error in the file. If it doesn't, the traceback
- # holds a reference to the ZipFile object and, indirectly, the file object.
+ # it opens if there's an error in the file. If it doesn't, the
+ # traceback holds a reference to the ZipFile object and, indirectly,
+ # the file object.
# On Windows, this causes the os.unlink() call to fail because the
# underlying file is still open. This is SF bug #412214.
#
- fp = open(TESTFN, "w")
- fp.write("this is not a legal zip file\n")
- fp.close()
+ with open(TESTFN, "w") as fp:
+ fp.write("this is not a legal zip file\n")
try:
zf = zipfile.ZipFile(TESTFN)
except zipfile.BadZipfile:
pass
def test_is_zip_erroneous_file(self):
- # This test checks that the is_zipfile function correctly identifies
- # a file that is not a zip file
-
+ """Check that is_zipfile() correctly identifies non-zip files."""
# - passing a filename
with open(TESTFN, "w") as fp:
fp.write("this is not a legal zip file\n")
chk = zipfile.is_zipfile(TESTFN)
- self.assertTrue(not chk)
+ self.assertFalse(chk)
# - passing a file object
with open(TESTFN, "rb") as fp:
chk = zipfile.is_zipfile(fp)
@@ -650,14 +649,12 @@
fp.write(b"this is not a legal zip file\n")
chk = zipfile.is_zipfile(fp)
self.assertTrue(not chk)
- fp.seek(0,0)
+ fp.seek(0, 0)
chk = zipfile.is_zipfile(fp)
self.assertTrue(not chk)
def test_is_zip_valid_file(self):
- # This test checks that the is_zipfile function correctly identifies
- # a file that is a zip file
-
+ """Check that is_zipfile() correctly identifies zip files."""
# - passing a filename
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", b"O, for a Muse of Fire!")
@@ -668,14 +665,14 @@
with open(TESTFN, "rb") as fp:
chk = zipfile.is_zipfile(fp)
self.assertTrue(chk)
- fp.seek(0,0)
+ fp.seek(0, 0)
zip_contents = fp.read()
# - passing a file-like object
fp = io.BytesIO()
fp.write(zip_contents)
chk = zipfile.is_zipfile(fp)
self.assertTrue(chk)
- fp.seek(0,0)
+ fp.seek(0, 0)
chk = zipfile.is_zipfile(fp)
self.assertTrue(chk)
@@ -698,13 +695,12 @@
f.close()
self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
- f = open(TESTFN, 'w')
- f.write("short file")
- f.close()
+ with open(TESTFN, 'w') as fp:
+ fp.write("short file")
self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
def test_closed_zip_raises_RuntimeError(self):
- # Verify that testzip() doesn't swallow inappropriate exceptions.
+ """Verify that testzip() doesn't swallow inappropriate exceptions."""
data = io.BytesIO()
with zipfile.ZipFile(data, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
@@ -721,11 +717,11 @@
self.assertRaises(RuntimeError, zipf.write, TESTFN)
def test_bad_constructor_mode(self):
- # Check that bad modes passed to ZipFile constructor are caught
+ """Check that bad modes passed to ZipFile constructor are caught."""
self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "q")
def test_bad_open_mode(self):
- # Check that bad modes passed to ZipFile.open are caught
+ """Check that bad modes passed to ZipFile.open are caught."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
@@ -735,8 +731,8 @@
self.assertRaises(RuntimeError, zipf.open, "foo.txt", "q")
def test_read0(self):
- # Check that calling read(0) on a ZipExtFile object returns an empty
- # string and doesn't advance file pointer
+ """Check that calling read(0) on a ZipExtFile object returns an empty
+ string and doesn't advance file pointer."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
# read the data to make sure the file is there
@@ -747,30 +743,32 @@
self.assertEqual(f.read(), b"O, for a Muse of Fire!")
def test_open_non_existent_item(self):
- # Check that attempting to call open() for an item that doesn't
- # exist in the archive raises a RuntimeError
+ """Check that attempting to call open() for an item that doesn't
+ exist in the archive raises a RuntimeError."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
self.assertRaises(KeyError, zipf.open, "foo.txt", "r")
def test_bad_compression_mode(self):
- # Check that bad compression methods passed to ZipFile.open are caught
+ """Check that bad compression methods passed to ZipFile.open are
+ caught."""
self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "w", -1)
def test_null_byte_in_filename(self):
- # Check that a filename containing a null byte is properly terminated
+ """Check that a filename containing a null byte is properly
+ terminated."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt\x00qqq", b"O, for a Muse of Fire!")
self.assertEqual(zipf.namelist(), ['foo.txt'])
def test_struct_sizes(self):
- # check that ZIP internal structure sizes are calculated correctly
+ """Check that ZIP internal structure sizes are calculated correctly."""
self.assertEqual(zipfile.sizeEndCentDir, 22)
self.assertEqual(zipfile.sizeCentralDir, 46)
self.assertEqual(zipfile.sizeEndCentDir64, 56)
self.assertEqual(zipfile.sizeEndCentDir64Locator, 20)
def test_comments(self):
- # This test checks that comments on the archive are handled properly
+ """Check that comments on the archive are handled properly."""
# check default comment is empty
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
@@ -811,9 +809,9 @@
class DecryptionTests(unittest.TestCase):
- # This test checks that ZIP decryption works. Since the library does not
- # support encryption at the moment, we use a pre-generated encrypted
- # ZIP file
+ """Check that ZIP decryption works. Since the library does not
+ support encryption at the moment, we use a pre-generated encrypted
+ ZIP file."""
data = (
b'PK\x03\x04\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00\x1a\x00'
@@ -837,13 +835,11 @@
plain2 = b'\x00'*512
def setUp(self):
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
self.zip = zipfile.ZipFile(TESTFN, "r")
- fp = open(TESTFN2, "wb")
- fp.write(self.data2)
- fp.close()
+ with open(TESTFN2, "wb") as fp:
+ fp.write(self.data2)
self.zip2 = zipfile.ZipFile(TESTFN2, "r")
def tearDown(self):
@@ -867,9 +863,9 @@
@skipUnless(zlib, "requires zlib")
def test_good_password(self):
self.zip.setpassword(b"python")
- self.assertEquals(self.zip.read("test.txt"), self.plain)
+ self.assertEqual(self.zip.read("test.txt"), self.plain)
self.zip2.setpassword(b"12345")
- self.assertEquals(self.zip2.read("zero"), self.plain2)
+ self.assertEqual(self.zip2.read("zero"), self.plain2)
class TestsWithRandomBinaryFiles(unittest.TestCase):
@@ -879,9 +875,8 @@
for i in range(datacount))
# Make a source file with some lines
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
def tearDown(self):
unlink(TESTFN)
@@ -933,8 +928,8 @@
self.assertEqual(testdata1, self.data)
testdata2 = b''.join(zipdata2)
- self.assertEqual(len(testdata1), len(self.data))
- self.assertEqual(testdata1, self.data)
+ self.assertEqual(len(testdata2), len(self.data))
+ self.assertEqual(testdata2, self.data)
def test_open_stored(self):
for f in (TESTFN2, TemporaryFile(), io.BytesIO()):
1
0
Author: ezio.melotti
Date: Thu Dec 31 14:00:43 2009
New Revision: 77178
Log:
cleanup and refactoring
Modified:
python/trunk/Lib/test/test_zipfile.py
Modified: python/trunk/Lib/test/test_zipfile.py
==============================================================================
--- python/trunk/Lib/test/test_zipfile.py (original)
+++ python/trunk/Lib/test/test_zipfile.py Thu Dec 31 14:00:43 2009
@@ -6,6 +6,7 @@
import os
import sys
+import time
import shutil
import struct
import zipfile
@@ -31,18 +32,17 @@
class TestsWithSourceFile(unittest.TestCase):
def setUp(self):
self.line_gen = ["Zipfile test line %d. random float: %f" % (i, random())
- for i in xrange(FIXEDTEST_SIZE)]
+ for i in xrange(FIXEDTEST_SIZE)]
self.data = '\n'.join(self.line_gen) + '\n'
# Make a source file with some lines
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
def make_test_archive(self, f, compression):
# Create the ZIP archive
with zipfile.ZipFile(f, "w", compression) as zipfp:
- zipfp.write(TESTFN, "another"+os.extsep+"name")
+ zipfp.write(TESTFN, "another.name")
zipfp.write(TESTFN, TESTFN)
zipfp.writestr("strfile", self.data)
@@ -52,7 +52,7 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
self.assertEqual(zipfp.read(TESTFN), self.data)
- self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data)
+ self.assertEqual(zipfp.read("another.name"), self.data)
self.assertEqual(zipfp.read("strfile"), self.data)
# Print the ZIP directory
@@ -66,39 +66,40 @@
directory = fp.getvalue()
lines = directory.splitlines()
- self.assertEquals(len(lines), 4) # Number of files + header
+ self.assertEqual(len(lines), 4) # Number of files + header
self.assertTrue('File Name' in lines[0])
self.assertTrue('Modified' in lines[0])
self.assertTrue('Size' in lines[0])
- fn, date, time, size = lines[1].split()
- self.assertEquals(fn, 'another.name')
- # XXX: timestamp is not tested
- self.assertEquals(size, str(len(self.data)))
+ fn, date, time_, size = lines[1].split()
+ self.assertEqual(fn, 'another.name')
+ self.assertTrue(time.strptime(date, '%Y-%m-%d'))
+ self.assertTrue(time.strptime(time_, '%H:%M:%S'))
+ self.assertEqual(size, str(len(self.data)))
# Check the namelist
names = zipfp.namelist()
- self.assertEquals(len(names), 3)
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
- self.assertTrue("another"+os.extsep+"name" in names)
+ self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
# Check infolist
infos = zipfp.infolist()
- names = [ i.filename for i in infos ]
- self.assertEquals(len(names), 3)
+ names = [i.filename for i in infos]
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
- self.assertTrue("another"+os.extsep+"name" in names)
+ self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
for i in infos:
- self.assertEquals(i.file_size, len(self.data))
+ self.assertEqual(i.file_size, len(self.data))
# check getinfo
- for nm in (TESTFN, "another"+os.extsep+"name", "strfile"):
+ for nm in (TESTFN, "another.name", "strfile"):
info = zipfp.getinfo(nm)
- self.assertEquals(info.filename, nm)
- self.assertEquals(info.file_size, len(self.data))
+ self.assertEqual(info.filename, nm)
+ self.assertEqual(info.file_size, len(self.data))
# Check that testzip doesn't raise an exception
zipfp.testzip()
@@ -121,7 +122,7 @@
zipdata1.append(read_data)
zipdata2 = []
- zipopen2 = zipfp.open("another"+os.extsep+"name")
+ zipopen2 = zipfp.open("another.name")
while True:
read_data = zipopen2.read(256)
if not read_data:
@@ -242,7 +243,7 @@
@skipUnless(zlib, "requires zlib")
def test_low_compression(self):
- # Checks for cases where compressed data is larger than original
+ """Check for cases where compressed data is larger than original."""
# Create the ZIP archive
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_DEFLATED) as zipfp:
zipfp.writestr("strfile", '12')
@@ -261,7 +262,7 @@
self.assertEqual(zipfp.namelist(), ["absolute"])
def test_append_to_zip_file(self):
- # Test appending to an existing zipfile
+ """Test appending to an existing zipfile."""
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
zipfp.write(TESTFN, TESTFN)
@@ -270,31 +271,32 @@
self.assertEqual(zipfp.namelist(), [TESTFN, "strfile"])
def test_append_to_non_zip_file(self):
- # Test appending to an existing file that is not a zipfile
+ """Test appending to an existing file that is not a zipfile."""
# NOTE: this test fails if len(d) < 22 because of the first
# line "fpin.seek(-22, 2)" in _EndRecData
- d = 'I am not a ZipFile!'*10
- f = file(TESTFN2, 'wb')
- f.write(d)
- f.close()
+ data = 'I am not a ZipFile!'*10
+ with open(TESTFN2, 'wb') as f:
+ f.write(data)
+
with zipfile.ZipFile(TESTFN2, "a", zipfile.ZIP_STORED) as zipfp:
zipfp.write(TESTFN, TESTFN)
- f = file(TESTFN2, 'rb')
- f.seek(len(d))
- with zipfile.ZipFile(f, "r") as zipfp:
- self.assertEqual(zipfp.namelist(), [TESTFN])
- f.close()
+ with open(TESTFN2, 'rb') as f:
+ f.seek(len(data))
+ with zipfile.ZipFile(f, "r") as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
def test_write_default_name(self):
- # Check that calling ZipFile.write without arcname specified produces the expected result
+ """Check that calling ZipFile.write without arcname specified
+ produces the expected result."""
with zipfile.ZipFile(TESTFN2, "w") as zipfp:
zipfp.write(TESTFN)
- self.assertEqual(zipfp.read(TESTFN), file(TESTFN).read())
+ self.assertEqual(zipfp.read(TESTFN), open(TESTFN).read())
@skipUnless(zlib, "requires zlib")
def test_per_file_compression(self):
- # Check that files within a Zip archive can have different compression options
+ """Check that files within a Zip archive can have different
+ compression options."""
with zipfile.ZipFile(TESTFN2, "w") as zipfp:
zipfp.write(TESTFN, 'storeme', zipfile.ZIP_STORED)
zipfp.write(TESTFN, 'deflateme', zipfile.ZIP_DEFLATED)
@@ -304,8 +306,8 @@
self.assertEqual(dinfo.compress_type, zipfile.ZIP_DEFLATED)
def test_write_to_readonly(self):
- # Check that trying to call write() on a readonly ZipFile object
- # raises a RuntimeError
+ """Check that trying to call write() on a readonly ZipFile object
+ raises a RuntimeError."""
with zipfile.ZipFile(TESTFN2, mode="w") as zipfp:
zipfp.writestr("somefile.txt", "bogus")
@@ -331,8 +333,7 @@
self.assertEqual(writtenfile, correctfile)
# make sure correct data is in correct file
- self.assertEqual(fdata, file(writtenfile, "rb").read())
-
+ self.assertEqual(fdata, open(writtenfile, "rb").read())
os.remove(writtenfile)
# remove the test file subdirectories
@@ -351,8 +352,7 @@
else:
outfile = os.path.join(os.getcwd(), fpath)
- self.assertEqual(fdata, file(outfile, "rb").read())
-
+ self.assertEqual(fdata, open(outfile, "rb").read())
os.remove(outfile)
# remove the test file subdirectories
@@ -409,23 +409,23 @@
self._limit = zipfile.ZIP64_LIMIT
zipfile.ZIP64_LIMIT = 5
- line_gen = ("Test of zipfile line %d." % i for i in range(0, FIXEDTEST_SIZE))
+ line_gen = ("Test of zipfile line %d." % i
+ for i in range(0, FIXEDTEST_SIZE))
self.data = '\n'.join(line_gen)
# Make a source file with some lines
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
def large_file_exception_test(self, f, compression):
with zipfile.ZipFile(f, "w", compression) as zipfp:
self.assertRaises(zipfile.LargeZipFile,
- zipfp.write, TESTFN, "another"+os.extsep+"name")
+ zipfp.write, TESTFN, "another.name")
def large_file_exception_test2(self, f, compression):
with zipfile.ZipFile(f, "w", compression) as zipfp:
self.assertRaises(zipfile.LargeZipFile,
- zipfp.writestr, "another"+os.extsep+"name", self.data)
+ zipfp.writestr, "another.name", self.data)
def test_large_file_exception(self):
for f in (TESTFN2, TemporaryFile(), StringIO()):
@@ -435,14 +435,14 @@
def zip_test(self, f, compression):
# Create the ZIP archive
with zipfile.ZipFile(f, "w", compression, allowZip64=True) as zipfp:
- zipfp.write(TESTFN, "another"+os.extsep+"name")
+ zipfp.write(TESTFN, "another.name")
zipfp.write(TESTFN, TESTFN)
zipfp.writestr("strfile", self.data)
# Read the ZIP archive
with zipfile.ZipFile(f, "r", compression) as zipfp:
self.assertEqual(zipfp.read(TESTFN), self.data)
- self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data)
+ self.assertEqual(zipfp.read("another.name"), self.data)
self.assertEqual(zipfp.read("strfile"), self.data)
# Print the ZIP directory
@@ -456,39 +456,40 @@
directory = fp.getvalue()
lines = directory.splitlines()
- self.assertEquals(len(lines), 4) # Number of files + header
+ self.assertEqual(len(lines), 4) # Number of files + header
self.assertTrue('File Name' in lines[0])
self.assertTrue('Modified' in lines[0])
self.assertTrue('Size' in lines[0])
- fn, date, time, size = lines[1].split()
- self.assertEquals(fn, 'another.name')
- # XXX: timestamp is not tested
- self.assertEquals(size, str(len(self.data)))
+ fn, date, time_, size = lines[1].split()
+ self.assertEqual(fn, 'another.name')
+ self.assertTrue(time.strptime(date, '%Y-%m-%d'))
+ self.assertTrue(time.strptime(time_, '%H:%M:%S'))
+ self.assertEqual(size, str(len(self.data)))
# Check the namelist
names = zipfp.namelist()
- self.assertEquals(len(names), 3)
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
- self.assertTrue("another"+os.extsep+"name" in names)
+ self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
# Check infolist
infos = zipfp.infolist()
- names = [ i.filename for i in infos ]
- self.assertEquals(len(names), 3)
+ names = [i.filename for i in infos]
+ self.assertEqual(len(names), 3)
self.assertTrue(TESTFN in names)
- self.assertTrue("another"+os.extsep+"name" in names)
+ self.assertTrue("another.name" in names)
self.assertTrue("strfile" in names)
for i in infos:
- self.assertEquals(i.file_size, len(self.data))
+ self.assertEqual(i.file_size, len(self.data))
# check getinfo
- for nm in (TESTFN, "another"+os.extsep+"name", "strfile"):
+ for nm in (TESTFN, "another.name", "strfile"):
info = zipfp.getinfo(nm)
- self.assertEquals(info.filename, nm)
- self.assertEquals(info.file_size, len(self.data))
+ self.assertEqual(info.filename, nm)
+ self.assertEqual(info.file_size, len(self.data))
# Check that testzip doesn't raise an exception
zipfp.testzip()
@@ -532,12 +533,12 @@
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
fn = __file__
- if fn.endswith('.pyc') or fn.endswith('.pyo'):
+ if fn.endswith(('.pyc', '.pyo')):
fn = fn[:-1]
zipfp.writepy(fn, "testpackage")
- bn = "%s/%s"%("testpackage", os.path.basename(fn))
+ bn = "%s/%s" % ("testpackage", os.path.basename(fn))
self.assertTrue(bn not in zipfp.namelist())
self.assertTrue(bn + 'o' in zipfp.namelist() or
bn + 'c' in zipfp.namelist())
@@ -549,7 +550,8 @@
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
zipfp.writepy(packagedir)
- # Check for a couple of modules at different levels of the hieararchy
+ # Check for a couple of modules at different levels of the
+ # hierarchy
names = zipfp.namelist()
self.assertTrue('email/__init__.pyo' in names or
'email/__init__.pyc' in names)
@@ -559,17 +561,14 @@
def test_write_python_directory(self):
os.mkdir(TESTFN2)
try:
- fp = open(os.path.join(TESTFN2, "mod1.py"), "w")
- fp.write("print 42\n")
- fp.close()
-
- fp = open(os.path.join(TESTFN2, "mod2.py"), "w")
- fp.write("print 42 * 42\n")
- fp.close()
-
- fp = open(os.path.join(TESTFN2, "mod2.txt"), "w")
- fp.write("bla bla bla\n")
- fp.close()
+ with open(os.path.join(TESTFN2, "mod1.py"), "w") as fp:
+ fp.write("print 42\n")
+
+ with open(os.path.join(TESTFN2, "mod2.py"), "w") as fp:
+ fp.write("print 42 * 42\n")
+
+ with open(os.path.join(TESTFN2, "mod2.txt"), "w") as fp:
+ fp.write("bla bla bla\n")
zipfp = zipfile.PyZipFile(TemporaryFile(), "w")
zipfp.writepy(TESTFN2)
@@ -584,7 +583,7 @@
def test_write_non_pyfile(self):
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
- file(TESTFN, 'w').write('most definitely not a python file')
+ open(TESTFN, 'w').write('most definitely not a python file')
self.assertRaises(RuntimeError, zipfp.writepy, TESTFN)
os.remove(TESTFN)
@@ -620,28 +619,26 @@
def test_close_erroneous_file(self):
# This test checks that the ZipFile constructor closes the file object
- # it opens if there's an error in the file. If it doesn't, the traceback
- # holds a reference to the ZipFile object and, indirectly, the file object.
+ # it opens if there's an error in the file. If it doesn't, the
+ # traceback holds a reference to the ZipFile object and, indirectly,
+ # the file object.
# On Windows, this causes the os.unlink() call to fail because the
# underlying file is still open. This is SF bug #412214.
#
- fp = open(TESTFN, "w")
- fp.write("this is not a legal zip file\n")
- fp.close()
+ with open(TESTFN, "w") as fp:
+ fp.write("this is not a legal zip file\n")
try:
zf = zipfile.ZipFile(TESTFN)
except zipfile.BadZipfile:
pass
def test_is_zip_erroneous_file(self):
- # This test checks that the is_zipfile function correctly identifies
- # a file that is not a zip file
-
+ """Check that is_zipfile() correctly identifies non-zip files."""
# - passing a filename
with open(TESTFN, "w") as fp:
fp.write("this is not a legal zip file\n")
chk = zipfile.is_zipfile(TESTFN)
- self.assertTrue(not chk)
+ self.assertFalse(chk)
# - passing a file object
with open(TESTFN, "rb") as fp:
chk = zipfile.is_zipfile(fp)
@@ -651,14 +648,12 @@
fp.write("this is not a legal zip file\n")
chk = zipfile.is_zipfile(fp)
self.assertTrue(not chk)
- fp.seek(0,0)
+ fp.seek(0, 0)
chk = zipfile.is_zipfile(fp)
self.assertTrue(not chk)
def test_is_zip_valid_file(self):
- # This test checks that the is_zipfile function correctly identifies
- # a file that is a zip file
-
+ """Check that is_zipfile() correctly identifies zip files."""
# - passing a filename
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
@@ -668,14 +663,14 @@
with open(TESTFN, "rb") as fp:
chk = zipfile.is_zipfile(fp)
self.assertTrue(chk)
- fp.seek(0,0)
+ fp.seek(0, 0)
zip_contents = fp.read()
# - passing a file-like object
fp = StringIO()
fp.write(zip_contents)
chk = zipfile.is_zipfile(fp)
self.assertTrue(chk)
- fp.seek(0,0)
+ fp.seek(0, 0)
chk = zipfile.is_zipfile(fp)
self.assertTrue(chk)
@@ -698,13 +693,12 @@
f.close()
self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
- f = open(TESTFN, 'w')
- f.write("short file")
- f.close()
+ with open(TESTFN, 'w') as fp:
+ fp.write("short file")
self.assertRaises(zipfile.BadZipfile, zipfile.ZipFile, TESTFN)
def test_closed_zip_raises_RuntimeError(self):
- # Verify that testzip() doesn't swallow inappropriate exceptions.
+ """Verify that testzip() doesn't swallow inappropriate exceptions."""
data = StringIO()
with zipfile.ZipFile(data, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
@@ -717,15 +711,15 @@
self.assertRaises(RuntimeError, zipf.open, "foo.txt")
self.assertRaises(RuntimeError, zipf.testzip)
self.assertRaises(RuntimeError, zipf.writestr, "bogus.txt", "bogus")
- file(TESTFN, 'w').write('zipfile test data')
+ open(TESTFN, 'w').write('zipfile test data')
self.assertRaises(RuntimeError, zipf.write, TESTFN)
def test_bad_constructor_mode(self):
- # Check that bad modes passed to ZipFile constructor are caught
+ """Check that bad modes passed to ZipFile constructor are caught."""
self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "q")
def test_bad_open_mode(self):
- # Check that bad modes passed to ZipFile.open are caught
+ """Check that bad modes passed to ZipFile.open are caught."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
@@ -735,8 +729,8 @@
self.assertRaises(RuntimeError, zipf.open, "foo.txt", "q")
def test_read0(self):
- # Check that calling read(0) on a ZipExtFile object returns an empty
- # string and doesn't advance file pointer
+ """Check that calling read(0) on a ZipExtFile object returns an empty
+ string and doesn't advance file pointer."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
# read the data to make sure the file is there
@@ -747,30 +741,32 @@
self.assertEqual(f.read(), "O, for a Muse of Fire!")
def test_open_non_existent_item(self):
- # Check that attempting to call open() for an item that doesn't
- # exist in the archive raises a RuntimeError
+ """Check that attempting to call open() for an item that doesn't
+ exist in the archive raises a RuntimeError."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
self.assertRaises(KeyError, zipf.open, "foo.txt", "r")
def test_bad_compression_mode(self):
- # Check that bad compression methods passed to ZipFile.open are caught
+ """Check that bad compression methods passed to ZipFile.open are
+ caught."""
self.assertRaises(RuntimeError, zipfile.ZipFile, TESTFN, "w", -1)
def test_null_byte_in_filename(self):
- # Check that a filename containing a null byte is properly terminated
+ """Check that a filename containing a null byte is properly
+ terminated."""
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
zipf.writestr("foo.txt\x00qqq", "O, for a Muse of Fire!")
self.assertEqual(zipf.namelist(), ['foo.txt'])
def test_struct_sizes(self):
- # check that ZIP internal structure sizes are calculated correctly
+ """Check that ZIP internal structure sizes are calculated correctly."""
self.assertEqual(zipfile.sizeEndCentDir, 22)
self.assertEqual(zipfile.sizeCentralDir, 46)
self.assertEqual(zipfile.sizeEndCentDir64, 56)
self.assertEqual(zipfile.sizeEndCentDir64Locator, 20)
def test_comments(self):
- # This test checks that comments on the archive are handled properly
+ """Check that comments on the archive are handled properly."""
# check default comment is empty
with zipfile.ZipFile(TESTFN, mode="w") as zipf:
@@ -810,9 +806,9 @@
class DecryptionTests(unittest.TestCase):
- # This test checks that ZIP decryption works. Since the library does not
- # support encryption at the moment, we use a pre-generated encrypted
- # ZIP file
+ """Check that ZIP decryption works. Since the library does not
+ support encryption at the moment, we use a pre-generated encrypted
+ ZIP file."""
data = (
'PK\x03\x04\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00\x1a\x00'
@@ -836,13 +832,11 @@
plain2 = '\x00'*512
def setUp(self):
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
self.zip = zipfile.ZipFile(TESTFN, "r")
- fp = open(TESTFN2, "wb")
- fp.write(self.data2)
- fp.close()
+ with open(TESTFN2, "wb") as fp:
+ fp.write(self.data2)
self.zip2 = zipfile.ZipFile(TESTFN2, "r")
def tearDown(self):
@@ -866,20 +860,20 @@
@skipUnless(zlib, "requires zlib")
def test_good_password(self):
self.zip.setpassword("python")
- self.assertEquals(self.zip.read("test.txt"), self.plain)
+ self.assertEqual(self.zip.read("test.txt"), self.plain)
self.zip2.setpassword("12345")
- self.assertEquals(self.zip2.read("zero"), self.plain2)
+ self.assertEqual(self.zip2.read("zero"), self.plain2)
class TestsWithRandomBinaryFiles(unittest.TestCase):
def setUp(self):
datacount = randint(16, 64)*1024 + randint(1, 1024)
- self.data = ''.join((struct.pack('<f', random()*randint(-1000, 1000)) for i in xrange(datacount)))
+ self.data = ''.join(struct.pack('<f', random()*randint(-1000, 1000))
+ for i in xrange(datacount))
# Make a source file with some lines
- fp = open(TESTFN, "wb")
- fp.write(self.data)
- fp.close()
+ with open(TESTFN, "wb") as fp:
+ fp.write(self.data)
def tearDown(self):
unlink(TESTFN)
@@ -888,7 +882,7 @@
def make_test_archive(self, f, compression):
# Create the ZIP archive
with zipfile.ZipFile(f, "w", compression) as zipfp:
- zipfp.write(TESTFN, "another"+os.extsep+"name")
+ zipfp.write(TESTFN, "another.name")
zipfp.write(TESTFN, TESTFN)
def zip_test(self, f, compression):
@@ -899,7 +893,7 @@
testdata = zipfp.read(TESTFN)
self.assertEqual(len(testdata), len(self.data))
self.assertEqual(testdata, self.data)
- self.assertEqual(zipfp.read("another"+os.extsep+"name"), self.data)
+ self.assertEqual(zipfp.read("another.name"), self.data)
def test_stored(self):
for f in (TESTFN2, TemporaryFile(), StringIO()):
@@ -919,7 +913,7 @@
zipdata1.append(read_data)
zipdata2 = []
- zipopen2 = zipfp.open("another"+os.extsep+"name")
+ zipopen2 = zipfp.open("another.name")
while True:
read_data = zipopen2.read(256)
if not read_data:
@@ -931,8 +925,8 @@
self.assertEqual(testdata1, self.data)
testdata2 = ''.join(zipdata2)
- self.assertEqual(len(testdata1), len(self.data))
- self.assertEqual(testdata1, self.data)
+ self.assertEqual(len(testdata2), len(self.data))
+ self.assertEqual(testdata2, self.data)
def test_open_stored(self):
for f in (TESTFN2, TemporaryFile(), StringIO()):
@@ -1040,7 +1034,8 @@
class UniversalNewlineTests(unittest.TestCase):
def setUp(self):
- self.line_gen = ["Test of zipfile line %d." % i for i in xrange(FIXEDTEST_SIZE)]
+ self.line_gen = ["Test of zipfile line %d." % i
+ for i in xrange(FIXEDTEST_SIZE)]
self.seps = ('\r', '\r\n', '\n')
self.arcdata, self.arcfiles = {}, {}
for n, s in enumerate(self.seps):
1
0
Dec. 31, 2009
Author: ezio.melotti
Date: Thu Dec 31 13:26:02 2009
New Revision: 77177
Log:
Merged revisions 77176 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r77176 | ezio.melotti | 2009-12-31 14:24:38 +0200 (Thu, 31 Dec 2009) | 1 line
#7612: typo in stdtypes.rst
........
Modified:
python/branches/release31-maint/ (props changed)
python/branches/release31-maint/Doc/library/stdtypes.rst
Modified: python/branches/release31-maint/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/stdtypes.rst (original)
+++ python/branches/release31-maint/Doc/library/stdtypes.rst Thu Dec 31 13:26:02 2009
@@ -650,7 +650,7 @@
Also, while in previous Python versions, byte strings and Unicode strings
could be exchanged for each other rather freely (barring encoding issues),
strings and bytes are now completely separate concepts. There's no implicit
- en-/decoding if you pass and object of the wrong type. A string always
+ en-/decoding if you pass an object of the wrong type. A string always
compares unequal to a bytes or bytearray object.
Lists are constructed with square brackets, separating items with commas: ``[a,
1
0
Author: ezio.melotti
Date: Thu Dec 31 13:24:38 2009
New Revision: 77176
Log:
#7612: typo in stdtypes.rst
Modified:
python/branches/py3k/Doc/library/stdtypes.rst
Modified: python/branches/py3k/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k/Doc/library/stdtypes.rst (original)
+++ python/branches/py3k/Doc/library/stdtypes.rst Thu Dec 31 13:24:38 2009
@@ -650,7 +650,7 @@
Also, while in previous Python versions, byte strings and Unicode strings
could be exchanged for each other rather freely (barring encoding issues),
strings and bytes are now completely separate concepts. There's no implicit
- en-/decoding if you pass and object of the wrong type. A string always
+ en-/decoding if you pass an object of the wrong type. A string always
compares unequal to a bytes or bytearray object.
Lists are constructed with square brackets, separating items with commas: ``[a,
1
0
Author: georg.brandl
Date: Thu Dec 31 09:22:12 2009
New Revision: 77175
Log:
Complain if filename does not match PEP number.
Modified:
peps/trunk/genpepindex.py
Modified: peps/trunk/genpepindex.py
==============================================================================
--- peps/trunk/genpepindex.py (original)
+++ peps/trunk/genpepindex.py Thu Dec 31 09:22:12 2009
@@ -41,10 +41,14 @@
if file_path.startswith("pep-") and file_path.endswith(".txt"):
with codecs.open(abs_file_path, 'r', encoding='UTF-8') as pep_file:
try:
- peps.append(PEP(pep_file))
+ pep = PEP(pep_file)
+ if pep.number != int(file_path[4:-4]):
+ raise PEPError('PEP number does not match file name',
+ file_path, pep.number)
+ peps.append(pep)
except PEPError, e:
- errmsg = "Error processing PEP %s, excluding:" % \
- (e.number,)
+ errmsg = "Error processing PEP %s (%s), excluding:" % \
+ (e.number, e.filename)
print >>sys.stderr, errmsg, e
sys.exit(1)
peps.sort(key=attrgetter('number'))
1
0
r77174 - in python/branches/py3k: Doc/c-api/object.rst Misc/NEWS Objects/bytesobject.c
by alexandre.vassalotti Dec. 30, 2009
by alexandre.vassalotti Dec. 30, 2009
Dec. 30, 2009
Author: alexandre.vassalotti
Date: Thu Dec 31 04:56:09 2009
New Revision: 77174
Log:
Issue #6687: Moved the special-case for integers out of PyBytes_FromObject.
Modified:
python/branches/py3k/Doc/c-api/object.rst
python/branches/py3k/Misc/NEWS
python/branches/py3k/Objects/bytesobject.c
Modified: python/branches/py3k/Doc/c-api/object.rst
==============================================================================
--- python/branches/py3k/Doc/c-api/object.rst (original)
+++ python/branches/py3k/Doc/c-api/object.rst Thu Dec 31 04:56:09 2009
@@ -142,10 +142,11 @@
.. index:: builtin: bytes
- Compute a bytes representation of object *o*. *NULL* is returned on failure
- and a bytes object on success. This is equivalent to the Python expression
- ``bytes(o)``.
-
+ Compute a bytes representation of object *o*. *NULL* is returned on
+ failure and a bytes object on success. This is equivalent to the Python
+ expression ``bytes(o)``, when *o* is not an integer. Unlike ``bytes(o)``,
+ a TypeError is raised when *o* is an integer instead of a zero-initialized
+ bytes object.
.. cfunction:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Thu Dec 31 04:56:09 2009
@@ -140,6 +140,9 @@
- Issue #4856: Remove checks for win NT.
+- Issue #6687: PyBytes_FromObject() no longer accepts an integer as its
+ argument to construct a null-initialized bytes object.
+
C-API
-----
Modified: python/branches/py3k/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k/Objects/bytesobject.c (original)
+++ python/branches/py3k/Objects/bytesobject.c Thu Dec 31 04:56:09 2009
@@ -2884,6 +2884,7 @@
const char *encoding = NULL;
const char *errors = NULL;
PyObject *new = NULL;
+ Py_ssize_t size;
static char *kwlist[] = {"source", "encoding", "errors", 0};
if (type != &PyBytes_Type)
@@ -2914,6 +2915,25 @@
assert(PyBytes_Check(new));
return new;
}
+ /* Is it an integer? */
+ size = PyNumber_AsSsize_t(x, PyExc_ValueError);
+ if (size == -1 && PyErr_Occurred()) {
+ PyErr_Clear();
+ }
+ else {
+ if (size < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative count");
+ return NULL;
+ }
+ new = PyBytes_FromStringAndSize(NULL, size);
+ if (new == NULL) {
+ return NULL;
+ }
+ if (size > 0) {
+ memset(((PyBytesObject*)new)->ob_sval, 0, size);
+ }
+ return new;
+ }
/* If it's not unicode, there can't be encoding or errors */
if (encoding != NULL || errors != NULL) {
@@ -2934,27 +2954,6 @@
PyErr_BadInternalCall();
return NULL;
}
-
- /* Is it an int? */
- size = PyNumber_AsSsize_t(x, PyExc_ValueError);
- if (size == -1 && PyErr_Occurred()) {
- PyErr_Clear();
- }
- else {
- if (size < 0) {
- PyErr_SetString(PyExc_ValueError, "negative count");
- return NULL;
- }
- new = PyBytes_FromStringAndSize(NULL, size);
- if (new == NULL) {
- return NULL;
- }
- if (size > 0) {
- memset(((PyBytesObject*)new)->ob_sval, 0, size);
- }
- return new;
- }
-
/* Use the modern buffer interface */
if (PyObject_CheckBuffer(x)) {
Py_buffer view;
@@ -2974,6 +2973,11 @@
PyBuffer_Release(&view);
return NULL;
}
+ if (PyUnicode_Check(x)) {
+ PyErr_SetString(PyExc_TypeError,
+ "cannot convert unicode object to bytes");
+ return NULL;
+ }
/* For iterator version, create a string object and resize as needed */
/* XXX(gb): is 64 a good value? also, optimize if length is known */
1
0
r77173 - in python/branches/py3k: Doc/Makefile Doc/README.txt Doc/make.bat
by benjamin.peterson Dec. 30, 2009
by benjamin.peterson Dec. 30, 2009
Dec. 30, 2009
Author: benjamin.peterson
Date: Thu Dec 31 04:35:15 2009
New Revision: 77173
Log:
Merged revisions 77151-77152 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77151 | georg.brandl | 2009-12-30 12:32:50 -0600 (Wed, 30 Dec 2009) | 1 line
#7487: update Pygments version.
........
r77152 | georg.brandl | 2009-12-30 12:36:09 -0600 (Wed, 30 Dec 2009) | 1 line
#7602: improve "clean" and "checkout" targets now that all tools are in externals.
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/Makefile
python/branches/py3k/Doc/README.txt
python/branches/py3k/Doc/make.bat
Modified: python/branches/py3k/Doc/Makefile
==============================================================================
--- python/branches/py3k/Doc/Makefile (original)
+++ python/branches/py3k/Doc/Makefile Thu Dec 31 04:35:15 2009
@@ -47,11 +47,7 @@
svn checkout $(SVNROOT)/external/Pygments-1.1.1/pygments tools/pygments; \
fi
-update: checkout
- svn update tools/sphinx
- svn update tools/docutils
- svn update tools/jinja2
- svn update tools/pygments
+update: clean checkout
build: checkout
mkdir -p build/$(BUILDER) build/doctrees
@@ -111,6 +107,9 @@
clean:
-rm -rf build/*
-rm -rf tools/sphinx
+ -rm -rf tools/pygments
+ -rm -rf tools/jinja2
+ -rm -rf tools/docutils
dist:
-rm -rf dist
Modified: python/branches/py3k/Doc/README.txt
==============================================================================
--- python/branches/py3k/Doc/README.txt (original)
+++ python/branches/py3k/Doc/README.txt Thu Dec 31 04:35:15 2009
@@ -95,7 +95,7 @@
You can optionally also install Pygments, either as a checkout via ::
- svn co http://svn.python.org/projects/external/Pygments-0.11.1/pygments tools/pygments
+ svn co http://svn.python.org/projects/external/Pygments-1.1.1/pygments tools/pygments
or from PyPI at http://pypi.python.org/pypi/Pygments.
Modified: python/branches/py3k/Doc/make.bat
==============================================================================
--- python/branches/py3k/Doc/make.bat (original)
+++ python/branches/py3k/Doc/make.bat Thu Dec 31 04:35:15 2009
@@ -37,7 +37,7 @@
svn co %SVNROOT%/external/Sphinx-0.6.3/sphinx tools/sphinx
svn co %SVNROOT%/external/docutils-0.5/docutils tools/docutils
svn co %SVNROOT%/external/Jinja-2.1.1/jinja2 tools/jinja2
-svn co %SVNROOT%/external/Pygments-0.11.1/pygments tools/pygments
+svn co %SVNROOT%/external/Pygments-1.1.1/pygments tools/pygments
goto end
:update
1
0
Dec. 30, 2009
Author: benjamin.peterson
Date: Thu Dec 31 04:31:15 2009
New Revision: 77172
Log:
Merged revisions 76852,77001,77115,77127 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76852 | benjamin.peterson | 2009-12-15 21:36:22 -0600 (Tue, 15 Dec 2009) | 1 line
remove type_compare, since type_richcompare does the same trick
........
r77001 | brett.cannon | 2009-12-21 20:37:37 -0600 (Mon, 21 Dec 2009) | 1 line
Make a word plural.
........
r77115 | andrew.kuchling | 2009-12-29 14:10:16 -0600 (Tue, 29 Dec 2009) | 1 line
Various additions
........
r77127 | andrew.kuchling | 2009-12-29 17:41:04 -0600 (Tue, 29 Dec 2009) | 1 line
Add various items
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/whatsnew/2.7.rst
Modified: python/branches/py3k/Doc/whatsnew/2.7.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/2.7.rst (original)
+++ python/branches/py3k/Doc/whatsnew/2.7.rst Thu Dec 31 04:31:15 2009
@@ -49,9 +49,9 @@
This saves the maintainer some effort going through the SVN logs
when researching a change.
-This article explains the new features in Python 2.7. No release
-schedule has been decided yet for 2.7; the schedule will eventually be
-described in :pep:`373`.
+This article explains the new features in Python 2.7. The final
+release of 2.7 is currently scheduled for June 2010; the detailed
+schedule is described in :pep:`373`.
.. Compare with previous release in 2 - 3 sentences here.
add hyperlink when the documentation becomes available online.
@@ -73,6 +73,11 @@
* The new format specifier described in :ref:`pep-0378`.
* The :class:`memoryview` object.
* A small subset of the :mod:`importlib` module `described below <#importlib-section>`__.
+* Float-to-string and string-to-float conversions now round their
+ results more correctly. And :func:`repr` of a floating-point
+ number *x* returns a result that's guaranteed to round back to the
+ same number when converted back to a string.
+* The :cfunc:`PyLong_AsLongAndOverflow` C API function.
One porting change: the :option:`-3` switch now automatically
enables the :option:`-Qwarn` switch that causes warnings
@@ -237,6 +242,33 @@
(Proposed in http://codereview.appspot.com/53094; implemented by
Georg Brandl.)
+* Conversions between floating-point numbers and strings are
+ now correctly rounded on most platforms. These conversions occur
+ in many different places: :func:`str` on
+ floats and complex numbers; the :class:`float` and :class:`complex`
+ constructors;
+ numeric formatting; serialization and
+ deserialization of floats and complex numbers using the
+ :mod:`marshal`, :mod:`pickle`
+ and :mod:`json` modules;
+ parsing of float and imaginary literals in Python code;
+ and :class:`Decimal`-to-float conversion.
+
+ Related to this, the :func:`repr` of a floating-point number *x*
+ now returns a result based on the shortest decimal string that's
+ guaranteed to round back to *x* under correct rounding (with
+ round-half-to-even rounding mode). Previously it gave a string
+ based on rounding x to 17 decimal digits.
+
+ The rounding library responsible for this improvement works on
+ Windows, and on Unix platforms using the gcc, icc, or suncc
+ compilers. There may be a small number of platforms where correct
+ operation of this code cannot be guaranteed, so the code is not
+ used on such systems.
+
+ Implemented by Mark Dickinson, using David Gay's :file:`dtoa.c` library;
+ :issue:`7117`.
+
* The :meth:`str.format` method now supports automatic numbering of the replacement
fields. This makes using :meth:`str.format` more closely resemble using
``%s`` formatting::
@@ -259,6 +291,10 @@
alignment is applied to the whole of the resulting ``1.5+3j``
output. (Contributed by Eric Smith; :issue:`1588`.)
+ The 'F' format code now always formats its output using uppercase characters,
+ so it will now produce 'INF' and 'NAN'.
+ (Contributed by Eric Smith; :issue:`3382`.)
+
* The :func:`int` and :func:`long` types gained a ``bit_length``
method that returns the number of bits necessary to represent
its argument in binary::
@@ -301,6 +337,9 @@
(Implemented by Mark Dickinson; :issue:`3166`.)
+ Integer division is also more accurate in its rounding behaviours. (Also
+ implemented by Mark Dickinson; :issue:`1811`.)
+
* The :class:`bytearray` type's :meth:`translate` method now accepts
``None`` as its first argument. (Fixed by Georg Brandl;
:issue:`4759`.)
@@ -315,6 +354,15 @@
supported. (Contributed by Alexander Belchenko and Amaury Forgeot
d'Arc; :issue:`1616979`.)
+* The :class:`file` object will now set the :attr:`filename` attribute
+ on the :exc:`IOError` exception when trying to open a directory
+ on POSIX platforms. (Noted by Jan Kaliszewski; :issue:`4764`.)
+
+* Extra parentheses in function definitions are illegal in Python 3.x,
+ meaning that you get a syntax error from ``def f((x)): pass``. In
+ Python3-warning mode, Python 2.7 will now warn about this odd usage.
+ (Noted by James Lingard; :issue:`7362`.)
+
.. ======================================================================
@@ -333,16 +381,16 @@
:keyword:`with` statements, looking up the :meth:`__enter__` and
:meth:`__exit__` methods. (Contributed by Benjamin Peterson.)
-* The garbage collector now performs better when many objects are
- being allocated without deallocating any. A full garbage collection
- pass is only performed when the middle generation has been collected
- 10 times and when the number of survivor objects from the middle
- generation exceeds 10% of the number of objects in the oldest
- generation. The second condition was added to reduce the number
- of full garbage collections as the number of objects on the heap grows,
- avoiding quadratic performance when allocating very many objects.
- (Suggested by Martin von Loewis and implemented by Antoine Pitrou;
- :issue:`4074`.)
+* The garbage collector now performs better for one common usage
+ pattern: when many objects are being allocated without deallocating
+ any of them. This would previously take quadratic
+ time for garbage collection, but now the number of full garbage collections
+ is reduced as the number of objects on the heap grows.
+ The new logic is to only perform a full garbage collection pass when
+ the middle generation has been collected 10 times and when the
+ number of survivor objects from the middle generation exceeds 10% of
+ the number of objects in the oldest generation. (Suggested by Martin
+ von Loewis and implemented by Antoine Pitrou; :issue:`4074`.)
* The garbage collector tries to avoid tracking simple containers
which can't be part of a cycle. In Python 2.7, this is now true for
@@ -410,7 +458,6 @@
conversion function that supports arbitrary bases.
(Patch by Gawain Bolton; :issue:`6713`.)
-
.. ======================================================================
New and Improved Modules
@@ -488,12 +535,22 @@
(Added by Raymond Hettinger; :issue:`1818`.)
The :class:`deque` data type now exposes its maximum length as the
- read-only :attr:`maxlen` attribute. (Added by Raymond Hettinger.)
+ read-only :attr:`maxlen` attribute, and has a
+ :meth:`reverse` method that reverses the elements of the deque in-place.
+ (Added by Raymond Hettinger.)
+
+* The :mod:`copy` module's :func:`deepcopy` function will now
+ correctly copy bound instance methods. (Implemented by
+ Robert Collins; :issue:`1515`.)
* The :mod:`ctypes` module now always converts ``None`` to a C NULL
pointer for arguments declared as pointers. (Changed by Thomas
Heller; :issue:`4606`.)
+* New method: the :mod:`datetime` module's :class:`timedelta` class
+ gained a :meth:`total_seconds` method that returns the number of seconds
+ in the duration. (Contributed by Brian Quinlan; :issue:`5788`.)
+
* New method: the :class:`Decimal` class gained a
:meth:`from_float` class method that performs an exact conversion
of a floating-point number to a :class:`Decimal`.
@@ -539,14 +596,24 @@
process, but instead simply not install the failing extension.
(Contributed by Georg Brandl; :issue:`5583`.)
- Issue #7457: added a read_pkg_file method to.distutils.dist.DistributionMetadata
- see file:///MacDev/svn.python.org/python-trunk/Doc/build/html/distutils/example…
- (:issue:`7457`, added by Tarek).
+ The :class:`distutils.dist.DistributionMetadata` class'
+ :meth:`read_pkg_file` method will read the contents of a package's
+ :file:`PKG-INFO` metadata file. For an example of its use,
+ XXX link to file:///MacDev/svn.python.org/python-trunk/Doc/build/html/distutils/example…
+ (Contributed by Tarek Ziade; :issue:`7457`.)
* The :class:`Fraction` class now accepts two rational numbers
as arguments to its constructor.
(Implemented by Mark Dickinson; :issue:`5812`.)
+* The :mod:`ftplib` module gained the ability to establish secure FTP
+ connections using TLS encapsulation of authentication as well as
+ subsequent control and data transfers. This is provided by the new
+ :class:`ftplib.FTP_TLS` class.
+ (Contributed by Giampaolo Rodola', :issue:`2054`.) The :meth:`storbinary`
+ method for binary uploads can now restart uploads thanks to an added
+ *rest* parameter (patch by Pablo Mouzo; :issue:`6845`.)
+
* New function: the :mod:`gc` module's :func:`is_tracked` returns
true if a given instance is tracked by the garbage collector, false
otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.)
@@ -627,8 +694,12 @@
with any object literal that decodes to a list of pairs.
(Contributed by Raymond Hettinger; :issue:`5381`.)
-* New functions: the :mod:`math` module now has
- a :func:`gamma` function.
+* New functions: the :mod:`math` module gained
+ :func:`erf` and :func:`erfc` for the error function and the complementary error function,
+ :func:`expm1` which computes ``e**x - 1`` with more precision than
+ using :func:`exp` and subtracting 1,
+ :func:`gamma` for the Gamma function, and
+ :func:`lgamma` for the natural log of the Gamma function.
(Contributed by Mark Dickinson and nirinA raseliarison; :issue:`3366`.)
* The :mod:`multiprocessing` module's :class:`Manager*` classes
@@ -640,6 +711,15 @@
* The :mod:`nntplib` module now supports IPv6 addresses.
(Contributed by Derek Morr; :issue:`1664`.)
+* New functions: the :mod:`os` module wraps the following POSIX system
+ calls: :func:`getresgid` and :func:`getresuid`, which return the
+ real, effective, and saved GIDs and UIDs;
+ :func:`setresgid` and :func:`setresuid`, which set
+ real, effective, and saved GIDs and UIDs to new values;
+ :func:`initgroups`. (GID/UID functions
+ contributed by Travis H.; :issue:`6508`. Support for initgroups added
+ by Jean-Paul Calderone; :issue:`7333`.)
+
* The :mod:`pydoc` module now has help for the various symbols that Python
uses. You can now do ``help('<<')`` or ``help('@')``, for example.
(Contributed by David Laban; :issue:`4739`.)
@@ -728,12 +808,6 @@
:mod:`zipfile` now supports archiving empty directories and
extracts them correctly. (Fixed by Kuba Wieczorek; :issue:`4710`.)
-* The :mod:`ftplib` module gains the ability to establish secure FTP
- connections using TLS encapsulation of authentication as well as
- subsequent control and data transfers. This is provided by the new
- :class:`ftplib.FTP_TLS` class.
- (Contributed by Giampaolo Rodola', :issue:`2054`.)
-
.. ======================================================================
.. whole new modules get described in subsections here
@@ -855,7 +929,7 @@
Python 3.1 includes the :mod:`importlib` package, a re-implementation
of the logic underlying Python's :keyword:`import` statement.
:mod:`importlib` is useful for implementors of Python interpreters and
-to user who wish to write new importers that can participate in the
+to users who wish to write new importers that can participate in the
import process. Python 2.7 doesn't contain the complete
:mod:`importlib` package, but instead has a tiny subset that contains
a single function, :func:`import_module`.
@@ -934,12 +1008,23 @@
extensions needed to call :cfunc:`PyCode_New`, which had many
more arguments. (Added by Jeffrey Yasskin.)
+* New function: :cfunc:`PyErr_NewExceptionWithDoc` creates a new
+ exception class, just as the existing :cfunc:`PyErr_NewException` does,
+ but takes an extra ``char *`` argument containing the docstring for the
+ new exception class. (Added by the 'lekma' user on the Python bug tracker;
+ :issue:`7033`.)
+
* New function: :cfunc:`PyFrame_GetLineNumber` takes a frame object
and returns the line number that the frame is currently executing.
Previously code would need to get the index of the bytecode
instruction currently executing, and then look up the line number
corresponding to that address. (Added by Jeffrey Yasskin.)
+* New function: :cfunc:`PyLong_AsLongAndOverflow` approximates a Python long
+ integer as a C :ctype:`long`. If the number is too large to fit into
+ a :ctype:`long`, an *overflow* flag is set and returned to the caller.
+ (Contributed by Case Van Horsen; :issue:`7528`.)
+
* New macros: the Python header files now define the following macros:
:cmacro:`Py_ISALNUM`,
:cmacro:`Py_ISALPHA`,
@@ -958,6 +1043,12 @@
.. XXX these macros don't seem to be described in the c-api docs.
+* New format codes: the :cfunc:`PyFormat_FromString`,
+ :cfunc:`PyFormat_FromStringV`, and :cfunc:`PyErr_Format` now
+ accepts ``%lld`` and ``%llu`` format codes for displaying values of
+ C's :ctype:`long long` types.
+ (Contributed by Mark Dickinson; :issue:`7228`.)
+
* The complicated interaction between threads and process forking has
been changed. Previously, the child process created by
:func:`os.fork` might fail because the child is created with only a
@@ -992,6 +1083,12 @@
* The build process now supports Subversion 1.7. (Contributed by
Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.)
+* Compiling Python with the :option:`--with-valgrind` option will now
+ disable the pymalloc allocator, which is difficult for the Valgrind to
+ analyze correctly. Valgrind will therefore be better at detecting
+ memory leaks and overruns. (Contributed by James Henstridge; :issue:`2422`.)
+
+
.. ======================================================================
Port-Specific Changes: Windows
@@ -1011,6 +1108,10 @@
* The :func:`os.listdir` function now correctly fails
for an empty path. (Fixed by Hirokazu Yamamoto; :issue:`5913`.)
+* The :mod:`mimelib` module will now read the MIME database from
+ the Windows registry when initializing.
+ (Patch by Gabriel Genellina; :issue:`4969`.)
+
.. ======================================================================
Port-Specific Changes: Mac OS X
@@ -1070,6 +1171,10 @@
affects new-style classes (derived from :class:`object`) and C extension
types. (:issue:`6101`.)
+* The :meth:`readline` method of :class:`StringIO` objects now does
+ nothing when a negative length is requested, as other file-like
+ objects do. (:issue:`7348`).
+
.. ======================================================================
1
0
Dec. 30, 2009
Author: benjamin.peterson
Date: Thu Dec 31 04:30:26 2009
New Revision: 77171
Log:
Merged revisions 77167 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77167 | benjamin.peterson | 2009-12-30 21:11:23 -0600 (Wed, 30 Dec 2009) | 61 lines
Merged revisions 76847,76851,76869,76882,76891-76892,76924,77007,77070,77092,77096,77120,77126,77155 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76847 | benjamin.peterson | 2009-12-14 21:25:27 -0600 (Mon, 14 Dec 2009) | 1 line
adverb
........
r76851 | benjamin.peterson | 2009-12-15 21:28:52 -0600 (Tue, 15 Dec 2009) | 1 line
remove lib2to3 resource
........
r76869 | vinay.sajip | 2009-12-17 08:52:00 -0600 (Thu, 17 Dec 2009) | 1 line
Issue #7529: logging: Minor correction to documentation.
........
r76882 | georg.brandl | 2009-12-19 11:30:28 -0600 (Sat, 19 Dec 2009) | 1 line
#7527: use standard versionadded tags.
........
r76891 | georg.brandl | 2009-12-19 12:16:31 -0600 (Sat, 19 Dec 2009) | 1 line
#7479: add note about function availability on Unices.
........
r76892 | georg.brandl | 2009-12-19 12:20:18 -0600 (Sat, 19 Dec 2009) | 1 line
#7480: remove tautology.
........
r76924 | georg.brandl | 2009-12-20 08:28:05 -0600 (Sun, 20 Dec 2009) | 1 line
Small indentation fix.
........
r77007 | gregory.p.smith | 2009-12-23 03:31:11 -0600 (Wed, 23 Dec 2009) | 3 lines
Fix possible integer overflow in lchown and fchown functions. For issue1747858.
........
r77070 | amaury.forgeotdarc | 2009-12-27 14:06:44 -0600 (Sun, 27 Dec 2009) | 2 lines
Fix a typo in comment
........
r77092 | georg.brandl | 2009-12-28 02:48:24 -0600 (Mon, 28 Dec 2009) | 1 line
#7404: remove reference to non-existing example files.
........
r77096 | benjamin.peterson | 2009-12-28 14:51:17 -0600 (Mon, 28 Dec 2009) | 1 line
document new fix_callable behavior
........
r77120 | georg.brandl | 2009-12-29 15:09:17 -0600 (Tue, 29 Dec 2009) | 1 line
#7595: fix typo in argument default constant.
........
r77126 | amaury.forgeotdarc | 2009-12-29 17:06:17 -0600 (Tue, 29 Dec 2009) | 2 lines
#7579: Add docstrings to the msvcrt module
........
r77155 | georg.brandl | 2009-12-30 13:03:00 -0600 (Wed, 30 Dec 2009) | 1 line
We only support Windows NT derivatives now.
........
................
Modified:
python/branches/release31-maint/ (props changed)
python/branches/release31-maint/Doc/faq/design.rst
python/branches/release31-maint/Doc/library/2to3.rst
python/branches/release31-maint/Doc/library/ctypes.rst
python/branches/release31-maint/Doc/library/logging.rst
python/branches/release31-maint/Doc/library/msvcrt.rst
python/branches/release31-maint/Doc/library/optparse.rst
python/branches/release31-maint/Doc/library/os.rst
python/branches/release31-maint/Doc/library/select.rst
python/branches/release31-maint/Doc/library/stdtypes.rst
python/branches/release31-maint/Doc/library/string.rst
python/branches/release31-maint/Lib/test/regrtest.py
python/branches/release31-maint/Lib/test/test_posix.py
python/branches/release31-maint/Modules/gcmodule.c
python/branches/release31-maint/Modules/posixmodule.c
python/branches/release31-maint/Modules/selectmodule.c
python/branches/release31-maint/PC/msvcrtmodule.c
Modified: python/branches/release31-maint/Doc/faq/design.rst
==============================================================================
--- python/branches/release31-maint/Doc/faq/design.rst (original)
+++ python/branches/release31-maint/Doc/faq/design.rst Thu Dec 31 04:30:26 2009
@@ -818,7 +818,7 @@
looks like this::
with obj:
- a = 1 # equivalent to obj.a = 1
+ a = 1 # equivalent to obj.a = 1
total = total + 1 # obj.total = obj.total + 1
In Python, such a construct would be ambiguous.
Modified: python/branches/release31-maint/Doc/library/2to3.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/2to3.rst (original)
+++ python/branches/release31-maint/Doc/library/2to3.rst Thu Dec 31 04:30:26 2009
@@ -122,7 +122,8 @@
.. 2to3fixer:: callable
- Converts ``callable(x)`` to ``hasattr(x, "__call_")``.
+ Converts ``callable(x)`` to ``isinstance(x, collections.Callable)``, adding
+ an import to :mod:`collections` if needed.
.. 2to3fixer:: dict
Modified: python/branches/release31-maint/Doc/library/ctypes.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/ctypes.rst (original)
+++ python/branches/release31-maint/Doc/library/ctypes.rst Thu Dec 31 04:30:26 2009
@@ -1005,7 +1005,7 @@
>>>
It is funny to see that on linux the sort function seems to work much more
-efficient, it is doing less comparisons::
+efficiently, it is doing less comparisons::
>>> qsort(ia, len(ia), sizeof(c_int), cmp_func) # doctest: +LINUX
py_cmp_func 5 1
Modified: python/branches/release31-maint/Doc/library/logging.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/logging.rst (original)
+++ python/branches/release31-maint/Doc/library/logging.rst Thu Dec 31 04:30:26 2009
@@ -1611,6 +1611,8 @@
and :meth:`flush` methods).
+.. currentmodule:: logging
+
.. class:: StreamHandler(stream=None)
Returns a new instance of the :class:`StreamHandler` class. If *stream* is
Modified: python/branches/release31-maint/Doc/library/msvcrt.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/msvcrt.rst (original)
+++ python/branches/release31-maint/Doc/library/msvcrt.rst Thu Dec 31 04:30:26 2009
@@ -144,6 +144,4 @@
.. function:: heapmin()
Force the :cfunc:`malloc` heap to clean itself up and return unused blocks to
- the operating system. This only works on Windows NT. On failure, this raises
- :exc:`IOError`.
-
+ the operating system. On failure, this raises :exc:`IOError`.
Modified: python/branches/release31-maint/Doc/library/optparse.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/optparse.rst (original)
+++ python/branches/release31-maint/Doc/library/optparse.rst Thu Dec 31 04:30:26 2009
@@ -153,9 +153,7 @@
an option that must be supplied on the command-line; note that the phrase
"required option" is self-contradictory in English. :mod:`optparse` doesn't
prevent you from implementing required options, but doesn't give you much
- help at it either. See ``examples/required_1.py`` and
- ``examples/required_2.py`` in the :mod:`optparse` source distribution for two
- ways to implement required options with :mod:`optparse`.
+ help at it either.
For example, consider this hypothetical command-line::
Modified: python/branches/release31-maint/Doc/library/os.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/os.rst (original)
+++ python/branches/release31-maint/Doc/library/os.rst Thu Dec 31 04:30:26 2009
@@ -13,26 +13,34 @@
module, and for high-level file and directory handling see the :mod:`shutil`
module.
-The design of all built-in operating system dependent modules of Python is such
-that as long as the same functionality is available, it uses the same interface;
-for example, the function ``os.stat(path)`` returns stat information about
-*path* in the same format (which happens to have originated with the POSIX
-interface).
+Notes on the availability of these functions:
-Extensions peculiar to a particular operating system are also available through
-the :mod:`os` module, but using them is of course a threat to portability!
-
-.. note::
-
- All functions accepting path or file names accept both bytes and string
- objects, and result in an object of the same type, if a path or file name is
- returned.
+* The design of all built-in operating system dependent modules of Python is
+ such that as long as the same functionality is available, it uses the same
+ interface; for example, the function ``os.stat(path)`` returns stat
+ information about *path* in the same format (which happens to have originated
+ with the POSIX interface).
+
+* Extensions peculiar to a particular operating system are also available
+ through the :mod:`os` module, but using them is of course a threat to
+ portability.
+
+* All functions accepting path or file names accept both bytes and string
+ objects, and result in an object of the same type, if a path or file name is
+ returned.
.. note::
If not separately noted, all functions that claim "Availability: Unix" are
supported on Mac OS X, which builds on a Unix core.
+* An "Availability: Unix" note means that this function is commonly found on
+ Unix systems. It does not make any claims about its existence on a specific
+ operating system.
+
+* If not separately noted, all functions that claim "Availability: Unix" are
+ supported on Mac OS X, which builds on a Unix core.
+
.. note::
All functions in this module raise :exc:`OSError` in the case of invalid or
@@ -46,9 +54,9 @@
.. data:: name
- The name of the operating system dependent module imported. The following names
- have currently been registered: ``'posix'``, ``'nt'``, ``'mac'``, ``'os2'``,
- ``'ce'``, ``'java'``.
+ The name of the operating system dependent module imported. The following
+ names have currently been registered: ``'posix'``, ``'nt'``, ``'mac'``,
+ ``'os2'``, ``'ce'``, ``'java'``.
.. _os-filenames:
Modified: python/branches/release31-maint/Doc/library/select.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/select.rst (original)
+++ python/branches/release31-maint/Doc/library/select.rst Thu Dec 31 04:30:26 2009
@@ -46,7 +46,7 @@
:ref:`kqueue-objects` below for the methods supported by kqueue objects.
-.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_ADD, fflags=0, data=0, udata=0)
+.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
(Only supported on BSD.) Returns a kernel event object object; see section
:ref:`kevent-objects` below for the methods supported by kqueue objects.
Modified: python/branches/release31-maint/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/stdtypes.rst (original)
+++ python/branches/release31-maint/Doc/library/stdtypes.rst Thu Dec 31 04:30:26 2009
@@ -2454,8 +2454,7 @@
.. attribute:: class.__bases__
- The tuple of base classes of a class object. If there are no base classes, this
- will be an empty tuple.
+ The tuple of base classes of a class object.
.. attribute:: class.__name__
Modified: python/branches/release31-maint/Doc/library/string.rst
==============================================================================
--- python/branches/release31-maint/Doc/library/string.rst (original)
+++ python/branches/release31-maint/Doc/library/string.rst Thu Dec 31 04:30:26 2009
@@ -86,6 +86,7 @@
you to create and customize your own string formatting behaviors using the same
implementation as the built-in :meth:`format` method.
+
.. class:: Formatter
The :class:`Formatter` class has the following public methods:
@@ -470,6 +471,8 @@
Template strings
----------------
+.. versionadded:: 2.4
+
Templates provide simpler string substitutions as described in :pep:`292`.
Instead of the normal ``%``\ -based substitutions, Templates support ``$``\
-based substitutions, using the following rules:
Modified: python/branches/release31-maint/Lib/test/regrtest.py
==============================================================================
--- python/branches/release31-maint/Lib/test/regrtest.py (original)
+++ python/branches/release31-maint/Lib/test/regrtest.py Thu Dec 31 04:30:26 2009
@@ -105,8 +105,6 @@
curses - Tests that use curses and will modify the terminal's
state and output modes.
- lib2to3 - Run the tests for 2to3 (They take a while.)
-
largefile - It is okay to run some test that may create huge
files. These tests can take a long time and may
consume >2GB of disk space temporarily.
Modified: python/branches/release31-maint/Lib/test/test_posix.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_posix.py (original)
+++ python/branches/release31-maint/Lib/test/test_posix.py Thu Dec 31 04:30:26 2009
@@ -131,32 +131,54 @@
if hasattr(posix, 'stat'):
self.assertTrue(posix.stat(support.TESTFN))
- if hasattr(posix, 'chown'):
- def test_chown(self):
- # raise an OSError if the file does not exist
- os.unlink(support.TESTFN)
- self.assertRaises(OSError, posix.chown, support.TESTFN, -1, -1)
-
- # re-create the file
- open(support.TESTFN, 'w').close()
- if os.getuid() == 0:
- try:
- # Many linux distros have a nfsnobody user as MAX_UID-2
- # that makes a good test case for signedness issues.
- # http://bugs.python.org/issue1747858
- # This part of the test only runs when run as root.
- # Only scary people run their tests as root.
- ent = pwd.getpwnam('nfsnobody')
- posix.chown(support.TESTFN, ent.pw_uid, ent.pw_gid)
- except KeyError:
- pass
- else:
- # non-root cannot chown to root, raises OSError
- self.assertRaises(OSError, posix.chown,
- support.TESTFN, 0, 0)
-
- # test a successful chown call
- posix.chown(support.TESTFN, os.getuid(), os.getgid())
+ def _test_all_chown_common(self, chown_func, first_param):
+ """Common code for chown, fchown and lchown tests."""
+ if os.getuid() == 0:
+ try:
+ # Many linux distros have a nfsnobody user as MAX_UID-2
+ # that makes a good test case for signedness issues.
+ # http://bugs.python.org/issue1747858
+ # This part of the test only runs when run as root.
+ # Only scary people run their tests as root.
+ ent = pwd.getpwnam('nfsnobody')
+ chown_func(first_param, ent.pw_uid, ent.pw_gid)
+ except KeyError:
+ pass
+ else:
+ # non-root cannot chown to root, raises OSError
+ self.assertRaises(OSError, chown_func,
+ first_param, 0, 0)
+ # test a successful chown call
+ chown_func(first_param, os.getuid(), os.getgid())
+
+ @unittest.skipUnless(hasattr(posix, 'chown'), "test needs os.chown()")
+ def test_chown(self):
+ # raise an OSError if the file does not exist
+ os.unlink(support.TESTFN)
+ self.assertRaises(OSError, posix.chown, support.TESTFN, -1, -1)
+
+ # re-create the file
+ open(support.TESTFN, 'w').close()
+ self._test_all_chown_common(posix.chown, support.TESTFN)
+
+ @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()")
+ def test_fchown(self):
+ os.unlink(support.TESTFN)
+
+ # re-create the file
+ test_file = open(support.TESTFN, 'w')
+ try:
+ fd = test_file.fileno()
+ self._test_all_chown_common(posix.fchown, fd)
+ finally:
+ test_file.close()
+
+ @unittest.skipUnless(hasattr(posix, 'lchown'), "test needs os.lchown()")
+ def test_lchown(self):
+ os.unlink(support.TESTFN)
+ # create a symlink
+ os.symlink('/tmp/dummy-symlink-target', support.TESTFN)
+ self._test_all_chown_common(posix.lchown, support.TESTFN)
def test_chdir(self):
if hasattr(posix, 'chdir'):
Modified: python/branches/release31-maint/Modules/gcmodule.c
==============================================================================
--- python/branches/release31-maint/Modules/gcmodule.c (original)
+++ python/branches/release31-maint/Modules/gcmodule.c Thu Dec 31 04:30:26 2009
@@ -927,7 +927,7 @@
*/
(void)handle_finalizers(&finalizers, old);
- /* Clear free list only during the collection of the higest
+ /* Clear free list only during the collection of the highest
* generation */
if (generation == NUM_GENERATIONS-1) {
clear_freelists();
@@ -948,7 +948,7 @@
int i;
Py_ssize_t n = 0;
- /* Find the oldest generation (higest numbered) where the count
+ /* Find the oldest generation (highest numbered) where the count
* exceeds the threshold. Objects in the that generation and
* generations younger than it will be collected. */
for (i = NUM_GENERATIONS-1; i >= 0; i--) {
Modified: python/branches/release31-maint/Modules/posixmodule.c
==============================================================================
--- python/branches/release31-maint/Modules/posixmodule.c (original)
+++ python/branches/release31-maint/Modules/posixmodule.c Thu Dec 31 04:30:26 2009
@@ -2088,9 +2088,10 @@
static PyObject *
posix_fchown(PyObject *self, PyObject *args)
{
- int fd, uid, gid;
+ int fd;
+ long uid, gid;
int res;
- if (!PyArg_ParseTuple(args, "iii:chown", &fd, &uid, &gid))
+ if (!PyArg_ParseTuple(args, "ill:chown", &fd, &uid, &gid))
return NULL;
Py_BEGIN_ALLOW_THREADS
res = fchown(fd, (uid_t) uid, (gid_t) gid);
@@ -2112,9 +2113,9 @@
{
PyObject *opath;
char *path;
- int uid, gid;
+ long uid, gid;
int res;
- if (!PyArg_ParseTuple(args, "O&ii:lchown",
+ if (!PyArg_ParseTuple(args, "O&ll:lchown",
PyUnicode_FSConverter, &opath,
&uid, &gid))
return NULL;
Modified: python/branches/release31-maint/Modules/selectmodule.c
==============================================================================
--- python/branches/release31-maint/Modules/selectmodule.c (original)
+++ python/branches/release31-maint/Modules/selectmodule.c Thu Dec 31 04:30:26 2009
@@ -1166,7 +1166,7 @@
#endif
PyDoc_STRVAR(kqueue_event_doc,
-"kevent(ident, filter=KQ_FILTER_READ, flags=KQ_ADD, fflags=0, data=0, udata=0)\n\
+"kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)\n\
\n\
This object is the equivalent of the struct kevent for the C API.\n\
\n\
Modified: python/branches/release31-maint/PC/msvcrtmodule.c
==============================================================================
--- python/branches/release31-maint/PC/msvcrtmodule.c (original)
+++ python/branches/release31-maint/PC/msvcrtmodule.c Thu Dec 31 04:30:26 2009
@@ -45,6 +45,12 @@
return Py_None;
}
+PyDoc_STRVAR(heapmin_doc,
+"heapmin() -> None\n\
+\n\
+Force the malloc() heap to clean itself up and return unused blocks\n\
+to the operating system. On failure, this raises IOError.");
+
// Perform locking operations on a C runtime file descriptor.
static PyObject *
msvcrt_locking(PyObject *self, PyObject *args)
@@ -67,6 +73,17 @@
return Py_None;
}
+PyDoc_STRVAR(locking_doc,
+"locking(fd, mode, nbytes) -> None\n\
+\n\
+Lock part of a file based on file descriptor fd from the C runtime.\n\
+Raises IOError on failure. The locked region of the file extends from\n\
+the current file position for nbytes bytes, and may continue beyond\n\
+the end of the file. mode must be one of the LK_* constants listed\n\
+below. Multiple regions in a file may be locked at the same time, but\n\
+may not overlap. Adjacent regions are not merged; they must be unlocked\n\
+individually.");
+
// Set the file translation mode for a C runtime file descriptor.
static PyObject *
msvcrt_setmode(PyObject *self, PyObject *args)
@@ -83,6 +100,13 @@
return PyLong_FromLong(flags);
}
+PyDoc_STRVAR(setmode_doc,
+"setmode(fd, mode) -> Previous mode\n\
+\n\
+Set the line-end translation mode for the file descriptor fd. To set\n\
+it to text mode, flags should be os.O_TEXT; for binary, it should be\n\
+os.O_BINARY.");
+
// Convert an OS file handle to a C runtime file descriptor.
static PyObject *
msvcrt_open_osfhandle(PyObject *self, PyObject *args)
@@ -101,6 +125,14 @@
return PyLong_FromLong(fd);
}
+PyDoc_STRVAR(open_osfhandle_doc,
+"open_osfhandle(handle, flags) -> file descriptor\n\
+\n\
+Create a C runtime file descriptor from the file handle handle. The\n\
+flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\
+and os.O_TEXT. The returned file descriptor may be used as a parameter\n\
+to os.fdopen() to create a file object.");
+
// Convert a C runtime file descriptor to an OS file handle.
static PyObject *
msvcrt_get_osfhandle(PyObject *self, PyObject *args)
@@ -121,6 +153,12 @@
return PyLong_FromVoidPtr((void*)handle);
}
+PyDoc_STRVAR(get_osfhandle_doc,
+"get_osfhandle(fd) -> file handle\n\
+\n\
+Return the file handle for the file descriptor fd. Raises IOError\n\
+if fd is not recognized.");
+
/* Console I/O */
static PyObject *
@@ -135,6 +173,11 @@
return PyLong_FromLong(ok);
}
+PyDoc_STRVAR(kbhit_doc,
+"kbhit() -> bool\n\
+\n\
+Return true if a keypress is waiting to be read.");
+
static PyObject *
msvcrt_getch(PyObject *self, PyObject *args)
{
@@ -151,6 +194,16 @@
return PyBytes_FromStringAndSize(s, 1);
}
+PyDoc_STRVAR(getch_doc,
+"getch() -> key character\n\
+\n\
+Read a keypress and return the resulting character. Nothing is echoed to\n\
+the console. This call will block if a keypress is not already\n\
+available, but will not wait for Enter to be pressed. If the pressed key\n\
+was a special function key, this will return '\\000' or '\\xe0'; the next\n\
+call will return the keycode. The Control-C keypress cannot be read with\n\
+this function.");
+
#ifdef _WCONIO_DEFINED
static PyObject *
msvcrt_getwch(PyObject *self, PyObject *args)
@@ -167,6 +220,11 @@
u[0] = ch;
return PyUnicode_FromUnicode(u, 1);
}
+
+PyDoc_STRVAR(getwch_doc,
+"getwch() -> Unicode key character\n\
+\n\
+Wide char variant of getch(), returning a Unicode value.");
#endif
static PyObject *
@@ -185,6 +243,12 @@
return PyBytes_FromStringAndSize(s, 1);
}
+PyDoc_STRVAR(getche_doc,
+"getche() -> key character\n\
+\n\
+Similar to getch(), but the keypress will be echoed if it represents\n\
+a printable character.");
+
#ifdef _WCONIO_DEFINED
static PyObject *
msvcrt_getwche(PyObject *self, PyObject *args)
@@ -201,6 +265,11 @@
s[0] = ch;
return PyUnicode_FromUnicode(s, 1);
}
+
+PyDoc_STRVAR(getwche_doc,
+"getwche() -> Unicode key character\n\
+\n\
+Wide char variant of getche(), returning a Unicode value.");
#endif
static PyObject *
@@ -216,6 +285,11 @@
return Py_None;
}
+PyDoc_STRVAR(putch_doc,
+"putch(char) -> None\n\
+\n\
+Print the character char to the console without buffering.");
+
#ifdef _WCONIO_DEFINED
static PyObject *
msvcrt_putwch(PyObject *self, PyObject *args)
@@ -229,6 +303,11 @@
Py_RETURN_NONE;
}
+
+PyDoc_STRVAR(putwch_doc,
+"putwch(unicode_char) -> None\n\
+\n\
+Wide char variant of putch(), accepting a Unicode value.");
#endif
static PyObject *
@@ -245,6 +324,12 @@
return Py_None;
}
+PyDoc_STRVAR(ungetch_doc,
+"ungetch(char) -> None\n\
+\n\
+Cause the character char to be \"pushed back\" into the console buffer;\n\
+it will be the next character read by getch() or getche().");
+
#ifdef _WCONIO_DEFINED
static PyObject *
msvcrt_ungetwch(PyObject *self, PyObject *args)
@@ -259,6 +344,11 @@
Py_INCREF(Py_None);
return Py_None;
}
+
+PyDoc_STRVAR(ungetwch_doc,
+"ungetwch(unicode_char) -> None\n\
+\n\
+Wide char variant of ungetch(), accepting a Unicode value.");
#endif
static void
@@ -332,16 +422,16 @@
/* List of functions exported by this module */
static struct PyMethodDef msvcrt_functions[] = {
- {"heapmin", msvcrt_heapmin, METH_VARARGS},
- {"locking", msvcrt_locking, METH_VARARGS},
- {"setmode", msvcrt_setmode, METH_VARARGS},
- {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS},
- {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS},
- {"kbhit", msvcrt_kbhit, METH_VARARGS},
- {"getch", msvcrt_getch, METH_VARARGS},
- {"getche", msvcrt_getche, METH_VARARGS},
- {"putch", msvcrt_putch, METH_VARARGS},
- {"ungetch", msvcrt_ungetch, METH_VARARGS},
+ {"heapmin", msvcrt_heapmin, METH_VARARGS, heapmin_doc},
+ {"locking", msvcrt_locking, METH_VARARGS, locking_doc},
+ {"setmode", msvcrt_setmode, METH_VARARGS, setmode_doc},
+ {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc},
+ {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc},
+ {"kbhit", msvcrt_kbhit, METH_VARARGS, kbhit_doc},
+ {"getch", msvcrt_getch, METH_VARARGS, getch_doc},
+ {"getche", msvcrt_getche, METH_VARARGS, getche_doc},
+ {"putch", msvcrt_putch, METH_VARARGS, putch_doc},
+ {"ungetch", msvcrt_ungetch, METH_VARARGS, ungetch_doc},
{"SetErrorMode", seterrormode, METH_VARARGS},
#ifdef _DEBUG
{"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS},
@@ -349,10 +439,10 @@
{"set_error_mode", msvcrt_seterrormode, METH_VARARGS},
#endif
#ifdef _WCONIO_DEFINED
- {"getwch", msvcrt_getwch, METH_VARARGS},
- {"getwche", msvcrt_getwche, METH_VARARGS},
- {"putwch", msvcrt_putwch, METH_VARARGS},
- {"ungetwch", msvcrt_ungetwch, METH_VARARGS},
+ {"getwch", msvcrt_getwch, METH_VARARGS, getwch_doc},
+ {"getwche", msvcrt_getwche, METH_VARARGS, getwche_doc},
+ {"putwch", msvcrt_putwch, METH_VARARGS, putwch_doc},
+ {"ungetwch", msvcrt_ungetwch, METH_VARARGS, ungetwch_doc},
#endif
{NULL, NULL}
};
1
0
r77170 - in python/branches/py3k: Misc/NEWS configure configure.in setup.py
by benjamin.peterson Dec. 30, 2009
by benjamin.peterson Dec. 30, 2009
Dec. 30, 2009
Author: benjamin.peterson
Date: Thu Dec 31 04:23:10 2009
New Revision: 77170
Log:
Merged revisions 77169 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77169 | benjamin.peterson | 2009-12-30 21:17:18 -0600 (Wed, 30 Dec 2009) | 2 lines
add a --with-system-expat option to build pyexpat against the system's lib #7609
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Misc/NEWS
python/branches/py3k/configure
python/branches/py3k/configure.in
python/branches/py3k/setup.py
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Thu Dec 31 04:23:10 2009
@@ -514,6 +514,10 @@
Build
-----
+- Issue #7609: Add a --with-system-expat option that causes the system's expat
+ library to be used for the pyexpat module instead of the one included with
+ Python.
+
- Issue #7589: Only build the nis module when the correct header files are
found.
Modified: python/branches/py3k/configure
==============================================================================
--- python/branches/py3k/configure (original)
+++ python/branches/py3k/configure Thu Dec 31 04:23:10 2009
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 76815 .
+# From configure.in Revision: 77032 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.61 for python 3.2.
#
@@ -1342,6 +1342,8 @@
--with-suffix=.exe set executable suffix
--with-pydebug build with Py_DEBUG defined
--with-libs='lib1 ...' link against additional libs
+ --with-system-expat build pyexpat module using an installed expat
+ library
--with-system-ffi build _ctypes module using an installed ffi library
--with-dbmliborder=db1:db2:...
order to check db backends for dbm. Valid value is a
@@ -3792,7 +3794,7 @@
{ echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6; }
fi
-rm -f -r conftest*
+rm -f conftest*
@@ -5335,7 +5337,7 @@
else
ac_cv_header_stdc=no
fi
-rm -f -r conftest*
+rm -f conftest*
fi
@@ -5356,7 +5358,7 @@
else
ac_cv_header_stdc=no
fi
-rm -f -r conftest*
+rm -f conftest*
fi
@@ -6454,7 +6456,7 @@
fi
-rm -f -r conftest*
+rm -f conftest*
{ echo "$as_me:$LINENO: result: $was_it_defined" >&5
echo "${ECHO_T}$was_it_defined" >&6; }
@@ -6984,7 +6986,7 @@
else
ac_cv_type_uid_t=no
fi
-rm -f -r conftest*
+rm -f conftest*
fi
{ echo "$as_me:$LINENO: result: $ac_cv_type_uid_t" >&5
@@ -15320,6 +15322,19 @@
fi
+# Check for use of the system expat library
+{ echo "$as_me:$LINENO: checking for --with-system-expat" >&5
+echo $ECHO_N "checking for --with-system-expat... $ECHO_C" >&6; }
+
+# Check whether --with-system_expat was given.
+if test "${with_system_expat+set}" = set; then
+ withval=$with_system_expat;
+fi
+
+
+{ echo "$as_me:$LINENO: result: $with_system_expat" >&5
+echo "${ECHO_T}$with_system_expat" >&6; }
+
# Check for use of the system libffi library
{ echo "$as_me:$LINENO: checking for --with-system-ffi" >&5
echo $ECHO_N "checking for --with-system-ffi... $ECHO_C" >&6; }
@@ -15526,7 +15541,7 @@
else
unistd_defines_pthreads=no
fi
-rm -f -r conftest*
+rm -f conftest*
{ echo "$as_me:$LINENO: result: $unistd_defines_pthreads" >&5
echo "${ECHO_T}$unistd_defines_pthreads" >&6; }
@@ -16824,7 +16839,7 @@
$EGREP "yes" >/dev/null 2>&1; then
ipv6type=$i
fi
-rm -f -r conftest*
+rm -f conftest*
;;
kame)
@@ -16847,7 +16862,7 @@
ipv6libdir=/usr/local/v6/lib
ipv6trylibc=yes
fi
-rm -f -r conftest*
+rm -f conftest*
;;
linux-glibc)
@@ -16868,7 +16883,7 @@
ipv6type=$i;
ipv6trylibc=yes
fi
-rm -f -r conftest*
+rm -f conftest*
;;
linux-inet6)
@@ -16906,7 +16921,7 @@
ipv6lib=inet6;
ipv6libdir=/usr/local/v6/lib
fi
-rm -f -r conftest*
+rm -f conftest*
;;
v6d)
@@ -16929,7 +16944,7 @@
ipv6libdir=/usr/local/v6/lib;
BASECFLAGS="-I/usr/local/v6/include $BASECFLAGS"
fi
-rm -f -r conftest*
+rm -f conftest*
;;
zeta)
@@ -16951,7 +16966,7 @@
ipv6lib=inet6;
ipv6libdir=/usr/local/v6/lib
fi
-rm -f -r conftest*
+rm -f conftest*
;;
esac
@@ -25292,7 +25307,7 @@
_ACEOF
fi
-rm -f -r conftest*
+rm -f conftest*
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
@@ -25311,7 +25326,7 @@
_ACEOF
fi
-rm -f -r conftest*
+rm -f conftest*
fi
@@ -25581,7 +25596,7 @@
_ACEOF
fi
-rm -f -r conftest*
+rm -f conftest*
fi
Modified: python/branches/py3k/configure.in
==============================================================================
--- python/branches/py3k/configure.in (original)
+++ python/branches/py3k/configure.in Thu Dec 31 04:23:10 2009
@@ -1856,6 +1856,13 @@
],
[AC_MSG_RESULT(no)])
+# Check for use of the system expat library
+AC_MSG_CHECKING(for --with-system-expat)
+AC_ARG_WITH(system_expat,
+ AC_HELP_STRING(--with-system-expat, build pyexpat module using an installed expat library))
+
+AC_MSG_RESULT($with_system_expat)
+
# Check for use of the system libffi library
AC_MSG_CHECKING(for --with-system-ffi)
AC_ARG_WITH(system_ffi,
Modified: python/branches/py3k/setup.py
==============================================================================
--- python/branches/py3k/setup.py (original)
+++ python/branches/py3k/setup.py Thu Dec 31 04:23:10 2009
@@ -1104,19 +1104,26 @@
#
# More information on Expat can be found at www.libexpat.org.
#
- expatinc = os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')
- define_macros = [
- ('HAVE_EXPAT_CONFIG_H', '1'),
- ]
+ if '--with-system-expat' in sysconfig.get_config_var("CONFIG_ARGS"):
+ expat_inc = []
+ define_macros = []
+ expat_lib = ['expat']
+ expat_sources = []
+ else:
+ expat_inc = [os.path.join(os.getcwd(), srcdir, 'Modules', 'expat')]
+ define_macros = [
+ ('HAVE_EXPAT_CONFIG_H', '1'),
+ ]
+ expat_lib = []
+ expat_sources = ['expat/xmlparse.c',
+ 'expat/xmlrole.c',
+ 'expat/xmltok.c']
exts.append(Extension('pyexpat',
define_macros = define_macros,
- include_dirs = [expatinc],
- sources = ['pyexpat.c',
- 'expat/xmlparse.c',
- 'expat/xmlrole.c',
- 'expat/xmltok.c',
- ],
+ include_dirs = expat_inc,
+ libraries = expat_lib,
+ sources = ['pyexpat.c'] + expat_sources
))
# Fredrik Lundh's cElementTree module. Note that this also
@@ -1126,7 +1133,8 @@
define_macros.append(('USE_PYEXPAT_CAPI', None))
exts.append(Extension('_elementtree',
define_macros = define_macros,
- include_dirs = [expatinc],
+ include_dirs = expat_inc,
+ libraries = expat_lib,
sources = ['_elementtree.c'],
))
else:
1
0