From a65a880cd2bfbda01d9e57bfb27ca279022b616d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Wed, 8 Jun 2011 01:11:36 +0200 Subject: Add examples that work on Windows to distutils docs (#1626300) --- Doc/distutils/introduction.rst | 10 ++++++++-- Doc/install/index.rst | 15 +++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Doc/distutils/introduction.rst b/Doc/distutils/introduction.rst index b772b01..2d5dbc7 100644 --- a/Doc/distutils/introduction.rst +++ b/Doc/distutils/introduction.rst @@ -79,11 +79,17 @@ Some observations: 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 index 0ad3f52..915654d 100644 --- a/Doc/install/index.rst +++ b/Doc/install/index.rst @@ -96,10 +96,16 @@ in the name of the downloaded archive, e.g. :file:`foo-1.0.tar.gz` or 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 @@ Standard Build and Install ========================== 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: -- cgit v0.12 From caea7e8d231bb78a32636890edfd8c350a70ea4b Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Wed, 8 Jun 2011 19:29:53 -0500 Subject: Merge --- Lib/ntpath.py | 12 ++++++++++++ Misc/NEWS | 3 +++ Modules/posixmodule.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 765e1bf..e121262 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -521,3 +521,15 @@ def relpath(path, start=curdir): 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 +except ImportError: + from genericpath import isdir as _isdir + +def isdir(path): + return _isdir(path) diff --git a/Misc/NEWS b/Misc/NEWS index f68a346..3419894 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Core and Builtins Library ------- +- 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 index 48762c1..e5fdc5a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4199,6 +4199,41 @@ win32_kill(PyObject *self, PyObject *args) CloseHandle(handle); return result; } + +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 +9003,7 @@ static PyMethodDef posix_methods[] = { {"abort", posix_abort, METH_NOARGS, posix_abort__doc__}, #ifdef MS_WINDOWS {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, + {"_isdir", posix__isdir, METH_VARARGS, NULL}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__}, -- cgit v0.12 From 5cf8660f0bd8ce16b0e9f5c95049966b653e6574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 9 Jun 2011 14:26:10 +0200 Subject: Fix a few misuses of :option: I missed in r86521. Extract of the commit message: Fix usage of :option: in the docs (#9312). :option: is used to create a link to an option of python, not to mark up any instance of any arbitrary command-line option. These were changed to ````. --- Doc/c-api/intro.rst | 4 ++-- Doc/license.rst | 4 ++-- Doc/using/cmdline.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index a2e47d9..94af0f5 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -594,8 +594,8 @@ frequently-used builds will be described in the remainder of this section. 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/license.rst b/Doc/license.rst index 4c654ae..7931cd0 100644 --- a/Doc/license.rst +++ b/Doc/license.rst @@ -889,7 +889,7 @@ expat ----- 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 @@ libffi ------ 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/using/cmdline.rst b/Doc/using/cmdline.rst index a10ab1c..becb3c9 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -569,7 +569,7 @@ Debug-mode variables ~~~~~~~~~~~~~~~~~~~~ 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 -- cgit v0.12 From 5446f08c608d8e0041c8bb27b74be713db050177 Mon Sep 17 00:00:00 2001 From: Brian Curtin Date: Thu, 9 Jun 2011 10:00:42 -0500 Subject: Correction to f1509fc75435 - Issue #11583 Rather than wrapping the C _isdir function in a Python function, just import the C _isdir function directly. Additionally, add in the docstring which was left out. --- Lib/ntpath.py | 8 +++----- Modules/posixmodule.c | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index e121262..4f8f423 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -527,9 +527,7 @@ try: # 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 + from nt import _isdir as isdir except ImportError: - from genericpath import isdir as _isdir - -def isdir(path): - return _isdir(path) + # Use genericpath.isdir as imported above. + pass diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e5fdc5a..2431e1c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4200,6 +4200,9 @@ win32_kill(PyObject *self, PyObject *args) 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) { @@ -9003,7 +9006,7 @@ static PyMethodDef posix_methods[] = { {"abort", posix_abort, METH_NOARGS, posix_abort__doc__}, #ifdef MS_WINDOWS {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, - {"_isdir", posix__isdir, METH_VARARGS, NULL}, + {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__}, -- cgit v0.12 From 873c583244193f15b57293bce579c8410e747e20 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 9 Jun 2011 16:01:09 -0400 Subject: #10694: zipfile now ignores garbage at the end of a zipfile. Original fix by 'rep', final patch (with tests) by Xuanji Li. --- Lib/test/test_zipfile.py | 18 ++++++++++++++++++ Lib/zipfile.py | 18 ++++++++---------- Misc/NEWS | 2 ++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index c4a64a3..6cba26c 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -335,6 +335,24 @@ class TestsWithSourceFile(unittest.TestCase): 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\n\00\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 index 7e3caf0..f876f42 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -236,16 +236,14 @@ def _EndRecData(fpin): # 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) - - # Try to read the "Zip64 end of central directory" structure - return _EndRecData64(fpin, maxCommentStart + start - filesize, - endrec) + 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) # Unable to find a valid end of central directory structure return diff --git a/Misc/NEWS b/Misc/NEWS index 3419894..4f4951c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,8 @@ Core and Builtins 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. -- cgit v0.12 From 761473f28adaa5b86009a8b76825a2271a1bc509 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 10 Jun 2011 10:36:34 +0300 Subject: Issue #12223: Typo fix in datamodel docs --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 7c2c9af..0cd4c62 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2308,7 +2308,7 @@ will not be supported. * - 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. -- cgit v0.12