1 """Stuff that differs in different Python versions and platform
8 __all__
= ["get_path_uid", "stdlib_pkgs", "WINDOWS"]
11 logger
= logging
.getLogger(__name__
)
14 def has_tls() -> bool:
16 import _ssl
# noqa: F401 # ignore unused
22 from pip
._vendor
.urllib3
.util
import IS_PYOPENSSL
27 def get_path_uid(path
: str) -> int:
31 Does not follow symlinks:
32 https://github.com/pypa/pip/pull/935#discussion_r5307003
34 Placed this function in compat due to differences on AIX and
35 Jython, that should eventually go away.
37 :raises OSError: When path is a symlink or can't be read.
39 if hasattr(os
, "O_NOFOLLOW"):
40 fd
= os
.open(path
, os
.O_RDONLY | os
.O_NOFOLLOW
)
41 file_uid
= os
.fstat(fd
).st_uid
43 else: # AIX and Jython
44 # WARNING: time of check vulnerability, but best we can do w/o NOFOLLOW
45 if not os
.path
.islink(path
):
46 # older versions of Jython don't have `os.fstat`
47 file_uid
= os
.stat(path
).st_uid
49 # raise OSError for parity with os.O_NOFOLLOW above
50 raise OSError(f
"{path} is a symlink; Will not return uid for symlinks")
54 # packages in the stdlib that may have installation metadata, but should not be
55 # considered 'installed'. this theoretically could be determined based on
56 # dist.location (py27:`sysconfig.get_paths()['stdlib']`,
57 # py26:sysconfig.get_config_vars('LIBDEST')), but fear platform variation may
58 # make this ineffective, so hard-coding
59 stdlib_pkgs
= {"python", "wsgiref", "argparse"}
62 # windows detection, covers cpython and ironpython
63 WINDOWS
= sys
.platform
.startswith("win") or (sys
.platform
== "cli" and os
.name
== "nt")