[Python-checkins] cpython (merge 2.7 -> 2.7): merge heads

benjamin.peterson python-checkins at python.org
Fri Jun 10 19:31:44 CEST 2011


http://hg.python.org/cpython/rev/73918d0c0bf2
changeset: 70768:73918d0c0bf2
branch: 2.7
parent: 70767:6993910be426
parent: 70752:3bb5400f5bea
user: Benjamin Peterson <benjamin at python.org>
date: Fri Jun 10 11:33:58 2011 -0500
summary:
 merge heads
files:
 Doc/c-api/intro.rst | 4 +-
 Doc/distutils/introduction.rst | 10 ++++-
 Doc/install/index.rst | 15 +++++---
 Doc/license.rst | 4 +-
 Doc/reference/datamodel.rst | 2 +-
 Doc/using/cmdline.rst | 2 +-
 Lib/ntpath.py | 10 +++++
 Lib/test/test_zipfile.py | 18 ++++++++++
 Lib/zipfile.py | 16 +++-----
 Misc/NEWS | 5 ++
 Modules/posixmodule.c | 39 ++++++++++++++++++++++
 11 files changed, 102 insertions(+), 23 deletions(-)
diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst
--- a/Doc/c-api/intro.rst
+++ b/Doc/c-api/intro.rst
@@ -594,8 +594,8 @@
 
 Compiling the interpreter with the :cmacro:`Py_DEBUG` macro defined produces
 what is generally meant by "a debug build" of Python. :cmacro:`Py_DEBUG` is
-enabled in the Unix build by adding :option:`--with-pydebug` to the
-:file:`configure` command. It is also implied by the presence of the
+enabled in the Unix build by adding ``--with-pydebug`` to the
+:file:`./configure` command. It is also implied by the presence of the
 not-Python-specific :cmacro:`_DEBUG` macro. When :cmacro:`Py_DEBUG` is enabled
 in the Unix build, compiler optimization is disabled.
 
diff --git a/Doc/distutils/introduction.rst b/Doc/distutils/introduction.rst
--- a/Doc/distutils/introduction.rst
+++ b/Doc/distutils/introduction.rst
@@ -79,11 +79,17 @@
 for an example)
 
 To create a source distribution for this module, you would create a setup
-script, :file:`setup.py`, containing the above code, and run::
+script, :file:`setup.py`, containing the above code, and run this command from a
+terminal::
 
 python setup.py sdist
 
-which will create an archive file (e.g., tarball on Unix, ZIP file on Windows)
+For Windows, open a command prompt windows ("DOS box") and change the command
+to::
+
+ setup.py sdist
+
+:command:`sdist` will create an archive file (e.g., tarball on Unix, ZIP file on Windows)
 containing your setup script :file:`setup.py`, and your module :file:`foo.py`.
 The archive file will be named :file:`foo-1.0.tar.gz` (or :file:`.zip`), and
 will unpack into a directory :file:`foo-1.0`.
diff --git a/Doc/install/index.rst b/Doc/install/index.rst
--- a/Doc/install/index.rst
+++ b/Doc/install/index.rst
@@ -96,10 +96,16 @@
 directory: :file:`foo-1.0` or :file:`widget-0.9.7`. Additionally, the
 distribution will contain a setup script :file:`setup.py`, and a file named
 :file:`README.txt` or possibly just :file:`README`, which should explain that
-building and installing the module distribution is a simple matter of running ::
+building and installing the module distribution is a simple matter of running
+one command from a terminal::
 
 python setup.py install
 
+For Windows, this command should be run from a command prompt windows ("DOS
+box")::
+
+ setup.py install
+
 If all these things are true, then you already know how to build and install the
 modules you've just downloaded: Run the command above. Unless you need to
 install things in a non-standard way or customize the build process, you don't
@@ -113,14 +119,11 @@
 ==========================
 
 As described in section :ref:`inst-new-standard`, building and installing a module
-distribution using the Distutils is usually one simple command::
+distribution using the Distutils is usually one simple command to run from a
+terminal::
 
 python setup.py install
 
-On Unix, you'd run this command from a shell prompt; on Windows, you have to
-open a command prompt window ("DOS box") and do it there; on Mac OS X, you open
-a :command:`Terminal` window to get a shell prompt.
-
 
 .. _inst-platform-variations:
 
diff --git a/Doc/license.rst b/Doc/license.rst
--- a/Doc/license.rst
+++ b/Doc/license.rst
@@ -889,7 +889,7 @@
 -----
 
 The :mod:`pyexpat` extension is built using an included copy of the expat
-sources unless the build is configured :option:`--with-system-expat`::
+sources unless the build is configured ``--with-system-expat``::
 
 Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
 and Clark Cooper
@@ -918,7 +918,7 @@
 ------
 
 The :mod:`_ctypes` extension is built using an included copy of the libffi
-sources unless the build is configured :option:`--with-system-libffi`::
+sources unless the build is configured ``--with-system-libffi``::
 
 Copyright (c) 1996-2008 Red Hat, Inc and others.
 
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -2308,7 +2308,7 @@
 
 *
 
- In ``x * y``, if one operator is a sequence that implements sequence
+ In ``x * y``, if one operand is a sequence that implements sequence
 repetition, and the other is an integer (:class:`int` or :class:`long`),
 sequence repetition is invoked.
 
diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst
--- a/Doc/using/cmdline.rst
+++ b/Doc/using/cmdline.rst
@@ -569,7 +569,7 @@
 ~~~~~~~~~~~~~~~~~~~~
 
 Setting these variables only has an effect in a debug build of Python, that is,
-if Python was configured with the :option:`--with-pydebug` build option.
+if Python was configured with the ``--with-pydebug`` build option.
 
 .. envvar:: PYTHONTHREADDEBUG
 
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -521,3 +521,13 @@
 if not rel_list:
 return curdir
 return join(*rel_list)
+
+try:
+ # The genericpath.isdir implementation uses os.stat and checks the mode
+ # attribute to tell whether or not the path is a directory.
+ # This is overkill on Windows - just pass the path to GetFileAttributes
+ # and check the attribute from there.
+ from nt import _isdir as isdir
+except ImportError:
+ # Use genericpath.isdir as imported above.
+ pass
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -335,6 +335,24 @@
 with zipfile.ZipFile(f, "r") as zipfp:
 self.assertEqual(zipfp.namelist(), [TESTFN])
 
+ def test_ignores_newline_at_end(self):
+ with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
+ zipfp.write(TESTFN, TESTFN)
+ with open(TESTFN2, 'a') as f:
+ f.write("\r\n00円00円00円")
+ with zipfile.ZipFile(TESTFN2, "r") as zipfp:
+ self.assertIsInstance(zipfp, zipfile.ZipFile)
+
+ def test_ignores_stuff_appended_past_comments(self):
+ with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
+ zipfp.comment = b"this is a comment"
+ zipfp.write(TESTFN, TESTFN)
+ with open(TESTFN2, 'a') as f:
+ f.write("abcdef\r\n")
+ with zipfile.ZipFile(TESTFN2, "r") as zipfp:
+ self.assertIsInstance(zipfp, zipfile.ZipFile)
+ self.assertEqual(zipfp.comment, b"this is a comment")
+
 def test_write_default_name(self):
 """Check that calling ZipFile.write without arcname specified
 produces the expected result."""
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -236,16 +236,14 @@
 # found the magic number; attempt to unpack and interpret
 recData = data[start:start+sizeEndCentDir]
 endrec = list(struct.unpack(structEndArchive, recData))
- comment = data[start+sizeEndCentDir:]
- # check that comment length is correct
- if endrec[_ECD_COMMENT_SIZE] == len(comment):
- # Append the archive comment and start offset
- endrec.append(comment)
- endrec.append(maxCommentStart + start)
+ commentSize = endrec[_ECD_COMMENT_SIZE] #as claimed by the zip file
+ comment = data[start+sizeEndCentDir:start+sizeEndCentDir+commentSize]
+ endrec.append(comment)
+ endrec.append(maxCommentStart + start)
 
- # Try to read the "Zip64 end of central directory" structure
- return _EndRecData64(fpin, maxCommentStart + start - filesize,
- endrec)
+ # Try to read the "Zip64 end of central directory" structure
+ return _EndRecData64(fpin, maxCommentStart + start - filesize,
+ endrec)
 
 # Unable to find a valid end of central directory structure
 return
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,11 @@
 Library
 -------
 
+- Issue #10694: zipfile now ignores garbage at the end of a zipfile.
+
+- Issue #11583: Speed up os.path.isdir on Windows by using GetFileAttributes
+ instead of os.stat.
+
 - Issue #12080: Fix a performance issue in Decimal._power_exact that caused
 some corner-case Decimal.__pow__ calls to take an unreasonably long time.
 
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4199,6 +4199,44 @@
 CloseHandle(handle);
 return result;
 }
+
+PyDoc_STRVAR(posix__isdir__doc__,
+"Return true if the pathname refers to an existing directory.");
+
+static PyObject *
+posix__isdir(PyObject *self, PyObject *args)
+{
+ PyObject *opath;
+ char *path;
+ PyUnicodeObject *po;
+ DWORD attributes;
+
+ if (PyArg_ParseTuple(args, "U|:_isdir", &po)) {
+ Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
+
+ attributes = GetFileAttributesW(wpath);
+ if (attributes == INVALID_FILE_ATTRIBUTES)
+ Py_RETURN_FALSE;
+ goto check;
+ }
+ /* Drop the argument parsing error as narrow strings
+ are also valid. */
+ PyErr_Clear();
+
+ if (!PyArg_ParseTuple(args, "et:_isdir",
+ Py_FileSystemDefaultEncoding, &path))
+ return NULL;
+
+ attributes = GetFileAttributesA(path);
+ if (attributes == INVALID_FILE_ATTRIBUTES)
+ Py_RETURN_FALSE;
+
+check:
+ if (attributes & FILE_ATTRIBUTE_DIRECTORY)
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
 #endif /* MS_WINDOWS */
 
 #ifdef HAVE_PLOCK
@@ -8968,6 +9006,7 @@
 {"abort", posix_abort, METH_NOARGS, posix_abort__doc__},
 #ifdef MS_WINDOWS
 {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
+ {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__},
 #endif
 #ifdef HAVE_GETLOADAVG
 {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /