summaryrefslogtreecommitdiff
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-12-02 18:29:18 +0000
committerBrian Curtin <brian.curtin@gmail.com>2010-12-02 18:29:18 +0000
commit52173d4959a1c1e961efab2522e4ba8a22a3c7c6 (patch)
treea89463de7c0db84aa60ef25bc05caf8837e2cc33 /Lib/test/support.py
parent02524629f39bb70f4ea00ab8e64d694e08719227 (diff)
downloadcpython-git-52173d4959a1c1e961efab2522e4ba8a22a3c7c6.tar.gz
Fix #9333. Expose os.symlink on Windows only when usable.
In order to create symlinks on Windows, SeCreateSymbolicLinkPrivilege is an account privilege that is required to be held by the user. Not only must the privilege be enabled for the account, the activated privileges for the currently running application must be adjusted to enable the requested privilege. Rather than exposing an additional function to be called prior to the user's first os.symlink call, we handle the AdjustTokenPrivileges Windows API call internally and only expose os.symlink when the privilege escalation was successful. Due to the change of only exposing os.symlink when it's available, we can go back to the original test skipping methods of checking via `hasattr`.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py23
1 files changed, 1 insertions, 22 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index fb43f3dbc5..535e2bec5b 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -42,7 +42,7 @@ __all__ = [
"set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner",
"run_unittest", "run_doctest", "threading_setup", "threading_cleanup",
"reap_children", "cpython_only", "check_impl_detail", "get_attribute",
- "swap_item", "swap_attr", "can_symlink", "skip_unless_symlink"]
+ "swap_item", "swap_attr"]
class Error(Exception):
@@ -1256,27 +1256,6 @@ def reap_children():
except:
break
-try:
- from .symlink_support import enable_symlink_privilege
-except:
- enable_symlink_privilege = lambda: True
-
-def can_symlink():
- """It's no longer sufficient to test for the presence of symlink in the
- os module - on Windows XP and earlier, os.symlink exists but a
- NotImplementedError is thrown.
- """
- has_symlink = hasattr(os, 'symlink')
- is_old_windows = sys.platform == "win32" and sys.getwindowsversion().major < 6
- has_privilege = False if is_old_windows else enable_symlink_privilege()
- return has_symlink and (not is_old_windows) and has_privilege
-
-def skip_unless_symlink(test):
- """Skip decorator for tests that require functional symlink"""
- selector = can_symlink()
- msg = "Requires functional symlink implementation"
- return [unittest.skip(msg)(test), test][selector]
-
@contextlib.contextmanager
def swap_attr(obj, attr, new_val):
"""Temporary swap out an attribute with a new object.