Path: blob/main/test/lib/python3.9/site-packages/pip/_internal/utils/compat.py
4804 views
"""Stuff that differs in different Python versions and platform1distributions."""23import logging4import os5import sys67__all__ = ["get_path_uid", "stdlib_pkgs", "WINDOWS"]8910logger = logging.getLogger(__name__)111213def has_tls() -> bool:14try:15import _ssl # noqa: F401 # ignore unused1617return True18except ImportError:19pass2021from pip._vendor.urllib3.util import IS_PYOPENSSL2223return IS_PYOPENSSL242526def get_path_uid(path: str) -> int:27"""28Return path's uid.2930Does not follow symlinks:31https://github.com/pypa/pip/pull/935#discussion_r53070033233Placed this function in compat due to differences on AIX and34Jython, that should eventually go away.3536:raises OSError: When path is a symlink or can't be read.37"""38if hasattr(os, "O_NOFOLLOW"):39fd = os.open(path, os.O_RDONLY | os.O_NOFOLLOW)40file_uid = os.fstat(fd).st_uid41os.close(fd)42else: # AIX and Jython43# WARNING: time of check vulnerability, but best we can do w/o NOFOLLOW44if not os.path.islink(path):45# older versions of Jython don't have `os.fstat`46file_uid = os.stat(path).st_uid47else:48# raise OSError for parity with os.O_NOFOLLOW above49raise OSError(f"{path} is a symlink; Will not return uid for symlinks")50return file_uid515253# packages in the stdlib that may have installation metadata, but should not be54# considered 'installed'. this theoretically could be determined based on55# dist.location (py27:`sysconfig.get_paths()['stdlib']`,56# py26:sysconfig.get_config_vars('LIBDEST')), but fear platform variation may57# make this ineffective, so hard-coding58stdlib_pkgs = {"python", "wsgiref", "argparse"}596061# windows detection, covers cpython and ironpython62WINDOWS = sys.platform.startswith("win") or (sys.platform == "cli" and os.name == "nt")636465