From 3b65fd7e9784967567e66bd67e9205cbb0d53d3a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 23 Jan 2012 20:19:33 +0100 Subject: #13816: fix two minor style issues. Thanks to Justin Wehnes for the patch. --- Doc/library/functools.rst | 2 +- Doc/library/stdtypes.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 7d44979..737cdd3 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -20,7 +20,7 @@ The :mod:`functools` module defines the following functions: .. function:: cmp_to_key(func) - Transform an old-style comparison function to a key-function. Used with + Transform an old-style comparison function to a key function. Used with tools that accept key functions (such as :func:`sorted`, :func:`min`, :func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`, :func:`itertools.groupby`). This function is primarily used as a transition diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 9e08c65..d32bf87 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -873,7 +873,7 @@ are sequences of the same type; *n*, *i*, *j* and *k* are integers. | ``s * n, n * s`` | *n* shallow copies of *s* | \(2) | | | concatenated | | +------------------+--------------------------------+----------+ -| ``s[i]`` | *i*'th item of *s*, origin 0 | \(3) | +| ``s[i]`` | *i*\ th item of *s*, origin 0 | \(3) | +------------------+--------------------------------+----------+ | ``s[i:j]`` | slice of *s* from *i* to *j* | (3)(4) | +------------------+--------------------------------+----------+ -- cgit v0.12 From cd27df3a9923c8c05b57f3f2a142cafd978220a2 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Mon, 23 Jan 2012 22:42:19 +0100 Subject: Fix compilation warnings (seen on win32 buildbot) --- Python/formatter_unicode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 609ac16..db8c27c 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -682,7 +682,7 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format) Py_ssize_t pos; Py_ssize_t len = PyUnicode_GET_LENGTH(value); PyObject *result = NULL; - int maxchar = 127; + Py_UCS4 maxchar = 127; /* sign is not allowed on strings */ if (format->sign != '\0') { @@ -749,7 +749,7 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format, IntOrLongToString tostring) { PyObject *result = NULL; - int maxchar = 127; + Py_UCS4 maxchar = 127; PyObject *tmp = NULL; Py_ssize_t inumeric_chars; Py_UCS4 sign_char = '\0'; @@ -926,7 +926,7 @@ format_float_internal(PyObject *value, NumberFieldWidths spec; int flags = 0; PyObject *result = NULL; - int maxchar = 127; + Py_UCS4 maxchar = 127; Py_UCS4 sign_char = '\0'; int float_type; /* Used to see if we have a nan, inf, or regular float. */ PyObject *unicode_tmp = NULL; @@ -1070,7 +1070,7 @@ format_complex_internal(PyObject *value, NumberFieldWidths im_spec; int flags = 0; PyObject *result = NULL; - int maxchar = 127; + Py_UCS4 maxchar = 127; int rkind; void *rdata; Py_ssize_t index; -- cgit v0.12 From 6d766fc3facd08615cd3cfe5699e864f196941b5 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Mon, 23 Jan 2012 23:20:43 +0100 Subject: Silence last compilation warning. --- Python/formatter_unicode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index db8c27c..eee9913 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -798,7 +798,7 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format, tmp = PyUnicode_FromOrdinal(x); inumeric_chars = 0; n_digits = 1; - maxchar = Py_MAX(maxchar, x); + maxchar = Py_MAX(maxchar, (Py_UCS4)x); /* As a sort-of hack, we tell calc_number_widths that we only have "remainder" characters. calc_number_widths thinks -- cgit v0.12 From 4ccc7277937650f2cbb3a5235f7b98f4fafa26fd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 23 Jan 2012 23:48:41 +0100 Subject: Issue #10278: wallclock() cannot go backward, but two consecutive calls may return the same time. --- Lib/test/test_time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index d34b870..685e821 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -334,7 +334,7 @@ class TimeTestCase(unittest.TestCase): def test_wallclock(self): t1 = time.wallclock() t2 = time.wallclock() - self.assertGreater(t2, t1) + self.assertGreaterEqual(t2, t1) t1 = time.wallclock() time.sleep(0.1) -- cgit v0.12 From 09406023a8c19febb3358008ddeabe4450c21b79 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 24 Jan 2012 01:12:54 +0100 Subject: Sort functions in the doc of the time module Move wallclock() at the end. --- Doc/library/time.rst | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Doc/library/time.rst b/Doc/library/time.rst index 757fbf3..2ba7c7b 100644 --- a/Doc/library/time.rst +++ b/Doc/library/time.rst @@ -183,19 +183,6 @@ The module defines the following functions and data items: .. versionadded:: 3.3 -.. function:: wallclock() - - .. index:: - single: Wallclock - single: benchmarking - - Return the current time in fractions of a second to the system's best ability. - Use this when the most accurate representation of wall-clock is required, i.e. - when "processor time" is inappropriate. The reference point of the returned - value is undefined so only the difference of consecutive calls is valid. - - .. versionadded: 3.3 - .. function:: ctime([secs]) Convert a time expressed in seconds since the epoch to a string representing @@ -550,6 +537,20 @@ The module defines the following functions and data items: ('EET', 'EEST') +.. function:: wallclock() + + .. index:: + single: Wallclock + single: benchmarking + + Return the current time in fractions of a second to the system's best ability. + Use this when the most accurate representation of wall-clock is required, i.e. + when "processor time" is inappropriate. The reference point of the returned + value is undefined so only the difference of consecutive calls is valid. + + .. versionadded: 3.3 + + .. seealso:: Module :mod:`datetime` -- cgit v0.12 From 5311c1d7ab24f862b9b0bb272a9aee9c4f4ac023 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 24 Jan 2012 08:59:28 +0100 Subject: Issue #13772: In os.symlink() under Windows, do not try to guess the link target's type (file or directory). The detection was buggy and made the call non-atomic (therefore prone to race conditions). --- Doc/library/os.rst | 9 +++------ Lib/test/test_os.py | 9 +++++++-- Misc/NEWS | 4 ++++ Modules/posixmodule.c | 11 ----------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index df9a6b6..be322a0 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1429,11 +1429,9 @@ Files and Directories *target_is_directory*, which defaults to ``False``. On Windows, a symlink represents a file or a directory, and does not morph to - the target dynamically. For this reason, when creating a symlink on Windows, - if the target is not already present, the symlink will default to being a - file symlink. If *target_is_directory* is set to ``True``, the symlink will - be created as a directory symlink. This parameter is ignored if the target - exists (and the symlink is created with the same type as the target). + the target dynamically. If *target_is_directory* is set to ``True``, the + symlink will be created as a directory symlink, otherwise as a file symlink + (the default). Symbolic link support was introduced in Windows 6.0 (Vista). :func:`symlink` will raise a :exc:`NotImplementedError` on Windows versions earlier than 6.0. @@ -1446,7 +1444,6 @@ Files and Directories administrator level. Either obtaining the privilege or running your application as an administrator are ways to successfully create symlinks. - :exc:`OSError` is raised when the function is called by an unprivileged user. diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 4da1f1d..e573bd2 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -476,7 +476,12 @@ class WalkTests(unittest.TestCase): f.write("I'm " + path + " and proud of it. Blame test_os.\n") f.close() if support.can_symlink(): - os.symlink(os.path.abspath(t2_path), link_path) + if os.name == 'nt': + def symlink_to_dir(src, dest): + os.symlink(src, dest, True) + else: + symlink_to_dir = os.symlink + symlink_to_dir(os.path.abspath(t2_path), link_path) sub2_tree = (sub2_path, ["link"], ["tmp3"]) else: sub2_tree = (sub2_path, [], ["tmp3"]) @@ -1106,7 +1111,7 @@ class Win32SymlinkTests(unittest.TestCase): os.remove(self.missing_link) def test_directory_link(self): - os.symlink(self.dirlink_target, self.dirlink) + os.symlink(self.dirlink_target, self.dirlink, True) self.assertTrue(os.path.exists(self.dirlink)) self.assertTrue(os.path.isdir(self.dirlink)) self.assertTrue(os.path.islink(self.dirlink)) diff --git a/Misc/NEWS b/Misc/NEWS index fba506c..3b0752e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,10 @@ Core and Builtins Library ------- +- Issue #13772: In os.symlink() under Windows, do not try to guess the link + target's type (file or directory). The detection was buggy and made the + call non-atomic (therefore prone to race conditions). + - Issue #6631: Disallow relative file paths in urllib urlopen methods. - Issue #13722: Avoid silencing ImportErrors when initializing the codecs diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 673877a..0afab3c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5330,7 +5330,6 @@ win_symlink(PyObject *self, PyObject *args, PyObject *kwargs) PyObject *src, *dest; int target_is_directory = 0; DWORD res; - WIN32_FILE_ATTRIBUTE_DATA src_info; if (!check_CreateSymbolicLinkW()) { @@ -5351,16 +5350,6 @@ win_symlink(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - /* if src is a directory, ensure target_is_directory==1 */ - if( - GetFileAttributesExW( - PyUnicode_AsUnicode(src), GetFileExInfoStandard, &src_info - )) - { - target_is_directory = target_is_directory || - (src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - } - Py_BEGIN_ALLOW_THREADS res = Py_CreateSymbolicLinkW( PyUnicode_AsUnicode(dest), -- cgit v0.12